Files
EchoionWeb/frontend/src/views/UpdatesView.tsx
T
faumaray 3632f2cd43 update
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-25 23:44:48 +03:00

1208 lines
32 KiB
TypeScript

import {
useCallback,
useEffect,
useMemo,
useState,
type ReactNode,
} from 'react';
import { t, tf } from '../i18n';
import { appStore, safeCall, toast } from '../lib/app';
import { confirmDialog, promptDialog } from '../lib/dialog';
import { rpc } from '../lib/rpc';
import { useStore } from '../lib/store';
import {
cloneUpdateConfig,
configForSave,
isValidSourceId,
normalizeUpdateConfig,
normalizeUpdateStatus,
type ComponentUpdatePolicy,
type ComponentUpdateStatus,
type PluginUpdateStatus,
type UpdateCandidate,
type UpdateComponent,
type UpdateConfig,
type UpdateSourceConfig,
type UpdateStatus,
} from '../lib/updates';
const COMPONENTS: readonly UpdateComponent[] = [
'runtime',
'core',
'plugins',
];
function componentLabel(component: UpdateComponent): string {
if (component === 'runtime') return t('Runtime bundle');
if (component === 'core') return t('Core');
return t('Plugins');
}
function formatTimestamp(value?: string | number): string {
if (value === undefined || value === '') return t('Never');
const numeric = typeof value === 'number' ? value : Number(value);
const date = Number.isFinite(numeric)
? new Date(numeric < 10_000_000_000 ? numeric * 1000 : numeric)
: new Date(value);
return Number.isNaN(date.getTime()) ? String(value) : date.toLocaleString();
}
function stateTone(state?: string): string {
const value = (state || '').toLowerCase();
if (
value.includes('fail') ||
value.includes('error') ||
value.includes('quarantine')
) return 'danger';
if (
value.includes('ready') ||
value.includes('healthy') ||
value.includes('current') ||
value.includes('success')
) return 'success';
if (
value.includes('pending') ||
value.includes('stage') ||
value.includes('download') ||
value.includes('wait')
) return 'warning';
return 'neutral';
}
function looksLikeStatusPayload(payload: unknown): boolean {
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
return false;
}
const value = payload as Record<string, unknown>;
return (
'components' in value ||
'runtime' in value ||
'core' in value ||
('status' in value && typeof value.status === 'object')
);
}
function StatusBadge(props: { children: ReactNode; tone?: string }) {
return (
<span className={`update-badge ${props.tone || 'neutral'}`}>
{props.children}
</span>
);
}
function CandidateBadges({ candidate }: { candidate: UpdateCandidate }) {
return (
<div className="update-badges" aria-label={t('Candidate attributes')}>
<StatusBadge tone={candidate.signed === false ? 'danger' : 'success'}>
{candidate.signed === false ? t('Unsigned') : t('Signed')}
</StatusBadge>
{candidate.downgrade && (
<StatusBadge tone="warning">{t('Downgrade')}</StatusBadge>
)}
{candidate.compatible === false && (
<StatusBadge tone="danger">{t('Incompatible')}</StatusBadge>
)}
{candidate.requiresRestart && (
<StatusBadge tone="warning">{t('Restart required')}</StatusBadge>
)}
</div>
);
}
function ComponentCard(props: {
status: ComponentUpdateStatus;
busy: boolean;
onApply: () => void;
onRollback: () => void;
}) {
const candidate = props.status.candidate;
const component = props.status.component;
return (
<article className="update-component-card">
<div className="update-component-head">
<div className={`update-component-mark ${component}`} aria-hidden="true">
{component === 'runtime' ? 'R' : component === 'core' ? 'C' : 'P'}
</div>
<div>
<h2>{componentLabel(component)}</h2>
<p className="muted mono">
{props.status.source || t('default source')} ·{' '}
{props.status.channel || t('stable')}
</p>
</div>
<StatusBadge tone={stateTone(props.status.state)}>
{props.status.state || t('Idle')}
</StatusBadge>
</div>
<div className="update-version-line">
<div>
<span>{t('Installed')}</span>
<strong>{props.status.currentVersion || '—'}</strong>
</div>
<span className="update-version-arrow" aria-hidden="true">→</span>
<div>
<span>{t('Available')}</span>
<strong>{candidate?.version || t('Up to date')}</strong>
</div>
</div>
{candidate && <CandidateBadges candidate={candidate} />}
{(candidate?.message || props.status.message) && (
<p className="update-card-message">
{candidate?.message || props.status.message}
</p>
)}
<div className="update-card-actions">
<button
className="btn btn-accent"
disabled={
props.busy ||
!candidate ||
candidate.compatible === false
}
onClick={props.onApply}
>
{candidate ? tf('Apply {0}', candidate.version) : t('No update')}
</button>
<button
className="btn btn-ghost"
disabled={props.busy || !props.status.rollbackVersion}
onClick={props.onRollback}
>
{props.status.rollbackVersion
? tf('Rollback to {0}', props.status.rollbackVersion)
: t('No rollback')}
</button>
</div>
</article>
);
}
function PolicyEditor(props: {
component: UpdateComponent;
policy: ComponentUpdatePolicy;
sourceIds: string[];
onChange: (policy: ComponentUpdatePolicy) => void;
}) {
const label = componentLabel(props.component);
return (
<div className="update-policy-row">
<div className="update-policy-name">
<strong>{label}</strong>
<label className="update-switch">
<input
type="checkbox"
checked={props.policy.enabled}
onChange={(event) =>
props.onChange({
...props.policy,
enabled: event.target.checked,
})
}
/>
<span>{t('Enabled')}</span>
</label>
</div>
<label className="update-field">
<span>{t('Source')}</span>
<select
aria-label={tf('{0} source', label)}
value={props.policy.source}
onChange={(event) =>
props.onChange({
...props.policy,
source: event.target.value,
})
}
>
{props.sourceIds.map((source) => (
<option key={source} value={source}>{source}</option>
))}
</select>
</label>
<label className="update-field">
<span>{t('Channel')}</span>
<input
aria-label={tf('{0} channel', label)}
value={props.policy.channel}
onChange={(event) =>
props.onChange({
...props.policy,
channel: event.target.value,
})
}
/>
</label>
<label className="update-switch update-auto-switch">
<input
type="checkbox"
checked={props.policy.autoApply}
onChange={(event) =>
props.onChange({
...props.policy,
autoApply: event.target.checked,
})
}
/>
<span>{t('Auto-apply')}</span>
</label>
</div>
);
}
function SourceEditor(props: {
id: string;
source: UpdateSourceConfig;
canDelete: boolean;
onChange: (source: UpdateSourceConfig) => void;
onDelete: () => void;
}) {
function updateKey(index: number, field: 'id' | 'ed25519', value: string) {
const keys = props.source.publicKeys.map((key, keyIndex) =>
keyIndex === index ? { ...key, [field]: value } : key
);
props.onChange({ ...props.source, publicKeys: keys });
}
return (
<fieldset className="update-source-card">
<legend>
<span className="mono">{props.id}</span>
{props.id === 'official' && (
<StatusBadge tone="success">{t('Build default')}</StatusBadge>
)}
</legend>
<div className="update-source-grid">
<label className="update-field update-field-wide">
<span>{t('Feed URL')}</span>
<input
type="url"
placeholder={
props.id === 'official'
? t('Empty uses the release build default')
: 'https://updates.example/feed.json'
}
value={props.source.url}
onChange={(event) =>
props.onChange({
...props.source,
url: event.target.value,
})
}
/>
</label>
<label className="update-field">
<span>{t('Bearer token environment variable')}</span>
<input
value={props.source.bearerTokenEnv}
placeholder="ECHOION_UPDATE_TOKEN"
autoComplete="off"
onChange={(event) =>
props.onChange({
...props.source,
bearerTokenEnv: event.target.value,
})
}
/>
<small>
{props.source.bearerTokenEnv
? props.source.bearerTokenPresent === true
? t('Secret is present in the service environment')
: props.source.bearerTokenPresent === false
? t('Secret is missing from the service environment')
: t('Secret presence was not reported')
: t('No bearer token configured')}
</small>
</label>
<label className="update-switch update-unsigned-switch">
<input
type="checkbox"
checked={props.source.allowUnsigned}
onChange={(event) =>
props.onChange({
...props.source,
allowUnsigned: event.target.checked,
})
}
/>
<span>{t('Permit manual unsigned staging')}</span>
</label>
</div>
<div className="update-key-head">
<div>
<strong>{t('Ed25519 trust keys')}</strong>
<p className="muted">
{t('Only public verification keys belong here.')}
</p>
</div>
<button
type="button"
className="btn btn-ghost"
onClick={() =>
props.onChange({
...props.source,
publicKeys: [
...props.source.publicKeys,
{ id: '', ed25519: '' },
],
})
}
>
{t('Add key')}
</button>
</div>
<div className="update-key-list">
{props.source.publicKeys.length ? (
props.source.publicKeys.map((key, index) => (
<div className="update-key-row" key={`${index}-${key.id}`}>
<label className="update-field">
<span>{t('Key ID')}</span>
<input
value={key.id}
onChange={(event) =>
updateKey(index, 'id', event.target.value)
}
/>
</label>
<label className="update-field update-key-value">
<span>{t('Public key')}</span>
<input
className="mono"
value={key.ed25519}
onChange={(event) =>
updateKey(index, 'ed25519', event.target.value)
}
/>
</label>
<button
type="button"
className="btn btn-danger-ghost update-key-remove"
aria-label={tf('Remove key {0}', key.id || index + 1)}
onClick={() =>
props.onChange({
...props.source,
publicKeys: props.source.publicKeys.filter(
(_, keyIndex) => keyIndex !== index
),
})
}
>
{t('Remove')}
</button>
</div>
))
) : (
<p className="muted update-empty-inline">
{t('No custom keys; the build-injected keyring is used when available.')}
</p>
)}
</div>
{props.canDelete && (
<div className="update-source-foot">
<button
type="button"
className="btn btn-danger-ghost"
onClick={props.onDelete}
>
{t('Remove source')}
</button>
</div>
)}
</fieldset>
);
}
function PluginRow(props: {
plugin: PluginUpdateStatus;
busy: boolean;
onApply: () => void;
onRollback: () => void;
}) {
const candidate = props.plugin.candidate;
return (
<div className="update-plugin-row">
<div className="update-plugin-main">
<strong>{props.plugin.name || props.plugin.id}</strong>
<span className="mono muted">{props.plugin.id}</span>
</div>
<StatusBadge tone={props.plugin.managed ? 'success' : 'neutral'}>
{props.plugin.managed ? t('Managed') : t('Unmanaged')}
</StatusBadge>
<div className="update-plugin-version mono">
{props.plugin.currentVersion || '—'}
{candidate && <> → {candidate.version}</>}
</div>
<div className="update-plugin-actions">
{props.plugin.managed && candidate && (
<button
className="btn btn-ghost"
disabled={
props.busy || candidate.compatible === false
}
onClick={props.onApply}
>
{t('Apply')}
</button>
)}
{props.plugin.managed && props.plugin.rollbackVersion && (
<button
className="btn btn-ghost"
disabled={props.busy}
onClick={props.onRollback}
>
{t('Rollback')}
</button>
)}
</div>
</div>
);
}
export function UpdatesView() {
const app = useStore(appStore);
const isAdmin = !!app.identity?.isAdmin;
const [status, setStatus] = useState<UpdateStatus | null>(null);
const [config, setConfig] = useState<UpdateConfig | null>(null);
const [draft, setDraft] = useState<UpdateConfig | null>(null);
const [dirty, setDirty] = useState(false);
const [loading, setLoading] = useState(false);
const [busy, setBusy] = useState('');
const loadStatus = useCallback(async () => {
const payload = await safeCall<unknown>('GetUpdateStatus');
if (payload !== null) setStatus(normalizeUpdateStatus(payload));
}, []);
const loadConfig = useCallback(async () => {
const payload = await safeCall<unknown>('GetUpdateConfig');
if (payload === null) return;
const next = normalizeUpdateConfig(payload);
setConfig(next);
setDraft(cloneUpdateConfig(next));
setDirty(false);
}, []);
const loadAll = useCallback(async () => {
setLoading(true);
await Promise.all([loadStatus(), loadConfig()]);
setLoading(false);
}, [loadConfig, loadStatus]);
useEffect(() => {
if (!isAdmin) return;
void loadAll();
return rpc.on('updates.changed', (payload) => {
if (looksLikeStatusPayload(payload)) {
setStatus(normalizeUpdateStatus(payload));
} else {
void loadStatus();
}
});
}, [isAdmin, loadAll, loadStatus]);
const sourceIds = useMemo(
() => Object.keys(draft?.sources || {}),
[draft?.sources]
);
function changeDraft(next: UpdateConfig) {
setDraft(next);
setDirty(true);
}
function changePolicy(
component: UpdateComponent,
policy: ComponentUpdatePolicy
) {
if (!draft) return;
if (component === 'plugins') {
changeDraft({
...draft,
plugins: { ...draft.plugins, ...policy },
});
return;
}
changeDraft({ ...draft, [component]: policy });
}
async function checkForUpdates() {
setBusy('check');
const payload = await safeCall<unknown>('CheckForUpdates');
if (payload !== null) {
await loadStatus();
toast(t('Update check completed'));
}
setBusy('');
}
async function confirmCandidate(
component: UpdateComponent,
candidate: UpdateCandidate,
pluginId?: string
): Promise<string | null | undefined> {
let confirmationToken: string | undefined;
if (candidate.signed === false) {
const phrase = `UNSIGNED ${candidate.version}`;
const entered = await promptDialog({
title: t('Confirm unsigned update'),
message: tf(
'This artifact has no trusted signature. Type {0} to authorize this exact candidate.',
phrase
),
placeholder: phrase,
confirmLabel: t('Authorize unsigned candidate'),
});
if (entered !== phrase) return null;
const approval = await safeCall<{ confirmationToken?: string }>(
'ConfirmUnsignedUpdate',
{
component,
pluginId,
candidateId: candidate.id || candidate.version,
version: candidate.version,
confirmation: phrase,
}
);
if (approval === null) return null;
confirmationToken = approval.confirmationToken;
}
if (candidate.downgrade) {
const entered = await promptDialog({
title: t('Confirm downgrade'),
message: t('A downgrade may make saved state incompatible. Type DOWNGRADE to continue.'),
placeholder: 'DOWNGRADE',
confirmLabel: t('Continue with downgrade'),
});
if (entered !== 'DOWNGRADE') return null;
}
if (component === 'runtime' || candidate.requiresRestart) {
const confirmed = await confirmDialog({
title: t('Restart Echoion'),
message: t('Applying this update restarts Echoion after it becomes idle. Continue?'),
confirmLabel: t('Apply and restart'),
});
if (!confirmed) return null;
}
return confirmationToken;
}
async function applyUpdate(
component: UpdateComponent,
candidate?: UpdateCandidate,
pluginId?: string
) {
if (!candidate || candidate.compatible === false) return;
const confirmationToken = await confirmCandidate(
component,
candidate,
pluginId
);
if (confirmationToken === null) return;
const key = `apply:${component}:${pluginId || ''}`;
setBusy(key);
const payload = await safeCall<unknown>('ApplyUpdate', {
component,
pluginId,
candidateId: candidate.id || candidate.version,
version: candidate.version,
confirmationToken,
});
if (payload !== null) {
await loadStatus();
toast(tf('{0} update queued', pluginId || componentLabel(component)));
}
setBusy('');
}
async function rollbackUpdate(
component: UpdateComponent,
version?: string,
pluginId?: string
) {
if (!version) return;
const confirmed = await confirmDialog({
title: t('Confirm rollback'),
message: tf('Roll back {0} to {1}?', pluginId || componentLabel(component), version),
confirmLabel: t('Rollback'),
danger: true,
});
if (!confirmed) return;
const key = `rollback:${component}:${pluginId || ''}`;
setBusy(key);
const payload = await safeCall<unknown>('RollbackUpdate', {
component,
pluginId,
version,
});
if (payload !== null) {
await loadStatus();
toast(t('Rollback queued'));
}
setBusy('');
}
async function saveConfig() {
if (!draft || !config) return;
const newlyUnsigned = Object.entries(draft.sources)
.filter(
([id, source]) =>
source.allowUnsigned && !config.sources[id]?.allowUnsigned
)
.map(([id]) => id);
if (newlyUnsigned.length) {
const entered = await promptDialog({
title: t('Enable unsigned update policy'),
message: tf(
'Unsigned staging will be permitted for: {0}. Type ENABLE UNSIGNED to save this policy.',
newlyUnsigned.join(', ')
),
placeholder: 'ENABLE UNSIGNED',
confirmLabel: t('Save unsafe policy'),
});
if (entered !== 'ENABLE UNSIGNED') return;
}
setBusy('save');
const payload = await safeCall<unknown>('SetUpdateConfig', {
config: configForSave(draft),
});
if (payload !== null) {
await loadConfig();
toast(t('Update policy saved'));
await loadStatus();
}
setBusy('');
}
async function addSource() {
if (!draft) return;
const id = await promptDialog({
title: t('Add update source'),
message: t('Use a short ID made from letters, numbers, dots, dashes, or underscores.'),
placeholder: 'private-stable',
confirmLabel: t('Add source'),
});
if (!id) return;
if (!isValidSourceId(id)) {
toast(t('Invalid source ID'));
return;
}
if (draft.sources[id]) {
toast(t('That source already exists'));
return;
}
changeDraft({
...draft,
sources: {
...draft.sources,
[id]: {
url: '',
publicKeys: [],
allowUnsigned: false,
bearerTokenEnv: '',
},
},
});
}
async function removeSource(id: string) {
if (!draft) return;
const used = COMPONENTS.some(
(component) => draft[component].source === id
) || Object.values(draft.plugins.overrides).some(
(override) => override.source === id
);
if (used) {
toast(t('Move every component off this source before removing it'));
return;
}
if (
!(await confirmDialog({
title: t('Remove update source'),
message: tf('Remove source {0} and its public keys?', id),
confirmLabel: t('Remove source'),
danger: true,
}))
) return;
const sources = { ...draft.sources };
delete sources[id];
changeDraft({ ...draft, sources });
}
async function addPluginOverride() {
if (!draft) return;
const id = await promptDialog({
title: t('Add plugin channel override'),
message: t('Enter the exact managed plugin ID.'),
placeholder: 'plugin.id',
confirmLabel: t('Add override'),
});
if (!id) return;
if (draft.plugins.overrides[id]) {
toast(t('That plugin override already exists'));
return;
}
changeDraft({
...draft,
plugins: {
...draft.plugins,
overrides: {
...draft.plugins.overrides,
[id]: {
source: draft.plugins.source,
channel: draft.plugins.channel,
autoApply: draft.plugins.autoApply,
},
},
},
});
}
if (!isAdmin) {
return (
<section className="view" id="view-updates">
<div className="card admin-guard">
<h2>{t('Administrator authentication required')}</h2>
<p className="muted">
{t('Update policy, trust keys, and activation controls are restricted to administrators.')}
</p>
</div>
</section>
);
}
return (
<section className="view updates-view" id="view-updates">
<div className="update-command-bar">
<div className="update-command-state">
<span
className={`update-beacon ${status?.enabled ? 'active' : ''}`}
aria-hidden="true"
/>
<div>
<strong>
{!status
? t('Loading update state…')
: status.enabled
? t('Automatic updates armed')
: t('Automatic updates paused')}
</strong>
<p className="muted">
{tf('Last check: {0}', formatTimestamp(status?.lastCheckAt))}
{status?.nextCheckAt && (
<> · {tf('Next: {0}', formatTimestamp(status.nextCheckAt))}</>
)}
</p>
</div>
</div>
<div className="row-gap">
<button
className="btn btn-ghost"
disabled={loading || !!busy}
onClick={() => void loadAll()}
>
{t('Refresh')}
</button>
<button
className="btn btn-accent"
disabled={loading || !!busy}
onClick={() => void checkForUpdates()}
>
{busy === 'check' ? t('Checking…') : t('Check now')}
</button>
</div>
</div>
<div className="update-live-region" role="status" aria-live="polite">
{loading ? t('Loading update state…') : status?.message || ''}
</div>
<div className="update-component-grid">
{status && COMPONENTS.map((component) => (
<ComponentCard
key={component}
status={status.components[component]}
busy={!!busy}
onApply={() =>
void applyUpdate(
component,
status.components[component].candidate
)
}
onRollback={() =>
void rollbackUpdate(
component,
status.components[component].rollbackVersion
)
}
/>
))}
</div>
<div className="updates-two-column">
<div className="card">
<div className="card-head">
<div>
<h2>{t('Installed plugins')}</h2>
<p className="muted">
{t('Only managed plugins participate in update activation.')}
</p>
</div>
<StatusBadge>
{status?.plugins.filter((plugin) => plugin.managed).length || 0} {t('managed')}
</StatusBadge>
</div>
<div className="update-plugin-list">
{status?.plugins.length ? status.plugins.map((plugin) => (
<PluginRow
key={plugin.id}
plugin={plugin}
busy={!!busy}
onApply={() =>
void applyUpdate('plugins', plugin.candidate, plugin.id)
}
onRollback={() =>
void rollbackUpdate(
'plugins',
plugin.rollbackVersion,
plugin.id
)
}
/>
)) : (
<p className="empty">{t('No installed plugins reported')}</p>
)}
</div>
</div>
<div className="card">
<div className="card-head">
<div>
<h2>{t('Update history')}</h2>
<p className="muted">{t('Checks, staging, activation, and rollback outcomes')}</p>
</div>
</div>
<div className="update-history-scroll">
<table className="update-history-table">
<thead>
<tr>
<th>{t('When')}</th>
<th>{t('Target')}</th>
<th>{t('Action')}</th>
<th>{t('Result')}</th>
</tr>
</thead>
<tbody>
{status?.history.length ? status.history.slice(0, 100).map((entry, index) => (
<tr key={`${entry.timestamp || 'event'}-${index}`}>
<td>{formatTimestamp(entry.timestamp)}</td>
<td>
<span>{entry.pluginId || entry.component || '—'}</span>
{entry.version && <small>{entry.version}</small>}
</td>
<td>{entry.action || '—'}</td>
<td title={entry.message}>
<StatusBadge tone={stateTone(entry.result)}>
{entry.result || t('Recorded')}
</StatusBadge>
</td>
</tr>
)) : (
<tr>
<td colSpan={4} className="empty">{t('No update history yet')}</td>
</tr>
)}
</tbody>
</table>
</div>
</div>
</div>
{draft && config && (
<form
className="update-config"
onSubmit={(event) => {
event.preventDefault();
void saveConfig();
}}
>
<div className="update-config-title">
<div>
<span className="update-kicker">{t('POLICY DECK')}</span>
<h2>{t('Automation and trust')}</h2>
<p className="muted">
{t('Configure timing, independent channels, feeds, and public trust roots.')}
</p>
</div>
<div className="row-gap">
<button
type="button"
className="btn btn-ghost"
disabled={!dirty || !!busy}
onClick={() => {
setDraft(cloneUpdateConfig(config));
setDirty(false);
}}
>
{t('Discard changes')}
</button>
<button
type="submit"
className="btn btn-accent"
disabled={!dirty || !!busy}
>
{busy === 'save' ? t('Saving…') : t('Save policy')}
</button>
</div>
</div>
<div className="card update-automation-card">
<div className="update-automation-grid">
<label className="update-switch update-master-switch">
<input
type="checkbox"
checked={draft.enabled}
onChange={(event) =>
changeDraft({
...draft,
enabled: event.target.checked,
})
}
/>
<span>{t('Enable the update scheduler')}</span>
</label>
<label className="update-field">
<span>{t('Check interval')}</span>
<input
value={draft.checkInterval}
onChange={(event) =>
changeDraft({ ...draft, checkInterval: event.target.value })
}
/>
</label>
<label className="update-field">
<span>{t('Schedule jitter')}</span>
<input
value={draft.jitter}
onChange={(event) =>
changeDraft({ ...draft, jitter: event.target.value })
}
/>
</label>
<label className="update-field">
<span>{t('Maintenance start (UTC)')}</span>
<input
type="time"
value={draft.maintenanceWindowUtc.start}
onChange={(event) =>
changeDraft({
...draft,
maintenanceWindowUtc: {
...draft.maintenanceWindowUtc,
start: event.target.value,
},
})
}
/>
</label>
<label className="update-field">
<span>{t('Maintenance duration')}</span>
<input
value={draft.maintenanceWindowUtc.duration}
onChange={(event) =>
changeDraft({
...draft,
maintenanceWindowUtc: {
...draft.maintenanceWindowUtc,
duration: event.target.value,
},
})
}
/>
</label>
<label className="update-field">
<span>{t('Maximum runtime deferral')}</span>
<input
value={draft.maxRuntimeDeferral}
onChange={(event) =>
changeDraft({ ...draft, maxRuntimeDeferral: event.target.value })
}
/>
</label>
<label className="update-field">
<span>{t('Previous healthy versions retained')}</span>
<input
type="number"
min={1}
max={10}
value={draft.retainHealthyVersions}
onChange={(event) =>
changeDraft({
...draft,
retainHealthyVersions: Number(event.target.value),
})
}
/>
</label>
</div>
</div>
<div className="card">
<div className="card-head">
<div>
<h2>{t('Component channels')}</h2>
<p className="muted">
{t('Selections remain independent; incompatible cohorts stay staged.')}
</p>
</div>
</div>
<div className="update-policy-list">
{COMPONENTS.map((component) => (
<PolicyEditor
key={component}
component={component}
policy={draft[component]}
sourceIds={sourceIds}
onChange={(policy) => changePolicy(component, policy)}
/>
))}
</div>
<label className="update-switch update-managed-only">
<input
type="checkbox"
checked
disabled
readOnly
/>
<span>{t('Never modify loose local plugin files')}</span>
</label>
</div>
<div className="card">
<div className="card-head">
<div>
<h2>{t('Plugin channel overrides')}</h2>
<p className="muted">{t('Pin individual managed plugins to another source or channel.')}</p>
</div>
<button type="button" className="btn btn-ghost" onClick={() => void addPluginOverride()}>
{t('Add override')}
</button>
</div>
<div className="update-override-list">
{Object.entries(draft.plugins.overrides).length ? Object.entries(draft.plugins.overrides).map(([id, policy]) => (
<div className="update-override-row" key={id}>
<span className="mono update-override-id">{id}</span>
<select
aria-label={tf('{0} source', id)}
value={policy.source}
onChange={(event) =>
changeDraft({
...draft,
plugins: {
...draft.plugins,
overrides: {
...draft.plugins.overrides,
[id]: { ...policy, source: event.target.value },
},
},
})
}
>
{sourceIds.map((source) => <option key={source} value={source}>{source}</option>)}
</select>
<input
aria-label={tf('{0} channel', id)}
value={policy.channel}
onChange={(event) =>
changeDraft({
...draft,
plugins: {
...draft.plugins,
overrides: {
...draft.plugins.overrides,
[id]: { ...policy, channel: event.target.value },
},
},
})
}
/>
<label className="update-switch">
<input
type="checkbox"
checked={policy.autoApply}
onChange={(event) =>
changeDraft({
...draft,
plugins: {
...draft.plugins,
overrides: {
...draft.plugins.overrides,
[id]: { ...policy, autoApply: event.target.checked },
},
},
})
}
/>
<span>{t('Auto-apply')}</span>
</label>
<button
type="button"
className="btn btn-danger-ghost"
onClick={() => {
const overrides = { ...draft.plugins.overrides };
delete overrides[id];
changeDraft({
...draft,
plugins: { ...draft.plugins, overrides },
});
}}
>
{t('Remove')}
</button>
</div>
)) : (
<p className="muted update-empty-inline">{t('No plugin overrides')}</p>
)}
</div>
</div>
<div className="update-sources-head">
<div>
<h2>{t('Sources and trust roots')}</h2>
<p className="muted">
{t('Secret values stay in the service environment and are never returned here.')}
</p>
</div>
<button type="button" className="btn btn-ghost" onClick={() => void addSource()}>
{t('Add source')}
</button>
</div>
<div className="update-source-list">
{Object.entries(draft.sources).map(([id, source]) => (
<SourceEditor
key={id}
id={id}
source={source}
canDelete={id !== 'official' && sourceIds.length > 1}
onChange={(next) =>
changeDraft({
...draft,
sources: { ...draft.sources, [id]: next },
})
}
onDelete={() => void removeSource(id)}
/>
))}
</div>
</form>
)}
</section>
);
}