Refine device inventory animations and diagnostics layout
Build and Deploy Gateway / build-and-push (push) Successful in 14s
Build and Deploy Gateway / deploy (push) Successful in 7s

This commit is contained in:
2026-08-07 21:35:46 +03:00
parent 0a4a6d9443
commit 70cc221f34
6 changed files with 67 additions and 88 deletions
@@ -63,19 +63,6 @@ function IpCell({ path, source, pending, route }) {
return <code aria-label={`${route}: ${value.address}`}>{value.address}</code>;
}
function PathDetails({ title, path }) {
if (!path?.available) return <section><strong>{title}</strong><p>VPN не запущен.</p></section>;
return <section>
<strong>{title}</strong>
{path.sites.map((site) => (
<p key={site.id}>
{site.label}: {site.stage}{site.httpStatus ? ` · HTTP ${site.httpStatus}` : ''}
{site.error ? ` · ${site.error}` : ''}
</p>
))}
</section>;
}
export function ConnectivityDiagnosticsPanel({ open, panelRef, closeRef, onClose }) {
const [result, setResult] = useState(null);
const [status, setStatus] = useState('idle');
@@ -172,7 +159,7 @@ export function ConnectivityDiagnosticsPanel({ open, panelRef, closeRef, onClose
</div>
</header>
<div className="client-diagnostics-feedback" aria-live="polite">
{(error || result) && <div className="client-diagnostics-feedback" aria-live="polite">
{error ? <div className="client-diagnostics-error" role="alert">
<span>{error.message}</span>
{error.retryable && <button type="button" onClick={run}>Повторить</button>}
@@ -180,7 +167,7 @@ export function ConnectivityDiagnosticsPanel({ open, panelRef, closeRef, onClose
<strong className={`client-diagnostics-summary ${summary[0]}`}>{summary[1]}</strong>
<span className="client-diagnostics-time">{checkedAt}</span>
</>}
</div>
</div>}
<section className="client-diagnostics-section" aria-labelledby="diagnostic-ip-title">
<div className="client-diagnostics-section-title">
@@ -266,13 +253,6 @@ export function ConnectivityDiagnosticsPanel({ open, panelRef, closeRef, onClose
</table>
</section>
{result && <details className="client-diagnostics-details">
<summary>Технические детали</summary>
<div>
<PathDetails title="Напрямую" path={result.direct} />
<PathDetails title="VPN" path={result.vpn} />
</div>
</details>}
</div>
</aside>
);
+33 -13
View File
@@ -192,9 +192,12 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
const [sortDirection, setSortDirection] = useState('desc');
const [trafficScale, setTrafficScale] = useState('linear');
const [copyFeedback, setCopyFeedback] = useState(null);
const [pencilAnimationId, setPencilAnimationId] = useState('');
const [trafficDeltas, setTrafficDeltas] = useState({});
const deviceNodes = useRef(new Map());
const previousPositions = useRef(new Map());
const previousOrder = useRef([]);
const previousScrollTop = useRef(0);
const movementAnimations = useRef(new Map());
const previousTraffic = useRef(new Map());
const copyTimer = useRef(null);
@@ -217,7 +220,7 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
setRefreshing(true);
try {
const next = await (discover ? api.devices.refresh() : api.devices.list());
setSnapshot((current) => !current || next.revision >= current.revision ? next : current);
setSnapshot((current) => !current || next.revision > current.revision ? next : current);
setError(null);
setStatus('ready');
} catch (requestError) {
@@ -278,6 +281,8 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
useLayoutEffect(() => {
if (!open) {
previousPositions.current.clear();
previousOrder.current = [];
previousScrollTop.current = 0;
for (const animation of movementAnimations.current.values()) animation.cancel();
movementAnimations.current.clear();
return;
@@ -287,10 +292,17 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
movementAnimations.current.get(id)?.cancel();
positions.set(id, node.getBoundingClientRect());
}
if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
const order = devices.map(({ id }) => id);
const orderChanged = previousOrder.current.length > 0
&& (order.length !== previousOrder.current.length
|| order.some((id, index) => id !== previousOrder.current[index]));
const currentScrollTop = panelRef.current?.scrollTop || 0;
if (orderChanged && !window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
for (const [id, after] of positions) {
const before = previousPositions.current.get(id);
const deltaY = before ? before.top - after.top : 0;
const deltaY = before
? before.top - after.top + previousScrollTop.current - currentScrollTop
: 0;
if (Math.abs(deltaY) < 1) continue;
const animation = deviceNodes.current.get(id)?.animate([
{ transform: `translateY(${deltaY}px)` },
@@ -303,7 +315,9 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
}
}
previousPositions.current = positions;
}, [devices, open]);
previousOrder.current = order;
previousScrollTop.current = currentScrollTop;
}, [devices, open, panelRef]);
async function updateDevice(device, patch) {
setSavingId(device.id);
@@ -314,14 +328,14 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
} catch (requestError) {
if (requestError.code !== 'STATE_CONFLICT') throw requestError;
const latest = await api.devices.list();
setSnapshot((current) => !current || latest.revision >= current.revision ? latest : current);
setSnapshot((current) => !current || latest.revision > current.revision ? latest : current);
const latestDevice = latest.devices.find((candidate) => candidate.id === device.id);
if (!latestDevice || Object.keys(patch).some((key) => latestDevice[key] !== device[key])) {
throw requestError;
}
next = await api.devices.update(device.id, patch, latest.revision);
}
setSnapshot((current) => !current || next.revision >= current.revision ? next : current);
setSnapshot((current) => !current || next.revision > current.revision ? next : current);
setError(null);
return true;
} catch (requestError) {
@@ -347,18 +361,18 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
} catch (requestError) {
if (requestError.code !== 'STATE_CONFLICT') throw requestError;
const latest = await api.devices.list();
setSnapshot((current) => !current || latest.revision >= current.revision ? latest : current);
setSnapshot((current) => !current || latest.revision > current.revision ? latest : current);
const latestDevice = latest.devices.find((candidate) => candidate.id === device.id);
if (!latestDevice || latestDevice.desiredPolicy !== device.desiredPolicy) throw requestError;
next = await api.devices.setPolicy(device.id, mode, latest.revision);
}
setSnapshot((current) => !current || next.revision >= current.revision ? next : current);
setSnapshot((current) => !current || next.revision > current.revision ? next : current);
setError(null);
} catch (requestError) {
if (requestError.code === 'DEVICE_POLICY_APPLY_FAILED') {
try {
const latest = await api.devices.list();
setSnapshot((current) => !current || latest.revision >= current.revision ? latest : current);
setSnapshot((current) => !current || latest.revision > current.revision ? latest : current);
} catch {
// Keep the policy error as the actionable result.
}
@@ -575,19 +589,25 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
onClick={() => copyDeviceIp(device)}
>{device.ip}</button> : !hasName && <span>Неизвестное устройство</span>}
</h3>
{!hasName && <span className="client-device-edit-wrap client-tooltip-anchor">
<span className="client-device-edit-wrap client-tooltip-anchor">
<button
className="client-device-edit"
className={`client-device-edit${pencilAnimationId === device.id ? ' is-writing' : ''}`}
type="button"
aria-label={`Изменить название ${title}`}
onPointerEnter={() => setPencilAnimationId(device.id)}
onFocus={() => setPencilAnimationId(device.id)}
onClick={() => startEditing(device)}
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<svg
viewBox="0 0 24 24"
aria-hidden="true"
onAnimationEnd={() => setPencilAnimationId((id) => id === device.id ? '' : id)}
>
<path d="m4 20 4.2-1 10.3-10.3a2 2 0 0 0-2.8-2.8L5.4 16.2 4 20ZM14.5 7.1l2.8 2.8" />
</svg>
</button>
<Tooltip>Изменить название</Tooltip>
</span>}
</span>
</>
)}
<span className={`client-device-last-seen${online ? ' is-online' : ''}`} tabIndex="0">
+15 -47
View File
@@ -946,7 +946,7 @@ p {
display: flex;
align-items: flex-end;
gap: 2px;
padding-top: 11px;
padding: 11px 27px 0 0;
}
.client-device-main > h3 {
@@ -1040,10 +1040,11 @@ p {
}
.client-device-edit-wrap {
flex: 0 0 auto;
position: absolute;
right: 0;
bottom: 0;
width: 23px;
height: 23px;
align-self: flex-end;
opacity: 0.34;
transition: opacity 180ms ease, filter 240ms ease, transform 320ms cubic-bezier(0.16, 1, 0.3, 1);
}
@@ -1093,9 +1094,16 @@ p {
color: var(--client-accent);
}
.client-device-edit:hover svg,
.client-device-edit:focus-visible svg {
transform: translate(1px, -1px) rotate(-4deg);
.client-device-edit.is-writing svg {
animation: client-device-pencil-write 620ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes client-device-pencil-write {
0%, 100% { transform: translate(0, 0) rotate(0); }
22% { transform: translate(1px, -1px) rotate(-5deg); }
44% { transform: translate(-1px, 1px) rotate(-2deg); }
66% { transform: translate(1px, 0) rotate(-5deg); }
84% { transform: translate(0, 1px) rotate(-2deg); }
}
.client-device-pin[aria-pressed="true"] {
@@ -4624,7 +4632,6 @@ p {
}
.client-diagnostics-feedback {
min-height: 34px;
display: flex;
align-items: center;
gap: 10px;
@@ -4838,43 +4845,6 @@ p {
color: oklch(0.68 0.15 28);
}
.client-diagnostics-details {
margin: 0 8px;
color: var(--client-muted);
font-size: 9px;
}
.client-diagnostics-details summary {
width: fit-content;
padding: 6px 0;
color: var(--client-text);
font-weight: 700;
cursor: pointer;
}
.client-diagnostics-details summary:focus-visible {
outline: 2px solid var(--client-accent);
outline-offset: 2px;
}
.client-diagnostics-details > div {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18px;
padding-top: 10px;
}
.client-diagnostics-details section {
min-width: 0;
display: grid;
gap: 5px;
}
.client-diagnostics-details p {
overflow-wrap: anywhere;
line-height: 1.55;
}
@media (max-width: 560px) {
.client-diagnostics-table th,
.client-diagnostics-table td {
@@ -4889,10 +4859,8 @@ p {
grid-template-columns: minmax(0, 1fr);
}
.client-diagnostics-add-action,
.client-diagnostics-details > div {
.client-diagnostics-add-action {
grid-column: 1;
grid-template-columns: minmax(0, 1fr);
}
}