Simplify failover settings UI
Build and Deploy Gateway / build-and-push (push) Successful in 25s
Build and Deploy Gateway / deploy (push) Successful in 7s

This commit is contained in:
2026-08-20 01:47:27 +03:00
parent 74227ae38c
commit c27c898ad5
5 changed files with 62 additions and 92 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
export const HARBOR_VERSIONS = Object.freeze({
macClient: '0.30.0',
gatewayClient: '0.31.0',
macClient: '0.30.1',
gatewayClient: '0.31.1',
gatewayBackend: '0.31.0',
});
+19 -42
View File
@@ -76,27 +76,26 @@ function pulseNumber(event: FormEvent<HTMLInputElement>) {
], { duration: 320, easing: 'cubic-bezier(0.16, 1, 0.3, 1)' });
}
function FailoverNumberSetting({ before, after, value, min, max, step = 10, disabled, ariaLabel, onChange, compact = false }: {
function FailoverNumberSetting({ before, after, value, min, max, disabled, ariaLabel, onChange }: {
before: string;
after: string;
value: number;
min: number;
max: number;
step?: number;
disabled?: boolean;
ariaLabel: string;
onChange: (value: number) => void;
compact?: boolean;
}) {
const set = (next: number) => onChange(Math.min(max, Math.max(min, next)));
return <div className={`client-failover-number-setting${compact ? ' is-compact' : ''}`}>
return <label className="client-failover-number-setting">
<span>{before}</span>
<input
className="client-failover-number-input"
type="number"
min={min}
max={max}
aria-label={ariaLabel}
value={value}
style={{ width: `${Math.max(2, String(value).length + 0.6)}ch` }}
disabled={disabled}
onInput={pulseNumber}
onChange={(event) => {
@@ -105,11 +104,7 @@ function FailoverNumberSetting({ before, after, value, min, max, step = 10, disa
}}
/>
<span>{after}</span>
<span className="client-failover-number-steps">
<button type="button" aria-label={`${ariaLabel}: уменьшить на ${step}`} disabled={disabled || value <= min} onClick={() => set(value - step)}>{step}</button>
<button type="button" aria-label={`${ariaLabel}: увеличить на ${step}`} disabled={disabled || value >= max} onClick={() => set(value + step)}>+{step}</button>
</span>
</div>;
</label>;
}
const reasonLabel = (reason: string | null) => ({
@@ -315,8 +310,6 @@ export function FailoverPanel({
const [serviceError, setServiceError] = useState('');
const [openPicker, setOpenPicker] = useState('');
const [removingCheckId, setRemovingCheckId] = useState('');
const [advancedOpen, setAdvancedOpen] = useState(false);
const [advancedClosing, setAdvancedClosing] = useState(false);
const [manualChecking, setManualChecking] = useState(false);
useEffect(() => {
if (!dirty) setDraft(snapshot.policy);
@@ -422,15 +415,6 @@ export function FailoverPanel({
if (!document.startViewTransition || matchMedia('(prefers-reduced-motion: reduce)').matches) finish();
else document.startViewTransition(finish);
};
const toggleAdvanced = () => {
if (!advancedOpen) {
setAdvancedOpen(true);
return;
}
if (matchMedia('(prefers-reduced-motion: reduce)').matches) setAdvancedOpen(false);
else setAdvancedClosing(true);
};
return <Drawer
panelRef={feature.panelRef}
closeRef={feature.closeRef}
@@ -510,7 +494,7 @@ export function FailoverPanel({
</section>
<fieldset className="client-failover-services">
<legend>Что проверять</legend>
<legend><span className="client-failover-section-header"><strong>Проверка доступности</strong><small>Harbor открывает эти адреса через оба канала и сравнивает результат.</small></span></legend>
{draft.checks.map((check) => {
const service = services.find(({ id }) => check.serviceId === id);
const removing = removingCheckId === check.serviceId;
@@ -525,12 +509,10 @@ export function FailoverPanel({
>
<span className="client-failover-service-name">{service?.label || 'Сервис недоступен'}</span>
<FailoverNumberSetting
compact
before="Ждать ответ не дольше"
after="секунд"
min={2}
max={30}
step={1}
ariaLabel={`Время ожидания ответа: ${service?.label || 'сервис недоступен'}`}
value={seconds(check.timeoutMs)}
disabled={blocked || !draft.enabled}
@@ -578,6 +560,10 @@ export function FailoverPanel({
</fieldset>
<section className="client-failover-timing" aria-label="Пороги переключения">
<header className="client-failover-section-header">
<h3>Когда переключать канал</h3>
<p>Harbor сначала подтверждает сбой и только затем переводит новые соединения на рабочий канал.</p>
</header>
<FailoverNumberSetting before="Проверять каналы каждые" after="секунд" min={15} max={900} ariaLabel="Интервал проверки каналов" value={seconds(draft.intervalMs)} disabled={blocked || !draft.enabled} onChange={(value) => update({ intervalMs: value * 1_000 })} />
<FailoverNumberSetting before="Считать основной недоступным после" after="секунд непрерывного сбоя" min={seconds(draft.intervalMs * 2)} max={1800} ariaLabel="Длительность сбоя основного канала" value={seconds(draft.failureWindowMs)} disabled={blocked || !draft.enabled} onChange={(value) => update({ failureWindowMs: value * 1_000 })} />
<FailoverNumberSetting before="Вернуться на основной после" after="секунд стабильной работы" min={60} max={86400} ariaLabel="Время стабильной работы основного канала" value={seconds(draft.recoveryWindowMs)} disabled={blocked || !draft.enabled} onChange={(value) => update({ recoveryWindowMs: value * 1_000 })} />
@@ -594,26 +580,17 @@ export function FailoverPanel({
<FailoverNumberSetting before="Считать работу активной при скорости от" after="КБ/с" min={1} max={102400} ariaLabel="Скорость активной работы" value={Math.round(draft.trafficGuard.thresholdBytesPerSecond / 1024)} disabled={blocked || !draft.enabled || !draft.trafficGuard.enabled} onChange={(value) => update({ trafficGuard: { ...draft.trafficGuard, thresholdBytesPerSecond: value * 1024 } })} />
</section>
<section className={`client-failover-advanced${advancedOpen ? ' is-open' : ''}${advancedClosing ? ' is-closing' : ''}`}>
<button type="button" aria-expanded={advancedOpen && !advancedClosing} aria-controls="client-failover-advanced-options" onClick={toggleAdvanced}>
<i aria-hidden="true" />
<span>Защита от повторных сбоев</span>
</button>
{advancedOpen && <div
id="client-failover-advanced-options"
className="client-failover-advanced-options"
inert={advancedClosing ? true : undefined}
onAnimationEnd={(event) => {
if (!advancedClosing || event.target !== event.currentTarget) return;
setAdvancedClosing(false);
setAdvancedOpen(false);
}}
>
<section className="client-failover-protection" aria-labelledby="client-failover-protection-title">
<header className="client-failover-section-header">
<h3 id="client-failover-protection-title">Защита от частых переключений</h3>
<p>Если основной канал падает снова, Harbor остаётся на резервном и даёт основному время восстановиться.</p>
</header>
<div className="client-failover-protection-options">
<FailoverNumberSetting before="Оставаться на резервном не меньше" after="секунд" min={60} max={86400} ariaLabel="Минимальное время на резервном канале" value={seconds(draft.minimumReserveMs)} disabled={blocked || !draft.enabled} onChange={(value) => update({ minimumReserveMs: value * 1_000 })} />
<FailoverNumberSetting before="Отправлять основной в карантин после" after="повторных сбоев" min={2} max={10} step={1} ariaLabel="Количество повторных сбоев" value={draft.flapProtection.count} disabled={blocked || !draft.enabled} onChange={(value) => update({ flapProtection: { ...draft.flapProtection, count: value } })} />
<FailoverNumberSetting before="Считать повторными сбои за последние" after="часов" min={1} max={72} step={1} ariaLabel="Период повторных сбоев" value={Math.round(draft.flapProtection.windowMs / 3_600_000)} disabled={blocked || !draft.enabled} onChange={(value) => update({ flapProtection: { ...draft.flapProtection, windowMs: value * 3_600_000 } })} />
<FailoverNumberSetting before="Отправлять основной в карантин после" after="повторных сбоев" min={2} max={10} ariaLabel="Количество повторных сбоев" value={draft.flapProtection.count} disabled={blocked || !draft.enabled} onChange={(value) => update({ flapProtection: { ...draft.flapProtection, count: value } })} />
<FailoverNumberSetting before="Считать повторными сбои за последние" after="часов" min={1} max={72} ariaLabel="Период повторных сбоев" value={Math.round(draft.flapProtection.windowMs / 3_600_000)} disabled={blocked || !draft.enabled} onChange={(value) => update({ flapProtection: { ...draft.flapProtection, windowMs: value * 3_600_000 } })} />
<FailoverNumberSetting before="Не возвращаться на основной после карантина" after="минут" min={10} max={10080} ariaLabel="Длительность карантина основного канала" value={Math.round(draft.flapProtection.quarantineMs / 60_000)} disabled={blocked || !draft.enabled} onChange={(value) => update({ flapProtection: { ...draft.flapProtection, quarantineMs: value * 60_000 } })} />
</div>}
</div>
</section>
<div className="client-failover-runtime">
+15 -26
View File
@@ -1,6 +1,6 @@
.client-failover-header { display: grid; gap: 8px; margin: 0 8px 30px; }
.client-failover-header > span, .client-failover-services legend { color: var(--client-muted); font: var(--type-label); letter-spacing: var(--type-label-tracking); text-transform: var(--type-label-transform); }
.client-failover-heading { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-right: 52px; }
.client-failover-header > span { color: var(--client-muted); font: var(--type-label); letter-spacing: var(--type-label-tracking); text-transform: var(--type-label-transform); }
.client-failover-heading { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.client-failover-header h2 { margin: 0; font: var(--type-drawer-title); letter-spacing: var(--type-drawer-title-tracking); text-transform: var(--type-drawer-title-transform); }
.client-failover-header p { margin: 0; color: var(--client-muted); font: var(--type-body); letter-spacing: var(--type-body-tracking); text-transform: var(--type-body-transform); }
.client-failover-global-actions { min-height: 30px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 3px 16px; }
@@ -39,19 +39,18 @@
.client-failover-picker.is-open .client-failover-picker-list button { opacity: 1; filter: blur(0); transform: translateY(0); transition-delay: calc(var(--picker-index) * 30ms); }
.client-failover-picker-list button:hover, .client-failover-picker-list button:focus-visible, .client-failover-picker-list button[aria-selected='true'] { outline: 0; color: var(--client-accent); text-shadow: 0 0 9px color-mix(in oklch, var(--client-accent) 38%, transparent); }
.client-failover-picker-list button[aria-disabled='true'] { color: color-mix(in oklch, var(--client-muted) 58%, transparent); cursor: default; text-shadow: none; }
.client-failover-number-setting { display: grid; grid-template-columns: minmax(0, 1fr) 68px max-content auto; align-items: center; gap: 8px; min-height: 42px; color: var(--client-muted); font: var(--type-body); letter-spacing: var(--type-body-tracking); text-transform: var(--type-body-transform); }
.client-failover-number-setting input { width: 68px; min-height: 34px; padding: 0 3px; border: 0; border-bottom: 1px solid var(--client-border); border-radius: 0; background: transparent; color: var(--client-text); font: var(--type-item-title); font-variant-numeric: var(--numeric-tabular); letter-spacing: var(--type-item-title-tracking); text-align: center; text-transform: var(--type-item-title-transform); appearance: textfield; transition: color 220ms ease, border-color 220ms ease, box-shadow 220ms ease, text-shadow 220ms ease; }
.client-failover-number-setting { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 .55ch; min-height: 42px; color: var(--client-muted); font: var(--type-body); letter-spacing: var(--type-body-tracking); text-transform: var(--type-body-transform); cursor: text; }
.client-failover-number-setting input { flex: 0 0 auto; min-width: 2ch; min-height: 1.35em; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--client-text); font: var(--type-item-title); font-variant-numeric: var(--numeric-tabular); letter-spacing: var(--type-item-title-tracking); text-align: center; text-transform: var(--type-item-title-transform); appearance: textfield; transition: color 220ms ease, text-shadow 220ms ease; }
.client-failover-number-setting input:disabled { color: var(--client-muted); opacity: .45; }
.client-failover-number-steps { justify-self: end; display: flex; align-items: center; gap: 10px; }
.client-failover-number-steps button { min-width: 34px; padding: 5px 0; border: 0; background: transparent; color: var(--client-accent); font: var(--type-control); font-variant-numeric: var(--numeric-tabular); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-transform); cursor: pointer; }
.client-failover-number-steps button:disabled, .client-failover-global-actions > button:disabled { color: var(--client-muted); cursor: default; opacity: .42; }
.client-failover-global-actions > button:disabled { color: var(--client-muted); cursor: default; opacity: .42; }
.client-failover-services { display: grid; gap: 9px; margin: 0; padding: 0; border: 0; }
.client-failover-services legend { margin-bottom: 10px; }
.client-failover-services legend { width: 100%; margin-bottom: 14px; padding: 0; }
.client-failover-section-header { display: grid; gap: 4px; margin-bottom: 12px; }
.client-failover-section-header h3, .client-failover-section-header strong { margin: 0; color: var(--client-text); font: var(--type-item-title); letter-spacing: var(--type-item-title-tracking); text-transform: var(--type-item-title-transform); }
.client-failover-section-header p, .client-failover-section-header small { margin: 0; color: var(--client-muted); font: var(--type-label); letter-spacing: var(--type-label-tracking); text-transform: var(--type-label-transform); }
.client-failover-service { display: grid; grid-template-columns: minmax(90px, .7fr) minmax(0, 1.3fr) 32px; align-items: center; gap: 12px; min-height: 42px; animation: failover-service-in 260ms cubic-bezier(0.16, 1, 0.3, 1) both; }
.client-failover-service.is-removing { animation: failover-service-out 300ms ease both; pointer-events: none; }
.client-failover-service-name { min-width: 0; overflow: hidden; color: var(--client-text); font: var(--type-body); letter-spacing: var(--type-body-tracking); text-overflow: ellipsis; text-transform: var(--type-body-transform); white-space: nowrap; }
.client-failover-number-setting.is-compact { grid-template-columns: minmax(0, 1fr) 52px max-content auto; min-height: 38px; font: var(--type-label); letter-spacing: var(--type-label-tracking); text-transform: var(--type-label-transform); }
.client-failover-number-setting.is-compact input { width: 52px; min-height: 32px; }
.client-failover-remove-service { width: 32px; height: 32px; display: grid; place-items: center; padding: 0; border: 0; background: transparent; color: oklch(0.62 0.16 28); cursor: pointer; transition: color 180ms ease, filter 240ms ease; }
.client-failover-remove-service svg { width: 19px; height: 19px; overflow: visible; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.client-failover-remove-lid { transform-origin: center 7px; transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1); }
@@ -73,16 +72,7 @@
.client-failover-traffic-switch > span { min-width: 0; display: grid; gap: 3px; }
.client-failover-traffic-switch strong { color: var(--client-text); font: var(--type-body); letter-spacing: var(--type-body-tracking); text-transform: var(--type-body-transform); }
.client-failover-traffic-switch small { color: var(--client-muted); font: var(--type-label); letter-spacing: var(--type-label-tracking); text-transform: var(--type-label-transform); }
.client-failover-advanced { display: grid; gap: 5px; }
.client-failover-advanced > button { width: fit-content; min-height: 42px; display: flex; align-items: center; gap: 10px; padding: 0; border: 0; background: transparent; color: var(--client-accent); font: var(--type-control); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-transform); cursor: pointer; }
.client-failover-advanced > button i { position: relative; width: 14px; height: 14px; }
.client-failover-advanced > button i::before, .client-failover-advanced > button i::after { content: ''; position: absolute; top: 6px; left: 0; width: 14px; height: 1px; background: currentColor; transform-origin: center; transition: transform 420ms cubic-bezier(0.16, 1, 0.3, 1), opacity 280ms ease; }
.client-failover-advanced > button i::after { transform: rotate(90deg); }
.client-failover-advanced.is-open > button i::before { transform: rotate(180deg); }
.client-failover-advanced.is-open > button i::after { opacity: 0; transform: rotate(180deg); }
.client-failover-advanced > button:focus-visible { outline: 0; text-shadow: 0 0 10px color-mix(in oklch, var(--client-accent) 44%, transparent); }
.client-failover-advanced-options { display: grid; gap: 5px; animation: failover-advanced-in 260ms cubic-bezier(0.16, 1, 0.3, 1) both; }
.client-failover-advanced.is-closing .client-failover-advanced-options { animation: failover-advanced-out 220ms ease both; pointer-events: none; }
.client-failover-protection, .client-failover-protection-options { display: grid; gap: 5px; }
.client-failover-runtime { min-height: 132px; display: grid; align-content: center; gap: 5px; padding: 14px 0; border-top: 1px solid color-mix(in oklch, var(--client-border) 48%, transparent); border-bottom: 1px solid color-mix(in oklch, var(--client-border) 48%, transparent); font-variant-numeric: var(--numeric-tabular); }
.client-failover-runtime strong { font: var(--type-body); letter-spacing: var(--type-body-tracking); text-transform: var(--type-body-transform); }
.client-failover-runtime span, .client-failover-runtime small { color: var(--client-muted); font: var(--type-label); letter-spacing: var(--type-label-tracking); text-transform: var(--type-label-transform); }
@@ -94,11 +84,10 @@
.client-failover-actions button { padding: 7px 0; border: 0; background: transparent; color: var(--client-accent); font: var(--type-control); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-transform); cursor: pointer; }
.client-failover-actions small { flex-basis: 100%; margin-top: -14px; color: var(--client-muted); font: var(--type-label); letter-spacing: var(--type-label-tracking); text-transform: var(--type-label-transform); }
.client-failover-actions button:disabled { color: var(--client-muted); cursor: default; opacity: .45; }
.client-failover-actions button:focus-visible, .client-failover-service-editor button:focus-visible, .client-failover-discard button:focus-visible, .client-failover-number-steps button:focus-visible, .client-failover-global-actions > button:focus-visible { outline: 2px solid var(--client-accent); outline-offset: 2px; }
.client-failover-form input:focus-visible { outline: 0; border-bottom-color: var(--client-accent); box-shadow: 0 1px 0 color-mix(in oklch, var(--client-accent) 60%, transparent); text-shadow: 0 0 9px color-mix(in oklch, var(--client-accent) 34%, transparent); }
.client-failover-actions button:focus-visible, .client-failover-service-editor button:focus-visible, .client-failover-discard button:focus-visible, .client-failover-global-actions > button:focus-visible { outline: 2px solid var(--client-accent); outline-offset: 2px; }
.client-failover-form input:not(.client-failover-number-input):focus-visible { outline: 0; border-bottom-color: var(--client-accent); box-shadow: 0 1px 0 color-mix(in oklch, var(--client-accent) 60%, transparent); text-shadow: 0 0 9px color-mix(in oklch, var(--client-accent) 34%, transparent); }
.client-failover-number-input:focus-visible { outline: 0; color: var(--client-accent); text-shadow: 0 0 9px color-mix(in oklch, var(--client-accent) 38%, transparent); }
@keyframes failover-service-in { from { opacity: 0; filter: blur(5px); transform: translateY(-4px); } to { opacity: 1; filter: blur(0); transform: translateY(0); } }
@keyframes failover-service-out { from { opacity: 1; filter: blur(0); transform: translateX(0) scale(1); } to { opacity: 0; filter: blur(6px); transform: translateX(16px) scale(.96); } }
@keyframes failover-advanced-in { from { opacity: 0; filter: blur(5px); transform: translateY(-5px); } to { opacity: 1; filter: blur(0); transform: translateY(0); } }
@keyframes failover-advanced-out { from { opacity: 1; filter: blur(0); transform: translateY(0); } to { opacity: 0; filter: blur(5px); transform: translateY(-5px); } }
@media (max-width: 560px) { .client-failover-heading { padding-right: 44px; } .client-failover-channels { grid-template-columns: minmax(0, 1fr); gap: 18px; } .client-failover-checking { grid-column: 1; margin-top: -6px; } .client-failover-number-setting { grid-template-columns: minmax(0, 1fr) 58px auto; gap: 5px 7px; } .client-failover-number-setting > span:first-child { grid-column: 1 / -1; } .client-failover-number-setting input { grid-column: 1; grid-row: 2; width: 58px; } .client-failover-number-setting > span:nth-child(3) { grid-column: 2; grid-row: 2; } .client-failover-number-steps { grid-column: 3; grid-row: 2; } .client-failover-service { grid-template-columns: minmax(0, 1fr) 32px; gap: 6px 10px; } .client-failover-service > .client-failover-number-setting { grid-column: 1; grid-row: 2; } .client-failover-remove-service { grid-column: 2; grid-row: 1 / span 2; } .client-failover-service-editor { grid-template-columns: 1fr; gap: 2px; } }
@media (prefers-reduced-motion: reduce) { .client-failover-channel-title strong, .client-failover-switch::before, .client-failover-switch > span, .client-failover-picker-trigger, .client-failover-picker-trigger::before, .client-failover-picker-trigger svg, .client-failover-picker-list, .client-failover-picker-list button, .client-failover-remove-service, .client-failover-remove-lid, .client-failover-advanced > button i::before, .client-failover-advanced > button i::after { transition: none; } .client-failover-service, .client-failover-service-editor, .client-failover-advanced-options { animation: none; } }
@media (max-width: 560px) { .client-failover-channels { grid-template-columns: minmax(0, 1fr); gap: 18px; } .client-failover-checking { grid-column: 1; margin-top: -6px; } .client-failover-service { grid-template-columns: minmax(0, 1fr) 32px; gap: 6px 10px; } .client-failover-service > .client-failover-number-setting { grid-column: 1; grid-row: 2; } .client-failover-remove-service { grid-column: 2; grid-row: 1 / span 2; } .client-failover-service-editor { grid-template-columns: 1fr; gap: 2px; } }
@media (prefers-reduced-motion: reduce) { .client-failover-channel-title strong, .client-failover-switch::before, .client-failover-switch > span, .client-failover-picker-trigger, .client-failover-picker-trigger::before, .client-failover-picker-trigger svg, .client-failover-picker-list, .client-failover-picker-list button, .client-failover-remove-service, .client-failover-remove-lid { transition: none; } .client-failover-service, .client-failover-service-editor { animation: none; } }