Refine device inventory layout and last-seen details
Build and Deploy Gateway / build-and-push (push) Successful in 11s
Build and Deploy Gateway / deploy (push) Successful in 6s

This commit is contained in:
2026-08-07 13:39:25 +03:00
parent 158aaadd23
commit 44367e0ef3
5 changed files with 291 additions and 119 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
export const HARBOR_VERSIONS = Object.freeze({
macClient: '0.9.0',
gatewayClient: '0.9.0',
macClient: '0.9.1',
gatewayClient: '0.9.1',
gatewayBackend: '0.9.0',
});
+76 -56
View File
@@ -1,5 +1,6 @@
import React, { useEffect, useState } from 'react';
import { api } from '../api.js';
import { formatLastSeen } from '../utils/format.js';
const STATUS_LABELS = {
online: 'В сети',
@@ -7,20 +8,8 @@ const STATUS_LABELS = {
offline: 'Не в сети',
};
const CONFIDENCE_LABELS = {
high: 'точная MAC',
medium: 'частная MAC',
low: 'приблизительно',
};
function seenAt(value) {
if (!value) return 'нет данных';
return new Date(value).toLocaleString('ru-RU', {
day: '2-digit',
month: 'short',
hour: '2-digit',
minute: '2-digit',
});
function Tooltip({ children }) {
return <span className="client-tooltip" role="tooltip">{children}</span>;
}
export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
@@ -101,7 +90,7 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
{snapshot?.source?.error && (
<p className="client-devices-source" role="status">
Источник временно недоступен. Показаны последние сохранённые данные.
Список временно не обновляется. Показаны последние сохранённые данные.
</p>
)}
{error && (
@@ -117,53 +106,84 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
<div className="client-devices-list" aria-live="polite" aria-busy={status === 'loading' || status === 'refreshing'}>
{devices.map((device) => {
const title = device.alias || device.hostname || device.manufacturer || device.ip;
const title = device.alias || device.hostname || device.ip || 'Неизвестное устройство';
const editing = editingId === device.id;
const saving = savingId === device.id;
const seen = formatLastSeen(device.lastSeenAt);
const uncertainIdentity = device.confidence !== 'high';
return <article className={`client-device is-${device.status}`} key={device.id}>
<div className="client-device-heading">
<div>
<span className="client-device-status">{STATUS_LABELS[device.status]}</span>
<h3>{title}</h3>
{device.manufacturer && device.manufacturer !== title && <p>{device.manufacturer}</p>}
</div>
<button
className="client-device-pin"
type="button"
aria-pressed={device.pinned}
aria-label={device.pinned ? `Открепить ${title}` : `Закрепить ${title}`}
disabled={saving}
onClick={() => updateDevice(device, { pinned: !device.pinned })}
>{device.pinned ? '◆' : '◇'}</button>
<span className="client-device-status">{STATUS_LABELS[device.status]}</span>
{editing ? (
<form className="client-device-alias" onSubmit={(event) => saveAlias(event, device)}>
<input
value={alias}
maxLength="64"
autoFocus
aria-label="Название устройства"
onChange={(event) => setAlias(event.target.value)}
/>
<button type="submit" aria-label="Сохранить название" disabled={saving}></button>
<button type="button" aria-label="Отменить изменение" disabled={saving} onClick={() => setEditingId('')}>×</button>
</form>
) : (
<div className="client-device-title">
<h3>{title}</h3>
<span className="client-device-edit-wrap client-tooltip-anchor">
<button
className="client-device-edit"
type="button"
aria-label={`Изменить название ${title}`}
onClick={() => {
setEditingId(device.id);
setAlias(device.alias || '');
}}
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<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>
</div>
)}
<span className="client-device-pin-wrap client-tooltip-anchor">
<button
className="client-device-pin"
type="button"
aria-pressed={device.pinned}
aria-label={device.pinned ? `Открепить ${title}` : `Закрепить ${title}`}
disabled={saving}
onClick={() => updateDevice(device, { pinned: !device.pinned })}
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M9 3h6l-1 5 3 3v2H7v-2l3-3-1-5ZM12 13v8" />
</svg>
</button>
<Tooltip>{device.pinned ? 'Открепить' : 'Закрепить'}</Tooltip>
</span>
</div>
<dl className="client-device-meta">
<div><dt>IP</dt><dd>{device.ip || '—'}</dd></div>
<div><dt>MAC</dt><dd>{device.mac || '—'}</dd></div>
<div><dt>Интерфейс</dt><dd>{device.interface || '—'}</dd></div>
<div><dt>Последний раз</dt><dd><time dateTime={device.lastSeenAt}>{seenAt(device.lastSeenAt)}</time></dd></div>
<div><dt>Источник</dt><dd>{device.source} · {CONFIDENCE_LABELS[device.confidence]}</dd></div>
</dl>
{editing ? (
<form className="client-device-alias" onSubmit={(event) => saveAlias(event, device)}>
<label>
<span>Название</span>
<input value={alias} maxLength="64" autoFocus onChange={(event) => setAlias(event.target.value)} />
</label>
<button type="submit" disabled={saving}>Сохранить</button>
<button type="button" disabled={saving} onClick={() => setEditingId('')}>Отмена</button>
</form>
) : (
<button
className="client-device-rename"
type="button"
onClick={() => {
setEditingId(device.id);
setAlias(device.alias || '');
}}
>Изменить название</button>
)}
<div className="client-device-meta">
<div className="client-device-addresses">
{title !== device.ip && device.ip && <span>{device.ip}</span>}
{device.mac && <span className="client-device-mac">
{device.mac}
{uncertainIdentity && <span className="client-device-identity client-tooltip-anchor" tabIndex="0" aria-label="Пояснение идентификации устройства">
<Tooltip>{device.confidence === 'medium'
? 'Устройство использует приватный MAC, производитель может не определиться'
: 'Устройство определено приблизительно'}</Tooltip>
</span>}
</span>}
{device.interface && <span>{device.interface}</span>}
</div>
<span className="client-device-last-seen client-tooltip-anchor" tabIndex="0" aria-label={seen.tooltip}>
<time dateTime={device.lastSeenAt}>{seen.label}</time>
<Tooltip>{seen.tooltip}</Tooltip>
</span>
</div>
{device.manufacturer && <p className="client-device-manufacturer">{device.manufacturer}</p>}
</article>;
})}
</div>
+161 -56
View File
@@ -746,7 +746,7 @@ p {
.client-devices-error button,
.client-device-pin,
.client-device-rename,
.client-device-edit,
.client-device-alias button {
padding: 0;
border: 0;
@@ -761,42 +761,49 @@ p {
.client-device {
display: grid;
gap: 14px;
padding: 20px 8px;
gap: 7px;
padding: 14px 8px;
border-top: 1px solid color-mix(in oklch, var(--client-border) 72%, transparent);
}
.client-device-heading {
display: grid;
grid-template-columns: minmax(0, 1fr) 32px;
gap: 12px;
align-items: start;
grid-template-columns: 68px minmax(0, 1fr) 32px;
align-items: center;
gap: 8px;
min-height: 32px;
}
.client-device-heading > div {
.client-device-title {
min-width: 0;
display: flex;
align-items: center;
gap: 4px;
}
.client-device-heading h3 {
.client-device-title h3 {
overflow: hidden;
margin: 4px 0 0;
font-size: 15px;
margin: 0;
font-size: 14px;
letter-spacing: -0.03em;
text-overflow: ellipsis;
white-space: nowrap;
}
.client-device-heading p,
.client-device-status {
display: flex;
align-items: center;
gap: 7px;
color: var(--client-muted);
font-size: 9px;
white-space: nowrap;
}
.client-device-status::before {
flex: 0 0 auto;
width: 6px;
height: 6px;
display: inline-block;
margin-right: 7px;
border-radius: 50%;
background: currentColor;
content: '';
@@ -810,11 +817,56 @@ p {
opacity: 0.56;
}
.client-device-pin {
.client-device-edit-wrap,
.client-device-pin-wrap {
width: 28px;
height: 28px;
display: grid;
place-items: center;
}
.client-device-edit-wrap {
flex: 0 0 auto;
opacity: 0.34;
transition: opacity 180ms ease;
}
.client-device:hover .client-device-edit-wrap,
.client-device:focus-within .client-device-edit-wrap {
opacity: 1;
}
.client-device-pin-wrap {
width: 32px;
height: 32px;
}
.client-device-edit,
.client-device-pin {
width: 28px;
height: 28px;
display: grid;
place-items: center;
color: var(--client-muted);
font-size: 16px;
}
.client-device-edit svg,
.client-device-pin svg {
width: 15px;
height: 15px;
fill: none;
stroke: currentColor;
stroke-width: 1.7;
stroke-linecap: round;
stroke-linejoin: round;
transition: color 180ms ease, filter 220ms ease;
}
.client-device-edit:hover,
.client-device-edit:focus-visible,
.client-device-pin:hover,
.client-device-pin:focus-visible {
color: var(--client-accent);
}
.client-device-pin[aria-pressed="true"] {
@@ -822,70 +874,118 @@ p {
}
.client-device-meta {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 9px 18px;
margin: 0;
}
.client-device-meta div {
min-width: 0;
}
.client-device-meta dt {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 10px 16px;
margin-left: 76px;
color: var(--client-muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
font-size: 9px;
line-height: 1.5;
}
.client-device-meta dd {
.client-device-addresses {
min-width: 0;
display: flex;
flex-wrap: wrap;
gap: 3px 0;
}
.client-device-addresses > span {
white-space: nowrap;
}
.client-device-addresses > span + span::before {
margin: 0 6px;
color: color-mix(in oklch, var(--client-muted) 58%, transparent);
content: '·';
}
.client-device-mac {
display: inline-flex;
align-items: center;
}
.client-device-identity {
position: relative;
margin-left: 4px;
color: var(--client-accent);
cursor: help;
}
.client-device-last-seen {
flex: 0 0 auto;
margin-left: auto;
color: var(--client-text);
cursor: help;
white-space: nowrap;
}
.client-device-last-seen > .client-tooltip,
.client-device-pin-wrap > .client-tooltip {
right: 0;
left: auto;
transform: translate(0, 2px);
}
.client-device-last-seen:hover > .client-tooltip,
.client-device-last-seen:focus-visible > .client-tooltip,
.client-device-pin-wrap:hover > .client-tooltip,
.client-device-pin-wrap:has(> :focus-visible) > .client-tooltip {
transform: translate(0, 0);
}
.client-device-last-seen:focus-visible,
.client-device-identity:focus-visible {
border-radius: 3px;
outline: 2px solid var(--client-accent);
outline-offset: 3px;
}
.client-device-manufacturer {
overflow: hidden;
margin: 3px 0 0;
margin: 0 0 0 76px;
color: var(--client-muted);
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.client-device-rename,
.client-device-alias button,
.client-devices-error button {
justify-self: start;
font-size: 9px;
font-weight: 700;
}
.client-device-alias {
display: grid;
grid-template-columns: minmax(0, 1fr) auto auto;
align-items: end;
gap: 10px;
}
.client-device-alias label {
display: grid;
gap: 5px;
color: var(--client-muted);
font-size: 8px;
text-transform: uppercase;
grid-template-columns: minmax(0, 1fr) 28px 28px;
align-items: center;
gap: 3px;
}
.client-device-alias input {
min-width: 0;
padding: 8px 0;
padding: 5px 0;
border: 0;
border-bottom: 1px solid var(--client-border);
outline: 0;
background: transparent;
color: var(--client-text);
font-size: 10px;
font-size: 12px;
}
.client-device-alias input:focus {
border-color: var(--client-accent);
}
.client-device-alias button {
width: 28px;
height: 28px;
font-size: 14px;
}
.client-devices-error button {
justify-self: start;
font-size: 9px;
font-weight: 700;
}
.client-devices button:focus-visible {
outline: 2px solid var(--client-accent);
outline-offset: 2px;
@@ -896,6 +996,12 @@ p {
opacity: 0.35;
}
@media (hover: none) {
.client-device-edit-wrap {
opacity: 0.72;
}
}
.client-instructions-toggle:hover,
.client-instructions-toggle:focus-visible,
.client-local-rules-toggle:hover,
@@ -3737,10 +3843,6 @@ p {
padding: 40px 58px 60px 18px;
}
.client-device-meta {
grid-template-columns: 1fr;
}
.client-local-rules-sheet {
padding: 40px 58px 60px 18px;
}
@@ -3841,7 +3943,10 @@ p {
.client-instruction-summary > i::after,
.client-device,
.client-device-pin,
.client-device-rename,
.client-device-pin svg,
.client-device-edit,
.client-device-edit svg,
.client-device-edit-wrap,
.client-subscription-edit,
.client-subscription-edit::after,
.client-subscription-submit,
+35
View File
@@ -29,3 +29,38 @@ export function formatTime(iso) {
if (!iso) return "";
return new Date(iso).toLocaleTimeString("ru-RU", { hour12: false });
}
export function formatLastSeen(iso, now = new Date()) {
const date = new Date(iso);
if (Number.isNaN(date.getTime())) return { label: "Нет данных", tooltip: "Нет данных" };
const current = new Date(now);
const day = (value) => Date.UTC(value.getFullYear(), value.getMonth(), value.getDate());
const daysAgo = Math.round((day(current) - day(date)) / 86_400_000);
const time = date.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" });
const dateLabel = daysAgo === 0
? "Сегодня"
: daysAgo === 1
? "Вчера"
: date.toLocaleDateString("ru-RU", {
day: "numeric",
month: "long",
...(date.getFullYear() === current.getFullYear() ? {} : { year: "numeric" }),
});
const elapsedMs = Math.max(0, current.getTime() - date.getTime());
const units = elapsedMs < 60 * 60 * 1000
? [Math.max(1, Math.floor(elapsedMs / 60_000)), "minute"]
: elapsedMs < 24 * 60 * 60 * 1000
? [Math.floor(elapsedMs / 3_600_000), "hour"]
: [Math.floor(elapsedMs / 86_400_000), "day"];
const relative = elapsedMs < 60_000
? "только что"
: new Intl.RelativeTimeFormat("ru-RU", { numeric: "always" }).format(-units[0], units[1]);
const full = date.toLocaleString("ru-RU", {
day: "numeric",
month: "long",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
});
return { label: `${dateLabel}, ${time}`, tooltip: `${full} (${relative})` };
}
+17 -5
View File
@@ -3,6 +3,7 @@ import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
import { fileURLToPath } from 'node:url';
import { formatLastSeen } from '../../src/web/utils/format.js';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
const overview = fs.readFileSync(path.join(root, 'src/web/components/ClientOverviewPage.jsx'), 'utf8');
@@ -13,12 +14,23 @@ test('Gateway device inventory uses the existing accessible responsive drawer',
assert.match(overview, /isGateway && <button[\s\S]*client-devices-toggle/);
assert.match(panel, /api\.devices\.list\(\)/);
assert.match(panel, /api\.devices\.update\(device\.id, patch, snapshot\.revision\)/);
for (const field of ['IP', 'MAC', 'Интерфейс', 'Последний раз', 'Источник']) {
assert.match(panel, new RegExp(field));
}
assert.match(panel, /<Tooltip>Изменить название<\/Tooltip>/);
assert.match(panel, /client-device-addresses/);
assert.doesNotMatch(panel, /точная MAC|частная MAC|<dt>Источник<\/dt>/);
assert.match(panel, /aria-pressed=\{device\.pinned\}/);
assert.match(panel, /maxLength="64" autoFocus/);
assert.match(panel, /maxLength="64"[\s\S]*autoFocus/);
assert.match(styles, /\.client-devices \{\s*width: min\(560px, 100vw\)/);
assert.match(styles, /@media \(max-width: 560px\)[\s\S]*\.client-device-meta \{\s*grid-template-columns: 1fr/);
assert.match(styles, /@media \(prefers-reduced-motion: reduce\)[\s\S]*\.client-device-pin/);
});
test('device last-seen copy is compact with a precise relative tooltip', () => {
const lastSeen = new Date(2026, 7, 7, 13, 15);
const now = new Date(2026, 7, 7, 13, 27);
assert.deepEqual(
formatLastSeen(lastSeen.toISOString(), now),
{
label: 'Сегодня, 13:15',
tooltip: '7 августа 2026 г. в 13:15 (12 минут назад)',
},
);
});