Improve failover controls and preserve manual switching state
This commit is contained in:
@@ -305,7 +305,7 @@ export function createFailoverService(dependencies: FailoverServiceDependencies)
|
||||
appliedServerId: target.serverId,
|
||||
appliedServerSnapshot: server,
|
||||
failoverPolicy: reason === 'manual'
|
||||
? { ...state.failoverPolicy, paused: true }
|
||||
? state.failoverPolicy
|
||||
: role === 'primary' ? { ...state.failoverPolicy, paused: false } : state.failoverPolicy,
|
||||
failoverRuntimeState: {
|
||||
...state.failoverRuntimeState,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export const HARBOR_VERSIONS = Object.freeze({
|
||||
macClient: '0.31.0',
|
||||
gatewayClient: '0.32.0',
|
||||
gatewayBackend: '0.32.0',
|
||||
macClient: '0.31.1',
|
||||
gatewayClient: '0.32.1',
|
||||
gatewayBackend: '0.32.1',
|
||||
});
|
||||
|
||||
export interface ParsedVersion {
|
||||
|
||||
@@ -710,6 +710,7 @@ export function ClientOverviewPage({
|
||||
activeSwitch?.finish();
|
||||
|
||||
if (current === target) {
|
||||
if (target === 'failover') failoverFeature.pendingTargetRef.current = null;
|
||||
drawerControls[target].close();
|
||||
return;
|
||||
}
|
||||
@@ -717,7 +718,13 @@ export function ClientOverviewPage({
|
||||
routingFeature.requestClose();
|
||||
return;
|
||||
}
|
||||
if (current === 'failover' && !failoverFeature.beforeCloseRef.current()) return;
|
||||
if (current === 'failover') {
|
||||
if (!failoverFeature.beforeCloseRef.current()) {
|
||||
failoverFeature.pendingTargetRef.current = () => switchDrawer(target);
|
||||
return;
|
||||
}
|
||||
failoverFeature.pendingTargetRef.current = null;
|
||||
}
|
||||
if (!current) {
|
||||
drawerControls[target].show();
|
||||
return;
|
||||
|
||||
@@ -3,23 +3,31 @@ import { flushSync } from 'react-dom';
|
||||
import { CONNECTIVITY_SITES, MAX_CUSTOM_DIAGNOSTIC_SERVICES, type DiagnosticSettings } from '../../../shared/connectivityDiagnostics.js';
|
||||
import { normalizeFailoverPolicy, type FailoverPolicy, type FailoverSnapshot } from '../../../shared/failover.js';
|
||||
import type { ProfileSnapshot } from '../../../shared/contracts/state.js';
|
||||
import { ConfirmationDialog } from '../../ui/ConfirmationDialog.js';
|
||||
import { Drawer } from '../../ui/Drawer.js';
|
||||
import { RailAction } from '../../ui/RailAction.js';
|
||||
import { Tooltip } from '../../ui/Tooltip.js';
|
||||
import { saveCustomDiagnosticService } from '../diagnostics/index.js';
|
||||
|
||||
export function useFailoverFeature() {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const panelRef = useRef<HTMLElement>(null);
|
||||
const toggleRef = useRef<HTMLButtonElement>(null);
|
||||
const closeRef = useRef<HTMLButtonElement>(null);
|
||||
const beforeCloseRef = useRef<() => boolean>(() => true);
|
||||
const pendingTargetRef = useRef<(() => void) | null>(null);
|
||||
const close = () => {
|
||||
if (beforeCloseRef.current()) setIsOpen(false);
|
||||
if (beforeCloseRef.current()) {
|
||||
pendingTargetRef.current = null;
|
||||
setIsOpen(false);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
if (!isOpen) return undefined;
|
||||
const frame = requestAnimationFrame(() => closeRef.current?.focus());
|
||||
const handleClose = (event: PointerEvent | KeyboardEvent) => {
|
||||
if (event.defaultPrevented) return;
|
||||
const target = event.target;
|
||||
if (target instanceof Element && target.closest('.client-confirmation-popup')) return;
|
||||
if (event.type === 'keydown' && (event as KeyboardEvent).key !== 'Escape') return;
|
||||
if (event.type !== 'keydown' && (
|
||||
panelRef.current?.contains(event.target as Node) || toggleRef.current?.contains(event.target as Node)
|
||||
@@ -38,7 +46,7 @@ export function useFailoverFeature() {
|
||||
};
|
||||
}, [isOpen]);
|
||||
return {
|
||||
isOpen, panelRef, toggleRef, closeRef, beforeCloseRef, close,
|
||||
isOpen, panelRef, toggleRef, closeRef, beforeCloseRef, pendingTargetRef, close,
|
||||
toggle: () => isOpen ? close() : setIsOpen(true),
|
||||
};
|
||||
}
|
||||
@@ -67,6 +75,14 @@ export function FailoverToggle({ feature, open, onToggle }: {
|
||||
}
|
||||
|
||||
const seconds = (milliseconds: number) => Math.round(milliseconds / 1000);
|
||||
const normalizeFailoverDraft = (policy: FailoverPolicy) => {
|
||||
const normalized = normalizeFailoverPolicy(policy);
|
||||
return {
|
||||
...normalized,
|
||||
minimumReserveMs: Math.round(normalized.minimumReserveMs / 60_000) * 60_000,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
function pulseNumber(event: FormEvent<HTMLInputElement>) {
|
||||
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
||||
@@ -309,7 +325,7 @@ export function FailoverPanel({
|
||||
onCheck: () => Promise<unknown>;
|
||||
onUpdateDiagnostics: (settings: unknown) => Promise<unknown>;
|
||||
}) {
|
||||
const [draft, setDraft] = useState(() => snapshot.policy);
|
||||
const [draft, setDraft] = useState(() => normalizeFailoverDraft(snapshot.policy));
|
||||
const [dirty, setDirty] = useState(false);
|
||||
const [confirmDiscard, setConfirmDiscard] = useState(false);
|
||||
const [addingService, setAddingService] = useState(false);
|
||||
@@ -319,25 +335,35 @@ export function FailoverPanel({
|
||||
const [openPicker, setOpenPicker] = useState('');
|
||||
const [removingCheckId, setRemovingCheckId] = useState('');
|
||||
const [manualChecking, setManualChecking] = useState(false);
|
||||
const discardContinuationFrameRef = useRef<number | null>(null);
|
||||
useEffect(() => {
|
||||
if (!dirty) setDraft(snapshot.policy);
|
||||
if (!dirty) setDraft(normalizeFailoverDraft(snapshot.policy));
|
||||
}, [snapshot.policy, dirty]);
|
||||
useEffect(() => {
|
||||
feature.beforeCloseRef.current = () => {
|
||||
if (!dirty) return true;
|
||||
if (!dirty) {
|
||||
feature.pendingTargetRef.current = null;
|
||||
return true;
|
||||
}
|
||||
setConfirmDiscard(true);
|
||||
return false;
|
||||
};
|
||||
const beforeUnload = (event: BeforeUnloadEvent) => {
|
||||
if (!dirty) return;
|
||||
event.preventDefault();
|
||||
event.returnValue = '';
|
||||
};
|
||||
window.addEventListener('beforeunload', beforeUnload);
|
||||
return () => {
|
||||
feature.beforeCloseRef.current = () => true;
|
||||
window.removeEventListener('beforeunload', beforeUnload);
|
||||
};
|
||||
}, [dirty, feature.beforeCloseRef]);
|
||||
}, [dirty, feature.beforeCloseRef, feature.pendingTargetRef]);
|
||||
useEffect(() => () => {
|
||||
if (discardContinuationFrameRef.current !== null) {
|
||||
cancelAnimationFrame(discardContinuationFrameRef.current);
|
||||
}
|
||||
}, []);
|
||||
const services = useMemo(() => [
|
||||
...CONNECTIVITY_SITES,
|
||||
...diagnostics.customServices,
|
||||
@@ -368,11 +394,11 @@ export function FailoverPanel({
|
||||
...(diagnostics.customServices.length < MAX_CUSTOM_DIAGNOSTIC_SERVICES ? [{ id: '__new-service', label: 'Новый HTTPS-сервис…' }] : []),
|
||||
], [diagnostics.customServices.length, draft.checks, services]);
|
||||
const update = (value: Partial<FailoverPolicy>) => {
|
||||
setDraft((current) => normalizeFailoverPolicy({ ...current, ...value }));
|
||||
setDraft((current) => normalizeFailoverDraft({ ...current, ...value }));
|
||||
setDirty(true);
|
||||
};
|
||||
const updateChecks = (change: (checks: FailoverPolicy['checks']) => FailoverPolicy['checks']) => {
|
||||
setDraft((current) => normalizeFailoverPolicy({ ...current, checks: change(current.checks) }));
|
||||
setDraft((current) => normalizeFailoverDraft({ ...current, checks: change(current.checks) }));
|
||||
setDirty(true);
|
||||
};
|
||||
const updateTarget = (channel: 'primary' | 'reserve', optionId: string) => {
|
||||
@@ -383,6 +409,7 @@ export function FailoverPanel({
|
||||
? snapshot.currentRole
|
||||
: null;
|
||||
const switchRole = role === 'primary' ? 'reserve' : role === 'reserve' ? 'primary' : null;
|
||||
const checking = manualChecking || snapshot.reason === 'checking-channels';
|
||||
const activity = snapshot.trafficActivity;
|
||||
const targetExists = (target: FailoverPolicy['primary']) => profiles
|
||||
.find(({ id }) => id === target.profileId)?.servers.some(({ id }) => id === target.serverId);
|
||||
@@ -437,27 +464,48 @@ export function FailoverPanel({
|
||||
<span>Gateway</span>
|
||||
<div className="client-failover-heading">
|
||||
<h2>Резервный канал</h2>
|
||||
<HarborSwitch
|
||||
checked={draft.enabled}
|
||||
label={draft.enabled ? 'Выключить резервный канал' : 'Включить резервный канал'}
|
||||
disabled={blocked}
|
||||
onChange={(enabled) => {
|
||||
setOpenPicker('');
|
||||
if (!enabled) setAddingService(false);
|
||||
update({ enabled });
|
||||
}}
|
||||
/>
|
||||
<div className="client-failover-header-actions">
|
||||
<div className="client-failover-switch-setting">
|
||||
<span>Канал</span>
|
||||
<HarborSwitch
|
||||
checked={draft.enabled}
|
||||
label={draft.enabled ? 'Выключить резервный канал' : 'Включить резервный канал'}
|
||||
disabled={blocked}
|
||||
onChange={(enabled) => {
|
||||
setOpenPicker('');
|
||||
if (!enabled) setAddingService(false);
|
||||
update({ enabled });
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="client-failover-switch-setting">
|
||||
<span>Автоматика</span>
|
||||
<HarborSwitch
|
||||
checked={!snapshot.paused}
|
||||
label={snapshot.paused ? 'Включить автоматическое переключение' : 'Остановить автоматическое переключение'}
|
||||
disabled={blocked || !snapshot.enabled}
|
||||
onChange={(automatic) => void onPause(!automatic)}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
className="client-failover-save"
|
||||
type="submit"
|
||||
form="client-failover-form"
|
||||
disabled={blocked || !dirty || !draftValid}
|
||||
>
|
||||
Сохранить
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p>Если основной канал перестанет работать, Harbor направит новые подключения через резервный канал. Уже открытые подключения продолжат работать через прежний канал.</p>
|
||||
{snapshot.enabled && <div className="client-failover-global-actions">
|
||||
<button type="button" disabled={blocked} onClick={() => void onPause(!snapshot.paused)}>{snapshot.paused ? 'Продолжить автоматическое переключение' : 'Приостановить автоматическое переключение'}</button>
|
||||
<small>{snapshot.paused ? 'Новые подключения продолжают идти через текущий канал.' : 'Harbor проверяет оба канала и при необходимости переключает новые подключения.'}</small>
|
||||
</div>}
|
||||
</header>
|
||||
<div className="client-failover-intro">
|
||||
<p>Если основной канал перестанет работать, Harbor направит новые подключения через резервный канал. Уже открытые подключения продолжат работать через прежний канал.</p>
|
||||
{snapshot.enabled && <small className="client-failover-pause-hint">{snapshot.paused ? 'Новые подключения продолжают идти через текущий канал.' : 'Harbor проверяет оба канала и при необходимости переключает новые подключения.'}</small>}
|
||||
</div>
|
||||
|
||||
<form className="client-failover-form" onSubmit={(event) => {
|
||||
<form id="client-failover-form" className="client-failover-form" onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
void onSave(draft).then((result) => { if (result !== false) setDirty(false); });
|
||||
void onSave(normalizeFailoverDraft(draft)).then((result) => { if (result !== false) setDirty(false); });
|
||||
}}>
|
||||
<section className="client-failover-channels" aria-label="Основной и резервный каналы">
|
||||
{(['primary', 'reserve'] as const).map((channel) => {
|
||||
@@ -479,7 +527,7 @@ export function FailoverPanel({
|
||||
: channel === 'primary' && snapshot.currentRole === 'reserve' && health === 'healthy' && snapshot.reason === 'recovery-hold'
|
||||
? 'Проверяем восстановление'
|
||||
: health === 'healthy' ? 'Работает' : health === 'unhealthy' ? 'Недоступен' : health === 'not-monitoring' ? 'Проверка выключена' : 'Ждёт проверки';
|
||||
return <article className="client-failover-channel" data-channel={channel} key={channel}>
|
||||
return <div className="client-failover-channel-slot" key={channel}><article className="client-failover-channel" data-channel={channel}>
|
||||
<div className="client-failover-channel-title">
|
||||
<h3>{channel === 'primary' ? 'Основной' : 'Резервный'}</h3>
|
||||
<strong className={health === 'healthy' ? 'is-healthy' : health === 'unhealthy' || missing ? 'is-unhealthy' : ''}>{healthLabel}</strong>
|
||||
@@ -494,13 +542,63 @@ export function FailoverPanel({
|
||||
onOpenChange={(open) => setOpenPicker(open ? channel : '')}
|
||||
onChange={(optionId) => updateTarget(channel, optionId)}
|
||||
/>
|
||||
</article>;
|
||||
</article>{channel === 'primary' && <div className="client-failover-channel-actions" aria-label="Действия с каналами">
|
||||
<button
|
||||
className={`client-failover-check-action client-tooltip-anchor${checking ? ' is-running' : ''}`}
|
||||
type="button"
|
||||
aria-label="Проверить оба канала"
|
||||
aria-busy={checking}
|
||||
disabled={blocked || checking || !snapshot.enabled || snapshot.activation !== 'active'}
|
||||
onClick={() => {
|
||||
setManualChecking(true);
|
||||
void onCheck().finally(() => setManualChecking(false));
|
||||
}}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M20 11a8 8 0 1 0-2.3 6.7M20 5v6h-6" />
|
||||
</svg>
|
||||
<Tooltip>Проверить оба канала</Tooltip>
|
||||
</button>
|
||||
<button
|
||||
className="client-failover-direction-action client-tooltip-anchor"
|
||||
type="button"
|
||||
aria-label={switchRole ? `Переключить на ${switchRole === 'primary' ? 'основной' : 'резервный'} канал` : 'Переключить канал'}
|
||||
disabled={blocked || !snapshot.enabled || snapshot.activation !== 'active' || !switchRole}
|
||||
onClick={() => { if (switchRole) void onSwitch(switchRole); }}
|
||||
>
|
||||
<svg className={`client-failover-direction-icon ${switchRole === 'primary' ? 'is-primary' : 'is-reserve'}`} viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M4 12h15M14 7l5 5-5 5" />
|
||||
</svg>
|
||||
<Tooltip>{switchRole ? `Переключить на ${switchRole === 'primary' ? 'основной' : 'резервный'} канал` : 'Переключение недоступно'}</Tooltip>
|
||||
</button>
|
||||
</div>}</div>;
|
||||
})}
|
||||
<div className="client-failover-checking" role="status" aria-live="polite">
|
||||
{(manualChecking || snapshot.reason === 'checking-channels' ? ['primary', 'reserve'] as const : []).map((checkingRole) => <span key={checkingRole}>Проверяем {checkingRole === 'primary' ? 'основной' : 'резервный'} канал</span>)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className={`client-failover-runtime ${role === 'primary' ? 'is-primary' : role === 'reserve' ? 'is-reserve' : 'is-none'}`} aria-label="Текущее состояние каналов">
|
||||
<span className="client-failover-runtime-label">Сейчас используется</span>
|
||||
<strong role="status" aria-live="polite">{blocked
|
||||
? 'Harbor завершает текущее действие'
|
||||
: role === 'primary'
|
||||
? 'Основной канал'
|
||||
: role === 'reserve'
|
||||
? 'Резервный канал'
|
||||
: 'Канал пока не выбран'}</strong>
|
||||
<span>{blocked ? 'Подождите…' : reasonLabel(snapshot.reason)}</span>
|
||||
<span>{role
|
||||
? `Новые подключения: ${targetLabel(profiles, snapshot[role].target)}`
|
||||
: snapshot.reason === 'vpn-stopped'
|
||||
? `При запуске VPN будет выбран: ${targetLabel(profiles, draft.primary)}`
|
||||
: `После перезапуска VPN будет выбран: ${targetLabel(profiles, draft.primary)}`}</span>
|
||||
{snapshot.nextDecisionAt && <span>Проверим каналы снова через {seconds(Math.max(0, Date.parse(snapshot.nextDecisionAt) - Date.now()))} с</span>}
|
||||
{activity && <span>{activity.state === 'active' ? `Сейчас передаётся ${Math.round(activity.totalBytesPerSecond / 1024)} КБ/с. Активных подключений: ${activity.transmittingConnections}` : activity.state === 'quiet' ? `Передачи данных нет: ${Math.min(seconds(quietElapsed), seconds(draft.trafficGuard.quietWindowMs))} из ${seconds(draft.trafficGuard.quietWindowMs)} с` : 'Не удалось проверить передачу данных. Автоматическое переключение остановлено'}</span>}
|
||||
{activity?.blockers.slice(0, 2).map((blocker) => <small key={`${blocker.device}:${blocker.service}`}>{blocker.device} · {blocker.service} · {Math.round((blocker.uploadBytesPerSecond + blocker.downloadBytesPerSecond) / 1024)} КБ/с</small>)}
|
||||
{activity && activity.blockers.length > 2 && <small>Ещё {activity.blockers.length - 2}</small>}
|
||||
</section>
|
||||
|
||||
<fieldset className="client-failover-services">
|
||||
<legend><span className="client-failover-section-header"><strong>Что проверять</strong><small>Harbor проверяет эти сайты через оба канала, чтобы понять, какой канал работает.</small></span></legend>
|
||||
{draft.checks.map((check) => {
|
||||
@@ -595,42 +693,41 @@ export function FailoverPanel({
|
||||
<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={1} max={1440} step={1} ariaLabel="Минимальное время на резервном канале" value={draft.minimumReserveMs / 60_000} disabled={blocked || !draft.enabled} onChange={(value) => update({ minimumReserveMs: Math.round(value) * 60_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={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>
|
||||
</section>
|
||||
|
||||
<div className="client-failover-runtime">
|
||||
<strong role="status" aria-live="polite">{blocked ? 'Подождите, Harbor завершает текущее действие…' : snapshot.activation === 'pending' ? 'Резервный канал включится при следующем запуске VPN' : reasonLabel(snapshot.reason)}</strong>
|
||||
<span>{role
|
||||
? `Новые подключения: ${targetLabel(profiles, snapshot[role].target)}`
|
||||
: snapshot.reason === 'vpn-stopped'
|
||||
? `При запуске VPN будет выбран: ${targetLabel(profiles, draft.primary)}`
|
||||
: `После перезапуска VPN будет выбран: ${targetLabel(profiles, draft.primary)}`}</span>
|
||||
{snapshot.nextDecisionAt && <span>Проверим каналы снова через {seconds(Math.max(0, Date.parse(snapshot.nextDecisionAt) - Date.now()))} с</span>}
|
||||
{activity && <span>{activity.state === 'active' ? `Сейчас передаётся ${Math.round(activity.totalBytesPerSecond / 1024)} КБ/с. Активных подключений: ${activity.transmittingConnections}` : activity.state === 'quiet' ? `Передачи данных нет: ${Math.min(seconds(quietElapsed), seconds(draft.trafficGuard.quietWindowMs))} из ${seconds(draft.trafficGuard.quietWindowMs)} с` : 'Не удалось проверить передачу данных. Автоматическое переключение остановлено'}</span>}
|
||||
{activity?.blockers.slice(0, 2).map((blocker) => <small key={`${blocker.device}:${blocker.service}`}>{blocker.device} · {blocker.service} · {Math.round((blocker.uploadBytesPerSecond + blocker.downloadBytesPerSecond) / 1024)} КБ/с</small>)}
|
||||
{activity && activity.blockers.length > 2 && <small>Ещё {activity.blockers.length - 2}</small>}
|
||||
</div>
|
||||
|
||||
{!draftValid && <p className="client-failover-validation">Выберите разные серверы для основного и резервного каналов и хотя бы один сайт для проверки.</p>}
|
||||
{confirmDiscard && <div className="client-failover-discard" role="alert">
|
||||
<span>Отменить несохранённые изменения?</span>
|
||||
<button type="button" onClick={() => { setDraft(snapshot.policy); setDirty(false); setConfirmDiscard(false); feature.beforeCloseRef.current = () => true; feature.close(); }}>Отменить изменения</button>
|
||||
<button type="button" onClick={() => setConfirmDiscard(false)}>Продолжить настройку</button>
|
||||
</div>}
|
||||
|
||||
<div className="client-failover-actions">
|
||||
<button type="button" disabled={blocked || manualChecking || !snapshot.enabled || snapshot.activation !== 'active'} onClick={() => {
|
||||
setManualChecking(true);
|
||||
void onCheck().finally(() => setManualChecking(false));
|
||||
}}>Проверить оба канала</button>
|
||||
<button type="submit" disabled={blocked || !dirty || !draftValid}>Сохранить</button>
|
||||
{switchRole && snapshot.enabled && snapshot.activation === 'active' && <button type="button" disabled={blocked} onClick={() => void onSwitch(switchRole)}>Переключить новые подключения на {switchRole === 'reserve' ? 'резервный канал' : 'основной канал'}</button>}
|
||||
{(snapshot.currentRole === 'primary' || snapshot.currentRole === 'reserve') && <small>Открытые подключения останутся на прежнем канале.</small>}
|
||||
</div>
|
||||
</form>
|
||||
<ConfirmationDialog
|
||||
open={confirmDiscard}
|
||||
id="discard-failover"
|
||||
title="Закрыть без сохранения?"
|
||||
description="Несохранённые настройки резервного канала будут потеряны."
|
||||
cancelLabel="Остаться"
|
||||
confirmLabel="Закрыть без сохранения"
|
||||
onCancel={() => {
|
||||
feature.pendingTargetRef.current = null;
|
||||
setConfirmDiscard(false);
|
||||
}}
|
||||
onConfirm={() => {
|
||||
const continueNavigation = feature.pendingTargetRef.current;
|
||||
feature.pendingTargetRef.current = null;
|
||||
feature.beforeCloseRef.current = () => true;
|
||||
flushSync(() => {
|
||||
setDraft(normalizeFailoverDraft(snapshot.policy));
|
||||
setDirty(false);
|
||||
setConfirmDiscard(false);
|
||||
});
|
||||
discardContinuationFrameRef.current = requestAnimationFrame(() => {
|
||||
discardContinuationFrameRef.current = null;
|
||||
if (continueNavigation) continueNavigation();
|
||||
else feature.close();
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Drawer>;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
.client-failover-header { display: grid; gap: 8px; margin: 0 8px 30px; }
|
||||
.client-failover-header { position: sticky; top: 0; z-index: 7; display: grid; gap: 8px; margin: -18px -8px 0; padding: 18px 16px 14px; background: color-mix(in oklch, var(--client-bg) 99%, var(--client-panel)); }
|
||||
.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-heading { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; }
|
||||
.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-data); font-variant-numeric: var(--numeric-tabular); letter-spacing: var(--type-data-tracking); text-transform: var(--type-data-transform); }
|
||||
.client-failover-global-actions { min-height: 30px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 3px 16px; }
|
||||
.client-failover-global-actions > button { padding: 6px 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-global-actions > small { color: var(--client-muted); font: var(--type-control); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-transform); }
|
||||
.client-failover-header-actions { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 16px; }
|
||||
.client-failover-switch-setting { display: flex; align-items: center; gap: 5px; color: var(--client-muted); font: var(--type-control); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-transform); }
|
||||
.client-failover-switch-setting .client-failover-switch { transform: scale(.78); }
|
||||
.client-failover-save { min-height: 36px; max-width: 100%; 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-save:disabled { color: var(--client-muted); cursor: default; opacity: .45; }
|
||||
.client-failover-intro { display: grid; gap: 8px; margin: 14px 8px 30px; }
|
||||
.client-failover-intro p { margin: 0; color: var(--client-muted); font: var(--type-data); font-variant-numeric: var(--numeric-tabular); letter-spacing: var(--type-data-tracking); text-transform: var(--type-data-transform); }
|
||||
.client-failover-form { display: grid; gap: 24px; margin: 0 8px; }
|
||||
.client-failover-switch { position: relative; flex: 0 0 auto; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; color: var(--client-muted); cursor: pointer; }
|
||||
.client-failover-switch::before { content: ''; position: absolute; inset: 11px 1px; border-radius: 999px; background: color-mix(in oklch, var(--client-muted) 24%, transparent); box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--client-muted) 24%, transparent); transition: background 240ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 240ms cubic-bezier(0.16, 1, 0.3, 1); }
|
||||
@@ -14,7 +17,8 @@
|
||||
.client-failover-switch[aria-checked='true'] > span { background: var(--client-text); box-shadow: 0 0 10px color-mix(in oklch, var(--client-accent) 46%, transparent); transform: translateX(22px); }
|
||||
.client-failover-switch:disabled { cursor: default; opacity: .42; }
|
||||
.client-failover-switch:focus-visible { outline: 2px solid var(--client-accent); outline-offset: 0; border-radius: 999px; }
|
||||
.client-failover-channels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 32px; }
|
||||
.client-failover-channels { display: grid; grid-template-columns: minmax(0, 1fr) 52px minmax(0, 1fr); gap: 12px; }
|
||||
.client-failover-channel-slot { display: contents; }
|
||||
.client-failover-channel { position: relative; display: grid; align-content: start; gap: 7px; min-width: 0; }
|
||||
.client-failover-channel-title { min-height: 24px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
|
||||
.client-failover-channel-title h3 { margin: 0; font: var(--type-data); font-variant-numeric: var(--numeric-tabular); letter-spacing: var(--type-data-tracking); text-transform: var(--type-data-transform); }
|
||||
@@ -25,6 +29,14 @@
|
||||
.client-failover-channel-title strong.is-unhealthy { color: oklch(0.68 0.15 28); }
|
||||
.client-failover-picker { position: relative; min-width: 0; z-index: 1; }
|
||||
.client-failover-checking { grid-column: 1 / -1; min-height: 22px; display: flex; flex-wrap: wrap; gap: 6px 22px; color: var(--client-muted); font: var(--type-control); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-transform); }
|
||||
.client-failover-channel-actions { grid-column: 2; grid-row: 1; min-height: 66px; display: grid; place-content: center; gap: 2px; }
|
||||
.client-failover-check-action, .client-failover-direction-action { width: 44px; height: 44px; display: grid; place-items: center; padding: 0; border: 0; background: transparent; color: var(--client-accent); cursor: pointer; }
|
||||
.client-failover-check-action:disabled, .client-failover-direction-action:disabled { color: var(--client-muted); cursor: default; opacity: .45; }
|
||||
.client-failover-save:focus-visible { outline: 2px solid var(--client-accent); outline-offset: 2px; }
|
||||
.client-failover-check-action svg { flex: 0 0 auto; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.client-failover-check-action.is-running svg { animation: client-spin 900ms linear infinite; }
|
||||
.client-failover-direction-action svg { flex: 0 0 auto; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; transform: rotate(0deg); transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1); }
|
||||
.client-failover-direction-action svg.is-primary { transform: rotate(180deg); }
|
||||
.client-failover-picker.is-open { z-index: 6; }
|
||||
.client-failover-picker-trigger { width: 100%; min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 2px; border: 0; border-bottom: 1px solid var(--client-border); background: transparent; color: var(--client-text); font: var(--type-data); font-variant-numeric: var(--numeric-tabular); letter-spacing: var(--type-data-tracking); text-transform: var(--type-data-transform); text-align: left; box-shadow: 0 1px 0 transparent; cursor: pointer; transition: color 220ms ease, box-shadow 300ms ease, text-shadow 300ms ease; }
|
||||
.client-failover-picker-trigger span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
@@ -47,7 +59,7 @@
|
||||
.client-failover-number-steps { position: absolute; left: 50%; bottom: 0; width: 44px; display: flex; justify-content: space-between; opacity: 0; filter: blur(3px); transform: translate(-50%, -2px); pointer-events: none; transition: opacity 260ms ease 80ms, filter 260ms ease 80ms, transform 260ms cubic-bezier(0.16, 1, 0.3, 1) 80ms; }
|
||||
.client-failover-number-control:hover .client-failover-number-steps, .client-failover-number-control:focus-within .client-failover-number-steps { opacity: 1; filter: blur(0); transform: translate(-50%, 0); pointer-events: auto; transition: opacity 180ms ease, filter 180ms ease, transform 220ms cubic-bezier(0.16, 1, 0.3, 1); }
|
||||
.client-failover-number-steps button { width: 20px; height: 18px; display: grid; place-items: center; 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-number-steps button:disabled, .client-failover-global-actions > button:disabled { color: var(--client-muted); cursor: default; opacity: .42; }
|
||||
.client-failover-number-steps button:disabled { color: var(--client-muted); cursor: default; opacity: .42; }
|
||||
.client-failover-services { display: grid; gap: 5px; margin: 0; padding: 0; border: 0; }
|
||||
.client-failover-services legend { width: 100%; margin-bottom: 14px; padding: 0; }
|
||||
.client-failover-section-header { display: grid; gap: 4px; margin-bottom: 12px; }
|
||||
@@ -79,21 +91,18 @@
|
||||
.client-failover-traffic-switch small { color: var(--client-muted); font: var(--type-control); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-transform); }
|
||||
.client-failover-protection { display: grid; gap: 5px; }
|
||||
.client-failover-protection-options { display: grid; gap: 0; }
|
||||
.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-data); font-variant-numeric: var(--numeric-tabular); letter-spacing: var(--type-data-tracking); text-transform: var(--type-data-transform); }
|
||||
.client-failover-runtime { display: grid; gap: 4px; margin-top: -10px; padding: 8px 0 2px; font-variant-numeric: var(--numeric-tabular); }
|
||||
.client-failover-runtime-label { color: var(--client-muted); font: var(--type-label); letter-spacing: var(--type-label-tracking); text-transform: var(--type-label-transform); }
|
||||
.client-failover-runtime strong { color: var(--client-muted); font: var(--type-item-title); font-variant-numeric: var(--numeric-tabular); letter-spacing: var(--type-item-title-tracking); text-transform: var(--type-item-title-transform); }
|
||||
.client-failover-runtime.is-primary strong { color: var(--harbor-connect); text-shadow: 0 0 9px color-mix(in oklch, var(--harbor-connect) 30%, transparent); }
|
||||
.client-failover-runtime.is-reserve strong { color: var(--harbor-gateway); text-shadow: 0 0 9px color-mix(in oklch, var(--harbor-gateway) 30%, transparent); }
|
||||
.client-failover-runtime span, .client-failover-runtime small { color: var(--client-muted); font: var(--type-control); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-transform); }
|
||||
.client-failover-validation { margin: -12px 0 0; color: oklch(0.68 0.15 28); font: var(--type-control); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-transform); }
|
||||
.client-failover-discard { min-height: 74px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 0; border-top: 1px solid var(--client-border); border-bottom: 1px solid var(--client-border); }
|
||||
.client-failover-discard span { flex-basis: 100%; color: var(--client-text); font: var(--type-data); font-variant-numeric: var(--numeric-tabular); letter-spacing: var(--type-data-tracking); text-transform: var(--type-data-transform); }
|
||||
.client-failover-discard button { padding: 4px 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 { min-height: 42px; display: flex; flex-wrap: wrap; gap: 18px; }
|
||||
.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-control); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-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-global-actions > button:focus-visible, .client-failover-number-steps button:focus-visible { outline: 2px solid var(--client-accent); outline-offset: 2px; }
|
||||
.client-failover-pause-hint { color: var(--client-muted); font: var(--type-control); letter-spacing: var(--type-control-tracking); text-transform: var(--type-control-transform); }
|
||||
.client-failover-check-action:focus-visible, .client-failover-direction-action:focus-visible, .client-failover-service-editor button:focus-visible, .client-failover-number-steps 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); } }
|
||||
@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-number-steps, .client-failover-number-control:hover .client-failover-number-steps, .client-failover-number-control:focus-within .client-failover-number-steps, .client-failover-remove-service, .client-failover-remove-lid { transition: none; } .client-failover-service, .client-failover-service-editor { animation: none; } }
|
||||
@media (max-width: 560px) { .client-failover-heading { align-items: flex-start; flex-wrap: wrap; } .client-failover-heading > h2 { min-width: 0; flex: 1 1 auto; } .client-failover-header-actions { flex: 1 1 100%; justify-content: flex-start; gap: 4px 10px; } .client-failover-channels { grid-template-columns: minmax(0, 1fr); gap: 12px; } .client-failover-checking { grid-column: 1; margin-top: -6px; } .client-failover-channel-actions { grid-column: 1; grid-row: auto; min-height: 44px; display: flex; justify-content: center; gap: 8px; } .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-number-steps, .client-failover-number-control:hover .client-failover-number-steps, .client-failover-number-control:focus-within .client-failover-number-steps, .client-failover-remove-service, .client-failover-remove-lid, .client-failover-direction-action svg { transition: none; } .client-failover-check-action.is-running svg { animation: none; } .client-failover-service, .client-failover-service-editor { animation: none; } }
|
||||
|
||||
Reference in New Issue
Block a user