diff --git a/frontend/src/blocks/output.js b/frontend/src/blocks/output.js index a4ea8b7..d36b4b4 100644 --- a/frontend/src/blocks/output.js +++ b/frontend/src/blocks/output.js @@ -8,31 +8,33 @@ import './output.css' export default class Output extends Component { constructor(props) { super(props) - this.state = { - job: null, - xhr: null + this.state = {job: null, xhr: null} + } + + componentWillReceiveProps(props) { + if (props.jobID && props.jobID !== this.props.jobID) { + this.loadJob(props.jobID) } } componentDidMount() { - let jobID = this.props.jobID - if (jobID !== null) { - this.loadCommandLog(jobID) - this.loadJobDetails(jobID) - } + this.loadJob(this.props.jobID) } componentWillUnmount() { - if (this.state.xhr !== null) { + if (this.state.xhr) { this.state.xhr.abort() } } - loadJobDetails(id) { - if (id === null) { - return + loadJob(id) { + if (id) { + this.loadJobDetails(id) + this.loadCommandLog(id) } + } + loadJobDetails(id) { httpGET(api("/jobs/" + id), (status, body) => { this.setState({job: JSON.parse(body)}) @@ -44,8 +46,8 @@ export default class Output extends Component { } loadCommandLog(id) { - if (id === null || this.state.xhr !== null) { - return + if (this.state.xhr) { + this.state.xhr.abort() } let xhr = httpStreamGET(api("/jobs/" + id + "/log"), diff --git a/frontend/src/pages/command.js b/frontend/src/pages/command.js index 4c991af..966f784 100644 --- a/frontend/src/pages/command.js +++ b/frontend/src/pages/command.js @@ -157,7 +157,7 @@ export default class Command extends Component { function formQuery(form) { var args = Object.keys(form.flags).map((name) => ["flags[" + name + "]", form.flags[name]]) - args.push(["command", form.command]) - args.push(["args", form.args]) - return args.map((pair) => pair[0] + "=" + encodeURIComponent(pair[1])) + args.unshift(["command", form.command], ["args", form.args]) + let param = (pair) => pair[0] + "=" + encodeURIComponent(pair[1]) + return args.map(param).join("&") }