feat(ui): support notification history and selectable side-panel actions
This commit is contained in:
@@ -65,6 +65,7 @@ import {
|
||||
TextField,
|
||||
ToastCard,
|
||||
ToastStack,
|
||||
ToastObserver,
|
||||
Toolbar,
|
||||
NavigationCube,
|
||||
UserProfileMenu,
|
||||
@@ -362,6 +363,7 @@ export function CatalogApp() {
|
||||
const [applicationSaveState, setApplicationSaveState] = useState<ApplicationDraftSaveState>("idle");
|
||||
const [applicationError, setApplicationError] = useState("");
|
||||
const [toasts, setToasts] = useState<ToastItem[]>([]);
|
||||
const [observedToasts, setObservedToasts] = useState<ToastItem[]>([]);
|
||||
const toastSequenceRef = useRef(0);
|
||||
const [sessionProfile, setSessionProfile] = useState<FoundrySessionProfile | null>(null);
|
||||
const [foundrySettingsOpen, setFoundrySettingsOpen] = useState(false);
|
||||
@@ -1657,6 +1659,7 @@ export function CatalogApp() {
|
||||
eyebrow="MAP / SETTINGS"
|
||||
title="Настройки карты"
|
||||
description="Theme-aware application panel"
|
||||
headerActions={<IconButton label="Настройки панели" onClick={() => setInspectorOpen(true)}><Icon name="settings" /></IconButton>}
|
||||
onClose={() => setSidePanelDemoOpen(false)}
|
||||
>
|
||||
<Inspector variant="panel" sections={environmentSections.slice(0, 3).map(section=>({...section,action:{label:`Действие секции ${section.label}`,icon:<Icon name="edit"/>,onAction:()=>setInspectorOpen(true)}}))} defaultOpen={[environmentSections[0]?.id ?? ""]} singleOpen />
|
||||
@@ -1801,6 +1804,7 @@ export function CatalogApp() {
|
||||
</div>
|
||||
</SettingsCard>
|
||||
<SettingsCard eyebrow="LIVE STATES" title="Проверка стека" description="Кнопки используют тот же bottom-right viewport, что и реальные save/update flows.">
|
||||
<Description>Последняя передача приложению: {observedToasts.map(item => item.title).join(', ') || 'нет уведомлений'}</Description>
|
||||
<div className="catalog-inline catalog-inline--wrap">
|
||||
<Button onClick={() => pushToast("success", "Изменения сохранены", "Статус автоматически исчезнет.")}>Success</Button>
|
||||
<Button onClick={() => pushToast("info", "Профиль применён", "Application использует выбранную версию.")}>Info</Button>
|
||||
@@ -2204,6 +2208,7 @@ export function CatalogApp() {
|
||||
<UserProfileMenu
|
||||
triggerLabel="Профиль"
|
||||
triggerIcon="inbox"
|
||||
headerAction={{label: 'Правая панель', pressed: sidePanelDemoOpen, onSelect: () => setSidePanelDemoOpen(open => !open)}}
|
||||
displayName={sessionProfile?.user?.displayName || "Профиль"}
|
||||
subtitle={sessionProfile?.user?.email || "NODE.DC Foundry"}
|
||||
avatarUrl={sessionProfile?.user?.avatarUrl || undefined}
|
||||
@@ -2645,7 +2650,9 @@ export function CatalogApp() {
|
||||
onClose={() => setConfirmOpen(false)}
|
||||
onConfirm={() => setConfirmOpen(false)}
|
||||
/>
|
||||
<ToastObserver onPresent={setObservedToasts}>
|
||||
<ToastStack items={toasts} onDismiss={dismissToast} />
|
||||
</ToastObserver>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -296,6 +296,13 @@ setup-команды, сохранение, API и права принадлеж
|
||||
|
||||
## SettingsCard и Switch
|
||||
|
||||
В `UserProfileMenu` необязательный `headerAction={{label, onSelect}}` отделяет
|
||||
действие средней иконки от меню профиля. Аватар и текст профиля сохраняют меню.
|
||||
`ToastObserver onPresent` сообщает приложению новые и изменённые завершённые
|
||||
уведомления из вложенных `ToastStack`; хранение, даты и история принадлежат
|
||||
приложению. `ToastStack observe={false}` исключает повторную регистрацию
|
||||
сообщений, уже записанных сервером. Отображение и таймеры не изменяются.
|
||||
|
||||
`SettingsCard` фиксирует нейтральную структуру админской группы: eyebrow/title/description/actions/body. `Switch` покрывает компактное включение/видимость внутри таких групп. Данные секции, сохранение и права остаются в consumer.
|
||||
|
||||
Промежуточный loading-контейнер не должен обнулять вертикальный ритм тела
|
||||
@@ -343,6 +350,8 @@ Reduced motion отключает анимацию. На узком экране
|
||||
|
||||
## ApplicationSidePanel
|
||||
|
||||
Перед кнопкой закрытия можно разместить действия через `headerActions`. Кнопка `UserProfileMenu.headerAction` принимает `pressed` и `controls` для связи с выдвижной панелью.
|
||||
|
||||
`ApplicationSidePanel` — правая application-level пара к `AdminNavigationPanel`.
|
||||
Она использует ту же ширину `332–352 px`, радиус, theme-aware surface, тень и
|
||||
круглые действия, но появляется справа налево. `ApplicationShell` размещает её
|
||||
|
||||
@@ -364,7 +364,8 @@
|
||||
color: var(--nodedc-text-primary);
|
||||
}
|
||||
|
||||
.nodedc-icon-button[aria-pressed="true"] {
|
||||
.nodedc-icon-button[aria-pressed="true"],
|
||||
.nodedc-header__profile .nodedc-icon-button[aria-pressed="true"] {
|
||||
background: var(--nodedc-glass-control-active);
|
||||
color: var(--nodedc-glass-control-active-text);
|
||||
}
|
||||
@@ -1632,6 +1633,8 @@ textarea.nodedc-field__control {
|
||||
.nodedc-app-shell__end-panel {
|
||||
right: var(--nodedc-app-page-pad);
|
||||
width: var(--nodedc-app-nav-width);
|
||||
transform: translateX(calc(100% + var(--nodedc-app-page-pad)));
|
||||
transition: transform var(--nodedc-app-navigation-motion), visibility 0s linear 440ms;
|
||||
visibility: hidden;
|
||||
pointer-events: none;
|
||||
}
|
||||
@@ -1642,6 +1645,8 @@ textarea.nodedc-field__control {
|
||||
}
|
||||
|
||||
.nodedc-app-shell[data-end-panel-open="true"] .nodedc-app-shell__end-panel {
|
||||
transform: translateX(0);
|
||||
transition-delay: 0s;
|
||||
visibility: visible;
|
||||
pointer-events: auto;
|
||||
}
|
||||
@@ -4910,3 +4915,7 @@ textarea.nodedc-field__control {
|
||||
.nodedc-window[data-header-stacked="true"]>.nodedc-window__head>.nodedc-window__titles{grid-row:2}
|
||||
|
||||
.nodedc-window[data-header-layout="adaptive"]>.nodedc-window__head>.nodedc-window__actions>*{flex-shrink:0}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.nodedc-app-shell__end-panel { transition: none; }
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface ApplicationSidePanelProps extends Omit<HTMLAttributes<HTMLEleme
|
||||
title: ReactNode;
|
||||
description?: ReactNode;
|
||||
closeLabel?: string;
|
||||
headerActions?: ReactNode;
|
||||
footer?: ReactNode;
|
||||
onClose: () => void;
|
||||
children: ReactNode;
|
||||
@@ -23,6 +24,7 @@ export function ApplicationSidePanel({
|
||||
title,
|
||||
description,
|
||||
closeLabel = "Закрыть панель",
|
||||
headerActions,
|
||||
footer,
|
||||
onClose,
|
||||
children,
|
||||
@@ -42,6 +44,7 @@ export function ApplicationSidePanel({
|
||||
{description ? <span className="nodedc-application-side-panel__description">{description}</span> : null}
|
||||
</div>
|
||||
<div className="nodedc-admin-panel__head-actions">
|
||||
{headerActions}
|
||||
<button type="button" className="nodedc-admin-panel__close" aria-label={closeLabel} onClick={onClose}>
|
||||
<Icon name="close" size={16} strokeWidth={1.6} />
|
||||
</button>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef, type HTMLAttributes } from "react";
|
||||
import { createContext, useContext, useEffect, useRef, type HTMLAttributes, type ReactNode } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { cn } from "./cn.js";
|
||||
import { Icon, type IconName } from "./Icon.js";
|
||||
@@ -13,6 +13,13 @@ export type ToastItem = {
|
||||
durationMs?: number | null;
|
||||
};
|
||||
|
||||
const ToastObservation = createContext<((items: ToastItem[]) => void) | null>(null);
|
||||
|
||||
/** The application owns history/storage; this only reports terminal presentations. */
|
||||
export function ToastObserver({onPresent, children}: {onPresent: (items: ToastItem[]) => void; children: ReactNode}) {
|
||||
return <ToastObservation.Provider value={onPresent}>{children}</ToastObservation.Provider>;
|
||||
}
|
||||
|
||||
const toastIcons: Record<ToastTone, IconName> = {
|
||||
success: "check",
|
||||
error: "alert",
|
||||
@@ -69,7 +76,21 @@ function TimedToastCard({ item, onDismiss }: { item: ToastItem; onDismiss: (id:
|
||||
return <ToastCard item={item} onDismiss={onDismiss} />;
|
||||
}
|
||||
|
||||
export function ToastStack({ items, onDismiss }: { items: ToastItem[]; onDismiss: (id: string) => void }) {
|
||||
export function ToastStack({ items, onDismiss, observe = true }: { items: ToastItem[]; onDismiss: (id: string) => void; observe?: boolean }) {
|
||||
const observer = useContext(ToastObservation);
|
||||
const presented = useRef(new Map<string, string>());
|
||||
useEffect(() => {
|
||||
const next = new Map<string, string>();
|
||||
const fresh: ToastItem[] = [];
|
||||
for (const item of items) {
|
||||
if (item.tone === 'loading') continue;
|
||||
const identity = JSON.stringify([item.tone, item.title, item.description]);
|
||||
next.set(item.id, identity);
|
||||
if (presented.current.get(item.id) !== identity) fresh.push(item);
|
||||
}
|
||||
presented.current = next;
|
||||
if (observe && fresh.length) observer?.(fresh);
|
||||
}, [items, observer, observe]);
|
||||
if (typeof document === "undefined" || items.length === 0) return null;
|
||||
return createPortal(
|
||||
<div className="nodedc-toast-viewport nodedc-ui-root" aria-live="polite" aria-relevant="additions removals">
|
||||
|
||||
@@ -24,6 +24,8 @@ export interface UserProfileMenuProps {
|
||||
triggerLabel?: ReactNode;
|
||||
/** Optional status glyph between the label and avatar. */
|
||||
triggerIcon?: IconName;
|
||||
/** Independent header action; the avatar still opens the profile menu. */
|
||||
headerAction?: { label: string; pressed?: boolean; controls?: string; onSelect: () => void };
|
||||
actions: readonly UserProfileMenuAction[];
|
||||
}
|
||||
|
||||
@@ -35,6 +37,7 @@ export function UserProfileMenu({
|
||||
coverImageUrl,
|
||||
triggerLabel,
|
||||
triggerIcon,
|
||||
headerAction,
|
||||
actions,
|
||||
}: UserProfileMenuProps) {
|
||||
const label = displayName || "NODE.DC";
|
||||
@@ -51,11 +54,15 @@ export function UserProfileMenu({
|
||||
</HeaderProfileButton>
|
||||
<IconButton
|
||||
ref={setTriggerRef}
|
||||
label={`Меню пользователя ${label}`}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={open}
|
||||
aria-controls={surfaceId}
|
||||
onClick={(event) => { setTriggerRef(event.currentTarget); toggle(); }}
|
||||
label={headerAction?.label ?? `Меню пользователя ${label}`}
|
||||
aria-haspopup={headerAction ? undefined : "menu"}
|
||||
aria-pressed={headerAction?.pressed}
|
||||
aria-expanded={headerAction ? headerAction.pressed : open}
|
||||
aria-controls={headerAction ? headerAction.controls : surfaceId}
|
||||
onClick={(event) => {
|
||||
if (headerAction) { if (open) toggle(); headerAction.onSelect(); }
|
||||
else { setTriggerRef(event.currentTarget); toggle(); }
|
||||
}}
|
||||
><Icon name={triggerIcon ?? "inbox"} size={20} strokeWidth={1.7} /></IconButton>
|
||||
<button type="button" className="nodedc-user-profile-menu__trigger" aria-label={`Профиль ${label}`} aria-haspopup="menu" aria-expanded={open} aria-controls={surfaceId}
|
||||
onClick={(event) => { setTriggerRef(event.currentTarget); toggle(); }}>
|
||||
|
||||
@@ -708,6 +708,7 @@
|
||||
"behavior": [
|
||||
"portal dropdown",
|
||||
"profile identity card",
|
||||
"optional pressed state and controlled region on independent header action; its selected circle and glyph use the active IconButton colors, including on hover",
|
||||
"theme-independent cover",
|
||||
"action links and callbacks",
|
||||
"outside pointer and Escape close",
|
||||
@@ -717,7 +718,8 @@
|
||||
"The component owns menu geometry and profile presentation; the application owns settings, profile and logout actions.",
|
||||
"Use the existing Dropdown engine so the menu is never clipped by the fixed application header.",
|
||||
"Do not embed product permissions or sharing rules in the visual menu.",
|
||||
"The default header composes HeaderProfileButton, an independent menu IconButton and HeaderAvatar using the existing header geometry. Application settings belong inside this menu; do not add an adjacent settings button or another HeaderProfile wrapper."
|
||||
"The default header composes HeaderProfileButton, an independent menu IconButton and HeaderAvatar using the existing header geometry. Application settings belong inside this menu; do not add an adjacent settings button or another HeaderProfile wrapper.",
|
||||
"Optional headerAction separates the middle icon action from the avatar/profile trigger; without it legacy behavior is preserved."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -908,7 +910,7 @@
|
||||
"nodedc-application-side-panel",
|
||||
"nodedc-app-shell__end-panel"
|
||||
],
|
||||
"summary": "Theme-aware trailing application panel paired with AdminNavigationPanel and hosted in a separate ApplicationShell end column.",
|
||||
"summary": "Theme-aware trailing application panel with optional header actions before close, hosted in a separate ApplicationShell end column.",
|
||||
"anatomy": [
|
||||
"eyebrow and title",
|
||||
"optional description",
|
||||
@@ -1013,7 +1015,8 @@
|
||||
"ToastCard",
|
||||
"ToastStack",
|
||||
"ToastItem",
|
||||
"ToastTone"
|
||||
"ToastTone",
|
||||
"ToastObserver"
|
||||
],
|
||||
"domContract": [
|
||||
"nodedc-toast-viewport",
|
||||
@@ -1041,7 +1044,8 @@
|
||||
"Errors and status copy use the compact Toast typography; consumers do not substitute browser-default paragraphs or title-sized text.",
|
||||
"Adding or updating another notification never restarts the lifetime of an existing item; each item owns its timer by stable id.",
|
||||
"Loading notifications remain until the operation updates or dismisses them.",
|
||||
"Status notifications never replace a blocking confirmation modal."
|
||||
"Status notifications never replace a blocking confirmation modal.",
|
||||
"ToastObserver reports new or changed terminal presentations to the consumer; storage and history belong to the application. Set observe=false for server-originated items already recorded in history."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user