@basaltkit/deploy-ui 0.3.0 → 0.5.0
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 +12 -1
- package/dist/client/api.js +6 -5
- package/dist/client/app.js +82 -38
- package/dist/client/dialog.js +3 -2
- package/dist/client/i18n-messages.js +14 -0
- package/dist/client/i18n.js +777 -0
- package/dist/client/icons.js +2 -0
- package/dist/client/main.js +12 -10
- package/dist/client/messages.d.ts +2 -0
- package/dist/client/reply.js +8 -7
- package/dist/client/version.js +70 -0
- package/dist/client/view-commits.js +10 -24
- package/dist/client/view-history.js +39 -34
- package/dist/client/view-plan.js +36 -35
- package/dist/client/view-run.js +52 -48
- package/dist/client/view-status.js +28 -26
- package/dist/client/view-targets.js +30 -25
- package/dist/page.d.ts +2 -2
- package/dist/page.js +10 -1
- package/dist/server.js +9 -3
- package/dist/targets.d.ts +6 -0
- package/dist/targets.js +8 -2
- package/package.json +7 -6
package/dist/client/icons.js
CHANGED
|
@@ -28,6 +28,8 @@ const PATHS = {
|
|
|
28
28
|
chevron: 'M9 6l6 6-6 6',
|
|
29
29
|
arrow: 'M5 12h14M13 6l6 6-6 6',
|
|
30
30
|
commit: 'M12 8.5a3.5 3.5 0 1 1 0 7 3.5 3.5 0 1 1 0-7zM3 12h5.5M15.5 12H21',
|
|
31
|
+
branch: 'M6 3v12M6 15a3 3 0 1 0 0 6 3 3 0 1 0 0-6zM18 3a3 3 0 1 0 0 6 3 3 0 1 0 0-6zM18 9c0 6-12 3-12 6',
|
|
32
|
+
globe: 'M12 3a9 9 0 1 1 0 18 9 9 0 1 1 0-18zM3 12h18M12 3c2.5 2.5 3.8 5.5 3.8 9s-1.3 6.5-3.8 9c-2.5-2.5-3.8-5.5-3.8-9s1.3-6.5 3.8-9z',
|
|
31
33
|
merge: 'M7 4v10M7 14a3 3 0 1 0 0 6 3 3 0 1 0 0-6zM17 4a3 3 0 1 0 0 6 3 3 0 1 0 0-6zM17 10c0 4-4 6-10 6',
|
|
32
34
|
};
|
|
33
35
|
const SVG = 'http://www.w3.org/2000/svg';
|
package/dist/client/main.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Api, ApiError, exchange, ServerGone } from './api.js';
|
|
2
|
-
import { App, forgetSession, SERVER_KEY, TOKEN_KEY } from './app.js';
|
|
2
|
+
import { App, applyShell, forgetSession, SERVER_KEY, TOKEN_KEY } from './app.js';
|
|
3
3
|
import { el, replace } from './dom.js';
|
|
4
|
+
import { pickLocale, setLocale, t } from './i18n.js';
|
|
4
5
|
import { describe } from './reply.js';
|
|
5
6
|
function storageOf(win) {
|
|
6
7
|
try {
|
|
@@ -19,6 +20,9 @@ function storageOf(win) {
|
|
|
19
20
|
*/
|
|
20
21
|
export async function boot(env) {
|
|
21
22
|
const doc = env.document;
|
|
23
|
+
const languages = env.languages ?? [];
|
|
24
|
+
setLocale(pickLocale(undefined, languages), languages);
|
|
25
|
+
applyShell(doc);
|
|
22
26
|
const shell = {
|
|
23
27
|
nav: doc.getElementById('nav'),
|
|
24
28
|
bar: doc.getElementById('target-bar'),
|
|
@@ -62,7 +66,7 @@ export async function boot(env) {
|
|
|
62
66
|
// The server is gone or not ours: the page already says so.
|
|
63
67
|
if (error instanceof ServerGone)
|
|
64
68
|
return undefined;
|
|
65
|
-
replace(shell.main, el('div', { class: 'banner err', role: 'alert' }, el('strong', {}, '
|
|
69
|
+
replace(shell.main, el('div', { class: 'banner err', role: 'alert' }, el('strong', {}, t('start.failed')), el('p', {}, describe(error))));
|
|
66
70
|
return undefined;
|
|
67
71
|
}
|
|
68
72
|
return app;
|
|
@@ -82,9 +86,7 @@ function keep(env, credentials) {
|
|
|
82
86
|
const final = (error) => error instanceof ApiError && (error.status === 409 || error.status === 410 || error.status === 429);
|
|
83
87
|
function refusal(error) {
|
|
84
88
|
const taken = error instanceof ApiError && error.status === 409;
|
|
85
|
-
return el('div', { class: 'banner err', role: 'alert' }, el('strong', {}, taken ? '
|
|
86
|
-
? 'Another tab or browser claimed it first. If that was not you, stop basalt-deploy-ui in your terminal now (Ctrl-C) and start it again.'
|
|
87
|
-
: `${describe(error)}. Start basalt-deploy-ui again.`));
|
|
89
|
+
return el('div', { class: 'banner err', role: 'alert' }, el('strong', {}, taken ? t('start.sessionTaken') : t('start.codeRefused')), el('p', {}, taken ? t('start.sessionTakenHelp') : t('start.again', { why: describe(error) })));
|
|
88
90
|
}
|
|
89
91
|
/**
|
|
90
92
|
* No session yet: the code the terminal shows, typed here (`--pair`: nothing
|
|
@@ -96,12 +98,12 @@ function pair(env, main) {
|
|
|
96
98
|
return new Promise((resolve) => {
|
|
97
99
|
const input = el('input', { id: 'pair-code', name: 'code', type: 'text', autocomplete: 'off', spellcheck: false, required: true, placeholder: 'ABCD-EFGH', aria: { describedby: 'pair-help' } });
|
|
98
100
|
const status = el('span', { class: 'field-error', role: 'alert' });
|
|
99
|
-
const submit = el('button', { type: 'submit', class: 'primary' }, '
|
|
100
|
-
const form = el('form', { class: 'card pair', aria: { label: '
|
|
101
|
+
const submit = el('button', { type: 'submit', class: 'primary' }, t('pair.open'));
|
|
102
|
+
const form = el('form', { class: 'card pair', aria: { label: t('pair.title') }, on: { submit: (event) => {
|
|
101
103
|
event.preventDefault();
|
|
102
104
|
const code = input.value.trim();
|
|
103
105
|
if (!/^[A-Za-z0-9_\s-]{1,128}$/.test(code)) {
|
|
104
|
-
replace(status, '
|
|
106
|
+
replace(status, t('pair.typeCode'));
|
|
105
107
|
return;
|
|
106
108
|
}
|
|
107
109
|
submit.disabled = true;
|
|
@@ -116,11 +118,11 @@ function pair(env, main) {
|
|
|
116
118
|
input.focus();
|
|
117
119
|
replace(status, describe(error));
|
|
118
120
|
});
|
|
119
|
-
} } }, el('div', { class: 'card-head' }, el('h3', {}, '
|
|
121
|
+
} } }, el('div', { class: 'card-head' }, el('h3', {}, t('pair.title'))), el('div', { class: 'card-body' }, el('div', { class: 'field' }, el('label', { for: 'pair-code' }, t('pair.code')), input, el('span', { id: 'pair-help', class: 'field-help' }, t('pair.help')), status)), el('div', { class: 'card-foot' }, submit));
|
|
120
122
|
replace(main, form);
|
|
121
123
|
input.focus();
|
|
122
124
|
});
|
|
123
125
|
}
|
|
124
126
|
if (typeof window !== 'undefined' && document.getElementById('app')) {
|
|
125
|
-
void boot({ location: window.location, history: window.history, storage: storageOf(window), fetch: (input, init) => window.fetch(input, init), document, crypto: window.crypto });
|
|
127
|
+
void boot({ location: window.location, history: window.history, storage: storageOf(window), fetch: (input, init) => window.fetch(input, init), document, crypto: window.crypto, languages: window.navigator.languages ?? [window.navigator.language] });
|
|
126
128
|
}
|
package/dist/client/reply.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { el, quiet } from './dom.js';
|
|
2
|
+
import { serverText, t } from './i18n.js';
|
|
2
3
|
import { icon } from './icons.js';
|
|
3
4
|
import { ApiError } from './api.js';
|
|
4
5
|
/** What went wrong, as a banner: a protocol error (code, message, hint), a failure of the connection, or the local server's refusal. */
|
|
5
6
|
export function problem(reply, error) {
|
|
6
7
|
if (error !== undefined)
|
|
7
|
-
return banner('err', '
|
|
8
|
+
return banner('err', t('reply.uiRefused'), [describe(error)]);
|
|
8
9
|
if (!reply)
|
|
9
10
|
return null;
|
|
10
11
|
if (reply.failure)
|
|
@@ -12,30 +13,30 @@ export function problem(reply, error) {
|
|
|
12
13
|
if (reply.error)
|
|
13
14
|
return errorBanner(reply.error, reply.diagnostics);
|
|
14
15
|
if (!reply.ok)
|
|
15
|
-
return banner('err', '
|
|
16
|
+
return banner('err', t('reply.commandFailed'), [t('reply.exitCode', { code: reply.exitCode ?? t('unknown') })], reply.diagnostics);
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
18
19
|
export function describe(error) {
|
|
19
20
|
if (error instanceof ApiError)
|
|
20
|
-
return `${error.message} (HTTP ${error.status})`;
|
|
21
|
+
return `${serverText(error.message)} (HTTP ${error.status})`;
|
|
21
22
|
return error instanceof Error ? error.message : String(error);
|
|
22
23
|
}
|
|
23
24
|
export function failureBanner(failure, diagnostics = []) {
|
|
24
|
-
return banner('err', failure.message, failure.hint ? [failure.hint] : [], diagnostics, failure.code);
|
|
25
|
+
return banner('err', serverText(failure.message), failure.hint ? [serverText(failure.hint)] : [], diagnostics, failure.code);
|
|
25
26
|
}
|
|
26
27
|
export function errorBanner(error, diagnostics = []) {
|
|
27
28
|
const lines = [];
|
|
28
29
|
if (error.hint)
|
|
29
30
|
lines.push(error.hint);
|
|
30
31
|
if (error.holder)
|
|
31
|
-
lines.push(
|
|
32
|
+
lines.push(t(error.holder.runId ? 'reply.heldByRun' : 'reply.heldBy', { ...error.holder }));
|
|
32
33
|
for (const finding of error.findings ?? [])
|
|
33
34
|
lines.push(`${finding.level}: ${finding.message}${finding.fix ? ` — ${finding.fix}` : ''}`);
|
|
34
35
|
return banner('err', error.message, lines, diagnostics, error.code);
|
|
35
36
|
}
|
|
36
37
|
export function banner(level, title, lines = [], diagnostics = [], code) {
|
|
37
|
-
return el('div', { class: `banner ${level}`, role: level === 'err' ? 'alert' : 'status' }, icon(level === 'ok' ? 'ok' : level === 'warn' ? 'alert' : 'error', 'icon banner-icon'), el('div', { class: 'banner-body' }, el('strong', { class: 'banner-title' }, quiet(level === 'ok' ? '
|
|
38
|
+
return el('div', { class: `banner ${level}`, role: level === 'err' ? 'alert' : 'status' }, icon(level === 'ok' ? 'ok' : level === 'warn' ? 'alert' : 'error', 'icon banner-icon'), el('div', { class: 'banner-body' }, el('strong', { class: 'banner-title' }, quiet(t(level === 'ok' ? 'level.ok' : level === 'warn' ? 'level.warn' : 'level.err')), title), code ? el('span', { class: 'banner-code' }, ` [${code}]`) : null, ...lines.filter((line) => line !== '' && line !== null && line !== undefined && line !== false).map((line) => el('p', {}, line)), diagnostics.length > 0 ? diagnosticsBlock(diagnostics) : null));
|
|
38
39
|
}
|
|
39
40
|
export function diagnosticsBlock(lines) {
|
|
40
|
-
return el('details', { class: 'disclosure' }, el('summary', {},
|
|
41
|
+
return el('details', { class: 'disclosure' }, el('summary', {}, t('reply.diagnostics', { count: lines.length })), el('pre', { class: 'diagnostics' }, lines.join('\n')));
|
|
41
42
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { el } from './dom.js';
|
|
2
|
+
import { t } from './i18n.js';
|
|
3
|
+
import { banner } from './reply.js';
|
|
4
|
+
import { clean } from './sanitize.js';
|
|
5
|
+
/**
|
|
6
|
+
* What this page uses from the server's @basaltkit/deploy, and from which
|
|
7
|
+
* version. A server behind is said plainly — what is missing, and the
|
|
8
|
+
* update — so an "unavailable" never has to be guessed at. The page imports
|
|
9
|
+
* no code from the deploy package: the versions are listed here.
|
|
10
|
+
*/
|
|
11
|
+
export const FEATURES = [
|
|
12
|
+
{ since: '0.8.0', key: 'feature.commits' },
|
|
13
|
+
{ since: '0.9.0', key: 'feature.source' },
|
|
14
|
+
];
|
|
15
|
+
const VERSION = /^(\d{1,6})\.(\d{1,6})\.(\d{1,6})(?:-[0-9A-Za-z.-]{1,64})?$/;
|
|
16
|
+
/** `x.y.z` compared numerically; a pre-release counts as before its release. Undefined when either is not a version. */
|
|
17
|
+
export function compareVersions(a, b) {
|
|
18
|
+
const x = VERSION.exec(a);
|
|
19
|
+
const y = VERSION.exec(b);
|
|
20
|
+
if (!x || !y)
|
|
21
|
+
return undefined;
|
|
22
|
+
for (let i = 1; i <= 3; i++) {
|
|
23
|
+
const d = Number(x[i]) - Number(y[i]);
|
|
24
|
+
if (d !== 0)
|
|
25
|
+
return Math.sign(d);
|
|
26
|
+
}
|
|
27
|
+
const pre = (v) => v.includes('-');
|
|
28
|
+
return pre(a) === pre(b) ? 0 : pre(a) ? -1 : 1;
|
|
29
|
+
}
|
|
30
|
+
/** The features a server's version lacks, and the version that has them all; undefined when it is current (or not a version). */
|
|
31
|
+
export function behind(version) {
|
|
32
|
+
if (typeof version !== 'string')
|
|
33
|
+
return undefined;
|
|
34
|
+
const missing = FEATURES.filter((f) => compareVersions(version, f.since) === -1);
|
|
35
|
+
if (missing.length === 0)
|
|
36
|
+
return undefined;
|
|
37
|
+
const needed = missing.reduce((top, f) => (compareVersions(f.since, top) === 1 ? f.since : top), missing[0]?.since);
|
|
38
|
+
return { needed, missing };
|
|
39
|
+
}
|
|
40
|
+
/** The notice: what is missing, and how to update — the second deploy included. Null when the server is current. */
|
|
41
|
+
export function driftBanner(version) {
|
|
42
|
+
const gap = behind(version);
|
|
43
|
+
if (!gap)
|
|
44
|
+
return null;
|
|
45
|
+
const current = clean(version);
|
|
46
|
+
const command = `pnpm add -D @basaltkit/deploy@^${gap.needed}`;
|
|
47
|
+
const lines = [
|
|
48
|
+
t('drift.missing', { list: gap.missing.map((f) => t(f.key, { since: f.since })).join(', ') }),
|
|
49
|
+
el('span', {}, t('drift.how'), ' ', el('code', {}, command), t('drift.howTail')),
|
|
50
|
+
t('drift.twice', { version: current, needed: gap.needed }),
|
|
51
|
+
];
|
|
52
|
+
const node = banner('warn', t('drift.title', { version: current, needed: gap.needed }), lines);
|
|
53
|
+
node.classList.add('drift');
|
|
54
|
+
return node;
|
|
55
|
+
}
|
|
56
|
+
/** A source from the server, checked: anything else is no source (an older deploy sends none). */
|
|
57
|
+
export function validSource(value) {
|
|
58
|
+
if (typeof value !== 'object' || value === null)
|
|
59
|
+
return undefined;
|
|
60
|
+
const s = value;
|
|
61
|
+
if (typeof s['remote'] !== 'string' || typeof s['branch'] !== 'string')
|
|
62
|
+
return undefined;
|
|
63
|
+
if (s['url'] !== undefined && typeof s['url'] !== 'string')
|
|
64
|
+
return undefined;
|
|
65
|
+
return { remote: clean(s['remote']), branch: clean(s['branch']), ...(typeof s['url'] === 'string' ? { url: clean(s['url']) } : {}) };
|
|
66
|
+
}
|
|
67
|
+
/** `github.com/acme/app (main)`, or `origin/main` when the address is not known. */
|
|
68
|
+
export function sourceText(source) {
|
|
69
|
+
return source.url ? `${source.url} (${source.branch})` : `${source.remote}/${source.branch}`;
|
|
70
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { el } from './dom.js';
|
|
2
|
+
import { formatLocale, reasonText, t } from './i18n.js';
|
|
2
3
|
import { icon } from './icons.js';
|
|
3
4
|
import { clean, short } from './sanitize.js';
|
|
4
5
|
/**
|
|
@@ -7,22 +8,7 @@ import { clean, short } from './sanitize.js';
|
|
|
7
8
|
* — rendered as text nodes only, cleaned again here, never a link. A list
|
|
8
9
|
* that is missing or unavailable is said so and never disables an action.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
const REASONS = {
|
|
12
|
-
'skipped': 'the fetch is skipped, so a run deploys the commit already checked out',
|
|
13
|
-
'not-fetched': 'the server could not fetch the branch from its remote',
|
|
14
|
-
'no-previous': 'there is no earlier release to compare with',
|
|
15
|
-
'missing-commit': 'a commit is not in the server\'s checkout (rewritten history, or never fetched there)',
|
|
16
|
-
'shallow': 'the server\'s checkout is a shallow clone, so its history is incomplete',
|
|
17
|
-
'unrelated': 'the two commits share no history',
|
|
18
|
-
'timeout': 'git took too long on the server',
|
|
19
|
-
'too-large': 'git\'s answer was too large',
|
|
20
|
-
'malformed': 'git\'s answer could not be read',
|
|
21
|
-
'git-failed': 'git failed on the server',
|
|
22
|
-
};
|
|
23
|
-
export function reasonText(reason) {
|
|
24
|
-
return typeof reason === 'string' && Object.hasOwn(REASONS, reason) ? REASONS[reason] : 'the server gave no usable reason';
|
|
25
|
-
}
|
|
11
|
+
export { reasonText };
|
|
26
12
|
/** A shape check: anything from the server that is not a list of commits is "unavailable", never a crash. */
|
|
27
13
|
export function validCommits(value) {
|
|
28
14
|
if (typeof value !== 'object' || value === null)
|
|
@@ -36,27 +22,27 @@ export function validCommits(value) {
|
|
|
36
22
|
}
|
|
37
23
|
/** Why there is no list: a quiet note, never an error the operator must clear. */
|
|
38
24
|
export function unavailable(text) {
|
|
39
|
-
return el('div', { class: 'commits-note' }, icon('info'), el('span', {}, el('strong', {}, '
|
|
25
|
+
return el('div', { class: 'commits-note' }, icon('info'), el('span', {}, el('strong', {}, t('commits.unavailable')), ` — ${text}.`));
|
|
40
26
|
}
|
|
41
|
-
/** `1 Oct 2026, 10:00` in the
|
|
27
|
+
/** `1 Oct 2026, 10:00` in the page's language (the browser's variant of it); the exact time in the tooltip. */
|
|
42
28
|
function date(at) {
|
|
43
29
|
if (typeof at !== 'string')
|
|
44
30
|
return null;
|
|
45
31
|
const parsed = new Date(at);
|
|
46
32
|
if (Number.isNaN(parsed.getTime()))
|
|
47
33
|
return null;
|
|
48
|
-
return el('time', { title: clean(at) }, parsed.toLocaleString(
|
|
34
|
+
return el('time', { title: clean(at) }, parsed.toLocaleString(formatLocale(), { dateStyle: 'medium', timeStyle: 'short' }));
|
|
49
35
|
}
|
|
50
36
|
function commitItem(c) {
|
|
51
37
|
const subject = clean(c.subject);
|
|
52
38
|
const author = clean(c.author);
|
|
53
|
-
return el('li', { class: c.merge ? 'commit is-merge' : 'commit' }, el('span', { class: 'commit-dot', aria: { hidden: 'true' } }), el('code', { class: 'commit-sha', title: short(c.sha) }, short(c.sha).slice(0, 7)), el('span', { class: 'commit-subject', title: subject }, c.merge ? icon('merge', 'icon commit-merge') : null, subject || el('span', { class: 'muted' },
|
|
39
|
+
return el('li', { class: c.merge ? 'commit is-merge' : 'commit' }, el('span', { class: 'commit-dot', aria: { hidden: 'true' } }), el('code', { class: 'commit-sha', title: short(c.sha) }, short(c.sha).slice(0, 7)), el('span', { class: 'commit-subject', title: subject }, c.merge ? icon('merge', 'icon commit-merge') : null, subject || el('span', { class: 'muted' }, t('commits.noSubject'))), el('span', { class: 'commit-meta' }, author ? el('span', { class: 'commit-author' }, author) : null, date(c.at)));
|
|
54
40
|
}
|
|
55
41
|
/** The most commits the server sends per list (COMMITS_LIMIT): the page imports no code from the deploy package. */
|
|
56
42
|
const LIST_LIMIT = 50;
|
|
57
43
|
/** One side of a range: a heading with its sign and count, the commits newest first, and what the cap left out. */
|
|
58
44
|
export function commitGroup(tone, label, list, total) {
|
|
59
|
-
return el('section', { class: `commit-group commit-group-${tone}`, aria: { label: `${label}: ${total}` } }, el('header', { class: 'commit-group-head' }, el('span', { class: 'commit-sign', aria: { hidden: 'true' } }, tone === 'added' ? '+' : '−'), el('span', { class: 'commit-group-title' }, label), el('span', { class: 'commit-count' }, String(total))), el('ol', { class: 'commit-list' }, ...list.map(commitItem)), total > list.length ? el('p', { class: 'commit-more' },
|
|
45
|
+
return el('section', { class: `commit-group commit-group-${tone}`, aria: { label: `${label}: ${total}` } }, el('header', { class: 'commit-group-head' }, el('span', { class: 'commit-sign', aria: { hidden: 'true' } }, tone === 'added' ? '+' : '−'), el('span', { class: 'commit-group-title' }, label), el('span', { class: 'commit-count' }, String(total))), el('ol', { class: 'commit-list' }, ...list.map(commitItem)), total > list.length ? el('p', { class: 'commit-more' }, t('commits.olderNotShown', { count: total - list.length, limit: LIST_LIMIT })) : null);
|
|
60
46
|
}
|
|
61
47
|
/** `abc1234 → def5678`, for a card's head. */
|
|
62
48
|
export function rangeSpan(range) {
|
|
@@ -68,9 +54,9 @@ export function rangeSpan(range) {
|
|
|
68
54
|
*/
|
|
69
55
|
export function commitsBlock(value, labels, order = ['added', 'removed']) {
|
|
70
56
|
if (value === undefined)
|
|
71
|
-
return unavailable('
|
|
57
|
+
return unavailable(t('commits.olderDeploy'));
|
|
72
58
|
if (!validCommits(value))
|
|
73
|
-
return unavailable('
|
|
59
|
+
return unavailable(t('commits.unreadable'));
|
|
74
60
|
if (!value.ok)
|
|
75
61
|
return unavailable(reasonText(value.reason));
|
|
76
62
|
const r = value.range;
|
|
@@ -85,5 +71,5 @@ export function commitsBlock(value, labels, order = ['added', 'removed']) {
|
|
|
85
71
|
/** A compact list for a confirmation dialog: at most `max` commits, then how many more. */
|
|
86
72
|
export function commitSummary(tone, label, list, total, max = 8) {
|
|
87
73
|
const shown = list.slice(0, max);
|
|
88
|
-
return el('span', { class: `commit-summary commit-group-${tone}` }, el('span', { class: 'commit-summary-head' }, el('span', { class: 'commit-sign', aria: { hidden: 'true' } }, tone === 'added' ? '+' : '−'), `${label} `, el('span', { class: 'commit-count' }, String(total))), ...shown.map((c) => el('span', { class: 'commit-summary-row' }, el('code', { class: 'commit-sha' }, short(c.sha).slice(0, 7)), el('span', { class: 'commit-subject' }, clean(c.subject)))), total > shown.length ? el('span', { class: 'commit-more' },
|
|
74
|
+
return el('span', { class: `commit-summary commit-group-${tone}` }, el('span', { class: 'commit-summary-head' }, el('span', { class: 'commit-sign', aria: { hidden: 'true' } }, tone === 'added' ? '+' : '−'), `${label} `, el('span', { class: 'commit-count' }, String(total))), ...shown.map((c) => el('span', { class: 'commit-summary-row' }, el('code', { class: 'commit-sha' }, short(c.sha).slice(0, 7)), el('span', { class: 'commit-subject' }, clean(c.subject)))), total > shown.length ? el('span', { class: 'commit-more' }, t('commits.andMore', { count: total - shown.length })) : null);
|
|
89
75
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { confirmDialog } from './dialog.js';
|
|
2
2
|
import { button, card, el, emptyState, pageHead, pill, replace, when } from './dom.js';
|
|
3
|
+
import { t } from './i18n.js';
|
|
3
4
|
import { icon } from './icons.js';
|
|
4
5
|
import { problem } from './reply.js';
|
|
5
6
|
import { clean, short } from './sanitize.js';
|
|
@@ -12,43 +13,45 @@ export function renderHistory(app) {
|
|
|
12
13
|
const preview = el('div', { class: 'rollback-preview', aria: { live: 'polite' } });
|
|
13
14
|
const current = releases.find((r) => r.status === 'ok');
|
|
14
15
|
const choices = releases.filter((r) => r.status === 'ok' && r !== current);
|
|
15
|
-
const select = el('select', { id: 'rollback-to', on: { change: () => replace(preview) } }, el('option', { value: '' },
|
|
16
|
-
return el('section', { aria: { labelledby: 'history-title' } }, pageHead('history-title', '
|
|
17
|
-
el('div', { class: 'field' }, el('label', { for: 'rollback-to' }, '
|
|
18
|
-
el('p', { class: 'form-note' }, icon('alert'), '
|
|
16
|
+
const select = el('select', { id: 'rollback-to', on: { change: () => replace(preview) } }, el('option', { value: '' }, t('history.lastHealthy')), ...choices.map((r) => el('option', { value: r.sha }, `${short(r.sha)} — ${when(r.at)}`)));
|
|
17
|
+
return el('section', { aria: { labelledby: 'history-title' } }, pageHead('history-title', t('screen.history'), t('history.sub'), el('button', { type: 'button', on: { click: () => { void app.refreshStatus(); } } }, icon('refresh'), t('refresh'))), !status ? emptyState('history', t('history.loadStatus'), t('history.loadStatusText')) : null, releases.length > 0 ? card(t('history.releases'), [table(app, releases, status?.subjects)], { bodyClass: 'flush', actions: [el('span', { class: 'muted num' }, t('history.recorded', { count: releases.length }))] }) : status ? emptyState('inbox', t('history.none'), t('history.noneText')) : null, status ? card(t('history.rollBack'), [
|
|
18
|
+
el('div', { class: 'field' }, el('label', { for: 'rollback-to' }, t('history.backTo')), select),
|
|
19
|
+
el('p', { class: 'form-note' }, icon('alert'), t('history.codeOnly')),
|
|
19
20
|
preview,
|
|
20
21
|
message,
|
|
21
22
|
], { foot: [
|
|
22
|
-
button('
|
|
23
|
-
button('
|
|
23
|
+
button(t('history.preview'), () => { void showPreview(app, select.value, preview); }),
|
|
24
|
+
button(t('history.rollBackEllipsis'), () => { void rollback(app, select.value, message, preview); }, { class: 'danger' }),
|
|
24
25
|
] }) : null);
|
|
25
26
|
}
|
|
27
|
+
/** A release's status in the page's language; one this UI does not know is shown as the server wrote it. */
|
|
28
|
+
const releaseStatus = (status) => (status === 'ok' || status === 'failed' ? t(`release.${status}`) : status);
|
|
26
29
|
/** The release each row is compared with: the one it was deployed over, else the next older one on record. */
|
|
27
30
|
const previousOf = (releases, index) => releases[index]?.previous || releases[index + 1]?.sha;
|
|
28
31
|
function table(app, releases, subjects) {
|
|
29
32
|
const known = typeof subjects === 'object' && subjects !== null ? subjects : {};
|
|
30
|
-
const columns = ['
|
|
31
|
-
return el('div', { class: 'table-wrap' }, el('table', { class: 'releases' }, el('thead', {}, el('tr', {}, el('th', { scope: 'col', class: 'disclosure' }, el('span', { class: 'visually-hidden' }, '
|
|
33
|
+
const columns = ['col.commit', 'col.when', 'col.status', 'col.actor', 'col.via', 'col.client', 'col.migrations', 'col.backup', 'col.note'].map((key) => t(key));
|
|
34
|
+
return el('div', { class: 'table-wrap' }, el('table', { class: 'releases' }, el('thead', {}, el('tr', {}, el('th', { scope: 'col', class: 'disclosure' }, el('span', { class: 'visually-hidden' }, t('history.changes'))), ...columns.map((h) => el('th', { scope: 'col' }, h)))), el('tbody', {}, ...releases.flatMap((r, index) => {
|
|
32
35
|
const from = previousOf(releases, index);
|
|
33
36
|
const detail = el('td', { colspan: columns.length + 1, class: 'release-changes-cell' });
|
|
34
37
|
const detailRow = el('tr', { class: 'release-changes', hidden: true }, detail);
|
|
35
38
|
const toggle = el('button', {
|
|
36
39
|
type: 'button', class: 'disclosure-button', disabled: !from,
|
|
37
|
-
title: from ?
|
|
38
|
-
aria: { expanded: 'false', label: from ?
|
|
40
|
+
title: from ? t('history.between', { from: short(from).slice(0, 7), to: short(r.sha).slice(0, 7) }) : t('history.noEarlier'),
|
|
41
|
+
aria: { expanded: 'false', label: from ? t('history.showCommits', { sha: short(r.sha).slice(0, 7) }) : t('history.noEarlier') },
|
|
39
42
|
on: { click: () => { void toggleChanges(app, from, r.sha, row, detailRow, detail, toggle); } },
|
|
40
43
|
}, icon('chevron'));
|
|
41
44
|
const subject = Object.hasOwn(known, r.sha) ? clean(known[r.sha]) : '';
|
|
42
|
-
const row = el('tr', { class: 'release-row' }, el('td', { class: 'disclosure' }, toggle), el('td', { class: 'release-commit' }, el('code', {}, short(r.sha).slice(0, 7)), subject ? el('span', { class: 'release-subject', title: subject }, subject) : null), el('td', { class: 'nowrap num' }, when(r.at)), el('td', {}, pill(r.status === 'ok' ? 'ok' : 'err', r.status)), el('td', {}, r.actor ?? r.user), el('td', { class: 'muted' }, r.via ?? ''), el('td', { class: 'mono' }, r.client ?? ''), el('td', { class: 'mono wrap' }, r.migrations.join(', ')), el('td', { class: 'mono wrap' }, r.backup ?? ''), el('td', { class: 'wrap' }, r.note ?? ''));
|
|
45
|
+
const row = el('tr', { class: 'release-row' }, el('td', { class: 'disclosure' }, toggle), el('td', { class: 'release-commit' }, el('code', {}, short(r.sha).slice(0, 7)), subject ? el('span', { class: 'release-subject', title: subject }, subject) : null), el('td', { class: 'nowrap num' }, when(r.at)), el('td', {}, pill(r.status === 'ok' ? 'ok' : 'err', releaseStatus(r.status))), el('td', {}, r.actor ?? r.user), el('td', { class: 'muted' }, r.via ?? ''), el('td', { class: 'mono' }, r.client ?? ''), el('td', { class: 'mono wrap' }, r.migrations.join(', ')), el('td', { class: 'mono wrap' }, r.backup ?? ''), el('td', { class: 'wrap' }, r.note ?? ''));
|
|
43
46
|
return [row, detailRow];
|
|
44
47
|
}))));
|
|
45
48
|
}
|
|
46
49
|
/** The server's answer to `commits`, as a block: an older deploy that does not know the command is said plainly. */
|
|
47
50
|
function commitsReply(reply, labels, order) {
|
|
48
51
|
if (reply.error?.code === 'usage' && /unknown command/.test(clean(reply.error.message)))
|
|
49
|
-
return unavailable('
|
|
52
|
+
return unavailable(t('commits.olderDeploy'));
|
|
50
53
|
if (!reply.ok && !reply.result)
|
|
51
|
-
return problem(reply) ?? unavailable('
|
|
54
|
+
return problem(reply) ?? unavailable(t('commits.noAnswer'));
|
|
52
55
|
const result = reply.result;
|
|
53
56
|
return commitsBlock(result?.commits, labels, order);
|
|
54
57
|
}
|
|
@@ -59,10 +62,10 @@ async function toggleChanges(app, from, to, row, detailRow, cell, toggle) {
|
|
|
59
62
|
toggle.setAttribute('aria-expanded', String(open));
|
|
60
63
|
if (!open || cell.dataset['loaded'] === 'yes')
|
|
61
64
|
return;
|
|
62
|
-
replace(cell, el('div', { class: 'commits-note' }, icon('refresh'), el('span', {}, '
|
|
65
|
+
replace(cell, el('div', { class: 'commits-note' }, icon('refresh'), el('span', {}, t('history.reading'))));
|
|
63
66
|
try {
|
|
64
67
|
const reply = await app.commits(from, to);
|
|
65
|
-
replace(cell, commitsReply(reply, { added: '
|
|
68
|
+
replace(cell, commitsReply(reply, { added: t('history.broughtIn'), removed: t('history.takenOut'), same: t('history.same') }));
|
|
66
69
|
if (reply.ok)
|
|
67
70
|
cell.dataset['loaded'] = 'yes';
|
|
68
71
|
}
|
|
@@ -77,55 +80,57 @@ async function readPreview(app, to) {
|
|
|
77
80
|
reply = await app.rollbackPreview(to || undefined);
|
|
78
81
|
}
|
|
79
82
|
catch (error) {
|
|
80
|
-
return { lines: ['
|
|
83
|
+
return { lines: [t('history.previewFailed')], block: problem(undefined, error) ?? unavailable(t('commits.noAnswer')) };
|
|
81
84
|
}
|
|
82
85
|
const result = reply.result;
|
|
83
|
-
const block = commitsReply(reply, { removed: '
|
|
86
|
+
const block = commitsReply(reply, { removed: t('history.leaves'), added: t('history.comesBack'), same: t('history.nothingChanges') }, ['removed', 'added']);
|
|
84
87
|
const commits = result?.commits;
|
|
85
88
|
if (!validCommits(commits))
|
|
86
|
-
return { lines: ['
|
|
89
|
+
return { lines: [t('history.previewUnavailable')], block };
|
|
87
90
|
if (!commits.ok)
|
|
88
|
-
return { lines: [
|
|
91
|
+
return { lines: [t('history.previewReason', { reason: reasonText(commits.reason) })], block };
|
|
89
92
|
const r = commits.range;
|
|
90
93
|
return {
|
|
91
94
|
...(typeof result?.to === 'string' ? { to: result.to } : {}),
|
|
92
95
|
block,
|
|
93
96
|
lines: [
|
|
94
|
-
r.removedTotal > 0 ? commitSummary('removed', '
|
|
95
|
-
r.addedTotal > 0 ? commitSummary('added', '
|
|
97
|
+
r.removedTotal > 0 ? commitSummary('removed', t('history.leaves'), r.removed, r.removedTotal) : t('history.noneLeaves'),
|
|
98
|
+
r.addedTotal > 0 ? commitSummary('added', t('history.comesBack'), r.added, r.addedTotal, 4) : null,
|
|
96
99
|
],
|
|
97
100
|
};
|
|
98
101
|
}
|
|
99
102
|
async function showPreview(app, to, area) {
|
|
100
|
-
replace(area, el('div', { class: 'commits-note' }, icon('refresh'), el('span', {}, '
|
|
103
|
+
replace(area, el('div', { class: 'commits-note' }, icon('refresh'), el('span', {}, t('history.reading'))));
|
|
101
104
|
replace(area, (await readPreview(app, to)).block);
|
|
102
105
|
}
|
|
103
106
|
async function rollback(app, to, message, area) {
|
|
104
|
-
const
|
|
105
|
-
if (!
|
|
107
|
+
const target = app.current;
|
|
108
|
+
if (!target)
|
|
106
109
|
return;
|
|
107
|
-
replace(area, el('div', { class: 'commits-note' }, icon('refresh'), el('span', {}, '
|
|
110
|
+
replace(area, el('div', { class: 'commits-note' }, icon('refresh'), el('span', {}, t('history.readingLeaving'))));
|
|
108
111
|
const preview = await readPreview(app, to);
|
|
109
112
|
replace(area, preview.block);
|
|
110
113
|
const ok = await confirmDialog({
|
|
111
|
-
title:
|
|
112
|
-
context:
|
|
114
|
+
title: t('history.rollBackTitle', { name: target.name }),
|
|
115
|
+
context: [target.ssh, target.dir, app.hello ? t('ctx.hostPart', { host: app.hello.host }) : null].filter(Boolean).join(' · '),
|
|
113
116
|
lines: [
|
|
114
|
-
to ?
|
|
117
|
+
to ? t('history.backToSha', { sha: short(to).slice(0, 7) })
|
|
118
|
+
: preview.to ? t('history.backToLastHealthyNow', { sha: short(preview.to).slice(0, 7) })
|
|
119
|
+
: t('history.backToLastHealthy'),
|
|
115
120
|
...preview.lines,
|
|
116
|
-
'
|
|
121
|
+
t('history.heldUntil'),
|
|
117
122
|
],
|
|
118
|
-
confirmLabel: '
|
|
123
|
+
confirmLabel: t('history.rollBackConfirm'),
|
|
119
124
|
danger: true,
|
|
120
|
-
...(
|
|
125
|
+
...(target.protected ? { typeToConfirm: target.name } : {}),
|
|
121
126
|
});
|
|
122
127
|
if (!ok)
|
|
123
128
|
return;
|
|
124
|
-
replace(message, el('p', { class: 'muted' }, '
|
|
129
|
+
replace(message, el('p', { class: 'muted' }, t('history.starting')));
|
|
125
130
|
let reply;
|
|
126
131
|
try {
|
|
127
132
|
// Exactly what it sent before the preview existed: the deploy still decides the target when none was picked.
|
|
128
|
-
reply = await app.api.post('rollback', { target:
|
|
133
|
+
reply = await app.api.post('rollback', { target: target.name, confirm: true, confirmedTarget: target, ...(target.protected ? { confirmName: target.name } : {}), ...(to ? { to } : {}) });
|
|
129
134
|
}
|
|
130
135
|
catch (error) {
|
|
131
136
|
replace(message, problem(undefined, error));
|
|
@@ -137,7 +142,7 @@ async function rollback(app, to, message, area) {
|
|
|
137
142
|
replace(message);
|
|
138
143
|
if (preview.to)
|
|
139
144
|
app.previewedRollbacks.set(result.runId, preview.to);
|
|
140
|
-
app.watch(result.runId,
|
|
145
|
+
app.watch(result.runId, t('run.rollbackTitle', { runId: result.runId }));
|
|
141
146
|
return;
|
|
142
147
|
}
|
|
143
148
|
replace(message, problem(reply));
|