forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeployStatusPage.tsx
142 lines (130 loc) · 5.38 KB
/
DeployStatusPage.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
import React from "react"
import { observer } from "mobx-react"
import { action, observable, runInAction } from "mobx"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import { faCheckCircle } from "@fortawesome/free-solid-svg-icons"
import { AdminLayout } from "./AdminLayout.js"
import { AdminAppContext, AdminAppContextType } from "./AdminAppContext.js"
import { Deploy, DeployStatus } from "@ourworldindata/utils"
import { Timeago } from "./Forms.js"
const statusLabel: Record<DeployStatus, string> = {
[DeployStatus.queued]: "Next up",
[DeployStatus.pending]: "Deploying",
}
@observer
export class DeployStatusPage extends React.Component {
static contextType = AdminAppContext
context!: AdminAppContextType
@observable deploys: Deploy[] = []
@observable canManuallyDeploy = true
refreshIntervalId?: number
componentDidMount() {
void this.getData()
document.addEventListener(
"visibilitychange",
this.handleVisibilityChange
)
}
componentWillUnmount() {
document.removeEventListener(
"visibilitychange",
this.handleVisibilityChange
)
}
render() {
return (
<AdminLayout title="Deploys">
<main className="DeploysPage">
<div className="topbar">
<h2>Deploy status</h2>
<button
className="btn btn-secondary"
type="button"
disabled={!this.canManuallyDeploy}
onClick={async () => {
this.canManuallyDeploy = false
await this.triggerDeploy()
await this.getData()
}}
>
Manually enqueue a deploy
</button>
</div>
{this.deploys.length > 0 ? (
<table className="DeploysTable">
<thead>
<tr>
<th>Status</th>
<th>Note</th>
<th>Author</th>
<th>Time</th>
</tr>
</thead>
<tbody>
{this.deploys.map((deploy) =>
deploy.changes.map((change, i) => (
<tr key={`${deploy.status}-${i}`}>
<td
className={`cell-status cell-status--${deploy.status}`}
>
{statusLabel[deploy.status]}
</td>
<td className="cell-message">
{change.message}
</td>
<td className="cell-author">
{change.authorName}
</td>
<td className="cell-time">
<Timeago
time={change.timeISOString}
/>
</td>
</tr>
))
)}
</tbody>
</table>
) : (
<div className="all-published-notice">
<p>
<span className="icon">
<FontAwesomeIcon icon={faCheckCircle} />
</span>{" "}
All changes are successfully deployed.
</p>
</div>
)}
<p>
Past deploys can be found in the{" "}
<a
href="https://github.com/owid/owid-static/commits/master"
target="_blank"
rel="noopener noreferrer"
>
<strong>owid-static</strong> GitHub repository
</a>
.
</p>
</main>
</AdminLayout>
)
}
@action.bound handleVisibilityChange = () => {
if (document.visibilityState === "visible") void this.getData()
}
@action.bound async triggerDeploy() {
const { admin } = this.context
await admin.rawRequest("/api/deploy", undefined, "PUT")
}
async getData() {
const { admin } = this.context
if (admin.currentRequests.length > 0) return
const json = (await admin.getJSON("/api/deploys.json")) as {
deploys: Deploy[]
}
runInAction(() => {
this.deploys = json.deploys
})
}
}