2026-05-11 12:26:57 +02:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { Loader2 } from 'lucide-react';
|
|
|
|
|
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
import type {
|
|
|
|
|
AggregatedFile,
|
|
|
|
|
AggregatedGroup,
|
|
|
|
|
AggregatedWorkflow,
|
|
|
|
|
} from '@/hooks/use-aggregated-listing';
|
2026-05-11 12:26:57 +02:00
|
|
|
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
/**
|
|
|
|
|
* Discriminated-union of the two item shapes the aggregated projection
|
|
|
|
|
* surfaces (files / workflows). Keeps `renderRow` strictly typed so callers
|
|
|
|
|
* don't have to widen to `unknown` or recast inside the row renderer.
|
|
|
|
|
*/
|
|
|
|
|
type AggregatedItemKind =
|
|
|
|
|
| { kind: 'files'; items: AggregatedFile[] }
|
|
|
|
|
| { kind: 'workflows'; items: AggregatedWorkflow[] };
|
|
|
|
|
|
|
|
|
|
type ItemOfKind<K extends AggregatedItemKind['kind']> = Extract<
|
|
|
|
|
AggregatedItemKind,
|
|
|
|
|
{ kind: K }
|
|
|
|
|
>['items'][number];
|
|
|
|
|
|
|
|
|
|
interface AggregatedSectionProps<K extends AggregatedItemKind['kind']> {
|
2026-05-11 12:26:57 +02:00
|
|
|
title: string;
|
|
|
|
|
icon?: React.ReactNode;
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
groups: AggregatedGroup<ItemOfKind<K>>[];
|
|
|
|
|
renderRow: (item: ItemOfKind<K>, group: AggregatedGroup<ItemOfKind<K>>) => React.ReactNode;
|
2026-05-11 12:26:57 +02:00
|
|
|
emptyMessage?: string;
|
|
|
|
|
loading?: boolean;
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
onShowAll?: (group: AggregatedGroup<ItemOfKind<K>>) => void;
|
2026-05-11 12:26:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Renders a Signing or Files section with one labelled subsection per
|
|
|
|
|
* owner-source group. Each group shows up to 20 rows; a `Show all (N)`
|
|
|
|
|
* link drills into the source-scoped flat list. Hidden when groups is
|
|
|
|
|
* empty.
|
|
|
|
|
*/
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
export function AggregatedSection<K extends AggregatedItemKind['kind']>({
|
2026-05-11 12:26:57 +02:00
|
|
|
title,
|
|
|
|
|
icon,
|
|
|
|
|
groups,
|
|
|
|
|
renderRow,
|
|
|
|
|
emptyMessage = 'Nothing here yet.',
|
|
|
|
|
loading,
|
|
|
|
|
onShowAll,
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
}: AggregatedSectionProps<K>) {
|
2026-05-11 12:26:57 +02:00
|
|
|
const total = groups.reduce((sum, g) => sum + g.total, 0);
|
|
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
return (
|
|
|
|
|
<section className="rounded-md border bg-white p-3">
|
|
|
|
|
<h3 className="flex items-center gap-2 text-sm font-semibold text-foreground">
|
|
|
|
|
{icon}
|
|
|
|
|
{title}
|
|
|
|
|
<Loader2 className="ml-1 h-3.5 w-3.5 animate-spin text-muted-foreground" />
|
|
|
|
|
</h3>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (groups.length === 0) {
|
|
|
|
|
return (
|
|
|
|
|
<section className="rounded-md border bg-white p-3 text-sm text-muted-foreground">
|
|
|
|
|
<h3 className="flex items-center gap-2 text-sm font-semibold text-foreground">
|
|
|
|
|
{icon}
|
|
|
|
|
{title}
|
|
|
|
|
<span className="ml-1 text-xs text-muted-foreground tabular-nums">· 0</span>
|
|
|
|
|
</h3>
|
|
|
|
|
<p className="mt-2">{emptyMessage}</p>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<section className="rounded-md border bg-white">
|
|
|
|
|
<h3 className="flex items-center gap-2 border-b px-3 py-2 text-sm font-semibold text-foreground">
|
|
|
|
|
{icon}
|
|
|
|
|
{title}
|
|
|
|
|
<span className="ml-1 text-xs text-muted-foreground tabular-nums">· {total}</span>
|
|
|
|
|
</h3>
|
|
|
|
|
<div className="divide-y">
|
|
|
|
|
{groups.map((g) => (
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
<GroupBlock<K>
|
2026-05-11 12:26:57 +02:00
|
|
|
key={`${g.source}-${g.label}`}
|
|
|
|
|
group={g}
|
|
|
|
|
renderRow={renderRow}
|
|
|
|
|
onShowAll={onShowAll}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
function GroupBlock<K extends AggregatedItemKind['kind']>({
|
2026-05-11 12:26:57 +02:00
|
|
|
group,
|
|
|
|
|
renderRow,
|
|
|
|
|
onShowAll,
|
|
|
|
|
}: {
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
group: AggregatedGroup<ItemOfKind<K>>;
|
|
|
|
|
renderRow: (item: ItemOfKind<K>, group: AggregatedGroup<ItemOfKind<K>>) => React.ReactNode;
|
|
|
|
|
onShowAll?: (group: AggregatedGroup<ItemOfKind<K>>) => void;
|
2026-05-11 12:26:57 +02:00
|
|
|
}) {
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
// The server always sets exactly one of `files` / `workflows` per group;
|
|
|
|
|
// unify them into a single list for rendering. The discriminated-union
|
|
|
|
|
// generic on `AggregatedSection` keeps the row type correct upstream.
|
|
|
|
|
const items = ((group.files ?? group.workflows ?? []) as unknown) as ItemOfKind<K>[];
|
2026-05-11 12:26:57 +02:00
|
|
|
return (
|
|
|
|
|
<div className="px-3 py-2">
|
|
|
|
|
<header className="mb-1 text-[0.7rem] font-medium uppercase tracking-wide text-muted-foreground">
|
|
|
|
|
{group.label}
|
|
|
|
|
<span className="ml-1.5 text-muted-foreground/70 tabular-nums">· {group.total}</span>
|
|
|
|
|
</header>
|
|
|
|
|
<ul className="space-y-1">
|
|
|
|
|
{items.map((item) => (
|
|
|
|
|
<li key={(item as { id: string }).id}>{renderRow(item, group)}</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
{group.total > items.length ? (
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="mt-1 min-h-[44px] px-2 text-xs text-brand hover:underline"
|
2026-05-11 12:26:57 +02:00
|
|
|
onClick={() => onShowAll?.(group)}
|
|
|
|
|
>
|
|
|
|
|
Show all ({group.total})
|
fix(documents-ui): a11y, mobile, realtime lift, type-safety, UI polish
- A2: lift useRealtimeInvalidation to DocumentsHub (covers all 3 render modes)
- B1-B4: aria-label, aria-pressed, aria-expanded, Lock SVG aria-hidden
- C1-C7: Sheet wrap for mobile sidebar, border axis fix, 44x44 tap targets
- Mobile Important: useMobileChrome title, FolderActionsMenu icon size, breadcrumb tap targets, signer email truncate
- Type-safety: ENTITY_TYPES guard, AggregatedSection discriminated union
- UI/UX: em-dash to colon in SigningDetailsDialog, Loading state normalize, StatusPill on HubRootView, view signing details as Button
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:56:05 +02:00
|
|
|
</Button>
|
2026-05-11 12:26:57 +02:00
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|