@basaltkit/deploy-ui 0.2.2 → 0.4.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 +10 -2
- package/dist/client/api.js +6 -5
- package/dist/client/app.js +96 -31
- package/dist/client/dialog.js +3 -2
- package/dist/client/dom.js +2 -0
- package/dist/client/i18n-messages.js +14 -0
- package/dist/client/i18n.js +756 -0
- package/dist/client/icons.js +5 -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/view-commits.js +75 -0
- package/dist/client/view-history.js +112 -20
- package/dist/client/view-plan.js +45 -27
- package/dist/client/view-run.js +59 -49
- package/dist/client/view-status.js +27 -26
- package/dist/client/view-targets.js +26 -25
- package/dist/page.d.ts +2 -2
- package/dist/page.js +70 -1
- package/dist/server.js +28 -3
- package/dist/ssh.d.ts +6 -2
- package/dist/ssh.js +16 -2
- package/dist/targets.d.ts +6 -0
- package/dist/targets.js +8 -2
- package/package.json +4 -3
package/dist/client/icons.js
CHANGED
|
@@ -25,6 +25,11 @@ const PATHS = {
|
|
|
25
25
|
refresh: 'M20 11a8 8 0 0 0-14.6-4.5M4 3v4h4M4 13a8 8 0 0 0 14.6 4.5M20 21v-4h-4',
|
|
26
26
|
inbox: 'M3 13l3-8h12l3 8v6H3zM3 13h5l1.5 2h5L16 13h5',
|
|
27
27
|
tag: 'M3 12V4h8l10 10-8 8zM7.5 8h.01',
|
|
28
|
+
chevron: 'M9 6l6 6-6 6',
|
|
29
|
+
arrow: 'M5 12h14M13 6l6 6-6 6',
|
|
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
|
+
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',
|
|
32
|
+
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',
|
|
28
33
|
};
|
|
29
34
|
const SVG = 'http://www.w3.org/2000/svg';
|
|
30
35
|
export function icon(name, className = 'icon') {
|
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,75 @@
|
|
|
1
|
+
import { el } from './dom.js';
|
|
2
|
+
import { formatLocale, reasonText, t } from './i18n.js';
|
|
3
|
+
import { icon } from './icons.js';
|
|
4
|
+
import { clean, short } from './sanitize.js';
|
|
5
|
+
/**
|
|
6
|
+
* The commit lists (RFC 0009 §7): what a run would deploy, what a release
|
|
7
|
+
* changed, what a rollback would take out. Every field is the author's text
|
|
8
|
+
* — rendered as text nodes only, cleaned again here, never a link. A list
|
|
9
|
+
* that is missing or unavailable is said so and never disables an action.
|
|
10
|
+
*/
|
|
11
|
+
export { reasonText };
|
|
12
|
+
/** A shape check: anything from the server that is not a list of commits is "unavailable", never a crash. */
|
|
13
|
+
export function validCommits(value) {
|
|
14
|
+
if (typeof value !== 'object' || value === null)
|
|
15
|
+
return false;
|
|
16
|
+
const c = value;
|
|
17
|
+
if (c['ok'] === false)
|
|
18
|
+
return true;
|
|
19
|
+
const r = c['range'];
|
|
20
|
+
return c['ok'] === true && typeof r === 'object' && r !== null && Array.isArray(r['added']) && Array.isArray(r['removed'])
|
|
21
|
+
&& typeof r['addedTotal'] === 'number' && typeof r['removedTotal'] === 'number' && typeof r['from'] === 'string' && typeof r['to'] === 'string';
|
|
22
|
+
}
|
|
23
|
+
/** Why there is no list: a quiet note, never an error the operator must clear. */
|
|
24
|
+
export function unavailable(text) {
|
|
25
|
+
return el('div', { class: 'commits-note' }, icon('info'), el('span', {}, el('strong', {}, t('commits.unavailable')), ` — ${text}.`));
|
|
26
|
+
}
|
|
27
|
+
/** `1 Oct 2026, 10:00` in the page's language (the browser's variant of it); the exact time in the tooltip. */
|
|
28
|
+
function date(at) {
|
|
29
|
+
if (typeof at !== 'string')
|
|
30
|
+
return null;
|
|
31
|
+
const parsed = new Date(at);
|
|
32
|
+
if (Number.isNaN(parsed.getTime()))
|
|
33
|
+
return null;
|
|
34
|
+
return el('time', { title: clean(at) }, parsed.toLocaleString(formatLocale(), { dateStyle: 'medium', timeStyle: 'short' }));
|
|
35
|
+
}
|
|
36
|
+
function commitItem(c) {
|
|
37
|
+
const subject = clean(c.subject);
|
|
38
|
+
const author = clean(c.author);
|
|
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)));
|
|
40
|
+
}
|
|
41
|
+
/** The most commits the server sends per list (COMMITS_LIMIT): the page imports no code from the deploy package. */
|
|
42
|
+
const LIST_LIMIT = 50;
|
|
43
|
+
/** One side of a range: a heading with its sign and count, the commits newest first, and what the cap left out. */
|
|
44
|
+
export function commitGroup(tone, label, list, total) {
|
|
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);
|
|
46
|
+
}
|
|
47
|
+
/** `abc1234 → def5678`, for a card's head. */
|
|
48
|
+
export function rangeSpan(range) {
|
|
49
|
+
return el('span', { class: 'commit-span' }, el('code', {}, short(range.from).slice(0, 7)), icon('arrow'), el('code', {}, short(range.to).slice(0, 7)));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Both sides of a range, under their labels, or why there are none. An
|
|
53
|
+
* absent field (an older deploy on the server) is said plainly too.
|
|
54
|
+
*/
|
|
55
|
+
export function commitsBlock(value, labels, order = ['added', 'removed']) {
|
|
56
|
+
if (value === undefined)
|
|
57
|
+
return unavailable(t('commits.olderDeploy'));
|
|
58
|
+
if (!validCommits(value))
|
|
59
|
+
return unavailable(t('commits.unreadable'));
|
|
60
|
+
if (!value.ok)
|
|
61
|
+
return unavailable(reasonText(value.reason));
|
|
62
|
+
const r = value.range;
|
|
63
|
+
if (r.addedTotal === 0 && r.removedTotal === 0)
|
|
64
|
+
return el('div', { class: 'commits-note is-ok' }, icon('ok'), el('span', {}, labels.same));
|
|
65
|
+
const groups = {
|
|
66
|
+
added: r.addedTotal > 0 ? commitGroup('added', labels.added, r.added, r.addedTotal) : null,
|
|
67
|
+
removed: r.removedTotal > 0 ? commitGroup('removed', labels.removed, r.removed, r.removedTotal) : null,
|
|
68
|
+
};
|
|
69
|
+
return el('div', { class: 'commits' }, ...order.map((tone) => groups[tone]));
|
|
70
|
+
}
|
|
71
|
+
/** A compact list for a confirmation dialog: at most `max` commits, then how many more. */
|
|
72
|
+
export function commitSummary(tone, label, list, total, max = 8) {
|
|
73
|
+
const shown = list.slice(0, max);
|
|
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);
|
|
75
|
+
}
|
|
@@ -1,46 +1,136 @@
|
|
|
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
|
-
import { short } from './sanitize.js';
|
|
6
|
+
import { clean, short } from './sanitize.js';
|
|
7
|
+
import { commitsBlock, commitSummary, reasonText, unavailable, validCommits } from './view-commits.js';
|
|
6
8
|
/** History: the last 10 releases, and rollback (to the last healthy release, or one picked here). */
|
|
7
9
|
export function renderHistory(app) {
|
|
8
10
|
const status = app.status;
|
|
9
11
|
const releases = status?.releases ?? [];
|
|
10
12
|
const message = el('div', { aria: { live: 'polite' } });
|
|
13
|
+
const preview = el('div', { class: 'rollback-preview', aria: { live: 'polite' } });
|
|
11
14
|
const current = releases.find((r) => r.status === 'ok');
|
|
12
15
|
const choices = releases.filter((r) => r.status === 'ok' && r !== current);
|
|
13
|
-
const select = el('select', { id: 'rollback-to' }, el('option', { value: '' },
|
|
14
|
-
return el('section', { aria: { labelledby: 'history-title' } }, pageHead('history-title', '
|
|
15
|
-
el('div', { class: 'field' }, el('label', { for: 'rollback-to' }, '
|
|
16
|
-
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')),
|
|
20
|
+
preview,
|
|
17
21
|
message,
|
|
18
|
-
], { foot: [
|
|
22
|
+
], { foot: [
|
|
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' }),
|
|
25
|
+
] }) : null);
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
|
|
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);
|
|
29
|
+
/** The release each row is compared with: the one it was deployed over, else the next older one on record. */
|
|
30
|
+
const previousOf = (releases, index) => releases[index]?.previous || releases[index + 1]?.sha;
|
|
31
|
+
function table(app, releases, subjects) {
|
|
32
|
+
const known = typeof subjects === 'object' && subjects !== null ? subjects : {};
|
|
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) => {
|
|
35
|
+
const from = previousOf(releases, index);
|
|
36
|
+
const detail = el('td', { colspan: columns.length + 1, class: 'release-changes-cell' });
|
|
37
|
+
const detailRow = el('tr', { class: 'release-changes', hidden: true }, detail);
|
|
38
|
+
const toggle = el('button', {
|
|
39
|
+
type: 'button', class: 'disclosure-button', disabled: !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') },
|
|
42
|
+
on: { click: () => { void toggleChanges(app, from, r.sha, row, detailRow, detail, toggle); } },
|
|
43
|
+
}, icon('chevron'));
|
|
44
|
+
const subject = Object.hasOwn(known, r.sha) ? clean(known[r.sha]) : '';
|
|
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 ?? ''));
|
|
46
|
+
return [row, detailRow];
|
|
47
|
+
}))));
|
|
22
48
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (
|
|
49
|
+
/** The server's answer to `commits`, as a block: an older deploy that does not know the command is said plainly. */
|
|
50
|
+
function commitsReply(reply, labels, order) {
|
|
51
|
+
if (reply.error?.code === 'usage' && /unknown command/.test(clean(reply.error.message)))
|
|
52
|
+
return unavailable(t('commits.olderDeploy'));
|
|
53
|
+
if (!reply.ok && !reply.result)
|
|
54
|
+
return problem(reply) ?? unavailable(t('commits.noAnswer'));
|
|
55
|
+
const result = reply.result;
|
|
56
|
+
return commitsBlock(result?.commits, labels, order);
|
|
57
|
+
}
|
|
58
|
+
async function toggleChanges(app, from, to, row, detailRow, cell, toggle) {
|
|
59
|
+
const open = detailRow.hidden === true;
|
|
60
|
+
detailRow.hidden = !open;
|
|
61
|
+
row.classList.toggle('is-open', open);
|
|
62
|
+
toggle.setAttribute('aria-expanded', String(open));
|
|
63
|
+
if (!open || cell.dataset['loaded'] === 'yes')
|
|
64
|
+
return;
|
|
65
|
+
replace(cell, el('div', { class: 'commits-note' }, icon('refresh'), el('span', {}, t('history.reading'))));
|
|
66
|
+
try {
|
|
67
|
+
const reply = await app.commits(from, to);
|
|
68
|
+
replace(cell, commitsReply(reply, { added: t('history.broughtIn'), removed: t('history.takenOut'), same: t('history.same') }));
|
|
69
|
+
if (reply.ok)
|
|
70
|
+
cell.dataset['loaded'] = 'yes';
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
replace(cell, problem(undefined, error));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** What `rollback` would take out of production, read now (never from an older status). */
|
|
77
|
+
async function readPreview(app, to) {
|
|
78
|
+
let reply;
|
|
79
|
+
try {
|
|
80
|
+
reply = await app.rollbackPreview(to || undefined);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
return { lines: [t('history.previewFailed')], block: problem(undefined, error) ?? unavailable(t('commits.noAnswer')) };
|
|
84
|
+
}
|
|
85
|
+
const result = reply.result;
|
|
86
|
+
const block = commitsReply(reply, { removed: t('history.leaves'), added: t('history.comesBack'), same: t('history.nothingChanges') }, ['removed', 'added']);
|
|
87
|
+
const commits = result?.commits;
|
|
88
|
+
if (!validCommits(commits))
|
|
89
|
+
return { lines: [t('history.previewUnavailable')], block };
|
|
90
|
+
if (!commits.ok)
|
|
91
|
+
return { lines: [t('history.previewReason', { reason: reasonText(commits.reason) })], block };
|
|
92
|
+
const r = commits.range;
|
|
93
|
+
return {
|
|
94
|
+
...(typeof result?.to === 'string' ? { to: result.to } : {}),
|
|
95
|
+
block,
|
|
96
|
+
lines: [
|
|
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,
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function showPreview(app, to, area) {
|
|
103
|
+
replace(area, el('div', { class: 'commits-note' }, icon('refresh'), el('span', {}, t('history.reading'))));
|
|
104
|
+
replace(area, (await readPreview(app, to)).block);
|
|
105
|
+
}
|
|
106
|
+
async function rollback(app, to, message, area) {
|
|
107
|
+
const target = app.current;
|
|
108
|
+
if (!target)
|
|
26
109
|
return;
|
|
110
|
+
replace(area, el('div', { class: 'commits-note' }, icon('refresh'), el('span', {}, t('history.readingLeaving'))));
|
|
111
|
+
const preview = await readPreview(app, to);
|
|
112
|
+
replace(area, preview.block);
|
|
27
113
|
const ok = await confirmDialog({
|
|
28
|
-
title:
|
|
29
|
-
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(' · '),
|
|
30
116
|
lines: [
|
|
31
|
-
to ?
|
|
32
|
-
|
|
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'),
|
|
120
|
+
...preview.lines,
|
|
121
|
+
t('history.heldUntil'),
|
|
33
122
|
],
|
|
34
|
-
confirmLabel: '
|
|
123
|
+
confirmLabel: t('history.rollBackConfirm'),
|
|
35
124
|
danger: true,
|
|
36
|
-
...(
|
|
125
|
+
...(target.protected ? { typeToConfirm: target.name } : {}),
|
|
37
126
|
});
|
|
38
127
|
if (!ok)
|
|
39
128
|
return;
|
|
40
|
-
replace(message, el('p', { class: 'muted' }, '
|
|
129
|
+
replace(message, el('p', { class: 'muted' }, t('history.starting')));
|
|
41
130
|
let reply;
|
|
42
131
|
try {
|
|
43
|
-
|
|
132
|
+
// Exactly what it sent before the preview existed: the deploy still decides the target when none was picked.
|
|
133
|
+
reply = await app.api.post('rollback', { target: target.name, confirm: true, confirmedTarget: target, ...(target.protected ? { confirmName: target.name } : {}), ...(to ? { to } : {}) });
|
|
44
134
|
}
|
|
45
135
|
catch (error) {
|
|
46
136
|
replace(message, problem(undefined, error));
|
|
@@ -50,7 +140,9 @@ async function rollback(app, to, message) {
|
|
|
50
140
|
const result = reply.result;
|
|
51
141
|
if (reply.ok && result?.runId) {
|
|
52
142
|
replace(message);
|
|
53
|
-
|
|
143
|
+
if (preview.to)
|
|
144
|
+
app.previewedRollbacks.set(result.runId, preview.to);
|
|
145
|
+
app.watch(result.runId, t('run.rollbackTitle', { runId: result.runId }));
|
|
54
146
|
return;
|
|
55
147
|
}
|
|
56
148
|
replace(message, problem(reply));
|
package/dist/client/view-plan.js
CHANGED
|
@@ -1,40 +1,58 @@
|
|
|
1
1
|
import { confirmDialog } from './dialog.js';
|
|
2
2
|
import { append, button, card, el, emptyState, pageHead, replace } from './dom.js';
|
|
3
|
+
import { t } from './i18n.js';
|
|
3
4
|
import { icon } from './icons.js';
|
|
4
5
|
import { banner, describe, diagnosticsBlock, problem } from './reply.js';
|
|
5
6
|
import { ApiError } from './api.js';
|
|
7
|
+
import { commitsBlock, rangeSpan, validCommits } from './view-commits.js';
|
|
6
8
|
/** Plan & deploy: what a run would do, the questions it would ask, and the `.env` form. */
|
|
7
9
|
export function renderPlan(app) {
|
|
8
10
|
const reply = app.planReply;
|
|
9
11
|
const plan = app.plan;
|
|
10
|
-
const root = el('section', { aria: { labelledby: 'plan-title' } }, pageHead('plan-title', '
|
|
12
|
+
const root = el('section', { aria: { labelledby: 'plan-title' } }, pageHead('plan-title', t('screen.plan'), t('plan.sub'), button(app.planBusy ? t('plan.planning') : plan ? t('plan.again') : t('plan.run'), () => { void app.runPlan(); }, { disabled: app.planBusy, class: plan ? '' : 'primary' })));
|
|
11
13
|
if (!reply) {
|
|
12
14
|
append(root, app.planBusy
|
|
13
|
-
? emptyState('refresh', '
|
|
14
|
-
: emptyState('plan', '
|
|
15
|
+
? emptyState('refresh', t('plan.planning'), t('plan.planningText'))
|
|
16
|
+
: emptyState('plan', t('plan.none'), t('plan.noneText')));
|
|
15
17
|
return root;
|
|
16
18
|
}
|
|
17
19
|
if (!plan) {
|
|
18
|
-
append(root, problem(reply) ?? el('p', {}, '
|
|
20
|
+
append(root, problem(reply) ?? el('p', {}, t('plan.noneBack')));
|
|
19
21
|
return root;
|
|
20
22
|
}
|
|
21
23
|
append(root, ...findings(plan.findings));
|
|
24
|
+
append(root, outgoing(plan.commits));
|
|
22
25
|
if (plan.lines.length > 0) {
|
|
23
|
-
append(root, card('
|
|
26
|
+
append(root, card(t('plan.wouldDo'), [el('div', { class: 'table-wrap' }, el('table', { class: 'plan-lines' }, el('tbody', {}, ...plan.lines.map((line) => el('tr', {}, el('th', { scope: 'row' }, el('span', { class: 'step-chip' }, line.step)), el('td', {}, line.text))))))], { bodyClass: 'flush' }));
|
|
24
27
|
}
|
|
25
28
|
if (reply.diagnostics.length > 0)
|
|
26
29
|
append(root, diagnosticsBlock(reply.diagnostics));
|
|
27
30
|
append(root, deployForm(app, plan.questions, plan.blocking));
|
|
28
31
|
return root;
|
|
29
32
|
}
|
|
33
|
+
/** What a run would deploy: HEAD on the server to the branch's tip on its remote. */
|
|
34
|
+
function outgoing(commits) {
|
|
35
|
+
const range = validCommits(commits) && commits.ok ? commits.range : undefined;
|
|
36
|
+
const summary = !range ? null
|
|
37
|
+
: range.relation === 'ahead' ? t('plan.commitCount', { count: range.addedTotal })
|
|
38
|
+
: range.relation === 'diverged' ? t('plan.diverged', { added: range.addedTotal, removed: range.removedTotal })
|
|
39
|
+
: range.relation === 'behind' ? t('plan.behindCount', { count: range.removedTotal })
|
|
40
|
+
: null;
|
|
41
|
+
return card(t('plan.goesOutTitle'), [
|
|
42
|
+
range?.relation === 'diverged' ? banner('warn', t('plan.rewritten'), [t('plan.rewrittenHelp')]) : null,
|
|
43
|
+
range?.relation === 'behind' ? banner('warn', t('plan.behind'), [t('plan.behindHelp')]) : null,
|
|
44
|
+
range?.held ? banner('warn', t('plan.heldByRollback'), [t('plan.heldByRollbackHelp')]) : null,
|
|
45
|
+
commitsBlock(commits, { added: t('plan.goesOut'), removed: t('plan.onlyOnServer'), same: t('plan.nothingNew') }),
|
|
46
|
+
], { actions: range && range.relation !== 'same' ? [summary ? el('span', { class: 'muted' }, summary) : null, rangeSpan(range)] : [] });
|
|
47
|
+
}
|
|
30
48
|
function findings(list) {
|
|
31
49
|
if (list.length === 0)
|
|
32
|
-
return [banner('ok', '
|
|
50
|
+
return [banner('ok', t('plan.noProblem'))];
|
|
33
51
|
const sorted = [...list].sort((a, b) => (a.level === b.level ? 0 : a.level === 'error' ? -1 : 1));
|
|
34
52
|
const errors = list.filter((f) => f.level === 'error').length;
|
|
35
|
-
return [card('
|
|
53
|
+
return [card(t('plan.findings'), [findingList(sorted)], {
|
|
36
54
|
bodyClass: 'flush',
|
|
37
|
-
actions: [el('span', { class: 'muted' }, `${errors
|
|
55
|
+
actions: [el('span', { class: 'muted' }, `${t('plan.errors', { count: errors })}, ${t('plan.warnings', { count: list.length - errors })}`)],
|
|
38
56
|
})];
|
|
39
57
|
}
|
|
40
58
|
/** Findings with a severity badge; the fix is copyable text, never run by the page. */
|
|
@@ -42,24 +60,24 @@ export function findingList(list, label) {
|
|
|
42
60
|
return el('ul', { class: 'findings', ...(label ? { aria: { label } } : {}) }, ...list.map((f) => findingItem(f)));
|
|
43
61
|
}
|
|
44
62
|
export function findingItem(f) {
|
|
45
|
-
return el('li', { class: 'finding' }, el('span', { class: `sev sev-${f.level === 'error' ? 'error' : 'warning'}` }, f.level === 'error' ? '
|
|
63
|
+
return el('li', { class: 'finding' }, el('span', { class: `sev sev-${f.level === 'error' ? 'error' : 'warning'}` }, f.level === 'error' ? t('sev.error') : t('sev.warning')), el('span', { class: 'finding-msg' }, f.id ? el('span', { class: 'finding-id' }, `[${f.id}] `) : null, f.message), f.fix ? el('div', { class: 'fix' }, el('span', { class: 'fix-label' }, t('plan.fix')), el('code', {}, f.fix)) : null);
|
|
46
64
|
}
|
|
47
65
|
function questionField(question, index) {
|
|
48
66
|
const id = `q-${index}`;
|
|
49
|
-
const label = el('label', { for: id }, question.message, question.optional ? '' : el('span', { class: 'required', title: 'required' }, ' *'), question.key ? el('span', { class: 'field-key' }, ` (${question.key})`) : null);
|
|
67
|
+
const label = el('label', { for: id }, question.message, question.optional ? '' : el('span', { class: 'required', title: t('form.required') }, ' *'), question.key ? el('span', { class: 'field-key' }, ` (${question.key})`) : null);
|
|
50
68
|
let input;
|
|
51
69
|
if (question.kind === 'secret') {
|
|
52
70
|
// No default, no autocomplete, no spellcheck: a secret is typed, sent once, and the field is emptied.
|
|
53
71
|
input = el('input', { type: 'password', id, autocomplete: 'off', spellcheck: false, required: !question.optional, aria: { describedby: `${id}-error` } });
|
|
54
72
|
}
|
|
55
73
|
else if (question.kind === 'choice') {
|
|
56
|
-
input = el('select', { id, aria: { describedby: `${id}-error` } }, ...(question.optional ? [el('option', { value: '' }, '
|
|
74
|
+
input = el('select', { id, aria: { describedby: `${id}-error` } }, ...(question.optional ? [el('option', { value: '' }, t('form.none'))] : []), ...(question.choices ?? []).map((c) => el('option', { value: c }, c)));
|
|
57
75
|
if (question.default !== undefined)
|
|
58
76
|
input.value = question.default;
|
|
59
77
|
}
|
|
60
78
|
else if (question.kind === 'confirm') {
|
|
61
79
|
input = el('input', { type: 'checkbox', id, checked: question.default === 'yes' || question.default === 'true', aria: { describedby: `${id}-error` } });
|
|
62
|
-
return { node: el('div', { class: 'field check' }, el('label', { for: id }, input, el('span', {}, question.message, question.optional ? '' : el('span', { class: 'required', title: 'required' }, ' *'), question.key ? el('span', { class: 'field-key' }, ` (${question.key})`) : null)), el('span', { id: `${id}-error`, class: 'field-error' })), field: { question, input } };
|
|
80
|
+
return { node: el('div', { class: 'field check' }, el('label', { for: id }, input, el('span', {}, question.message, question.optional ? '' : el('span', { class: 'required', title: t('form.required') }, ' *'), question.key ? el('span', { class: 'field-key' }, ` (${question.key})`) : null)), el('span', { id: `${id}-error`, class: 'field-error' })), field: { question, input } };
|
|
63
81
|
}
|
|
64
82
|
else {
|
|
65
83
|
input = el('input', { type: 'text', id, value: question.default ?? '', autocomplete: 'off', spellcheck: false, required: !question.optional, aria: { describedby: `${id}-error` } });
|
|
@@ -87,7 +105,7 @@ function clearFields(fields) {
|
|
|
87
105
|
}
|
|
88
106
|
}
|
|
89
107
|
function deployForm(app, questions, blocking) {
|
|
90
|
-
const
|
|
108
|
+
const target = app.current;
|
|
91
109
|
const fields = [];
|
|
92
110
|
const nodes = questions.map((q, i) => {
|
|
93
111
|
const { node, field } = questionField(q, i);
|
|
@@ -105,7 +123,7 @@ function deployForm(app, questions, blocking) {
|
|
|
105
123
|
replace(slot, text);
|
|
106
124
|
};
|
|
107
125
|
const send = async (route) => {
|
|
108
|
-
if (!
|
|
126
|
+
if (!target)
|
|
109
127
|
return;
|
|
110
128
|
replace(message);
|
|
111
129
|
for (let i = 0; i < questions.length; i++) {
|
|
@@ -115,33 +133,33 @@ function deployForm(app, questions, blocking) {
|
|
|
115
133
|
}
|
|
116
134
|
const deploy = route === 'run';
|
|
117
135
|
const ok = await confirmDialog({
|
|
118
|
-
title: deploy ?
|
|
119
|
-
context:
|
|
136
|
+
title: deploy ? t('plan.deployTo', { name: target.name }) : t('plan.writeEnvOn', { name: target.name }),
|
|
137
|
+
context: [target.ssh, target.dir, app.hello ? t('ctx.hostPart', { host: app.hello.host }) : null, app.status ? t('ctx.appPart', { app: app.status.app }) : null].filter(Boolean).join(' · '),
|
|
120
138
|
lines: [
|
|
121
|
-
deploy ? '
|
|
122
|
-
deploy && app.plan?.lines.some((l) => /migrat/i.test(l.step) || /migrat/i.test(l.text)) ? el('strong', {}, '
|
|
139
|
+
deploy ? t('plan.deployLine') : t('plan.envLine'),
|
|
140
|
+
deploy && app.plan?.lines.some((l) => /migrat/i.test(l.step) || /migrat/i.test(l.text)) ? el('strong', {}, t('plan.willMigrate')) : null,
|
|
123
141
|
],
|
|
124
|
-
confirmLabel: deploy ? '
|
|
142
|
+
confirmLabel: deploy ? t('plan.deploy') : t('plan.writeEnv'),
|
|
125
143
|
danger: true,
|
|
126
|
-
...(
|
|
144
|
+
...(target.protected ? { typeToConfirm: target.name } : {}),
|
|
127
145
|
});
|
|
128
146
|
if (!ok)
|
|
129
147
|
return;
|
|
130
148
|
const answers = collectAnswers(fields);
|
|
131
149
|
clearFields(fields);
|
|
132
|
-
const body = { target:
|
|
150
|
+
const body = { target: target.name, confirm: true, confirmedTarget: target, answers, ...(target.protected ? { confirmName: target.name } : {}) };
|
|
133
151
|
if (!deploy) {
|
|
134
|
-
app.attended(
|
|
152
|
+
app.attended(t('plan.envOn', { name: target.name }), 'env', body);
|
|
135
153
|
return;
|
|
136
154
|
}
|
|
137
155
|
if (unhold.checked)
|
|
138
156
|
body['unhold'] = true;
|
|
139
157
|
if (attended.checked) {
|
|
140
158
|
body['attended'] = true;
|
|
141
|
-
app.attended(
|
|
159
|
+
app.attended(t('plan.runAttended', { name: target.name }), 'run', body);
|
|
142
160
|
return;
|
|
143
161
|
}
|
|
144
|
-
replace(message, el('p', { class: 'muted' }, '
|
|
162
|
+
replace(message, el('p', { class: 'muted' }, t('plan.starting')));
|
|
145
163
|
let reply;
|
|
146
164
|
try {
|
|
147
165
|
reply = await app.api.post('run', body);
|
|
@@ -157,15 +175,15 @@ function deployForm(app, questions, blocking) {
|
|
|
157
175
|
const result = reply.result;
|
|
158
176
|
if (reply.ok && result?.runId) {
|
|
159
177
|
replace(message);
|
|
160
|
-
app.watch(result.runId,
|
|
178
|
+
app.watch(result.runId, t('run.title', { runId: result.runId }));
|
|
161
179
|
return;
|
|
162
180
|
}
|
|
163
181
|
if (reply.error && /^answer-/.test(reply.error.code)) {
|
|
164
182
|
const id = /env\.[A-Z_][A-Z0-9_]*/.exec(reply.error.message)?.[0];
|
|
165
183
|
if (id)
|
|
166
|
-
showFieldError(id,
|
|
184
|
+
showFieldError(id, t('plan.typeAgain', { message: reply.error.message }));
|
|
167
185
|
}
|
|
168
186
|
replace(message, problem(reply));
|
|
169
187
|
};
|
|
170
|
-
return el('form', { class: 'card', aria: { label: '
|
|
188
|
+
return el('form', { class: 'card', aria: { label: t('plan.deploy') }, on: { submit: (event) => { event.preventDefault(); void send('run'); } } }, el('div', { class: 'card-head' }, el('h3', {}, questions.length > 0 ? t('plan.willAsk') : t('plan.deploy')), target?.protected ? el('span', { class: 'badge badge-protected' }, icon('shield'), t('protected.badge')) : null), el('div', { class: 'card-body' }, el('p', { class: 'form-note' }, icon(questions.length > 0 ? 'lock' : 'ok'), questions.length > 0 ? t('plan.secrets') : t('plan.nothingToAnswer')), nodes.length > 0 ? el('div', { class: 'form-section' }, ...nodes) : null, el('div', { class: 'form-section' }, hold ? el('div', { class: 'field check' }, el('label', { for: 'unhold' }, unhold, el('span', {}, t('plan.unhold'), el('code', {}, hold.sha.slice(0, 12)), t('plan.unholdTail')))) : null, el('details', { class: 'advanced' }, el('summary', {}, t('plan.advanced')), el('div', { class: 'field check' }, el('label', { for: 'attended' }, attended, el('span', {}, t('plan.attended')))))), blocking ? banner('err', t('plan.blocks')) : null, message), el('div', { class: 'card-foot' }, button(t('plan.writeEnvOnly'), () => { void send('env'); }), el('button', { type: 'submit', class: 'primary', disabled: blocking }, t('plan.deployEllipsis'))));
|
|
171
189
|
}
|