@gntik-ai/blocks 0.11.0 → 0.13.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 +1501 -1232
- package/dist/index.js +1891 -840
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/ai/EvaluationScorecard/EvaluationScorecard.test.tsx +10 -0
- package/src/ai/EvaluationScorecard/EvaluationScorecard.tsx +2 -1
- package/src/ai/PromptEditor/PromptEditor.tsx +2 -2
- package/src/ai/PromptEditor/examples/controlled-variables.tsx +1 -1
- package/src/ai/TokenCostCard/TokenCostCard.test.tsx +10 -0
- package/src/ai/TokenCostCard/TokenCostCard.tsx +2 -1
- package/src/ai/TraceWaterfall/TraceWaterfall.tsx +2 -2
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.test.tsx +6 -0
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.tsx +4 -1
- package/src/auth/ForgotPasswordForm/block.meta.ts +1 -1
- package/src/auth/ForgotPasswordForm/examples/LargeFields.tsx +6 -0
- package/src/auth/MfaChallenge/MfaChallenge.test.tsx +9 -0
- package/src/auth/MfaChallenge/MfaChallenge.tsx +5 -2
- package/src/auth/MfaChallenge/block.meta.ts +1 -1
- package/src/auth/MfaChallenge/examples/LargeFields.tsx +6 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.test.tsx +7 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.tsx +5 -3
- package/src/auth/ResetPasswordForm/block.meta.ts +1 -1
- package/src/auth/ResetPasswordForm/examples/LargeFields.tsx +6 -0
- package/src/auth/SignInForm/SignInForm.test.tsx +7 -0
- package/src/auth/SignInForm/SignInForm.tsx +5 -1
- package/src/auth/SignInForm/block.meta.ts +1 -1
- package/src/auth/SignInForm/examples/LargeFields.tsx +6 -0
- package/src/auth/SignUpForm/SignUpForm.test.tsx +22 -0
- package/src/auth/SignUpForm/SignUpForm.tsx +7 -1
- package/src/auth/SignUpForm/block.meta.ts +1 -1
- package/src/auth/SignUpForm/examples/LargeFields.tsx +6 -0
- package/src/auth/__snapshots__/field-size.test.tsx.snap +11 -0
- package/src/auth/field-size.test.tsx +21 -0
- package/src/auth/large-examples.test.tsx +30 -0
- package/src/auth/shared.tsx +7 -2
- package/src/billing/PaymentMethodCard/PaymentMethodCard.tsx +1 -1
- package/src/billing/PlanCard/PlanCard.baseline.test.tsx +3 -2
- package/src/billing/PlanCard/__snapshots__/PlanCard.baseline.test.tsx.snap +2 -2
- package/src/billing/PlanDefinitionCard/examples/Compact.tsx +1 -4
- package/src/billing/PlanDefinitionCard/examples/Full.tsx +1 -4
- package/src/builders/CodePanel/CodePanel.test.tsx +11 -0
- package/src/builders/CodePanel/CodePanel.tsx +4 -3
- package/src/builders/FlowBuilder/FlowBuilder.tsx +4 -19
- package/src/builders/FlowBuilder/parts.tsx +4 -4
- package/src/builders/LogViewer/LogViewer.follow.test.tsx +29 -0
- package/src/builders/LogViewer/LogViewer.test.tsx +24 -0
- package/src/builders/LogViewer/LogViewer.tsx +67 -20
- package/src/builders/LogViewer/block.meta.ts +2 -1
- package/src/builders/LogViewer/examples/Spanish.tsx +2 -1
- package/src/data-display/ActivityFeed/ActivityFeed.tsx +1 -1
- package/src/data-display/ChartCard/ChartCard.tsx +2 -2
- package/src/data-display/ChartCard/examples/ContainerPanel.tsx +16 -0
- package/src/data-display/CommentThread/CommentThread.test.tsx +70 -1
- package/src/data-display/CommentThread/CommentThread.tsx +22 -6
- package/src/data-display/CommentThread/block.meta.ts +1 -1
- package/src/data-display/CommentThread/examples/RenderedBody.tsx +20 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.test.tsx +24 -1
- package/src/data-display/DescriptionListCard/DescriptionListCard.tsx +14 -20
- package/src/data-display/DescriptionListCard/block.meta.ts +2 -1
- package/src/data-display/DescriptionListCard/examples/Spanish.tsx +2 -1
- package/src/data-display/KpiRow/KpiRow.doc.ts +14 -0
- package/src/data-display/KpiRow/KpiRow.test.tsx +11 -0
- package/src/data-display/KpiRow/KpiRow.tsx +72 -55
- package/src/data-display/KpiRow/examples/ContainerPanel.tsx +47 -0
- package/src/data-display/ResourceCardGrid/ResourceCardGrid.doc.ts +19 -0
- package/src/data-display/ResourceCardGrid/ResourceCardGrid.test.tsx +13 -0
- package/src/data-display/ResourceCardGrid/ResourceCardGrid.tsx +49 -40
- package/src/data-display/ResourceCardGrid/examples/ContainerPanel.tsx +18 -0
- package/src/data-display/StatusTimeline/StatusTimeline.tsx +1 -1
- package/src/feedback/EmptyStates/EmptyStates.test.tsx +42 -0
- package/src/feedback/EmptyStates/EmptyStates.tsx +5 -3
- package/src/feedback/EmptyStates/block.meta.ts +1 -1
- package/src/feedback/EmptyStates/examples/HiddenAction.tsx +13 -0
- package/src/feedback/ErrorPanel/ErrorPanel.tsx +13 -15
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.lifecycle.test.tsx +123 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.tsx +128 -139
- package/src/forms/CreateApiKeyDialog/block.meta.ts +12 -1
- package/src/forms/FileUploadPanel/FileUploadPanel.controlled.test.tsx +482 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.drag.test.tsx +60 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.lifecycle.test.tsx +165 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.tsx +267 -69
- package/src/forms/FileUploadPanel/block.meta.ts +5 -1
- package/src/forms/FileUploadPanel/examples/AutoCancel.tsx +38 -0
- package/src/forms/FileUploadPanel/examples/Labels.tsx +1 -1
- package/src/forms/FileUploadPanel/examples/ManualForm.tsx +36 -0
- package/src/forms/FileUploadPanel/fixtures.ts +31 -16
- package/src/forms/FileUploadPanel/simulate-upload.test.ts +24 -0
- package/src/forms/FormSection/FormSection.test.tsx +11 -0
- package/src/forms/FormSection/FormSection.tsx +20 -22
- package/src/forms/FormSection/block.meta.ts +1 -1
- package/src/forms/FormSection/examples/ContainerPanel.tsx +16 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.lifecycle.test.tsx +80 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.tsx +90 -109
- package/src/forms/InviteMembersDialog/block.meta.ts +1 -1
- package/src/forms/ValidationSummary/ValidationSummary.tsx +1 -4
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useTableData.integration.test.tsx +89 -0
- package/src/hooks/useTableData.test.tsx +613 -0
- package/src/hooks/useTableData.ts +377 -0
- package/src/index.ts +1 -0
- package/src/marketing/ComparisonTable/ComparisonTable.tsx +2 -2
- package/src/marketing/FeatureGrid/FeatureGrid.tsx +1 -1
- package/src/marketing/LogoCloud/LogoCloud.doc.ts +13 -0
- package/src/marketing/LogoCloud/LogoCloud.test.tsx +155 -0
- package/src/marketing/LogoCloud/LogoCloud.tsx +89 -0
- package/src/marketing/LogoCloud/block.meta.ts +10 -0
- package/src/marketing/LogoCloud/examples/CaptionStart.tsx +6 -0
- package/src/marketing/LogoCloud/examples/Custom.tsx +25 -0
- package/src/marketing/LogoCloud/examples/Empty.tsx +6 -0
- package/src/marketing/LogoCloud/examples/Grid.tsx +13 -0
- package/src/marketing/LogoCloud/examples/Row.tsx +6 -0
- package/src/marketing/LogoCloud/examples/UnderHero.tsx +13 -0
- package/src/marketing/LogoCloud/fixtures.ts +23 -0
- package/src/marketing/PricingTable/PricingTable.tsx +1 -1
- package/src/marketing/SiteFooter/SiteFooter.doc.ts +18 -0
- package/src/marketing/SiteFooter/SiteFooter.test.tsx +236 -0
- package/src/marketing/SiteFooter/SiteFooter.tsx +160 -0
- package/src/marketing/SiteFooter/block.meta.ts +10 -0
- package/src/marketing/SiteFooter/examples/Centered.tsx +15 -0
- package/src/marketing/SiteFooter/examples/Columns.tsx +15 -0
- package/src/marketing/SiteFooter/examples/Custom.tsx +35 -0
- package/src/marketing/SiteFooter/examples/Empty.tsx +6 -0
- package/src/marketing/SiteFooter/examples/Simple.tsx +14 -0
- package/src/marketing/SiteFooter/fixtures.ts +36 -0
- package/src/marketing/index.ts +6 -0
- package/src/page-chrome/PageHeader/EditableTitle.test.tsx +26 -0
- package/src/page-chrome/PageHeader/PageHeader.tsx +4 -4
- package/src/page-chrome/PageHeader/block.meta.ts +1 -1
- package/src/page-chrome/PageHeader/examples/ContainerPanel.tsx +16 -0
- package/src/page-chrome/PageHeader/examples/EditableTitle.tsx +23 -0
- package/src/page-chrome/PageToolbar/PageToolbar.test.tsx +3 -1
- package/src/page-chrome/PageToolbar/PageToolbar.tsx +2 -2
- package/src/page-chrome/StickyActionBar/StickyActionBar.tsx +1 -1
- package/src/scheduling/AgendaList/AgendaList.tsx +39 -15
- package/src/scheduling/AgendaList/AgendaListZone.test.tsx +38 -0
- package/src/scheduling/AgendaList/block.meta.ts +1 -1
- package/src/scheduling/AgendaList/examples/TimeZone.tsx +28 -0
- package/src/scheduling/MonthCalendar/MonthCalendar.tsx +51 -40
- package/src/scheduling/MonthCalendar/MonthCalendarZone.test.tsx +44 -0
- package/src/scheduling/MonthCalendar/block.meta.ts +1 -1
- package/src/scheduling/MonthCalendar/examples/TimeZone.tsx +28 -0
- package/src/scheduling/WeekCalendar/WeekCalendar.tsx +37 -28
- package/src/scheduling/WeekCalendar/WeekCalendarZone.test.tsx +41 -0
- package/src/scheduling/WeekCalendar/block.meta.ts +1 -1
- package/src/scheduling/WeekCalendar/examples/TimeZone.tsx +28 -0
- package/src/scheduling/shared/CalendarHeader.tsx +26 -1
- package/src/scheduling/shared/dates.ts +102 -58
- package/src/scheduling/shared/events.ts +2 -2
- package/src/shell/AppSidebar/AppSidebar.context.test.tsx +175 -0
- package/src/shell/AppSidebar/AppSidebar.doc.ts +29 -0
- package/src/shell/AppSidebar/AppSidebar.tsx +97 -25
- package/src/shell/AppSidebar/block.meta.ts +1 -1
- package/src/shell/GlobalSearch/GlobalSearch.test.tsx +1 -0
- package/src/shell/GlobalSearch/GlobalSearch.tsx +1 -1
- package/src/tables/DataTable/DataTable.cursor-example.test.tsx +67 -0
- package/src/tables/DataTable/DataTable.export.test.tsx +511 -0
- package/src/tables/DataTable/DataTable.inline-edit-focus.test.tsx +32 -0
- package/src/tables/DataTable/DataTable.layout.test.tsx +6 -5
- package/src/tables/DataTable/DataTable.link-actions.test.tsx +18 -0
- package/src/tables/DataTable/DataTable.server-pagination.test.tsx +328 -14
- package/src/tables/DataTable/DataTable.test.tsx +85 -1
- package/src/tables/DataTable/DataTable.tsx +108 -14
- package/src/tables/DataTable/block.meta.ts +11 -1
- package/src/tables/DataTable/column-sizing.ts +2 -2
- package/src/tables/DataTable/data-table-props.ts +29 -1
- package/src/tables/DataTable/data-table-row.tsx +2 -2
- package/src/tables/DataTable/data-table-utils.ts +4 -0
- package/src/tables/DataTable/editable-cell.tsx +20 -79
- package/src/tables/DataTable/examples/csv-export.tsx +74 -0
- package/src/tables/DataTable/examples/cursor-load-more.tsx +87 -0
- package/src/tables/DataTable/examples/server-pagination.tsx +47 -40
- package/src/tables/DataTable/export-menu.tsx +58 -0
- package/src/tables/DataTable/header-cell.tsx +1 -1
- package/src/tables/DataTable/labels.ts +7 -0
- package/src/tables/DataTable/resize-handle.tsx +2 -2
- package/src/tables/DataTable/use-table-export.ts +117 -0
- package/src/tables/FilterBar/FilterBar.test.tsx +12 -0
- package/src/tables/FilterBar/FilterBar.tsx +5 -7
- package/src/team/ProfileHeader/ProfileHeader.picker.test.tsx +34 -0
- package/src/team/ProfileHeader/ProfileHeader.test.tsx +2 -2
- package/src/team/ProfileHeader/ProfileHeader.tsx +17 -24
- package/src/team/ProfileHeader/block.meta.ts +1 -1
- package/src/test/OptInDefaults.test.tsx +10 -1
- package/src/test/clipboard-fallback.test.tsx +49 -0
- package/src/test/copy-examples.test.tsx +29 -0
- package/src/test/copy-feedback.test.tsx +166 -0
- package/src/test/fixtures/opt-in-defaults.json +5 -5
- package/src/test/without-forced-colors.test.ts +44 -0
- package/src/test/without-forced-colors.ts +14 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { render, screen, within } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { MenuItem } from '@gntik-ai/ui';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
6
|
+
import { expectNoAxeViolations } from '../../test/a11y';
|
|
7
|
+
import { AppSidebar, AppSidebarFooter, AppSidebarHeader, AppSidebarNav } from './AppSidebar';
|
|
8
|
+
|
|
9
|
+
const tenants = [
|
|
10
|
+
{ id: 't1', name: 'One' },
|
|
11
|
+
{ id: 't2', name: 'Two' },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
describe('AppSidebar context', () => {
|
|
15
|
+
it('keeps the default header markup byte-identical to 0.11.0, including generated IDs', () => {
|
|
16
|
+
// Captured from the assigned immutable base dbf5a248e551cace019a26c105a8d76f866b2647.
|
|
17
|
+
const html = renderToStaticMarkup(<AppSidebarHeader />);
|
|
18
|
+
expect(createHash('sha256').update(html).digest('hex')).toBe(
|
|
19
|
+
'4aeef719ee282401ef33d640e7e4745d3bfbbb93e81b6e6e15ab2290fad2b2fc',
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
it('forwards context, branding and menu content through the composite sidebar', async () => {
|
|
23
|
+
const onTenantSelect = vi.fn();
|
|
24
|
+
render(
|
|
25
|
+
<AppSidebar
|
|
26
|
+
tenants={tenants}
|
|
27
|
+
currentTenantId="t1"
|
|
28
|
+
onTenantSelect={onTenantSelect}
|
|
29
|
+
tenantLabel="Organization"
|
|
30
|
+
tenantEmptyText="No organizations"
|
|
31
|
+
workspaceLabel="Spaces"
|
|
32
|
+
workspaceEmptyText="No spaces"
|
|
33
|
+
contextRegionLabel="Active context"
|
|
34
|
+
contextBusy
|
|
35
|
+
contextStatus={<span role="status">Syncing</span>}
|
|
36
|
+
brand={<span>Console identity</span>}
|
|
37
|
+
userMenuChildren={<MenuItem>Language</MenuItem>}
|
|
38
|
+
/>,
|
|
39
|
+
);
|
|
40
|
+
const region = screen.getByRole('region', { name: 'Active context' });
|
|
41
|
+
expect(region).toHaveAttribute('aria-busy', 'true');
|
|
42
|
+
expect(within(region).getByRole('status')).toHaveTextContent('Syncing');
|
|
43
|
+
const tenant = within(region).getByRole('combobox', { name: 'Organization' });
|
|
44
|
+
expect(tenant).toHaveTextContent('One');
|
|
45
|
+
expect(within(region).getByRole('button', { name: /Spaces/ })).toBeInTheDocument();
|
|
46
|
+
expect(screen.getByText('Console identity')).toBeInTheDocument();
|
|
47
|
+
await userEvent.click(tenant);
|
|
48
|
+
await userEvent.click(await screen.findByRole('option', { name: 'Two' }));
|
|
49
|
+
expect(onTenantSelect).toHaveBeenCalledWith('t2');
|
|
50
|
+
await userEvent.click(screen.getByRole('button', { name: /Dana Whitfield/ }));
|
|
51
|
+
expect(within(await screen.findByRole('menu')).getByRole('menuitem', { name: 'Language' })).toBeInTheDocument();
|
|
52
|
+
await expectNoAxeViolations();
|
|
53
|
+
});
|
|
54
|
+
it('adds footer menu children alongside items while allowing usage and help to be hidden', async () => {
|
|
55
|
+
render(
|
|
56
|
+
<AppSidebarFooter
|
|
57
|
+
usage={null}
|
|
58
|
+
helpHref=""
|
|
59
|
+
userMenuItems={[{ label: 'Account' }]}
|
|
60
|
+
userMenuChildren={<MenuItem>Language</MenuItem>}
|
|
61
|
+
/>,
|
|
62
|
+
);
|
|
63
|
+
expect(screen.queryByRole('meter')).toBeNull();
|
|
64
|
+
expect(screen.queryByRole('link')).toBeNull();
|
|
65
|
+
await userEvent.click(screen.getByRole('button', { name: /Dana Whitfield/ }));
|
|
66
|
+
const menu = await screen.findByRole('menu');
|
|
67
|
+
expect(within(menu).getByRole('menuitem', { name: 'Language' })).toBeInTheDocument();
|
|
68
|
+
expect(within(menu).getByRole('menuitem', { name: 'Account' })).toBeInTheDocument();
|
|
69
|
+
await expectNoAxeViolations();
|
|
70
|
+
});
|
|
71
|
+
it('replaces the logo with a brand in expanded, logo-only, hidden-context and rail headers', () => {
|
|
72
|
+
const brand = <span>Console identity</span>;
|
|
73
|
+
const { rerender } = render(<AppSidebarHeader brand={brand} />);
|
|
74
|
+
expect(screen.getByText('Console identity')).toBeInTheDocument();
|
|
75
|
+
expect(screen.getByRole('button', { name: /Acme Industries/ })).toBeInTheDocument();
|
|
76
|
+
for (const props of [
|
|
77
|
+
{ workspaces: null },
|
|
78
|
+
{ workspaces: [] },
|
|
79
|
+
{ hideWorkspaceContext: true },
|
|
80
|
+
{ collapsed: true },
|
|
81
|
+
]) {
|
|
82
|
+
rerender(<AppSidebarHeader brand={brand} tenants={tenants} contextRegionLabel="Active context" {...props} />);
|
|
83
|
+
expect(screen.getByText('Console identity')).toBeInTheDocument();
|
|
84
|
+
expect(screen.queryByRole('img')).toBeNull();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
it('opts into a named busy region and hides context in platform-wide and collapsed modes', () => {
|
|
88
|
+
const props = {
|
|
89
|
+
tenants,
|
|
90
|
+
contextRegionLabel: 'Active context',
|
|
91
|
+
contextBusy: true,
|
|
92
|
+
contextStatus: <span role="status">Updating context</span>,
|
|
93
|
+
};
|
|
94
|
+
const { container, rerender } = render(<AppSidebarHeader {...props} />);
|
|
95
|
+
const region = screen.getByRole('region', { name: 'Active context' });
|
|
96
|
+
expect(region).toHaveAttribute('aria-busy', 'true');
|
|
97
|
+
expect(within(region).getByRole('combobox', { name: 'Tenant' })).toBeInTheDocument();
|
|
98
|
+
expect(within(region).getByRole('button', { name: /Acme Industries/ })).toBeInTheDocument();
|
|
99
|
+
expect(within(region).getByRole('status')).toHaveTextContent('Updating context');
|
|
100
|
+
rerender(<AppSidebarHeader {...props} contextRegionLabel={undefined} />);
|
|
101
|
+
expect(container.querySelector('section')).toBeNull();
|
|
102
|
+
expect(screen.getByRole('status')).toBeInTheDocument();
|
|
103
|
+
rerender(<AppSidebarHeader {...props} hideWorkspaceContext />);
|
|
104
|
+
expect(screen.queryByRole('region')).toBeNull();
|
|
105
|
+
expect(screen.queryByRole('combobox')).toBeNull();
|
|
106
|
+
expect(screen.queryByRole('button')).toBeNull();
|
|
107
|
+
expect(screen.queryByRole('status')).toBeNull();
|
|
108
|
+
expect(screen.getByRole('img')).toBeInTheDocument();
|
|
109
|
+
rerender(<AppSidebarHeader {...props} collapsed />);
|
|
110
|
+
expect(screen.queryByRole('region')).toBeNull();
|
|
111
|
+
expect(screen.queryByRole('combobox')).toBeNull();
|
|
112
|
+
expect(screen.queryByRole('status')).toBeNull();
|
|
113
|
+
expect(screen.getByRole('img')).toBeInTheDocument();
|
|
114
|
+
});
|
|
115
|
+
it('passes workspace headings and search empty copy without adding a create entry', async () => {
|
|
116
|
+
const user = userEvent.setup();
|
|
117
|
+
const { rerender } = render(<AppSidebarHeader workspaceLabel="Available spaces" />);
|
|
118
|
+
await user.click(screen.getByRole('button', { name: /Acme Industries/ }));
|
|
119
|
+
expect(await screen.findByRole('group', { name: 'Available spaces' })).toBeInTheDocument();
|
|
120
|
+
expect(screen.queryByRole('menuitem', { name: 'Create workspace' })).toBeNull();
|
|
121
|
+
await user.keyboard('{Escape}');
|
|
122
|
+
rerender(
|
|
123
|
+
<AppSidebarHeader
|
|
124
|
+
workspaceLabel="Available spaces"
|
|
125
|
+
workspaceEmptyText="No matching spaces"
|
|
126
|
+
workspaces={Array.from({ length: 7 }, (_, i) => ({ id: `w${i}`, name: `Space ${i}` }))}
|
|
127
|
+
/>,
|
|
128
|
+
);
|
|
129
|
+
await user.click(screen.getByRole('combobox', { name: /Available spaces/ }));
|
|
130
|
+
expect(await screen.findByRole('listbox', { name: 'Available spaces' })).toBeInTheDocument();
|
|
131
|
+
await user.type(screen.getByRole('combobox', { name: 'Find a workspace' }), 'no match');
|
|
132
|
+
expect(await screen.findByText('No matching spaces')).toBeInTheDocument();
|
|
133
|
+
expect(screen.queryByRole('option', { name: 'Create workspace' })).toBeNull();
|
|
134
|
+
});
|
|
135
|
+
it('omits tenants by default and shows the empty tenant text even without workspaces', () => {
|
|
136
|
+
const { rerender } = render(<AppSidebarHeader />);
|
|
137
|
+
expect(screen.queryByRole('combobox')).toBeNull();
|
|
138
|
+
rerender(
|
|
139
|
+
<AppSidebarHeader tenants={[]} tenantLabel="Organization" tenantEmptyText="No organizations" workspaces={null} />,
|
|
140
|
+
);
|
|
141
|
+
expect(screen.getByRole('combobox', { name: 'Organization' })).toHaveTextContent('No organizations');
|
|
142
|
+
expect(screen.getByRole('img')).toBeInTheDocument();
|
|
143
|
+
});
|
|
144
|
+
it('selects and clears a tenant before workspace and navigation in keyboard order', async () => {
|
|
145
|
+
const user = userEvent.setup();
|
|
146
|
+
const onTenantSelect = vi.fn();
|
|
147
|
+
const { container } = render(
|
|
148
|
+
<>
|
|
149
|
+
<AppSidebarHeader tenants={tenants} currentTenantId="t1" tenantLabel="Tenant" onTenantSelect={onTenantSelect} />
|
|
150
|
+
<AppSidebarNav />
|
|
151
|
+
</>,
|
|
152
|
+
);
|
|
153
|
+
const tenant = screen.getByRole('combobox', { name: 'Tenant' });
|
|
154
|
+
expect(tenant).toHaveTextContent('One');
|
|
155
|
+
expect(container.querySelector('section')).toBeNull();
|
|
156
|
+
await user.tab();
|
|
157
|
+
expect(tenant).toHaveFocus();
|
|
158
|
+
await user.tab();
|
|
159
|
+
expect(screen.getByRole('button', { name: 'Clear Tenant' })).toHaveFocus();
|
|
160
|
+
await user.tab();
|
|
161
|
+
expect(screen.getByRole('button', { name: /Acme Industries/ })).toHaveFocus();
|
|
162
|
+
await user.tab();
|
|
163
|
+
expect(screen.getByRole('link', { name: 'Overview' })).toHaveFocus();
|
|
164
|
+
await user.click(tenant);
|
|
165
|
+
await screen.findByRole('listbox', { name: 'Tenant' });
|
|
166
|
+
await expectNoAxeViolations();
|
|
167
|
+
await user.click(await screen.findByRole('option', { name: 'Two' }));
|
|
168
|
+
expect(onTenantSelect).toHaveBeenCalledWith('t2');
|
|
169
|
+
await user.click(tenant);
|
|
170
|
+
await user.keyboard('{Escape}');
|
|
171
|
+
tenant.focus();
|
|
172
|
+
await user.keyboard('{Delete}');
|
|
173
|
+
expect(onTenantSelect).toHaveBeenLastCalledWith(null);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ComponentDoc } from '@gntik-ai/ui';
|
|
2
|
+
import { meta } from './block.meta';
|
|
3
|
+
|
|
4
|
+
export const doc: ComponentDoc = {
|
|
5
|
+
name: 'AppSidebar',
|
|
6
|
+
group: 'Navigation',
|
|
7
|
+
status: 'beta',
|
|
8
|
+
description:
|
|
9
|
+
`${meta.description} Optional tenants render before the workspace control using the kit Select. ` +
|
|
10
|
+
'tenantLabel and tenantEmptyText customize its name and empty placeholder; clearing reports null. ' +
|
|
11
|
+
'workspaceLabel and workspaceEmptyText customize the workspace popup and search results. ' +
|
|
12
|
+
'hideWorkspaceContext hides both controls, contextStatus and the region, preserving brand or Logo. ' +
|
|
13
|
+
'contextRegionLabel opts into a named section; without it, controls and contextStatus have no extra wrapper. ' +
|
|
14
|
+
'The consumer owns contextBusy and must reset it when loading completes. The collapsed rail hides context; ' +
|
|
15
|
+
'expand the sidebar or open its mobile drawer to switch tenants. brand replaces Logo in either state. ' +
|
|
16
|
+
'userMenuChildren adds popup content alongside userMenuItems; usage=null and helpHref="" hide usage and help. ' +
|
|
17
|
+
'ConsoleShell forwards these props and also shows brand in the mobile topbar. See the five Sidebar shell examples.',
|
|
18
|
+
primitive: 'Select, WorkspaceSwitcher, NavList and UserMenu from @gntik-ai/ui',
|
|
19
|
+
pattern: 'Optional named context region, select-only combobox, navigation and account menu',
|
|
20
|
+
keyboard: [
|
|
21
|
+
['Tab', 'Tenant picker and its clear control, then workspace picker, then navigation'],
|
|
22
|
+
['Enter / Space', 'Open the focused tenant or workspace picker, or account menu'],
|
|
23
|
+
['ArrowDown / ArrowUp', 'Move through the open picker or menu'],
|
|
24
|
+
['Enter', 'Select the highlighted item'],
|
|
25
|
+
['Escape', 'Close the popup and return focus to its trigger'],
|
|
26
|
+
['Delete / Backspace', 'On a selected tenant trigger, clear to the platform-wide context'],
|
|
27
|
+
],
|
|
28
|
+
tokens: ['chrome', 'card', 'border', 'foreground', 'muted-foreground', 'focus-ring'],
|
|
29
|
+
};
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
Logo,
|
|
5
5
|
Meter,
|
|
6
6
|
NavList,
|
|
7
|
+
SimpleSelect,
|
|
7
8
|
UserMenu,
|
|
8
9
|
WorkspaceSwitcher,
|
|
9
10
|
cn,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
type UserMenuUser,
|
|
14
15
|
type Workspace,
|
|
15
16
|
} from '@gntik-ai/ui';
|
|
16
|
-
import { useState } from 'react';
|
|
17
|
+
import { useState, type ReactNode } from 'react';
|
|
17
18
|
import {
|
|
18
19
|
appSidebarNavGroups,
|
|
19
20
|
appSidebarUsage,
|
|
@@ -30,6 +31,23 @@ export interface AppSidebarHeaderProps {
|
|
|
30
31
|
currentWorkspaceId?: string;
|
|
31
32
|
onWorkspaceChange?: (workspace: Workspace) => void;
|
|
32
33
|
onCreateWorkspace?: () => void;
|
|
34
|
+
/** Omit to hide the tenant picker. Clearing selects the platform-wide context. */
|
|
35
|
+
tenants?: { id: string; name: string }[];
|
|
36
|
+
currentTenantId?: string | null;
|
|
37
|
+
onTenantSelect?: (id: string | null) => void;
|
|
38
|
+
tenantLabel?: string;
|
|
39
|
+
tenantEmptyText?: string;
|
|
40
|
+
workspaceLabel?: string;
|
|
41
|
+
workspaceEmptyText?: string;
|
|
42
|
+
/** Platform-wide mode: hide all context controls and status. */
|
|
43
|
+
hideWorkspaceContext?: boolean;
|
|
44
|
+
/** Opt into a named section around the controls and status. */
|
|
45
|
+
contextRegionLabel?: string;
|
|
46
|
+
/** Consumer-owned loading state; reset when the context finishes changing. */
|
|
47
|
+
contextBusy?: boolean;
|
|
48
|
+
contextStatus?: ReactNode;
|
|
49
|
+
/** Product-owned identity, rendered in place of the default logo. */
|
|
50
|
+
brand?: ReactNode;
|
|
33
51
|
className?: string;
|
|
34
52
|
}
|
|
35
53
|
|
|
@@ -40,23 +58,79 @@ export function AppSidebarHeader({
|
|
|
40
58
|
currentWorkspaceId,
|
|
41
59
|
onWorkspaceChange,
|
|
42
60
|
onCreateWorkspace,
|
|
61
|
+
tenants,
|
|
62
|
+
currentTenantId,
|
|
63
|
+
onTenantSelect,
|
|
64
|
+
tenantLabel = 'Tenant',
|
|
65
|
+
tenantEmptyText = 'No tenants',
|
|
66
|
+
workspaceLabel,
|
|
67
|
+
workspaceEmptyText,
|
|
68
|
+
hideWorkspaceContext,
|
|
69
|
+
contextRegionLabel,
|
|
70
|
+
contextBusy,
|
|
71
|
+
contextStatus,
|
|
72
|
+
brand,
|
|
43
73
|
className,
|
|
44
74
|
}: AppSidebarHeaderProps) {
|
|
45
75
|
const [current, setCurrent] = useState(currentWorkspaceId ?? workspaces?.[0]?.id ?? '');
|
|
46
76
|
const currentId = currentWorkspaceId ?? current;
|
|
47
|
-
if (collapsed) return <Logo size={26} className={className} />;
|
|
48
|
-
if (
|
|
77
|
+
if (collapsed) return brand ?? <Logo size={26} className={className} />;
|
|
78
|
+
if (hideWorkspaceContext) return brand ?? <Logo size={24} wordmark className={cn('px-1', className)} />;
|
|
79
|
+
// Stack the existing slot parent only for opted-in content, without adding a wrapper.
|
|
80
|
+
const stackParent = '[:has(>_&)]:flex-col [:has(>_&)]:items-stretch [:has(>_&)]:gap-2';
|
|
81
|
+
const workspaceControl =
|
|
82
|
+
!workspaces || workspaces.length === 0 ? (
|
|
83
|
+
brand == null && (
|
|
84
|
+
<Logo size={24} wordmark className={cn('px-1', contextStatus != null && stackParent, className)} />
|
|
85
|
+
)
|
|
86
|
+
) : (
|
|
87
|
+
<WorkspaceSwitcher
|
|
88
|
+
label={workspaceLabel}
|
|
89
|
+
emptyText={workspaceEmptyText}
|
|
90
|
+
className={cn('w-full', (brand != null || contextStatus != null) && stackParent, className)}
|
|
91
|
+
workspaces={workspaces}
|
|
92
|
+
currentId={currentId}
|
|
93
|
+
onCreate={onCreateWorkspace}
|
|
94
|
+
onSelect={(w) => {
|
|
95
|
+
setCurrent(w.id);
|
|
96
|
+
onWorkspaceChange?.(w);
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
// Preserve the original tree path as well as its DOM: Base UI derives IDs from it during SSR.
|
|
101
|
+
if (!tenants && brand == null && !contextRegionLabel && contextStatus == null) return workspaceControl;
|
|
102
|
+
const controls = (
|
|
103
|
+
<>
|
|
104
|
+
{tenants && (
|
|
105
|
+
<SimpleSelect
|
|
106
|
+
items={tenants.map(({ id, name }) => ({ value: id, label: name }))}
|
|
107
|
+
value={currentTenantId}
|
|
108
|
+
onValueChange={(id) => onTenantSelect?.(id)}
|
|
109
|
+
aria-label={tenantLabel}
|
|
110
|
+
placeholder={tenants.length === 0 ? tenantEmptyText : 'Select tenant'}
|
|
111
|
+
clearable
|
|
112
|
+
className="w-full [&+button]:min-h-6 [&+button]:min-w-6 [:has(>_*_>_&)]:flex-col [:has(>_*_>_&)]:items-stretch [:has(>_*_>_&)]:gap-2"
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
{workspaceControl}
|
|
116
|
+
{contextStatus}
|
|
117
|
+
</>
|
|
118
|
+
);
|
|
49
119
|
return (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
120
|
+
<>
|
|
121
|
+
{brand}
|
|
122
|
+
{contextRegionLabel ? (
|
|
123
|
+
<section
|
|
124
|
+
aria-label={contextRegionLabel}
|
|
125
|
+
aria-busy={contextBusy}
|
|
126
|
+
className={cn('flex w-full min-w-0 flex-col gap-2', brand != null && stackParent)}
|
|
127
|
+
>
|
|
128
|
+
{controls}
|
|
129
|
+
</section>
|
|
130
|
+
) : (
|
|
131
|
+
controls
|
|
132
|
+
)}
|
|
133
|
+
</>
|
|
60
134
|
);
|
|
61
135
|
}
|
|
62
136
|
|
|
@@ -101,6 +175,8 @@ export interface AppSidebarFooterProps {
|
|
|
101
175
|
/** Signed-in user; `null` hides the user menu. */
|
|
102
176
|
user?: UserMenuUser | null;
|
|
103
177
|
userMenuItems?: UserMenuEntry[];
|
|
178
|
+
/** Extra content inside the account menu popup, before sign out. */
|
|
179
|
+
userMenuChildren?: ReactNode;
|
|
104
180
|
onSignOut?: () => void;
|
|
105
181
|
className?: string;
|
|
106
182
|
}
|
|
@@ -113,6 +189,7 @@ export function AppSidebarFooter({
|
|
|
113
189
|
helpLabel = 'Help & docs',
|
|
114
190
|
user = appSidebarUser,
|
|
115
191
|
userMenuItems,
|
|
192
|
+
userMenuChildren,
|
|
116
193
|
onSignOut,
|
|
117
194
|
className,
|
|
118
195
|
}: AppSidebarFooterProps) {
|
|
@@ -152,7 +229,9 @@ export function AppSidebarFooter({
|
|
|
152
229
|
onSignOut={onSignOut}
|
|
153
230
|
showName={!collapsed}
|
|
154
231
|
className={collapsed ? undefined : 'w-full justify-start'}
|
|
155
|
-
|
|
232
|
+
>
|
|
233
|
+
{userMenuChildren}
|
|
234
|
+
</UserMenu>
|
|
156
235
|
)}
|
|
157
236
|
</div>
|
|
158
237
|
);
|
|
@@ -174,10 +253,6 @@ export interface AppSidebarProps
|
|
|
174
253
|
*/
|
|
175
254
|
export function AppSidebar({
|
|
176
255
|
collapsed = false,
|
|
177
|
-
workspaces,
|
|
178
|
-
currentWorkspaceId,
|
|
179
|
-
onWorkspaceChange,
|
|
180
|
-
onCreateWorkspace,
|
|
181
256
|
navGroups,
|
|
182
257
|
navLabel,
|
|
183
258
|
currentHref,
|
|
@@ -187,19 +262,15 @@ export function AppSidebar({
|
|
|
187
262
|
helpLabel,
|
|
188
263
|
user,
|
|
189
264
|
userMenuItems,
|
|
265
|
+
userMenuChildren,
|
|
190
266
|
onSignOut,
|
|
191
267
|
className,
|
|
268
|
+
...headerProps
|
|
192
269
|
}: AppSidebarProps) {
|
|
193
270
|
return (
|
|
194
271
|
<div className={cn('flex h-full min-h-0 flex-col bg-chrome', collapsed ? 'w-16' : 'w-[248px]', className)}>
|
|
195
272
|
<div className={cn('flex shrink-0 items-center pt-4 pb-3', collapsed ? 'justify-center px-2' : 'px-3')}>
|
|
196
|
-
<AppSidebarHeader
|
|
197
|
-
collapsed={collapsed}
|
|
198
|
-
workspaces={workspaces}
|
|
199
|
-
currentWorkspaceId={currentWorkspaceId}
|
|
200
|
-
onWorkspaceChange={onWorkspaceChange}
|
|
201
|
-
onCreateWorkspace={onCreateWorkspace}
|
|
202
|
-
/>
|
|
273
|
+
<AppSidebarHeader collapsed={collapsed} {...headerProps} />
|
|
203
274
|
</div>
|
|
204
275
|
<div className={cn('min-h-0 flex-1 overflow-y-auto pt-1 pb-3', collapsed ? 'px-2' : 'px-3')}>
|
|
205
276
|
<AppSidebarNav
|
|
@@ -218,6 +289,7 @@ export function AppSidebar({
|
|
|
218
289
|
helpLabel={helpLabel}
|
|
219
290
|
user={user}
|
|
220
291
|
userMenuItems={userMenuItems}
|
|
292
|
+
userMenuChildren={userMenuChildren}
|
|
221
293
|
onSignOut={onSignOut}
|
|
222
294
|
/>
|
|
223
295
|
</div>
|
|
@@ -6,5 +6,5 @@ export const meta: BlockMeta = {
|
|
|
6
6
|
status: 'beta',
|
|
7
7
|
description:
|
|
8
8
|
'Application sidebar: workspace switcher (or logo) header, NavList body with icon-rail support, and a footer with plan usage, help link and user menu. Exposes header / nav / footer parts for the SidebarLayout slots.',
|
|
9
|
-
uses: ['WorkspaceSwitcher', 'Logo', 'NavList', 'Meter', 'Link', 'UserMenu'],
|
|
9
|
+
uses: ['SimpleSelect', 'WorkspaceSwitcher', 'Logo', 'NavList', 'Meter', 'Link', 'UserMenu'],
|
|
10
10
|
};
|
|
@@ -23,6 +23,7 @@ describe('GlobalSearch', () => {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
it('⌘K opens it with recent and grouped results; choosing one reports its group', async () => {
|
|
26
|
+
vi.stubGlobal('navigator', { platform: 'MacIntel' });
|
|
26
27
|
const user = userEvent.setup();
|
|
27
28
|
const onSelect = vi.fn();
|
|
28
29
|
render(<GlobalSearch onSelect={onSelect} />);
|
|
@@ -13,7 +13,7 @@ export interface GlobalSearchProps {
|
|
|
13
13
|
onSelect?: (item: CommandItem, group: GlobalSearchGroup) => void;
|
|
14
14
|
/** Group headings. */
|
|
15
15
|
labels?: Partial<Record<GlobalSearchGroup, string>>;
|
|
16
|
-
/** Registers ⌘K / Ctrl+K. */
|
|
16
|
+
/** Registers ⌘K on macOS/iOS and Ctrl+K on other platforms. */
|
|
17
17
|
shortcut?: boolean;
|
|
18
18
|
open?: boolean;
|
|
19
19
|
defaultOpen?: boolean;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { act, render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { ThemeProvider } from '@gntik-ai/ui';
|
|
4
|
+
import { expectNoAxeViolations } from '../../test/a11y';
|
|
5
|
+
import type { TableDataParams, TableDataResult } from '../../hooks/useTableData';
|
|
6
|
+
import CursorLoadMoreExample from './examples/cursor-load-more';
|
|
7
|
+
|
|
8
|
+
it.each(['dark', 'light', 'high_contrast'] as const)(
|
|
9
|
+
'appends, retries and exhausts the cursor example accessibly in %s',
|
|
10
|
+
async (theme) => {
|
|
11
|
+
const user = userEvent.setup();
|
|
12
|
+
const getRows = vi
|
|
13
|
+
.fn<(params: TableDataParams<{ search: string }>) => Promise<TableDataResult<{ id: number; name: string }>>>()
|
|
14
|
+
.mockResolvedValueOnce({ rows: [{ id: 1, name: 'First item' }], nextCursor: 'c2' })
|
|
15
|
+
.mockRejectedValueOnce(new Error('Service unavailable'))
|
|
16
|
+
.mockResolvedValueOnce({ rows: [{ id: 2, name: 'Second item' }], nextCursor: null });
|
|
17
|
+
const { container } = render(
|
|
18
|
+
<ThemeProvider defaultMode={theme} storageKey={null}>
|
|
19
|
+
<CursorLoadMoreExample getRows={getRows} />
|
|
20
|
+
</ThemeProvider>,
|
|
21
|
+
);
|
|
22
|
+
await screen.findByText('First item');
|
|
23
|
+
expect(screen.queryByRole('navigation', { name: /pagination/i })).not.toBeInTheDocument();
|
|
24
|
+
await expectNoAxeViolations(container);
|
|
25
|
+
await user.click(screen.getByRole('button', { name: 'Load more' }));
|
|
26
|
+
expect((await screen.findAllByText('Service unavailable')).length).toBeGreaterThan(0);
|
|
27
|
+
await expectNoAxeViolations(container);
|
|
28
|
+
await user.click(screen.getByRole('button', { name: 'Try again' }));
|
|
29
|
+
await screen.findByText('Second item');
|
|
30
|
+
expect(screen.getByText('First item')).toBeInTheDocument();
|
|
31
|
+
expect(getRows.mock.calls.map(([params]) => params.cursor)).toEqual([null, 'c2', 'c2']);
|
|
32
|
+
expect(screen.queryByRole('button', { name: 'Load more' })).not.toBeInTheDocument();
|
|
33
|
+
await act(async () => {});
|
|
34
|
+
await expectNoAxeViolations(container);
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
it('demonstrates an error and retry through the live preview controls', async () => {
|
|
39
|
+
const user = userEvent.setup();
|
|
40
|
+
render(<CursorLoadMoreExample />);
|
|
41
|
+
await screen.findByText('Item 1');
|
|
42
|
+
await user.click(screen.getByRole('checkbox', { name: 'Fail next request' }));
|
|
43
|
+
await user.click(screen.getByRole('button', { name: 'Load more' }));
|
|
44
|
+
expect((await screen.findAllByText('Request failed. Try again.')).length).toBeGreaterThan(0);
|
|
45
|
+
expect(screen.getByText('Item 1')).toBeInTheDocument();
|
|
46
|
+
await user.click(screen.getByRole('button', { name: 'Try again' }));
|
|
47
|
+
await screen.findByText('Item 35');
|
|
48
|
+
expect(screen.queryByRole('button', { name: 'Load more' })).not.toBeInTheDocument();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('offers a retry after refetch fails on an exhausted list', async () => {
|
|
52
|
+
const user = userEvent.setup();
|
|
53
|
+
const getRows = vi
|
|
54
|
+
.fn<(params: TableDataParams<{ search: string }>) => Promise<TableDataResult<{ id: number; name: string }>>>()
|
|
55
|
+
.mockResolvedValueOnce({ rows: [{ id: 1, name: 'First item' }], nextCursor: null })
|
|
56
|
+
.mockRejectedValueOnce(new Error('Service unavailable'))
|
|
57
|
+
.mockResolvedValueOnce({ rows: [{ id: 2, name: 'Refreshed item' }], nextCursor: null });
|
|
58
|
+
render(<CursorLoadMoreExample getRows={getRows} />);
|
|
59
|
+
await screen.findByText('First item');
|
|
60
|
+
await user.click(screen.getByRole('button', { name: 'Refetch' }));
|
|
61
|
+
await screen.findByRole('heading', { name: 'Service unavailable' });
|
|
62
|
+
expect(screen.getByText('First item')).toBeInTheDocument();
|
|
63
|
+
await user.click(screen.getByRole('button', { name: 'Try again' }));
|
|
64
|
+
await screen.findByText('Refreshed item');
|
|
65
|
+
expect(getRows.mock.calls.map(([params]) => params.cursor)).toEqual([null, null, null]);
|
|
66
|
+
expect(screen.queryByText('First item')).not.toBeInTheDocument();
|
|
67
|
+
});
|