/
BuildHistory.tsx
163 lines (154 loc) · 5.26 KB
/
BuildHistory.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import moment = require("moment");
import React = require("react");
import ReactLoading from "react-loading";
import { Row, Col, Card, Button, Table } from "react-bootstrap";
import { AuthPortal, AuthButtons } from "../../auth";
import { Tip } from "../../components";
import { Project, AccessStatus, Build } from "../../types";
import API from "../API";
import { AppTitle, SettingsSidebar } from "../components";
import { Match, ProjectSettingsSection } from "../types";
const BuildStatus: React.FC<{ status: string }> = ({ status }) => {
switch (status) {
case "success":
return (
<Tip id="build-status" tip="Success">
<i className="fas fa-check-circle text-success"></i>
</Tip>
);
case "failure":
return (
<Tip id="build-status" tip="Failure">
<i className="fas fa-times-circle text-danger"></i>
</Tip>
);
case "cancelled":
return (
<Tip id="build-status" tip="Cancelled">
<i className="fas fa-exclamation-circle text-info"></i>
</Tip>
);
default:
return (
<Tip id="build-status" tip="Running">
<ReactLoading type="spin" color="#DBAB0A" height={"20px"} width={"20px"} />
</Tip>
);
}
};
class BuildHistory extends React.Component<
{ match: Match; section?: ProjectSettingsSection },
{ project?: Project; accessStatus?: AccessStatus; builds?: Build[]; errorMessage?: string }
> {
api: API;
constructor(props) {
super(props);
this.state = {};
const owner = this.props.match.params.username;
const title = this.props.match.params.app_name;
this.api = new API(owner, title);
this.resetAccessStatus = this.resetAccessStatus.bind(this);
}
async resetAccessStatus() {
const accessStatus = await this.api.getAccessStatus();
this.setState({ accessStatus });
return accessStatus;
}
async startNewBuild() {
const { username, app_name, build_id } = this.props.match.params;
const build = await this.api.createBuild({});
if ((build as any).errors) {
this.setState({ errorMessage: (build as any).errors });
window.scrollTo(0, 0);
return;
}
window.location.replace(`/${username}/${app_name}/builds/${build.id}/`);
}
async componentDidMount() {
const project = await this.api.getProject();
const accessStatus = await this.api.getAccessStatus();
const buildResults = await this.api.listBuilds();
this.setState({
accessStatus,
project,
builds: buildResults.results,
});
}
render() {
const username = this.props.match.params.username;
const app_name = this.props.match.params.app_name;
const { project, accessStatus, builds } = this.state;
const id = `${username}/${app_name}`;
if (!project || !accessStatus || builds === undefined) {
return <div />;
}
return (
<>
<AuthPortal>
<AuthButtons
accessStatus={this.state.accessStatus}
resetAccessStatus={this.resetAccessStatus}
message="You must be logged in to update an app."
/>
</AuthPortal>
<Card className="card-outer p-4">
<Row className="w-100 justify-content-center">
<Col className="col-md-3">
<SettingsSidebar project={project} section="build-history" />
</Col>
<Col className="col-md-9">
<Card.Body>
<Card.Title>
<AppTitle project={this.state.project} />
</Card.Title>
{this.state.errorMessage && (
<div className="alert alert-danger" role="alert">
{this.state.errorMessage}
</div>
)}
<Table>
<thead>
<tr>
<th>Link</th>
<th>Created at</th>
<th>Status</th>
<th>Tag</th>
<th>Version</th>
</tr>
</thead>
<tbody>
{this.state.builds.map((build, index) => (
<tr key={index}>
<th>
<a href={`/${build.project}/builds/${build.id}/`}>
<i className="fas fa-link" />
</a>
</th>
<th>{build.created_at && moment(build.created_at).format("lll")}</th>
<th>
<BuildStatus status={build.status} />
</th>
<th>
{build.tag?.image_tag ? (
<code>{build.tag.image_tag.slice(0, 6)}</code>
) : (
"N/A"
)}
</th>
<th>{build.tag?.version || "N/A"}</th>
</tr>
))}
</tbody>
</Table>
<Button variant="success" onClick={async () => await this.startNewBuild()}>
New Build
</Button>
</Card.Body>
</Col>
</Row>
</Card>
</>
);
}
}
export { BuildHistory };