Refine device inventory layout and last-seen details
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
export const HARBOR_VERSIONS = Object.freeze({
|
export const HARBOR_VERSIONS = Object.freeze({
|
||||||
macClient: '0.9.0',
|
macClient: '0.9.1',
|
||||||
gatewayClient: '0.9.0',
|
gatewayClient: '0.9.1',
|
||||||
gatewayBackend: '0.9.0',
|
gatewayBackend: '0.9.0',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { api } from '../api.js';
|
import { api } from '../api.js';
|
||||||
|
import { formatLastSeen } from '../utils/format.js';
|
||||||
|
|
||||||
const STATUS_LABELS = {
|
const STATUS_LABELS = {
|
||||||
online: 'В сети',
|
online: 'В сети',
|
||||||
@@ -7,20 +8,8 @@ const STATUS_LABELS = {
|
|||||||
offline: 'Не в сети',
|
offline: 'Не в сети',
|
||||||
};
|
};
|
||||||
|
|
||||||
const CONFIDENCE_LABELS = {
|
function Tooltip({ children }) {
|
||||||
high: 'точная MAC',
|
return <span className="client-tooltip" role="tooltip">{children}</span>;
|
||||||
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',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
|
export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
|
||||||
@@ -101,7 +90,7 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
|
|||||||
|
|
||||||
{snapshot?.source?.error && (
|
{snapshot?.source?.error && (
|
||||||
<p className="client-devices-source" role="status">
|
<p className="client-devices-source" role="status">
|
||||||
Источник временно недоступен. Показаны последние сохранённые данные.
|
Список временно не обновляется. Показаны последние сохранённые данные.
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
{error && (
|
{error && (
|
||||||
@@ -117,16 +106,48 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
|
|||||||
|
|
||||||
<div className="client-devices-list" aria-live="polite" aria-busy={status === 'loading' || status === 'refreshing'}>
|
<div className="client-devices-list" aria-live="polite" aria-busy={status === 'loading' || status === 'refreshing'}>
|
||||||
{devices.map((device) => {
|
{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 editing = editingId === device.id;
|
||||||
const saving = savingId === 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}>
|
return <article className={`client-device is-${device.status}`} key={device.id}>
|
||||||
<div className="client-device-heading">
|
<div className="client-device-heading">
|
||||||
<div>
|
|
||||||
<span className="client-device-status">{STATUS_LABELS[device.status]}</span>
|
<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>
|
<h3>{title}</h3>
|
||||||
{device.manufacturer && device.manufacturer !== title && <p>{device.manufacturer}</p>}
|
<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>
|
</div>
|
||||||
|
)}
|
||||||
|
<span className="client-device-pin-wrap client-tooltip-anchor">
|
||||||
<button
|
<button
|
||||||
className="client-device-pin"
|
className="client-device-pin"
|
||||||
type="button"
|
type="button"
|
||||||
@@ -134,36 +155,35 @@ export function DevicesPanel({ open, panelRef, closeRef, onClose }) {
|
|||||||
aria-label={device.pinned ? `Открепить ${title}` : `Закрепить ${title}`}
|
aria-label={device.pinned ? `Открепить ${title}` : `Закрепить ${title}`}
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
onClick={() => updateDevice(device, { pinned: !device.pinned })}
|
onClick={() => updateDevice(device, { pinned: !device.pinned })}
|
||||||
>{device.pinned ? '◆' : '◇'}</button>
|
>
|
||||||
|
<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>
|
</div>
|
||||||
|
|
||||||
<dl className="client-device-meta">
|
<div className="client-device-meta">
|
||||||
<div><dt>IP</dt><dd>{device.ip || '—'}</dd></div>
|
<div className="client-device-addresses">
|
||||||
<div><dt>MAC</dt><dd>{device.mac || '—'}</dd></div>
|
{title !== device.ip && device.ip && <span>{device.ip}</span>}
|
||||||
<div><dt>Интерфейс</dt><dd>{device.interface || '—'}</dd></div>
|
{device.mac && <span className="client-device-mac">
|
||||||
<div><dt>Последний раз</dt><dd><time dateTime={device.lastSeenAt}>{seenAt(device.lastSeenAt)}</time></dd></div>
|
{device.mac}
|
||||||
<div><dt>Источник</dt><dd>{device.source} · {CONFIDENCE_LABELS[device.confidence]}</dd></div>
|
{uncertainIdentity && <span className="client-device-identity client-tooltip-anchor" tabIndex="0" aria-label="Пояснение идентификации устройства">
|
||||||
</dl>
|
ⓘ
|
||||||
|
<Tooltip>{device.confidence === 'medium'
|
||||||
{editing ? (
|
? 'Устройство использует приватный MAC, производитель может не определиться'
|
||||||
<form className="client-device-alias" onSubmit={(event) => saveAlias(event, device)}>
|
: 'Устройство определено приблизительно'}</Tooltip>
|
||||||
<label>
|
</span>}
|
||||||
<span>Название</span>
|
</span>}
|
||||||
<input value={alias} maxLength="64" autoFocus onChange={(event) => setAlias(event.target.value)} />
|
{device.interface && <span>{device.interface}</span>}
|
||||||
</label>
|
</div>
|
||||||
<button type="submit" disabled={saving}>Сохранить</button>
|
<span className="client-device-last-seen client-tooltip-anchor" tabIndex="0" aria-label={seen.tooltip}>
|
||||||
<button type="button" disabled={saving} onClick={() => setEditingId('')}>Отмена</button>
|
<time dateTime={device.lastSeenAt}>{seen.label}</time>
|
||||||
</form>
|
<Tooltip>{seen.tooltip}</Tooltip>
|
||||||
) : (
|
</span>
|
||||||
<button
|
</div>
|
||||||
className="client-device-rename"
|
{device.manufacturer && <p className="client-device-manufacturer">{device.manufacturer}</p>}
|
||||||
type="button"
|
|
||||||
onClick={() => {
|
|
||||||
setEditingId(device.id);
|
|
||||||
setAlias(device.alias || '');
|
|
||||||
}}
|
|
||||||
>Изменить название</button>
|
|
||||||
)}
|
|
||||||
</article>;
|
</article>;
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+161
-56
@@ -746,7 +746,7 @@ p {
|
|||||||
|
|
||||||
.client-devices-error button,
|
.client-devices-error button,
|
||||||
.client-device-pin,
|
.client-device-pin,
|
||||||
.client-device-rename,
|
.client-device-edit,
|
||||||
.client-device-alias button {
|
.client-device-alias button {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border: 0;
|
border: 0;
|
||||||
@@ -761,42 +761,49 @@ p {
|
|||||||
|
|
||||||
.client-device {
|
.client-device {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 14px;
|
gap: 7px;
|
||||||
padding: 20px 8px;
|
padding: 14px 8px;
|
||||||
border-top: 1px solid color-mix(in oklch, var(--client-border) 72%, transparent);
|
border-top: 1px solid color-mix(in oklch, var(--client-border) 72%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.client-device-heading {
|
.client-device-heading {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: minmax(0, 1fr) 32px;
|
grid-template-columns: 68px minmax(0, 1fr) 32px;
|
||||||
gap: 12px;
|
align-items: center;
|
||||||
align-items: start;
|
gap: 8px;
|
||||||
|
min-height: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.client-device-heading > div {
|
.client-device-title {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.client-device-heading h3 {
|
.client-device-title h3 {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin: 4px 0 0;
|
margin: 0;
|
||||||
font-size: 15px;
|
font-size: 14px;
|
||||||
letter-spacing: -0.03em;
|
letter-spacing: -0.03em;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.client-device-heading p,
|
|
||||||
.client-device-status {
|
.client-device-status {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 7px;
|
||||||
color: var(--client-muted);
|
color: var(--client-muted);
|
||||||
font-size: 9px;
|
font-size: 9px;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.client-device-status::before {
|
.client-device-status::before {
|
||||||
|
flex: 0 0 auto;
|
||||||
width: 6px;
|
width: 6px;
|
||||||
height: 6px;
|
height: 6px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-right: 7px;
|
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background: currentColor;
|
background: currentColor;
|
||||||
content: '';
|
content: '';
|
||||||
@@ -810,11 +817,56 @@ p {
|
|||||||
opacity: 0.56;
|
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;
|
width: 32px;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-device-edit,
|
||||||
|
.client-device-pin {
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
color: var(--client-muted);
|
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"] {
|
.client-device-pin[aria-pressed="true"] {
|
||||||
@@ -822,70 +874,118 @@ p {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.client-device-meta {
|
.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;
|
min-width: 0;
|
||||||
}
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
.client-device-meta dt {
|
align-items: baseline;
|
||||||
|
gap: 10px 16px;
|
||||||
|
margin-left: 76px;
|
||||||
color: var(--client-muted);
|
color: var(--client-muted);
|
||||||
font-size: 8px;
|
font-size: 9px;
|
||||||
font-weight: 700;
|
line-height: 1.5;
|
||||||
letter-spacing: 0.07em;
|
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.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;
|
overflow: hidden;
|
||||||
margin: 3px 0 0;
|
margin: 0 0 0 76px;
|
||||||
|
color: var(--client-muted);
|
||||||
font-size: 9px;
|
font-size: 9px;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
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 {
|
.client-device-alias {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: minmax(0, 1fr) auto auto;
|
grid-template-columns: minmax(0, 1fr) 28px 28px;
|
||||||
align-items: end;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 3px;
|
||||||
}
|
|
||||||
|
|
||||||
.client-device-alias label {
|
|
||||||
display: grid;
|
|
||||||
gap: 5px;
|
|
||||||
color: var(--client-muted);
|
|
||||||
font-size: 8px;
|
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.client-device-alias input {
|
.client-device-alias input {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
padding: 8px 0;
|
padding: 5px 0;
|
||||||
border: 0;
|
border: 0;
|
||||||
border-bottom: 1px solid var(--client-border);
|
border-bottom: 1px solid var(--client-border);
|
||||||
outline: 0;
|
outline: 0;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: var(--client-text);
|
color: var(--client-text);
|
||||||
font-size: 10px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.client-device-alias input:focus {
|
.client-device-alias input:focus {
|
||||||
border-color: var(--client-accent);
|
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 {
|
.client-devices button:focus-visible {
|
||||||
outline: 2px solid var(--client-accent);
|
outline: 2px solid var(--client-accent);
|
||||||
outline-offset: 2px;
|
outline-offset: 2px;
|
||||||
@@ -896,6 +996,12 @@ p {
|
|||||||
opacity: 0.35;
|
opacity: 0.35;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (hover: none) {
|
||||||
|
.client-device-edit-wrap {
|
||||||
|
opacity: 0.72;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.client-instructions-toggle:hover,
|
.client-instructions-toggle:hover,
|
||||||
.client-instructions-toggle:focus-visible,
|
.client-instructions-toggle:focus-visible,
|
||||||
.client-local-rules-toggle:hover,
|
.client-local-rules-toggle:hover,
|
||||||
@@ -3737,10 +3843,6 @@ p {
|
|||||||
padding: 40px 58px 60px 18px;
|
padding: 40px 58px 60px 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.client-device-meta {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
.client-local-rules-sheet {
|
.client-local-rules-sheet {
|
||||||
padding: 40px 58px 60px 18px;
|
padding: 40px 58px 60px 18px;
|
||||||
}
|
}
|
||||||
@@ -3841,7 +3943,10 @@ p {
|
|||||||
.client-instruction-summary > i::after,
|
.client-instruction-summary > i::after,
|
||||||
.client-device,
|
.client-device,
|
||||||
.client-device-pin,
|
.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,
|
||||||
.client-subscription-edit::after,
|
.client-subscription-edit::after,
|
||||||
.client-subscription-submit,
|
.client-subscription-submit,
|
||||||
|
|||||||
@@ -29,3 +29,38 @@ export function formatTime(iso) {
|
|||||||
if (!iso) return "";
|
if (!iso) return "";
|
||||||
return new Date(iso).toLocaleTimeString("ru-RU", { hour12: false });
|
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})` };
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import fs from 'node:fs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import test from 'node:test';
|
import test from 'node:test';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { formatLastSeen } from '../../src/web/utils/format.js';
|
||||||
|
|
||||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
||||||
const overview = fs.readFileSync(path.join(root, 'src/web/components/ClientOverviewPage.jsx'), 'utf8');
|
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(overview, /isGateway && <button[\s\S]*client-devices-toggle/);
|
||||||
assert.match(panel, /api\.devices\.list\(\)/);
|
assert.match(panel, /api\.devices\.list\(\)/);
|
||||||
assert.match(panel, /api\.devices\.update\(device\.id, patch, snapshot\.revision\)/);
|
assert.match(panel, /api\.devices\.update\(device\.id, patch, snapshot\.revision\)/);
|
||||||
for (const field of ['IP', 'MAC', 'Интерфейс', 'Последний раз', 'Источник']) {
|
assert.match(panel, /<Tooltip>Изменить название<\/Tooltip>/);
|
||||||
assert.match(panel, new RegExp(field));
|
assert.match(panel, /client-device-addresses/);
|
||||||
}
|
assert.doesNotMatch(panel, /точная MAC|частная MAC|<dt>Источник<\/dt>/);
|
||||||
assert.match(panel, /aria-pressed=\{device\.pinned\}/);
|
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, /\.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/);
|
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 минут назад)',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user