From aec2cdd644b8d6bf1846f0d26d1485ef669f5f98 Mon Sep 17 00:00:00 2001 From: "Zimin A.N." Date: Wed, 13 May 2026 11:03:47 +0300 Subject: [PATCH] =?UTF-8?q?fix(sidebar,audit):=20badges=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20Outbox=20+=20Webhooks,=20clarify=20audit=20scope=20lab?= =?UTF-8?q?el?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sidebar: - Outbox: бэйдж = outbox.pending (события queued, не отосланы). DLQ отдельно — alarming но не actionable из бэйджа, видно на /outbox. - Webhooks: бэйдж = count активных subscriptions (w.active === true). User feedback: 'вебхуки активные есть а цифры с бэйджем нет'. Audit log column header: - 'Scope' → 'Доступ актора' (ru) / 'Actor scope' (en) - Backend audit_log хранит userScope (claim из JWT актора), НЕ scope изменённого ресурса. User confusion: 'правки в public были а тут RESTRICTED' — потому что у пользователя scope-привилегия RESTRICTED. Уточнённая label убирает путаницу. - TODO: backend feature — добавить dictionaryScope в AuditEntry чтобы показать обе ('Актор: RESTRICTED → Ресурс: PUBLIC' — двусторонний audit trail для compliance). --- .../src/components/layout/Sidebar.tsx | 58 ++++++++++++++++--- ordinis-admin-ui/src/i18n.ts | 9 ++- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/ordinis-admin-ui/src/components/layout/Sidebar.tsx b/ordinis-admin-ui/src/components/layout/Sidebar.tsx index 84fa3be..0d5f690 100644 --- a/ordinis-admin-ui/src/components/layout/Sidebar.tsx +++ b/ordinis-admin-ui/src/components/layout/Sidebar.tsx @@ -14,7 +14,13 @@ import { } from 'lucide-react' import { useAuth } from 'react-oidc-context' import { useCanMutate } from '@/auth/useCanMutate' -import { useDictionaries, useMyDrafts, useReviewsBadgeCount } from '@/api/queries' +import { + useDictionaries, + useMyDrafts, + useOutboxStats, + useReviewsBadgeCount, + useWebhookSubscriptions, +} from '@/api/queries' import { Sheet, SheetContent } from '@/ui' import { ThemeSwitch } from '@/components/layout/ThemeSwitch' import { cn } from '@/lib/utils' @@ -56,13 +62,22 @@ export function Sidebar() { // Loaded just for сидбар counter — light request, кэшируется. const myDrafts = useMyDrafts(0, 1) // Reviews badge — суммирует record-reviews + schema-reviews pending queues - // через size=1 paged запросы (cheap: одна запись + metadata). Gated на - // authenticated, чтобы anonymous не пытался admin endpoint'ы. + // через size=1 paged запросы. Gated на authenticated. const reviews = useReviewsBadgeCount(auth.isAuthenticated) + // Outbox/Webhooks badges — light periodic poll. Backend гейтит, поэтому + // anonymous safe (просто 401 проигнорируется). + const outboxStats = useOutboxStats() + const webhooks = useWebhookSubscriptions() const dictsCount = dictsQuery.data?.length ?? 0 const myDraftsCount = myDrafts.data?.totalElements ?? 0 const reviewsCount = reviews.total + // Pending events ждут dispatch. dlq отдельно — alarming, но не блокирует + // нормальную работу, можно увидеть на /outbox. Badge показывает только + // pending (actionable: 'надо разобраться почему queue растёт'). + const outboxPending = outboxStats.data?.pending ?? 0 + const webhooksActive = + webhooks.data?.filter((w) => w.active).length ?? 0 // Flat list per redesign/compact.html — no section labels, /graph removed // (now reachable via catalog toolbar "Граф ⇄" button). Order: Главная → @@ -91,8 +106,20 @@ export function Sidebar() { badge: reviewsCount > 0 ? reviewsCount : undefined, authRequired: true, }, - { to: '/outbox', label: t('nav.outbox'), icon: Inbox, authRequired: true }, - { to: '/webhooks', label: t('nav.webhooks'), icon: Webhook, authRequired: true }, + { + to: '/outbox', + label: t('nav.outbox'), + icon: Inbox, + badge: outboxPending > 0 ? outboxPending : undefined, + authRequired: true, + }, + { + to: '/webhooks', + label: t('nav.webhooks'), + icon: Webhook, + badge: webhooksActive > 0 ? webhooksActive : undefined, + authRequired: true, + }, { to: '/audit', label: t('nav.audit'), icon: ScrollText, authRequired: true }, { to: '/search', label: t('nav.search'), icon: Search }, ], @@ -394,10 +421,15 @@ export function MobileSidebar({ open, onClose }: { open: boolean; onClose: () => const dictsQuery = useDictionaries() const myDrafts = useMyDrafts(0, 1) const reviews = useReviewsBadgeCount(auth.isAuthenticated) + const outboxStats = useOutboxStats() + const webhooks = useWebhookSubscriptions() const dictsCount = dictsQuery.data?.length ?? 0 const myDraftsCount = myDrafts.data?.totalElements ?? 0 const reviewsCount = reviews.total + const outboxPending = outboxStats.data?.pending ?? 0 + const webhooksActive = + webhooks.data?.filter((w) => w.active).length ?? 0 // Flat list per redesign — same as desktop Sidebar above. const sections: NavSection[] = [ @@ -424,8 +456,20 @@ export function MobileSidebar({ open, onClose }: { open: boolean; onClose: () => badge: reviewsCount > 0 ? reviewsCount : undefined, authRequired: true, }, - { to: '/outbox', label: t('nav.outbox'), icon: Inbox, authRequired: true }, - { to: '/webhooks', label: t('nav.webhooks'), icon: Webhook, authRequired: true }, + { + to: '/outbox', + label: t('nav.outbox'), + icon: Inbox, + badge: outboxPending > 0 ? outboxPending : undefined, + authRequired: true, + }, + { + to: '/webhooks', + label: t('nav.webhooks'), + icon: Webhook, + badge: webhooksActive > 0 ? webhooksActive : undefined, + authRequired: true, + }, { to: '/audit', label: t('nav.audit'), icon: ScrollText, authRequired: true }, { to: '/search', label: t('nav.search'), icon: Search }, ], diff --git a/ordinis-admin-ui/src/i18n.ts b/ordinis-admin-ui/src/i18n.ts index 9c06035..ae03752 100644 --- a/ordinis-admin-ui/src/i18n.ts +++ b/ordinis-admin-ui/src/i18n.ts @@ -268,7 +268,12 @@ i18n 'audit.col.dictionary': 'Справочник', 'audit.col.businessKey': 'Бизнес-ключ', 'audit.col.user': 'Пользователь', - 'audit.col.scope': 'Scope', + // 'Scope' колонка показывает scope актора (claim из JWT), а НЕ + // scope ресурса. Backend audit log не хранит scope dictionary'я. + // User confusion: 'правки в public были, а тут RESTRICTED' — + // потому что у пользователя scope=RESTRICTED привилегия. Label + // 'Доступ актора' разъясняет это. + 'audit.col.scope': 'Доступ актора', 'audit.col.trace': 'Trace', 'audit.col.diff': 'Изменения', 'audit.action.expand': 'Раскрыть', @@ -972,7 +977,7 @@ i18n 'audit.col.dictionary': 'Dictionary', 'audit.col.businessKey': 'Business key', 'audit.col.user': 'User', - 'audit.col.scope': 'Scope', + 'audit.col.scope': 'Actor scope', 'audit.col.trace': 'Trace', 'audit.col.diff': 'Diff', 'audit.action.expand': 'Expand',