@gntik-ai/templates 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +58 -18
- package/dist/index.js +471 -391
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/assistant-chat/Page.test.tsx +37 -7
- package/src/assistant-chat/Page.tsx +98 -137
- package/src/assistant-chat/data.ts +69 -1
- package/src/assistant-chat/examples/AdapterChat.tsx +9 -0
- package/src/assistant-chat/template.meta.ts +1 -1
- package/src/board/Lane.tsx +1 -1
- package/src/code-editor/Page.test.tsx +12 -0
- package/src/code-editor/Page.tsx +2 -1
- package/src/code-editor/examples/PaletteTypography.tsx +130 -0
- package/src/code-editor/template.meta.ts +1 -1
- package/src/contact/Page.test.tsx +106 -0
- package/src/contact/Page.tsx +21 -3
- package/src/contact/PublicFrame.tsx +2 -17
- package/src/contact/examples/CustomFailure.tsx +24 -0
- package/src/contact/examples/FailedSend.tsx +19 -0
- package/src/contact/template.meta.ts +2 -2
- package/src/docs-article/Page.tsx +1 -1
- package/src/help-home/Page.test.tsx +10 -0
- package/src/help-home/Page.tsx +2 -4
- package/src/incident-console/Page.tsx +1 -1
- package/src/keyboard-shortcuts/Page.test.tsx +23 -1
- package/src/keyboard-shortcuts/Page.tsx +13 -3
- package/src/keyboard-shortcuts/ShortcutSheet.tsx +4 -5
- package/src/landing/Page.tsx +3 -17
- package/src/landing/template.meta.ts +1 -1
- package/src/messaging/Page.test.tsx +20 -3
- package/src/messaging/Page.tsx +15 -43
- package/src/messaging/template.meta.ts +1 -1
- package/src/notification-inbox/Page.tsx +1 -1
- package/src/pending-activation/Page.test.tsx +1 -1
- package/src/pricing/PublicFrame.tsx +2 -17
- package/src/pricing/template.meta.ts +1 -1
- package/src/resource-detail/CustomTabs.tsx +41 -0
- package/src/resource-detail/Page.default.test.tsx +29 -0
- package/src/resource-detail/Page.shell-less.test.tsx +36 -0
- package/src/resource-detail/Page.tabs.test.tsx +116 -0
- package/src/resource-detail/Page.tsx +62 -27
- package/src/resource-detail/__snapshots__/Page.default.test.tsx.snap +5 -0
- package/src/resource-detail/examples/embedded-custom-tabs.tsx +44 -0
- package/src/resource-detail/template.meta.ts +1 -1
- package/src/resource-index/Page.test.tsx +178 -1
- package/src/resource-index/Page.tsx +59 -3
- package/src/resource-index/examples/UrlSynced.tsx +10 -0
- package/src/resource-index/template.meta.ts +1 -1
- package/src/resource-tree/Page.tsx +1 -1
- package/src/run-trace/Page.tsx +2 -2
- package/src/scorecard/Page.test.tsx +54 -0
- package/src/scorecard/Page.tsx +2 -0
- package/src/scorecard/data.ts +1 -1
- package/src/search-results/Page.tsx +3 -6
- package/src/settings-appearance/Page.test.tsx +36 -1
- package/src/settings-appearance/Page.tsx +15 -2
- package/src/settings-appearance/template.meta.ts +2 -1
- package/src/settings-profile/__tests__/dom.ts +4 -2
- package/src/settings-profile/fixtures/editable.snap +1 -1
- package/src/shared/ConsoleShell.context.test.tsx +125 -0
- package/src/shared/ConsoleShell.navigation.test.tsx +100 -0
- package/src/shared/ConsoleShell.tsx +38 -9
- package/src/shell-sidebar/Examples.test.tsx +73 -0
- package/src/shell-sidebar/examples/Brand.tsx +16 -0
- package/src/shell-sidebar/examples/ContextRegion.tsx +26 -0
- package/src/shell-sidebar/examples/PlatformWide.tsx +11 -0
- package/src/shell-sidebar/examples/Tenants.tsx +42 -0
- package/src/shell-sidebar/examples/UserMenuChildren.tsx +23 -0
- package/src/shell-sidebar/template.meta.ts +1 -1
- package/src/sign-in/BrandPanel.tsx +2 -2
- package/src/sign-in/Page.test.tsx +5 -0
- package/src/sso-login/Page.test.tsx +6 -0
- package/src/sso-login/Page.tsx +1 -0
- package/src/test/public-footer.test.tsx +44 -0
- package/src/test/without-forced-colors.test.ts +44 -0
- package/src/test/without-forced-colors.ts +14 -0
|
@@ -9,8 +9,14 @@ describe('MessagingPage', () => {
|
|
|
9
9
|
render(<MessagingPage />);
|
|
10
10
|
expect(screen.getByRole('main')).toBeInTheDocument();
|
|
11
11
|
expect(screen.getByRole('heading', { level: 1, name: 'Messages' })).toBeInTheDocument();
|
|
12
|
-
const list = screen.getByRole('
|
|
13
|
-
expect(
|
|
12
|
+
const list = screen.getByRole('navigation', { name: 'Conversations' });
|
|
13
|
+
expect(
|
|
14
|
+
within(list)
|
|
15
|
+
.getAllByRole('button')
|
|
16
|
+
.filter((el) => !el.hasAttribute('aria-haspopup')),
|
|
17
|
+
).toHaveLength(conversations.length);
|
|
18
|
+
expect(within(list).queryByRole('heading')).toBeNull();
|
|
19
|
+
expect([...list.querySelectorAll<HTMLElement>('button')].filter((el) => el.tabIndex === 0)).toHaveLength(1);
|
|
14
20
|
expect(within(list).getByText('2')).toBeInTheDocument();
|
|
15
21
|
expect(screen.getByRole('heading', { name: 'Select a conversation' })).toBeInTheDocument();
|
|
16
22
|
await expectNoAxeViolations();
|
|
@@ -20,8 +26,9 @@ describe('MessagingPage', () => {
|
|
|
20
26
|
const onSend = vi.fn();
|
|
21
27
|
render(<MessagingPage onSend={onSend} />);
|
|
22
28
|
await userEvent.click(
|
|
23
|
-
within(screen.getByRole('
|
|
29
|
+
within(screen.getByRole('navigation', { name: 'Conversations' })).getByRole('button', { name: /^Release 2\.14/ }),
|
|
24
30
|
);
|
|
31
|
+
expect(screen.queryByLabelText('2 unread messages')).toBeNull();
|
|
25
32
|
const log = screen.getByRole('log', { name: 'Messages in Release 2.14' });
|
|
26
33
|
expect(within(log).getAllByRole('article')).toHaveLength(4);
|
|
27
34
|
expect(within(log).getByText('rollback-runbook.pdf')).toBeInTheDocument();
|
|
@@ -32,3 +39,13 @@ describe('MessagingPage', () => {
|
|
|
32
39
|
await expectNoAxeViolations();
|
|
33
40
|
});
|
|
34
41
|
});
|
|
42
|
+
|
|
43
|
+
it.each(['dark', 'light', 'high_contrast'])(
|
|
44
|
+
'history and thread are axe clean in %s',
|
|
45
|
+
{ timeout: 15000 },
|
|
46
|
+
async (theme) => {
|
|
47
|
+
document.documentElement.className = theme;
|
|
48
|
+
render(<MessagingPage defaultConversationId="c-release" />);
|
|
49
|
+
await expectNoAxeViolations();
|
|
50
|
+
},
|
|
51
|
+
);
|
package/src/messaging/Page.tsx
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { PageHeader } from '@gntik-ai/blocks';
|
|
2
|
-
import { ChatComposer, ChatMessage } from '@gntik-ai/chat';
|
|
2
|
+
import { ChatComposer, ChatMessage, ConversationList } from '@gntik-ai/chat';
|
|
3
3
|
import { MessagesSquare, SquarePen } from '@gntik-ai/icons';
|
|
4
4
|
import {
|
|
5
5
|
Avatar,
|
|
6
6
|
AvatarGroup,
|
|
7
|
-
Badge,
|
|
8
7
|
EmptyState,
|
|
9
8
|
Heading,
|
|
10
9
|
Page,
|
|
@@ -12,9 +11,7 @@ import {
|
|
|
12
11
|
Text,
|
|
13
12
|
Thumbnail,
|
|
14
13
|
ThumbnailList,
|
|
15
|
-
Timestamp,
|
|
16
14
|
TooltipProvider,
|
|
17
|
-
cn,
|
|
18
15
|
type BreadcrumbItem,
|
|
19
16
|
} from '@gntik-ai/ui';
|
|
20
17
|
import { useId, useState } from 'react';
|
|
@@ -86,47 +83,22 @@ export default function MessagingPage(props: Partial<MessagingProps>) {
|
|
|
86
83
|
};
|
|
87
84
|
|
|
88
85
|
const list = (
|
|
89
|
-
<
|
|
90
|
-
{
|
|
86
|
+
<ConversationList
|
|
87
|
+
groupBy={false}
|
|
88
|
+
activeId={selectedId}
|
|
89
|
+
onActiveChange={openConversation}
|
|
90
|
+
items={items.map((c) => {
|
|
91
91
|
const last = c.messages[c.messages.length - 1];
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
<Avatar size="sm" name={c.title} aria-hidden />
|
|
101
|
-
<span className="min-w-0 flex-1">
|
|
102
|
-
<span className="flex items-baseline gap-2">
|
|
103
|
-
<span
|
|
104
|
-
className={cn(
|
|
105
|
-
'min-w-0 flex-1 truncate text-[13px] text-foreground',
|
|
106
|
-
c.unread > 0 && 'font-semibold',
|
|
107
|
-
)}
|
|
108
|
-
>
|
|
109
|
-
{c.title}
|
|
110
|
-
</span>
|
|
111
|
-
{last && <Timestamp value={last.at} tooltip={false} className="shrink-0 font-mono text-[11px]" />}
|
|
112
|
-
</span>
|
|
113
|
-
<span className="mt-0.5 flex items-center gap-2">
|
|
114
|
-
<span className="min-w-0 flex-1 truncate text-[12px] text-muted-foreground">
|
|
115
|
-
{last ? `${last.mine ? 'You' : last.author.split(' ')[0]}: ${last.text}` : 'No messages yet'}
|
|
116
|
-
</span>
|
|
117
|
-
{c.unread > 0 && (
|
|
118
|
-
<Badge tone="primary" size="sm">
|
|
119
|
-
{c.unread}
|
|
120
|
-
<span className="sr-only"> unread</span>
|
|
121
|
-
</Badge>
|
|
122
|
-
)}
|
|
123
|
-
</span>
|
|
124
|
-
</span>
|
|
125
|
-
</button>
|
|
126
|
-
</li>
|
|
127
|
-
);
|
|
92
|
+
return {
|
|
93
|
+
id: c.id,
|
|
94
|
+
title: c.title,
|
|
95
|
+
preview: last ? `${last.mine ? 'You' : last.author.split(' ')[0]}: ${last.text}` : 'No messages yet',
|
|
96
|
+
updatedAt: last?.at ?? 0,
|
|
97
|
+
unread: c.unread,
|
|
98
|
+
icon: <Avatar size="sm" name={c.title} aria-hidden />,
|
|
99
|
+
};
|
|
128
100
|
})}
|
|
129
|
-
|
|
101
|
+
/>
|
|
130
102
|
);
|
|
131
103
|
|
|
132
104
|
const detail = selected ? (
|
|
@@ -6,7 +6,7 @@ export const meta: TemplateMeta = {
|
|
|
6
6
|
priority: 'P3',
|
|
7
7
|
status: 'experimental',
|
|
8
8
|
description:
|
|
9
|
-
'Team messaging in the console: SplitLayout
|
|
9
|
+
'Team messaging in the console: SplitLayout with ConversationList (roving focus, unread counts, last message) → thread of ChatMessages with Thumbnail attachments, participants AvatarGroup, and a ChatComposer with file attachments; Back on small screens.',
|
|
10
10
|
layout: 'SidebarLayout · Page · SplitLayout',
|
|
11
11
|
blocks: ['app-sidebar', 'app-topbar', 'page-header'],
|
|
12
12
|
};
|
|
@@ -106,7 +106,7 @@ export default function NotificationInboxPage(props: Partial<NotificationInboxPr
|
|
|
106
106
|
type="button"
|
|
107
107
|
aria-current={n.id === selectedId ? 'true' : undefined}
|
|
108
108
|
onClick={() => open(n)}
|
|
109
|
-
className="flex w-full items-start gap-3 rounded-lg px-3 py-2.5 text-start hover:bg-accent/55 focus-
|
|
109
|
+
className="flex w-full items-start gap-3 rounded-lg px-3 py-2.5 text-start hover:bg-accent/55 focus-ring aria-[current=true]:bg-accent"
|
|
110
110
|
>
|
|
111
111
|
<span className="mt-1.5 flex w-2 shrink-0 justify-center">
|
|
112
112
|
{!n.read && <StatusDot tone={n.tone} aria-hidden />}
|
|
@@ -65,7 +65,7 @@ describe('PendingActivationPage', () => {
|
|
|
65
65
|
await user.tab();
|
|
66
66
|
const control = screen.getByRole(name === 'Retry' || name === 'Check status' ? 'button' : 'link', { name });
|
|
67
67
|
expect(control).toHaveFocus();
|
|
68
|
-
expect(control).toHaveClass('focus-
|
|
68
|
+
expect(control).toHaveClass('focus-ring');
|
|
69
69
|
}
|
|
70
70
|
await user.tab();
|
|
71
71
|
expect(document.body).toHaveFocus();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { SiteFooter } from '@gntik-ai/blocks';
|
|
1
2
|
import {
|
|
2
3
|
Button,
|
|
3
|
-
Link,
|
|
4
4
|
Logo,
|
|
5
5
|
MegaMenu,
|
|
6
6
|
MobileNav,
|
|
@@ -61,22 +61,7 @@ export function PublicFrame({
|
|
|
61
61
|
</>
|
|
62
62
|
}
|
|
63
63
|
subnav={<MegaMenu items={menu} currentHref={currentHref} label="Primary" className="hidden lg:block" />}
|
|
64
|
-
footer={
|
|
65
|
-
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
66
|
-
<span>{copyright}</span>
|
|
67
|
-
<nav aria-label="Footer">
|
|
68
|
-
<ul className="flex flex-wrap gap-x-4 gap-y-1">
|
|
69
|
-
{footerLinks.map((l) => (
|
|
70
|
-
<li key={l.href}>
|
|
71
|
-
<Link href={l.href} tone="muted" underline="hover">
|
|
72
|
-
{l.label}
|
|
73
|
-
</Link>
|
|
74
|
-
</li>
|
|
75
|
-
))}
|
|
76
|
-
</ul>
|
|
77
|
-
</nav>
|
|
78
|
-
</div>
|
|
79
|
-
}
|
|
64
|
+
footer={<SiteFooter layout="simple" links={footerLinks} copyright={copyright} />}
|
|
80
65
|
>
|
|
81
66
|
{children}
|
|
82
67
|
</StackedLayout>
|
|
@@ -8,5 +8,5 @@ export const meta: TemplateMeta = {
|
|
|
8
8
|
description:
|
|
9
9
|
'Public pricing page: StackedLayout with a MegaMenu (MobileNav below lg), PricingTable with the monthly / annual toggle, FeatureGrid highlights, a plan comparison table grouped by section, and Faq.',
|
|
10
10
|
layout: 'StackedLayout',
|
|
11
|
-
blocks: ['pricing-table', 'feature-grid', 'faq'],
|
|
11
|
+
blocks: ['site-footer', 'pricing-table', 'feature-grid', 'faq'],
|
|
12
12
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Tabs, TabsList, TabsPanel, TabsTab } from '@gntik-ai/ui';
|
|
2
|
+
import { useState, type ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface CustomTabsProps {
|
|
5
|
+
tabs: { value: string; label: string; content: ReactNode }[];
|
|
6
|
+
defaultTab?: string;
|
|
7
|
+
onTabChange?: (tab: string) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function CustomTabs({ tabs, defaultTab, onTabChange, label }: CustomTabsProps & { label: string }) {
|
|
11
|
+
const [selected, setSelected] = useState(defaultTab);
|
|
12
|
+
const value = tabs.find((tab) => tab.value === selected)?.value ?? tabs[0]?.value ?? null;
|
|
13
|
+
|
|
14
|
+
if (tabs.length === 0) return null;
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Tabs
|
|
18
|
+
value={value}
|
|
19
|
+
onValueChange={(next) => {
|
|
20
|
+
const tab = tabs.find((tab) => tab.value === next);
|
|
21
|
+
if (tab) {
|
|
22
|
+
setSelected(tab.value);
|
|
23
|
+
onTabChange?.(tab.value);
|
|
24
|
+
}
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
<TabsList aria-label={label}>
|
|
28
|
+
{tabs.map((tab) => (
|
|
29
|
+
<TabsTab key={tab.value} value={tab.value}>
|
|
30
|
+
{tab.label}
|
|
31
|
+
</TabsTab>
|
|
32
|
+
))}
|
|
33
|
+
</TabsList>
|
|
34
|
+
{tabs.map((tab) => (
|
|
35
|
+
<TabsPanel key={tab.value} value={tab.value}>
|
|
36
|
+
{tab.content}
|
|
37
|
+
</TabsPanel>
|
|
38
|
+
))}
|
|
39
|
+
</Tabs>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import ResourceDetailPage from './Page';
|
|
3
|
+
import { shell } from './examples/shell';
|
|
4
|
+
import { withoutForcedColors } from '../test/without-forced-colors';
|
|
5
|
+
|
|
6
|
+
vi.hoisted(() => {
|
|
7
|
+
vi.useFakeTimers({ now: new Date('2026-10-23T12:00:00Z'), toFake: ['Date'] });
|
|
8
|
+
});
|
|
9
|
+
afterAll(() => vi.useRealTimers());
|
|
10
|
+
|
|
11
|
+
// React's client IDs advance across roots. Preserve their relationships while
|
|
12
|
+
// canonicalizing only the generated IDs so the original markup is comparable.
|
|
13
|
+
function stableIds(html: string) {
|
|
14
|
+
const ids = new Map<string, string>();
|
|
15
|
+
return html.replace(/_r_[\da-z]+_/g, (id) => {
|
|
16
|
+
if (!ids.has(id)) ids.set(id, `_stable_${ids.size}_`);
|
|
17
|
+
return ids.get(id)!;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
it('preserves the original default shell markup', () => {
|
|
22
|
+
const { container } = render(<ResourceDetailPage />);
|
|
23
|
+
expect(stableIds(withoutForcedColors(container).innerHTML)).toMatchSnapshot();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('preserves the original explicit shell markup', () => {
|
|
27
|
+
const { container } = render(<ResourceDetailPage shell={shell} />);
|
|
28
|
+
expect(stableIds(withoutForcedColors(container).innerHTML)).toMatchSnapshot();
|
|
29
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { render, screen, within } from '@testing-library/react';
|
|
2
|
+
import ResourceDetailPage from './Page';
|
|
3
|
+
import { expectNoAxeViolations } from '../test/a11y';
|
|
4
|
+
|
|
5
|
+
it('renders only page content and the default breadcrumb navigation without a shell', () => {
|
|
6
|
+
render(<ResourceDetailPage shell={null} />);
|
|
7
|
+
for (const role of ['complementary', 'banner', 'main']) {
|
|
8
|
+
expect(screen.queryByRole(role)).not.toBeInTheDocument();
|
|
9
|
+
}
|
|
10
|
+
expect(screen.getAllByRole('navigation')).toHaveLength(1);
|
|
11
|
+
expect(screen.getByRole('heading', { level: 1 })).toBeVisible();
|
|
12
|
+
expect(screen.getByRole('tablist', { name: 'Resource sections' })).toBeVisible();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('shows explicit breadcrumbs and omits navigation for an empty trail', () => {
|
|
16
|
+
const { rerender } = render(
|
|
17
|
+
<ResourceDetailPage shell={null} breadcrumbs={[{ label: 'Ops', href: '/ops' }, { label: 'Op 1' }]} />,
|
|
18
|
+
);
|
|
19
|
+
const nav = screen.getByRole('navigation');
|
|
20
|
+
expect(within(nav).getByRole('link', { name: 'Ops' })).toHaveAttribute('href', '/ops');
|
|
21
|
+
expect(within(nav).getByText('Op 1')).toBeVisible();
|
|
22
|
+
rerender(<ResourceDetailPage shell={null} breadcrumbs={[]} />);
|
|
23
|
+
expect(screen.queryByRole('navigation')).not.toBeInTheDocument();
|
|
24
|
+
rerender(<ResourceDetailPage shell={null} readOnly name="Resource record" />);
|
|
25
|
+
expect(screen.queryByRole('navigation')).not.toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('fits accessibly inside the host main landmark', { timeout: 15000 }, async () => {
|
|
29
|
+
const { container } = render(
|
|
30
|
+
<main>
|
|
31
|
+
<ResourceDetailPage shell={null} />
|
|
32
|
+
</main>,
|
|
33
|
+
);
|
|
34
|
+
expect(screen.getAllByRole('main')).toHaveLength(1);
|
|
35
|
+
await expectNoAxeViolations(container);
|
|
36
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { act, render, screen, waitFor, within } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { expectTypeOf } from 'vitest';
|
|
4
|
+
import type { ComponentProps } from 'react';
|
|
5
|
+
import { expectNoAxeViolations } from '../test/a11y';
|
|
6
|
+
import ResourceDetailPage, { type ResourceDetailTab } from './Page';
|
|
7
|
+
|
|
8
|
+
const tabs = [
|
|
9
|
+
{ value: 'A', label: 'First section', content: <p>Content A</p> },
|
|
10
|
+
{ value: 'B', label: 'Second section', content: <p>Content B</p> },
|
|
11
|
+
{ value: 'C', label: 'Third section', content: <p>Content C</p> },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
it('replaces built-in tabs with caller labels, order and content', async () => {
|
|
15
|
+
const user = userEvent.setup();
|
|
16
|
+
render(<ResourceDetailPage tabs={tabs} />);
|
|
17
|
+
expect(screen.getAllByRole('tab').map((tab) => tab.textContent)).toEqual([
|
|
18
|
+
'First section',
|
|
19
|
+
'Second section',
|
|
20
|
+
'Third section',
|
|
21
|
+
]);
|
|
22
|
+
for (const name of ['Overview', 'Activity', 'Settings']) {
|
|
23
|
+
expect(screen.queryByRole('tab', { name })).not.toBeInTheDocument();
|
|
24
|
+
}
|
|
25
|
+
expect(screen.getByText('Content A')).toBeVisible();
|
|
26
|
+
await user.click(screen.getByRole('tab', { name: 'Second section' }));
|
|
27
|
+
await waitFor(() => expect(screen.getAllByRole('tabpanel')).toHaveLength(1));
|
|
28
|
+
expect(within(screen.getByRole('tabpanel')).getByText('Content B')).toBeVisible();
|
|
29
|
+
expect(screen.queryByText('Content A')).not.toBeInTheDocument();
|
|
30
|
+
expect(screen.queryByText('Content C')).not.toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('uses caller defaults, panel associations and manual keyboard activation', async () => {
|
|
34
|
+
const user = userEvent.setup();
|
|
35
|
+
const onTabChange = vi.fn();
|
|
36
|
+
render(<ResourceDetailPage tabs={tabs} defaultTab="B" onTabChange={onTabChange} />);
|
|
37
|
+
const first = screen.getByRole('tab', { name: 'First section' });
|
|
38
|
+
const second = screen.getByRole('tab', { name: 'Second section' });
|
|
39
|
+
const third = screen.getByRole('tab', { name: 'Third section' });
|
|
40
|
+
expect(second).toHaveAttribute('aria-selected', 'true');
|
|
41
|
+
act(() => second.focus());
|
|
42
|
+
await user.keyboard('{ArrowRight}');
|
|
43
|
+
expect(third).toHaveFocus();
|
|
44
|
+
expect(second).toHaveAttribute('aria-selected', 'true');
|
|
45
|
+
expect(onTabChange).not.toHaveBeenCalled();
|
|
46
|
+
await user.keyboard('{Enter}');
|
|
47
|
+
expect(third).toHaveAttribute('aria-selected', 'true');
|
|
48
|
+
expect(onTabChange).toHaveBeenCalledWith('C');
|
|
49
|
+
await user.keyboard('{Home}');
|
|
50
|
+
expect(first).toHaveFocus();
|
|
51
|
+
await user.keyboard('{End}');
|
|
52
|
+
expect(third).toHaveFocus();
|
|
53
|
+
for (const tab of [first, second, third]) {
|
|
54
|
+
await user.click(tab);
|
|
55
|
+
const panel = await screen.findByRole('tabpanel');
|
|
56
|
+
expect(tab).toHaveAttribute('aria-controls', panel.id);
|
|
57
|
+
expect(panel).toHaveAttribute('aria-labelledby', tab.id);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('falls back to the first caller tab for an unknown default', () => {
|
|
62
|
+
render(<ResourceDetailPage tabs={tabs} defaultTab="unknown" />);
|
|
63
|
+
expect(screen.getByRole('tab', { name: 'First section' })).toHaveAttribute('aria-selected', 'true');
|
|
64
|
+
expect(screen.getByText('Content A')).toBeVisible();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('renders only the heading and header when caller tabs are empty', () => {
|
|
68
|
+
render(<ResourceDetailPage tabs={[]} />);
|
|
69
|
+
expect(screen.queryByRole('tablist')).not.toBeInTheDocument();
|
|
70
|
+
expect(screen.queryByRole('tabpanel')).not.toBeInTheDocument();
|
|
71
|
+
expect(screen.getByRole('heading', { level: 1 })).toBeVisible();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('selects the first caller tab when no default is supplied, including built-in value names', () => {
|
|
75
|
+
render(<ResourceDetailPage tabs={[tabs[0]!, { ...tabs[1]!, value: 'overview' }]} />);
|
|
76
|
+
expect(screen.getByRole('tab', { name: 'First section' })).toHaveAttribute('aria-selected', 'true');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('does not filter custom tabs or their selection in read-only mode', async () => {
|
|
80
|
+
const user = userEvent.setup();
|
|
81
|
+
render(<ResourceDetailPage readOnly name="Resource record" tabs={tabs.slice(0, 2)} />);
|
|
82
|
+
expect(screen.getAllByRole('tab')).toHaveLength(2);
|
|
83
|
+
await user.click(screen.getByRole('tab', { name: 'Second section' }));
|
|
84
|
+
expect(screen.getByText('Content B')).toBeVisible();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it.each([undefined, null])('keeps custom tabs accessible with shell=%s', { timeout: 15000 }, async (shell) => {
|
|
88
|
+
const { container } = render(
|
|
89
|
+
<ResourceDetailPage shell={shell} tabs={tabs} labels={{ sections: 'Record sections' }} />,
|
|
90
|
+
);
|
|
91
|
+
expect(screen.getByRole('tablist', { name: 'Record sections' })).toBeVisible();
|
|
92
|
+
await expectNoAxeViolations(container);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('keeps built-in callback values narrow and custom callback values as strings', () => {
|
|
96
|
+
type Props = ComponentProps<typeof ResourceDetailPage>;
|
|
97
|
+
type BuiltIn = Extract<Props, { tabs?: undefined }>;
|
|
98
|
+
type Custom = Extract<Props, { tabs: unknown[] }>;
|
|
99
|
+
expectTypeOf<BuiltIn['defaultTab']>().toEqualTypeOf<ResourceDetailTab | undefined>();
|
|
100
|
+
expectTypeOf<NonNullable<BuiltIn['onTabChange']>>().parameter(0).toEqualTypeOf<ResourceDetailTab>();
|
|
101
|
+
expectTypeOf<Custom['defaultTab']>().toEqualTypeOf<string | undefined>();
|
|
102
|
+
expectTypeOf<NonNullable<Custom['onTabChange']>>().parameter(0).toEqualTypeOf<string>();
|
|
103
|
+
expectTypeOf<{ defaultTab: 'B' }>().not.toExtend<Props>();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('smoke-loads the embedded custom tabs preview inside one accessible main', { timeout: 15000 }, async () => {
|
|
107
|
+
const { default: EmbeddedCustomTabs } = await import('./examples/embedded-custom-tabs');
|
|
108
|
+
const { container } = render(<EmbeddedCustomTabs />);
|
|
109
|
+
expect(screen.getAllByRole('main')).toHaveLength(1);
|
|
110
|
+
expect(screen.queryByRole('banner')).not.toBeInTheDocument();
|
|
111
|
+
expect(screen.queryByRole('complementary')).not.toBeInTheDocument();
|
|
112
|
+
expect(screen.getAllByRole('tab').map((tab) => tab.textContent)).toEqual(['Summary', 'Output']);
|
|
113
|
+
await userEvent.click(screen.getByRole('tab', { name: 'Output' }));
|
|
114
|
+
expect(screen.getByText('The resource completed successfully.')).toBeVisible();
|
|
115
|
+
await expectNoAxeViolations(container);
|
|
116
|
+
});
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
} from '@gntik-ai/ui';
|
|
34
34
|
import { useState } from 'react';
|
|
35
35
|
import { ConsoleShell, type ConsoleShellProps } from '../shared/ConsoleShell';
|
|
36
|
+
import { CustomTabs, type CustomTabsProps } from './CustomTabs';
|
|
36
37
|
import {
|
|
37
38
|
detailActivity,
|
|
38
39
|
detailBreadcrumbs,
|
|
@@ -53,11 +54,11 @@ export interface ResourceDetailLabels {
|
|
|
53
54
|
sections: string;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
interface ResourceDetailBaseProps {
|
|
57
58
|
/** Per-key copy overrides; explicit props take precedence, then labels, then the active catalog. */
|
|
58
59
|
labels?: Partial<ResourceDetailLabels>;
|
|
59
60
|
/**
|
|
60
|
-
* Optional boolean, default false.
|
|
61
|
+
* Optional boolean, default false. With built-in tabs, shows only the keyboard-accessible Overview tab in
|
|
61
62
|
* the "Resource sections" tablist, using explicit resource props without sample defaults.
|
|
62
63
|
* Ignores activity, events, dangerActions, defaultTab, onSaveSettings and onDangerAction.
|
|
63
64
|
* Explicit actions and onEditDetails are still honored. ConsoleShell defaults are unchanged.
|
|
@@ -86,19 +87,38 @@ export interface ResourceDetailProps {
|
|
|
86
87
|
events: readonly StatusEvent[];
|
|
87
88
|
activity: readonly ActivityItem[];
|
|
88
89
|
dangerActions: DangerZoneAction[];
|
|
89
|
-
defaultTab: ResourceDetailTab;
|
|
90
|
-
onTabChange: (tab: ResourceDetailTab) => void;
|
|
91
90
|
onEditDetails: () => void;
|
|
92
91
|
onSaveSettings: (settings: ResourceSettings) => void;
|
|
93
92
|
/** Confirmed Danger zone action id (e.g. `pause`, `delete`). */
|
|
94
93
|
onDangerAction: (actionId: string) => void | Promise<void>;
|
|
95
|
-
|
|
94
|
+
/** null omits ConsoleShell; undefined or an object preserves the default frame. */
|
|
95
|
+
shell: Omit<ConsoleShellProps, 'children'> | null;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
// Custom tabs require an explicit list; omitted tabs retain the built-in value types.
|
|
99
|
+
type ResourceDetailTabsProps =
|
|
100
|
+
| {
|
|
101
|
+
tabs?: undefined;
|
|
102
|
+
defaultTab?: ResourceDetailTab;
|
|
103
|
+
onTabChange?: (tab: ResourceDetailTab) => void;
|
|
104
|
+
}
|
|
105
|
+
/** Replaces the built-in tabs, including in read-only mode; [] hides the tab set. */
|
|
106
|
+
| CustomTabsProps;
|
|
107
|
+
|
|
108
|
+
export type ResourceDetailProps = ResourceDetailBaseProps & ResourceDetailTabsProps;
|
|
109
|
+
|
|
98
110
|
const TABS: ResourceDetailTab[] = ['overview', 'activity', 'settings'];
|
|
99
111
|
|
|
100
|
-
/**
|
|
101
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Resource detail: editable tabs by default, or explicit-only Overview when readOnly is true.
|
|
114
|
+
* Pass tabs to replace the built-in sections with caller labels, values and content; readOnly
|
|
115
|
+
* does not filter custom tabs. An omitted or unknown defaultTab selects the first custom tab.
|
|
116
|
+
* shell={null} renders only Page and its header. The host owns the main landmark and must
|
|
117
|
+
* provide ChartLocaleProvider when its custom chart content needs a locale. Breadcrumbs
|
|
118
|
+
* render in the header in this mode: pass a trail or [] to avoid the editable sample trail.
|
|
119
|
+
* Omitted or object shells and omitted tabs preserve the existing default output.
|
|
120
|
+
*/
|
|
121
|
+
export default function ResourceDetailPage(props: Partial<ResourceDetailBaseProps> & ResourceDetailTabsProps) {
|
|
102
122
|
const { t } = useI18n();
|
|
103
123
|
const readOnly = props.readOnly ?? false;
|
|
104
124
|
const {
|
|
@@ -116,7 +136,6 @@ export default function ResourceDetailPage(props: Partial<ResourceDetailProps>)
|
|
|
116
136
|
activity = readOnly ? [] : detailActivity,
|
|
117
137
|
dangerActions = readOnly ? [] : detailDangerActions,
|
|
118
138
|
defaultTab = 'overview',
|
|
119
|
-
onTabChange,
|
|
120
139
|
onEditDetails,
|
|
121
140
|
onSaveSettings,
|
|
122
141
|
onDangerAction,
|
|
@@ -134,7 +153,7 @@ export default function ResourceDetailPage(props: Partial<ResourceDetailProps>)
|
|
|
134
153
|
]);
|
|
135
154
|
const details = detailsProp ?? (readOnly ? [] : detailItems);
|
|
136
155
|
const historyEvents = readOnly ? props.history : events;
|
|
137
|
-
const [tab, setTab] = useState
|
|
156
|
+
const [tab, setTab] = useState(defaultTab);
|
|
138
157
|
const [settings, setSettings] = useState<ResourceSettings>({ name, description });
|
|
139
158
|
const [saved, setSaved] = useState<ResourceSettings>({ name, description });
|
|
140
159
|
const dirty = settings.name !== saved.name || settings.description !== saved.description;
|
|
@@ -143,28 +162,36 @@ export default function ResourceDetailPage(props: Partial<ResourceDetailProps>)
|
|
|
143
162
|
label: labels?.[value] ?? t(`resourceDetail.${value}`),
|
|
144
163
|
}));
|
|
145
164
|
|
|
146
|
-
|
|
147
|
-
<
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
165
|
+
const content = (
|
|
166
|
+
<Page
|
|
167
|
+
width="wide"
|
|
168
|
+
header={
|
|
169
|
+
<PageHeader
|
|
170
|
+
as={shell === null ? 'div' : undefined}
|
|
171
|
+
breadcrumbs={shell === null ? breadcrumbs : null}
|
|
172
|
+
title={name}
|
|
173
|
+
description={description}
|
|
174
|
+
status={status}
|
|
175
|
+
meta={meta}
|
|
176
|
+
actions={actions}
|
|
177
|
+
tabs={null}
|
|
178
|
+
/>
|
|
179
|
+
}
|
|
180
|
+
>
|
|
181
|
+
{props.tabs !== undefined ? (
|
|
182
|
+
<CustomTabs
|
|
183
|
+
tabs={props.tabs}
|
|
184
|
+
defaultTab={props.defaultTab}
|
|
185
|
+
onTabChange={props.onTabChange}
|
|
186
|
+
label={labels?.sections ?? t('resourceDetail.sections')}
|
|
187
|
+
/>
|
|
188
|
+
) : (
|
|
162
189
|
<Tabs
|
|
163
190
|
value={readOnly ? 'overview' : tab}
|
|
164
191
|
onValueChange={(v) => {
|
|
165
192
|
const next = tabs.find((t) => t.value === v)?.value ?? 'overview';
|
|
166
193
|
setTab(next);
|
|
167
|
-
onTabChange?.(next);
|
|
194
|
+
if (props.tabs === undefined) props.onTabChange?.(next);
|
|
168
195
|
}}
|
|
169
196
|
>
|
|
170
197
|
<TabsList aria-label={labels?.sections ?? t('resourceDetail.sections')}>
|
|
@@ -267,7 +294,15 @@ export default function ResourceDetailPage(props: Partial<ResourceDetailProps>)
|
|
|
267
294
|
</TabsPanel>
|
|
268
295
|
)}
|
|
269
296
|
</Tabs>
|
|
270
|
-
|
|
297
|
+
)}
|
|
298
|
+
</Page>
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
return shell === null ? (
|
|
302
|
+
content
|
|
303
|
+
) : (
|
|
304
|
+
<ConsoleShell currentHref="/deployments" breadcrumbs={breadcrumbs} {...shell}>
|
|
305
|
+
{content}
|
|
271
306
|
</ConsoleShell>
|
|
272
307
|
);
|
|
273
308
|
}
|