Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Update protocol form
Browse files Browse the repository at this point in the history
Update protocol form.
  • Loading branch information
abuccts committed Apr 1, 2019
1 parent c20f12d commit de591d1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
36 changes: 31 additions & 5 deletions contrib/submit-protocol/src/App/ProtocolForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ import { DefaultButton, PrimaryButton } from "office-ui-fabric-react/lib/Button"
import MonacoEditor from "react-monaco-editor";
import jsyaml from "js-yaml";

interface IProtocolProps {
api: string;
user: string;
token: string;
}

interface IProtocolState {
jobName: string;
protocol: {[key: string]: string | object};
protocolYAML: string;
showEditor: boolean;
}

export default class ProtocolForm extends React.Component<{}, IProtocolState> {
constructor(props: {}) {
export default class ProtocolForm extends React.Component<IProtocolProps, IProtocolState> {
constructor(props: IProtocolProps) {
super(props);
initializeIcons();
this.state = {
Expand Down Expand Up @@ -101,7 +107,7 @@ export default class ProtocolForm extends React.Component<{}, IProtocolState> {
</div>
</div>
<div className="modal-footer" style={{ marginTop: "256px" }}>
<PrimaryButton text="Submit Job" onClick={this.submit} />
<PrimaryButton text="Submit Job" onClick={this.submitProtocol} />
</div>
</div>
</form>
Expand Down Expand Up @@ -173,8 +179,28 @@ export default class ProtocolForm extends React.Component<{}, IProtocolState> {
this.setState({ showEditor: false });
}

private submit = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
private submitProtocol = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
event.preventDefault();
alert(this.state.protocolYAML);
if (this.state.protocolYAML == null) {
return;
}
window.fetch(`${this.props.api}/api/v2/jobs`, {
body: this.state.protocolYAML,
headers: {
"Authorization": `Bearer ${this.props.token}`,
"Content-Type": "text/yaml",
},
method: "POST",
}).then((res) => {
return res.json();
}).then((body) => {
if (parseInt(body.status) >= 400) {
window.alert(body.message);
} else {
window.location.href = `/job-detail.html?username=${this.props.user}&jobName=${this.state.jobName}`;
}
}).catch((error) => {
window.alert(error.message);
});
}
}
8 changes: 7 additions & 1 deletion contrib/submit-protocol/src/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ interface IProps {
}

export default function App({api, user, token}: IProps) {
return <ProtocolForm />;
return (
<ProtocolForm
api={api}
user={user}
token={token}
/>
);
}

0 comments on commit de591d1

Please sign in to comment.