@tsplc/tmp-agent 0.0.0-stage → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -2
- package/dist/cli.js +4888 -0
- package/dist/cli.js.map +53 -0
- package/dist/client.js +514 -0
- package/dist/client.js.map +12 -0
- package/dist/index.js +3680 -0
- package/dist/index.js.map +41 -0
- package/package.json +61 -4
- package/src/access.ts +260 -0
- package/src/agent.ts +461 -0
- package/src/audit.ts +74 -0
- package/src/cli.ts +290 -0
- package/src/client.ts +407 -0
- package/src/codesys.ts +195 -0
- package/src/dashboard/index.ts +159 -0
- package/src/dashboard/ui/access.ts +191 -0
- package/src/dashboard/ui/actions.ts +207 -0
- package/src/dashboard/ui/api.ts +138 -0
- package/src/dashboard/ui/app.ts +41 -0
- package/src/dashboard/ui/approval.ts +131 -0
- package/src/dashboard/ui/audit.ts +115 -0
- package/src/dashboard/ui/contract.ts +19 -0
- package/src/dashboard/ui/dashboard.css +1332 -0
- package/src/dashboard/ui/deployment.ts +431 -0
- package/src/dashboard/ui/deployments.ts +319 -0
- package/src/dashboard/ui/details.ts +214 -0
- package/src/dashboard/ui/dom.ts +87 -0
- package/src/dashboard/ui/environment.ts +345 -0
- package/src/dashboard/ui/format.ts +124 -0
- package/src/dashboard/ui/logs.ts +126 -0
- package/src/dashboard/ui/main.ts +88 -0
- package/src/dashboard/ui/overlay.ts +144 -0
- package/src/dashboard/ui/shell.ts +185 -0
- package/src/dashboard/ui/source.ts +144 -0
- package/src/debugging.ts +142 -0
- package/src/deploy.ts +203 -0
- package/src/deployments/health.ts +98 -0
- package/src/deployments/retention.ts +44 -0
- package/src/deployments/routes.ts +281 -0
- package/src/deployments/runner.ts +900 -0
- package/src/deployments/store.ts +209 -0
- package/src/deployments/submission.ts +78 -0
- package/src/discovery.ts +90 -0
- package/src/environment.ts +214 -0
- package/src/errors.ts +12 -0
- package/src/index.ts +36 -0
- package/src/instance.ts +51 -0
- package/src/login.ts +267 -0
- package/src/logs.ts +115 -0
- package/src/maintenance.ts +303 -0
- package/src/operations.ts +149 -0
- package/src/processes.ts +41 -0
- package/src/protocol.ts +557 -0
- package/src/releases.ts +414 -0
- package/src/restarts.ts +96 -0
- package/src/routes.ts +128 -0
- package/src/secrets.ts +174 -0
- package/src/server-process.ts +264 -0
- package/src/service.ts +194 -0
- package/src/sessions.ts +58 -0
- package/src/state.ts +126 -0
- package/src/tailscale.ts +112 -0
- package/src/terminal.ts +57 -0
- package/src/transfer.ts +94 -0
- package/src/upgrade.ts +153 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { errorMessage } from "../../errors";
|
|
2
|
+
import type { DeploymentRecord, DeploymentState } from "../../protocol";
|
|
3
|
+
import { deploymentMenu } from "./actions";
|
|
4
|
+
import { api, type DeploymentList } from "./api";
|
|
5
|
+
import { type App, deploymentHref } from "./app";
|
|
6
|
+
import {
|
|
7
|
+
badge,
|
|
8
|
+
dot,
|
|
9
|
+
empty,
|
|
10
|
+
fill,
|
|
11
|
+
h,
|
|
12
|
+
icon,
|
|
13
|
+
icons,
|
|
14
|
+
pageHeader,
|
|
15
|
+
type View,
|
|
16
|
+
} from "./dom";
|
|
17
|
+
import {
|
|
18
|
+
formatAgo,
|
|
19
|
+
formatDeploymentDuration,
|
|
20
|
+
isFinished,
|
|
21
|
+
modeLabels,
|
|
22
|
+
shortCommit,
|
|
23
|
+
shortId,
|
|
24
|
+
states,
|
|
25
|
+
userAtHost,
|
|
26
|
+
} from "./format";
|
|
27
|
+
import { menuButton, overlayOpen } from "./overlay";
|
|
28
|
+
|
|
29
|
+
interface Filter {
|
|
30
|
+
label: string;
|
|
31
|
+
matches: (state: DeploymentState) => boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const all: Filter = { label: "All", matches: () => true };
|
|
35
|
+
|
|
36
|
+
const filters: Filter[] = [
|
|
37
|
+
all,
|
|
38
|
+
{ label: "In progress", matches: (state) => !isFinished(state) },
|
|
39
|
+
{ label: "Ready", matches: (state) => state === "ready" },
|
|
40
|
+
{ label: "Error", matches: (state) => state === "error" },
|
|
41
|
+
{ label: "Canceled", matches: (state) => state === "canceled" },
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
/** What a refresh waits: shorter while a deployment runs, so its state moves on screen. */
|
|
45
|
+
const refreshEvery = { running: 3000, idle: 15_000 };
|
|
46
|
+
|
|
47
|
+
export const origin = (record: DeploymentRecord, app: App) => {
|
|
48
|
+
if (record.origin.kind === "upload") {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const { from } = record.origin;
|
|
52
|
+
return h(
|
|
53
|
+
"span",
|
|
54
|
+
{ class: "origin" },
|
|
55
|
+
record.origin.kind === "redeploy" ? "Redeploy of " : "Rollback to ",
|
|
56
|
+
h(
|
|
57
|
+
"a",
|
|
58
|
+
{
|
|
59
|
+
class: "mono",
|
|
60
|
+
href: deploymentHref(from),
|
|
61
|
+
onclick: (event) => {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
event.stopPropagation();
|
|
64
|
+
app.navigate(deploymentHref(from));
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
shortId(from),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** Where a deployment's release came from: its commit, branch and subject, or that it wasn't built in git. */
|
|
73
|
+
export const gitSummary = (record: DeploymentRecord) => {
|
|
74
|
+
const { git } = record;
|
|
75
|
+
if (!git) {
|
|
76
|
+
return h("span", { class: "muted" }, "No git source");
|
|
77
|
+
}
|
|
78
|
+
return h(
|
|
79
|
+
"div",
|
|
80
|
+
{ class: "git" },
|
|
81
|
+
h(
|
|
82
|
+
"div",
|
|
83
|
+
{ class: "git-ref" },
|
|
84
|
+
git.branch
|
|
85
|
+
? h("span", { class: "branch" }, icon(icons.branch), git.branch)
|
|
86
|
+
: null,
|
|
87
|
+
h("span", { class: "mono commit" }, icon(icons.commit), shortCommit(git)),
|
|
88
|
+
git.dirty
|
|
89
|
+
? h(
|
|
90
|
+
"span",
|
|
91
|
+
{ class: "dirty", title: "Built with uncommitted changes" },
|
|
92
|
+
"modified",
|
|
93
|
+
)
|
|
94
|
+
: null,
|
|
95
|
+
),
|
|
96
|
+
h(
|
|
97
|
+
"div",
|
|
98
|
+
{ class: "git-message", title: git.message ?? "" },
|
|
99
|
+
git.message ?? "",
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const requester = (record: DeploymentRecord) => {
|
|
105
|
+
const { identity } = record.requestedBy;
|
|
106
|
+
const machine = userAtHost(record.requestedBy);
|
|
107
|
+
return h(
|
|
108
|
+
"span",
|
|
109
|
+
{ class: "requester", title: machine ? `From ${machine}` : identity.name },
|
|
110
|
+
identity.name,
|
|
111
|
+
machine && machine !== identity.name
|
|
112
|
+
? h("span", { class: "muted" }, ` · ${machine}`)
|
|
113
|
+
: null,
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const row = (
|
|
118
|
+
app: App,
|
|
119
|
+
record: DeploymentRecord,
|
|
120
|
+
list: DeploymentList,
|
|
121
|
+
now: number,
|
|
122
|
+
) => {
|
|
123
|
+
const state = states[record.state];
|
|
124
|
+
const current = list.current === record.id;
|
|
125
|
+
const href = deploymentHref(record.id);
|
|
126
|
+
return h(
|
|
127
|
+
"div",
|
|
128
|
+
{
|
|
129
|
+
class: "deployment-row",
|
|
130
|
+
role: "link",
|
|
131
|
+
tabindex: 0,
|
|
132
|
+
onclick: () => app.navigate(href),
|
|
133
|
+
onkeydown: (event) => {
|
|
134
|
+
if (event instanceof KeyboardEvent && event.key === "Enter") {
|
|
135
|
+
app.navigate(href);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
h(
|
|
140
|
+
"div",
|
|
141
|
+
{ class: "cell id-cell" },
|
|
142
|
+
h(
|
|
143
|
+
"a",
|
|
144
|
+
{
|
|
145
|
+
class: "mono id",
|
|
146
|
+
href,
|
|
147
|
+
onclick: (event) => {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
shortId(record.id),
|
|
152
|
+
),
|
|
153
|
+
h(
|
|
154
|
+
"div",
|
|
155
|
+
{ class: "tags" },
|
|
156
|
+
h("span", { class: "muted" }, modeLabels[record.mode]),
|
|
157
|
+
current ? badge("Current", "ok") : null,
|
|
158
|
+
list.lastGood === record.id && !current
|
|
159
|
+
? badge("Last good", "neutral")
|
|
160
|
+
: null,
|
|
161
|
+
),
|
|
162
|
+
),
|
|
163
|
+
h(
|
|
164
|
+
"div",
|
|
165
|
+
{ class: "cell state-cell" },
|
|
166
|
+
h("div", { class: "state" }, dot(state.tone), state.label),
|
|
167
|
+
h(
|
|
168
|
+
"div",
|
|
169
|
+
{ class: "muted mono" },
|
|
170
|
+
formatDeploymentDuration(record, now),
|
|
171
|
+
record.operation === "download" ? " · download" : "",
|
|
172
|
+
),
|
|
173
|
+
),
|
|
174
|
+
h(
|
|
175
|
+
"div",
|
|
176
|
+
{ class: "cell git-cell" },
|
|
177
|
+
gitSummary(record),
|
|
178
|
+
origin(record, app),
|
|
179
|
+
),
|
|
180
|
+
h(
|
|
181
|
+
"div",
|
|
182
|
+
{ class: "cell when-cell" },
|
|
183
|
+
h("div", { title: record.createdAt }, formatAgo(record.createdAt, now)),
|
|
184
|
+
h("div", { class: "muted" }, requester(record)),
|
|
185
|
+
),
|
|
186
|
+
h(
|
|
187
|
+
"div",
|
|
188
|
+
{ class: "cell menu-cell" },
|
|
189
|
+
menuButton(`Actions for ${shortId(record.id)}`, () =>
|
|
190
|
+
deploymentMenu(app, record, { current, open: true }),
|
|
191
|
+
),
|
|
192
|
+
),
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/** Every deployment, newest first, refreshed while the page is visible. */
|
|
197
|
+
export const deploymentsView = (app: App): View => {
|
|
198
|
+
const search = h("input", {
|
|
199
|
+
class: "input search",
|
|
200
|
+
type: "search",
|
|
201
|
+
placeholder: "Search by id, branch, commit, message or person…",
|
|
202
|
+
});
|
|
203
|
+
let filter = all;
|
|
204
|
+
const filterButtons = h("div", { class: "segmented" });
|
|
205
|
+
const rows = h(
|
|
206
|
+
"div",
|
|
207
|
+
{ class: "deployment-list" },
|
|
208
|
+
empty("Loading deployments…"),
|
|
209
|
+
);
|
|
210
|
+
let list: DeploymentList | null = null;
|
|
211
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
212
|
+
let disposed = false;
|
|
213
|
+
|
|
214
|
+
const matches = (record: DeploymentRecord) => {
|
|
215
|
+
const text = search.value.trim().toLowerCase();
|
|
216
|
+
if (!filter.matches(record.state)) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
if (!text) {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
return [
|
|
223
|
+
record.id,
|
|
224
|
+
record.release,
|
|
225
|
+
record.git?.branch,
|
|
226
|
+
record.git?.commit,
|
|
227
|
+
record.git?.message,
|
|
228
|
+
record.requestedBy.identity.name,
|
|
229
|
+
record.requestedBy.user,
|
|
230
|
+
record.requestedBy.host,
|
|
231
|
+
].some((field) => field?.toLowerCase().includes(text));
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const render = () => {
|
|
235
|
+
fill(
|
|
236
|
+
filterButtons,
|
|
237
|
+
...filters.map((option) =>
|
|
238
|
+
h(
|
|
239
|
+
"button",
|
|
240
|
+
{
|
|
241
|
+
class: option === filter ? "on" : "",
|
|
242
|
+
onclick: () => {
|
|
243
|
+
filter = option;
|
|
244
|
+
render();
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
option.label,
|
|
248
|
+
),
|
|
249
|
+
),
|
|
250
|
+
);
|
|
251
|
+
if (!list) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const shown = list.deployments.filter(matches);
|
|
255
|
+
const now = Date.now();
|
|
256
|
+
const current = list;
|
|
257
|
+
fill(
|
|
258
|
+
rows,
|
|
259
|
+
...(shown.length
|
|
260
|
+
? shown.map((record) => row(app, record, current, now))
|
|
261
|
+
: [
|
|
262
|
+
empty(
|
|
263
|
+
list.deployments.length
|
|
264
|
+
? "No deployment matches."
|
|
265
|
+
: "No deployments yet. Run tsplc deploy in a project to make the first.",
|
|
266
|
+
),
|
|
267
|
+
]),
|
|
268
|
+
);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const refresh = async () => {
|
|
272
|
+
clearTimeout(timer);
|
|
273
|
+
if (!document.hidden && !overlayOpen()) {
|
|
274
|
+
try {
|
|
275
|
+
list = await api.deployments();
|
|
276
|
+
render();
|
|
277
|
+
} catch (error) {
|
|
278
|
+
fill(rows, h("p", { class: "error-text" }, errorMessage(error)));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (disposed) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const running = list?.deployments.some(
|
|
285
|
+
(record) => !isFinished(record.state),
|
|
286
|
+
);
|
|
287
|
+
timer = setTimeout(
|
|
288
|
+
refresh,
|
|
289
|
+
running ? refreshEvery.running : refreshEvery.idle,
|
|
290
|
+
);
|
|
291
|
+
};
|
|
292
|
+
search.addEventListener("input", render);
|
|
293
|
+
const visible = () => {
|
|
294
|
+
if (!document.hidden) {
|
|
295
|
+
void refresh();
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
document.addEventListener("visibilitychange", visible);
|
|
299
|
+
render();
|
|
300
|
+
void refresh();
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
element: h(
|
|
304
|
+
"div",
|
|
305
|
+
{ class: "page" },
|
|
306
|
+
pageHeader(
|
|
307
|
+
"Deployments",
|
|
308
|
+
"Every deployment to the controller, newest first.",
|
|
309
|
+
),
|
|
310
|
+
h("div", { class: "toolbar" }, search, filterButtons),
|
|
311
|
+
rows,
|
|
312
|
+
),
|
|
313
|
+
dispose: () => {
|
|
314
|
+
disposed = true;
|
|
315
|
+
clearTimeout(timer);
|
|
316
|
+
document.removeEventListener("visibilitychange", visible);
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
};
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { DeploymentRecord } from "../../protocol";
|
|
2
|
+
import { badge, dot, empty, h, type Tone } from "./dom";
|
|
3
|
+
import { formatTimestamp, operationLabels } from "./format";
|
|
4
|
+
|
|
5
|
+
type Finding = DeploymentRecord["findings"][number];
|
|
6
|
+
type Health = NonNullable<DeploymentRecord["health"]>;
|
|
7
|
+
type Rollback = NonNullable<NonNullable<DeploymentRecord["error"]>["rollback"]>;
|
|
8
|
+
|
|
9
|
+
const findingKinds: Record<Finding["kind"], string> = {
|
|
10
|
+
type: "Type change",
|
|
11
|
+
tasks: "Task change",
|
|
12
|
+
restart: "Restart",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** What became of the controller after a download failed mid-transfer. */
|
|
16
|
+
const rollbackNotes: Record<Rollback, { text: string; tone: Tone }> = {
|
|
17
|
+
intact: {
|
|
18
|
+
text: "The controller still runs the application it ran before this deployment.",
|
|
19
|
+
tone: "ok",
|
|
20
|
+
},
|
|
21
|
+
restored: {
|
|
22
|
+
text: "The controller runs the previous application again, restored from the last committed download.",
|
|
23
|
+
tone: "ok",
|
|
24
|
+
},
|
|
25
|
+
failed: {
|
|
26
|
+
text: "Restoring the previous application failed: the controller may hold no application.",
|
|
27
|
+
tone: "error",
|
|
28
|
+
},
|
|
29
|
+
unavailable: {
|
|
30
|
+
text: "No committed download existed to restore: the controller may hold no application.",
|
|
31
|
+
tone: "error",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const change = (finding: Finding) => {
|
|
36
|
+
if (finding.before === null && finding.after === null) {
|
|
37
|
+
return h("span", { class: "muted" }, "—");
|
|
38
|
+
}
|
|
39
|
+
return h(
|
|
40
|
+
"span",
|
|
41
|
+
{ class: "mono change" },
|
|
42
|
+
h("span", { class: "before" }, finding.before ?? "none"),
|
|
43
|
+
" → ",
|
|
44
|
+
h("span", { class: "after" }, finding.after ?? "none"),
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Findings as a table: what changes, whether it refuses an online change, and the advice. */
|
|
49
|
+
const findingsTable = (findings: readonly Finding[]) =>
|
|
50
|
+
h(
|
|
51
|
+
"table",
|
|
52
|
+
{ class: "table" },
|
|
53
|
+
h(
|
|
54
|
+
"thead",
|
|
55
|
+
{},
|
|
56
|
+
h(
|
|
57
|
+
"tr",
|
|
58
|
+
{},
|
|
59
|
+
...["Kind", "Object", "Change", "Effect", "Advice"].map((label) =>
|
|
60
|
+
h("th", {}, label),
|
|
61
|
+
),
|
|
62
|
+
),
|
|
63
|
+
),
|
|
64
|
+
h(
|
|
65
|
+
"tbody",
|
|
66
|
+
{},
|
|
67
|
+
...findings.map((finding) =>
|
|
68
|
+
h(
|
|
69
|
+
"tr",
|
|
70
|
+
{},
|
|
71
|
+
h("td", { class: "nowrap" }, findingKinds[finding.kind]),
|
|
72
|
+
h(
|
|
73
|
+
"td",
|
|
74
|
+
{ class: "mono" },
|
|
75
|
+
finding.object,
|
|
76
|
+
finding.variable
|
|
77
|
+
? h("span", { class: "muted" }, `.${finding.variable}`)
|
|
78
|
+
: null,
|
|
79
|
+
),
|
|
80
|
+
h("td", {}, change(finding)),
|
|
81
|
+
h(
|
|
82
|
+
"td",
|
|
83
|
+
{ class: "nowrap" },
|
|
84
|
+
finding.refuses
|
|
85
|
+
? badge("Refuses online change", "error")
|
|
86
|
+
: badge("Online change", "neutral"),
|
|
87
|
+
),
|
|
88
|
+
h("td", {}, finding.advice),
|
|
89
|
+
),
|
|
90
|
+
),
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
export const changesTab = (record: DeploymentRecord) => {
|
|
95
|
+
if (record.findings.length) {
|
|
96
|
+
return h("div", {}, findingsTable(record.findings));
|
|
97
|
+
}
|
|
98
|
+
const reviewed = record.phases.some(
|
|
99
|
+
(phase) => phase.name === "review" && phase.outcome === "ok",
|
|
100
|
+
);
|
|
101
|
+
return empty(
|
|
102
|
+
reviewed
|
|
103
|
+
? "The online-change check found nothing to report."
|
|
104
|
+
: "This deployment wasn't checked for an online change.",
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
type HealthValue = Health[keyof Omit<Health, "detail">];
|
|
109
|
+
|
|
110
|
+
const healthTones: Record<HealthValue, Tone> = {
|
|
111
|
+
ok: "ok",
|
|
112
|
+
failed: "error",
|
|
113
|
+
none: "idle",
|
|
114
|
+
unknown: "idle",
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const healthItem = (label: string, value: HealthValue) =>
|
|
118
|
+
h(
|
|
119
|
+
"span",
|
|
120
|
+
{ class: "health-item" },
|
|
121
|
+
dot(healthTones[value]),
|
|
122
|
+
h("span", { class: "muted" }, label),
|
|
123
|
+
value,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const healthValue = (value: HealthValue) =>
|
|
127
|
+
h("span", {}, dot(healthTones[value]), value);
|
|
128
|
+
|
|
129
|
+
/** The check after applying: the controller, the server and the PLC connection. */
|
|
130
|
+
export const healthSummary = (health: DeploymentRecord["health"]) =>
|
|
131
|
+
health
|
|
132
|
+
? h(
|
|
133
|
+
"span",
|
|
134
|
+
{ class: "health", title: health.detail ?? "" },
|
|
135
|
+
healthItem("Controller", health.controller),
|
|
136
|
+
healthItem("Server", health.server),
|
|
137
|
+
healthItem("PLC", health.plc),
|
|
138
|
+
)
|
|
139
|
+
: h("span", { class: "muted" }, "Not checked yet");
|
|
140
|
+
|
|
141
|
+
const facts = (...entries: [string, Node | string][]) =>
|
|
142
|
+
h(
|
|
143
|
+
"dl",
|
|
144
|
+
{ class: "facts" },
|
|
145
|
+
...entries.flatMap(([term, value]) => [
|
|
146
|
+
h("dt", {}, term),
|
|
147
|
+
h("dd", {}, value),
|
|
148
|
+
]),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
export const activeWindow = (record: DeploymentRecord) => {
|
|
152
|
+
if (!record.activeFrom) {
|
|
153
|
+
return "Never ran on the line";
|
|
154
|
+
}
|
|
155
|
+
return `${formatTimestamp(record.activeFrom)} – ${
|
|
156
|
+
record.activeUntil ? formatTimestamp(record.activeUntil) : "now"
|
|
157
|
+
}`;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const runtimeTab = (record: DeploymentRecord) => {
|
|
161
|
+
const { error } = record;
|
|
162
|
+
const note = error?.rollback ? rollbackNotes[error.rollback] : null;
|
|
163
|
+
return h(
|
|
164
|
+
"div",
|
|
165
|
+
{ class: "runtime" },
|
|
166
|
+
error
|
|
167
|
+
? h(
|
|
168
|
+
"section",
|
|
169
|
+
{ class: "callout t-error" },
|
|
170
|
+
h("h3", {}, "Error"),
|
|
171
|
+
h("p", { class: "mono pre" }, error.message),
|
|
172
|
+
error.downloadRequired
|
|
173
|
+
? h(
|
|
174
|
+
"p",
|
|
175
|
+
{},
|
|
176
|
+
"Only a full download can deploy this release, which stops the line while it runs.",
|
|
177
|
+
)
|
|
178
|
+
: null,
|
|
179
|
+
note ? h("p", { class: `rollback t-${note.tone}` }, note.text) : null,
|
|
180
|
+
)
|
|
181
|
+
: null,
|
|
182
|
+
h(
|
|
183
|
+
"section",
|
|
184
|
+
{ class: "card" },
|
|
185
|
+
h("h3", {}, "Health"),
|
|
186
|
+
record.health
|
|
187
|
+
? facts(
|
|
188
|
+
["Controller", healthValue(record.health.controller)],
|
|
189
|
+
["Server", healthValue(record.health.server)],
|
|
190
|
+
["PLC", healthValue(record.health.plc)],
|
|
191
|
+
["Detail", record.health.detail ?? "—"],
|
|
192
|
+
)
|
|
193
|
+
: empty("The health check hasn't run."),
|
|
194
|
+
),
|
|
195
|
+
h(
|
|
196
|
+
"section",
|
|
197
|
+
{ class: "card" },
|
|
198
|
+
h("h3", {}, "On the controller"),
|
|
199
|
+
facts(
|
|
200
|
+
["Active", activeWindow(record)],
|
|
201
|
+
["Operation", operationLabels[record.operation]],
|
|
202
|
+
[
|
|
203
|
+
"Code id",
|
|
204
|
+
h("span", { class: "mono" }, record.controllerIds?.codeId ?? "—"),
|
|
205
|
+
],
|
|
206
|
+
[
|
|
207
|
+
"Data id",
|
|
208
|
+
h("span", { class: "mono" }, record.controllerIds?.dataId ?? "—"),
|
|
209
|
+
],
|
|
210
|
+
["Build", h("span", { class: "mono" }, record.build ?? "—")],
|
|
211
|
+
),
|
|
212
|
+
),
|
|
213
|
+
);
|
|
214
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export type Child = Node | string | null | undefined | false;
|
|
2
|
+
type Attribute =
|
|
3
|
+
| string
|
|
4
|
+
| number
|
|
5
|
+
| boolean
|
|
6
|
+
| null
|
|
7
|
+
| undefined
|
|
8
|
+
| ((event: Event) => void);
|
|
9
|
+
|
|
10
|
+
/** An element with `attributes`; a function is an `on…` listener, and absent or false ones are left out. */
|
|
11
|
+
export const h = <K extends keyof HTMLElementTagNameMap>(
|
|
12
|
+
tag: K,
|
|
13
|
+
attributes: Record<string, Attribute> = {},
|
|
14
|
+
...children: Child[]
|
|
15
|
+
): HTMLElementTagNameMap[K] => {
|
|
16
|
+
const element = document.createElement(tag);
|
|
17
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
18
|
+
if (value === undefined || value === null || value === false) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === "function") {
|
|
22
|
+
element.addEventListener(name.slice(2), value);
|
|
23
|
+
} else {
|
|
24
|
+
element.setAttribute(name, value === true ? "" : String(value));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return fill(element, ...children);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const fill = <E extends Element>(element: E, ...children: Child[]) => {
|
|
31
|
+
element.replaceChildren(
|
|
32
|
+
...children.filter((child): child is Node | string => Boolean(child)),
|
|
33
|
+
);
|
|
34
|
+
return element;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** A page: its element, and what to stop when another page replaces it. */
|
|
38
|
+
export interface View {
|
|
39
|
+
element: HTMLElement;
|
|
40
|
+
dispose?(): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const empty = (text: string) => h("p", { class: "empty" }, text);
|
|
44
|
+
|
|
45
|
+
/** How a status is coloured, as the stylesheet's `t-` classes name it. */
|
|
46
|
+
export type Tone = "ok" | "error" | "active" | "waiting" | "idle" | "neutral";
|
|
47
|
+
|
|
48
|
+
/** A status dot in a tone's colour, pulsing while the tone is active. */
|
|
49
|
+
export const dot = (tone: Tone) => h("span", { class: `dot t-${tone}` });
|
|
50
|
+
|
|
51
|
+
export const badge = (text: string, tone: Tone = "neutral") =>
|
|
52
|
+
h("span", { class: `badge t-${tone}` }, text);
|
|
53
|
+
|
|
54
|
+
export const pageHeader = (
|
|
55
|
+
title: string,
|
|
56
|
+
description: string,
|
|
57
|
+
...actions: Child[]
|
|
58
|
+
) =>
|
|
59
|
+
h(
|
|
60
|
+
"div",
|
|
61
|
+
{ class: "page-header" },
|
|
62
|
+
h("div", {}, h("h1", {}, title), h("p", { class: "muted" }, description)),
|
|
63
|
+
h("div", { class: "actions" }, ...actions),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
/** An inline SVG icon from a path in a 16-unit box. */
|
|
67
|
+
export const icon = (path: string) => {
|
|
68
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
69
|
+
svg.setAttribute("viewBox", "0 0 16 16");
|
|
70
|
+
svg.setAttribute("class", "icon");
|
|
71
|
+
svg.setAttribute("aria-hidden", "true");
|
|
72
|
+
const shape = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
73
|
+
shape.setAttribute("d", path);
|
|
74
|
+
svg.append(shape);
|
|
75
|
+
return svg;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const icons = {
|
|
79
|
+
branch:
|
|
80
|
+
"M5 3.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Zm0 9a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Zm9-6a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0ZM3.5 5v6M12.5 8c0 2-2 3-5 3.5L3.5 11",
|
|
81
|
+
commit: "M10.5 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0ZM1 8h4.5M10.5 8H15",
|
|
82
|
+
more: "M3 8h.01M8 8h.01M13 8h.01",
|
|
83
|
+
file: "M4 1.5h5l3.5 3.5v9.5h-8.5zM9 1.5V5h3.5",
|
|
84
|
+
folder: "M1.5 3.5h4.5l1.5 1.5h7v8.5h-13z",
|
|
85
|
+
sun: "M8 11a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM8 1v1.5M8 13.5V15M1 8h1.5M13.5 8H15M3 3l1 1M12 12l1 1M3 13l1-1M12 4l1-1",
|
|
86
|
+
moon: "M13.5 9.5A5.5 5.5 0 0 1 6.5 2.5a5.5 5.5 0 1 0 7 7Z",
|
|
87
|
+
} as const;
|