History page refactoring
This commit is contained in:
parent
dd66be1d75
commit
9f1efeee7d
|
@ -1,61 +1,68 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react'
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom'
|
||||||
|
|
||||||
import Nav from '../blocks/nav.js';
|
import Nav from '../blocks/nav.js'
|
||||||
import JobList from '../blocks/job_list.js';
|
import JobList from '../blocks/job_list.js'
|
||||||
import User from '../blocks/user.js';
|
import User from '../blocks/user.js'
|
||||||
import { api, httpGET } from '../http.js';
|
import Alert from '../blocks/alert.js'
|
||||||
import './history.css';
|
import { api, httpGET } from '../http.js'
|
||||||
|
import './history.css'
|
||||||
|
|
||||||
export default class History extends Component {
|
export default class History extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props)
|
||||||
this.state = {};
|
this.state = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
var url;
|
httpGET(this.endpointFromProps(this.props),
|
||||||
if (this.props.cmd !== undefined) {
|
|
||||||
url = api("/commands/" + this.props.cmd + "/jobs")
|
|
||||||
} else if (this.props.userID !== undefined) {
|
|
||||||
url = api("/users/" + this.props.userID + "/jobs")
|
|
||||||
} else {
|
|
||||||
url = api("/jobs")
|
|
||||||
}
|
|
||||||
httpGET(url,
|
|
||||||
(status, body) => {
|
(status, body) => {
|
||||||
let jobs = JSON.parse(body);
|
let jobs = JSON.parse(body)
|
||||||
this.setState({jobs: jobs});
|
this.setState({jobs: jobs})
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
console.log("Failed to load jobs:", error);
|
this.setState({error: "Failed to load jobs: "+ error})
|
||||||
},
|
},
|
||||||
);
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
endpointFromProps(props) {
|
||||||
|
if (props.cmd !== undefined) {
|
||||||
|
return api("/commands/" + props.cmd + "/jobs")
|
||||||
|
} else if (props.userID !== undefined) {
|
||||||
|
return api("/users/" + props.userID + "/jobs")
|
||||||
|
} else {
|
||||||
|
return api("/jobs")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let details;
|
|
||||||
if (this.props.cmd !== undefined) {
|
|
||||||
details = (
|
|
||||||
<div className="command-details">
|
|
||||||
<span>Command</span>
|
|
||||||
<div className="cmd-name"><Link to={"/cmd/"+ this.props.cmd}>{this.props.cmd}</Link></div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
} else if (this.props.userID !== undefined) {
|
|
||||||
details = (
|
|
||||||
<User id={this.props.userID} />
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<Nav commands={this.props.commands} active={this.props.cmd}
|
<Nav commands={this.props.commands} active={this.props.cmd}
|
||||||
query={this.props.query} onQueryChange={this.props.onQueryChange} />
|
query={this.props.query} onQueryChange={this.props.onQueryChange} />
|
||||||
<main>
|
<main>
|
||||||
{details}
|
{this.renderJobDetails()}
|
||||||
|
<Alert type="error" message={this.state.error} />
|
||||||
<JobList jobs={this.state.jobs} />
|
<JobList jobs={this.state.jobs} />
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
renderJobDetails() {
|
||||||
|
if (this.props.cmd !== undefined) {
|
||||||
|
return (
|
||||||
|
<div className="command-details">
|
||||||
|
<span>Command</span>
|
||||||
|
<div className="cmd-name"><Link to={"/cmd/"+ this.props.cmd}>{this.props.cmd}</Link></div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
} else if (this.props.userID !== undefined) {
|
||||||
|
return (
|
||||||
|
<User id={this.props.userID} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue