@gntik-ai/blocks 0.8.0 → 0.10.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 +138 -21
- package/dist/index.js +897 -376
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/billing/CostBreakdown/CostBreakdown.test.tsx +10 -0
- package/src/billing/CostBreakdown/CostBreakdown.tsx +50 -43
- package/src/billing/SpendVsBudget/SpendVsBudget.test.tsx +10 -0
- package/src/billing/SpendVsBudget/SpendVsBudget.tsx +35 -31
- package/src/builders/FlowBuilder/FlowBuilder.test.tsx +237 -2
- package/src/builders/FlowBuilder/FlowBuilder.tsx +101 -29
- package/src/builders/FlowBuilder/block.meta.ts +1 -1
- package/src/builders/FlowBuilder/connections.ts +30 -12
- package/src/builders/FlowBuilder/examples/ControlledGraph.tsx +8 -0
- package/src/builders/FlowBuilder/graph-state.ts +78 -0
- package/src/builders/LogViewer/LogViewer.labels.test.tsx +90 -0
- package/src/builders/LogViewer/LogViewer.test.tsx +11 -0
- package/src/builders/LogViewer/LogViewer.tsx +70 -31
- package/src/builders/LogViewer/block.meta.ts +14 -1
- package/src/builders/LogViewer/examples/Spanish.tsx +30 -0
- package/src/data-display/ChartCard/ChartCard.locale.test.tsx +15 -0
- package/src/data-display/ChartCard/ChartCard.test.tsx +9 -0
- package/src/data-display/ChartCard/ChartCard.tsx +81 -67
- package/src/data-display/ChartCard/block.meta.ts +1 -1
- package/src/data-display/DescriptionListCard/DescriptionListCard.labels.test.tsx +73 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.tsx +37 -7
- package/src/data-display/DescriptionListCard/block.meta.ts +11 -1
- package/src/data-display/DescriptionListCard/examples/Spanish.tsx +22 -0
- package/src/feedback/EmptyStates/EmptyStates.labels.test.tsx +185 -0
- package/src/feedback/EmptyStates/EmptyStates.tsx +73 -20
- package/src/feedback/EmptyStates/block.meta.ts +73 -1
- package/src/feedback/EmptyStates/examples/Spanish.tsx +41 -0
- package/src/feedback/ErrorPanel/ErrorPanel.labels.test.tsx +99 -0
- package/src/feedback/ErrorPanel/ErrorPanel.tsx +38 -9
- package/src/feedback/ErrorPanel/block.meta.ts +19 -1
- package/src/feedback/ErrorPanel/examples/Spanish.tsx +30 -0
- package/src/feedback/InlineCallout/InlineCallout.labels.test.tsx +62 -0
- package/src/feedback/InlineCallout/InlineCallout.tsx +22 -9
- package/src/feedback/InlineCallout/block.meta.ts +9 -1
- package/src/feedback/InlineCallout/examples/Spanish.tsx +19 -0
- package/src/feedback/Skeletons/Skeletons.labels.test.tsx +24 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.test.tsx +22 -1
- package/src/forms/FileUploadPanel/FileUploadPanel.tsx +4 -4
- package/src/forms/FileUploadPanel/fixtures.ts +0 -12
- package/src/forms/FileUploadPanel/format-bytes.test.ts +8 -0
- package/src/page-chrome/PageHeader/PageHeader.labels.test.tsx +56 -0
- package/src/page-chrome/PageHeader/PageHeader.test.tsx +18 -0
- package/src/page-chrome/PageHeader/PageHeader.tsx +21 -4
- package/src/page-chrome/PageHeader/block.meta.ts +8 -1
- package/src/page-chrome/PageHeader/examples/Labels.tsx +16 -0
- package/src/page-chrome/PageHeader/examples/Spanish.tsx +11 -0
- package/src/scheduling/AgendaList/AgendaList.test.tsx +25 -0
- package/src/scheduling/AgendaList/AgendaList.tsx +7 -2
- package/src/scheduling/AgendaList/AgendaListLocale.test.tsx +11 -0
- package/src/scheduling/AgendaList/block.meta.ts +1 -1
- package/src/scheduling/AgendaList/examples/Locale.tsx +29 -0
- package/src/scheduling/MonthCalendar/MonthCalendar.test.tsx +111 -1
- package/src/scheduling/MonthCalendar/MonthCalendar.tsx +19 -9
- package/src/scheduling/MonthCalendar/block.meta.ts +1 -1
- package/src/scheduling/MonthCalendar/examples/Locale.tsx +19 -0
- package/src/scheduling/WeekCalendar/WeekCalendar.test.tsx +73 -2
- package/src/scheduling/WeekCalendar/WeekCalendar.tsx +26 -12
- package/src/scheduling/WeekCalendar/block.meta.ts +1 -1
- package/src/scheduling/WeekCalendar/examples/Locale.tsx +19 -0
- package/src/scheduling/shared/dates.test.ts +75 -0
- package/src/scheduling/shared/dates.ts +46 -22
- package/src/scheduling/shared/useSchedulingClock.ts +13 -0
- package/src/shell/GlobalSearch/GlobalSearch.test.tsx +12 -0
- package/src/shell/GlobalSearch/fixtures.ts +2 -2
- package/src/tables/DataTable/DataTable.labels.test.tsx +2 -0
- package/src/tables/DataTable/DataTable.locale.test.tsx +153 -0
- package/src/tables/DataTable/DataTable.server-pagination.test.tsx +1 -1
- package/src/tables/DataTable/DataTable.test.tsx +16 -0
- package/src/tables/DataTable/block.meta.ts +2 -0
- package/src/tables/DataTable/data-table-row.tsx +18 -2
- package/src/tables/DataTable/data-table-utils.ts +18 -4
- package/src/tables/DataTable/labels.ts +2 -0
- package/src/tables/PaginationFooter/PaginationFooter.i18n.test.tsx +26 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useId, useMemo, useRef, useState, type ReactNode, type UIEvent } from 'react';
|
|
2
2
|
import { Check, Copy, Eye, Search } from '@gntik-ai/icons';
|
|
3
|
-
import { IconButton, Input, Switch, Toggle, ToggleGroup, cn } from '@gntik-ai/ui';
|
|
3
|
+
import { IconButton, Input, Switch, Toggle, ToggleGroup, cn, foldText, matchRanges, useI18n } from '@gntik-ai/ui';
|
|
4
4
|
import { logLines as defaultLines, type LogLevel, type LogLine } from './fixtures';
|
|
5
5
|
|
|
6
6
|
export type { LogLevel, LogLine } from './fixtures';
|
|
@@ -14,7 +14,22 @@ const LEVEL_STYLE: Record<LogLevel, { label: string; className: string }> = {
|
|
|
14
14
|
error: { label: 'ERROR', className: 'bg-destructive/15 text-destructive-chip-text' },
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
export interface LogViewerLabels {
|
|
18
|
+
title: string;
|
|
19
|
+
levelFilter: string;
|
|
20
|
+
searchLabel: string;
|
|
21
|
+
searchPlaceholder: string;
|
|
22
|
+
follow: string;
|
|
23
|
+
count: (visible: number, total: number) => string;
|
|
24
|
+
empty: string;
|
|
25
|
+
inspect: (timestamp: string) => string;
|
|
26
|
+
copy: (timestamp: string) => string;
|
|
27
|
+
copied: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
export interface LogViewerProps {
|
|
31
|
+
/** Per-key copy overrides; explicit props take precedence, then labels, then the active catalog. */
|
|
32
|
+
labels?: Partial<LogViewerLabels>;
|
|
18
33
|
/** Log lines, oldest first. */
|
|
19
34
|
lines?: LogLine[];
|
|
20
35
|
/** Accessible name of the log region and visible title. */
|
|
@@ -43,24 +58,19 @@ export interface LogViewerProps {
|
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
/** Wraps case-insensitive matches of `query` in <mark>. */
|
|
46
|
-
function highlight(text: string, query: string): ReactNode {
|
|
47
|
-
if (!query) return text;
|
|
48
|
-
const lower = text.toLowerCase();
|
|
49
|
-
const q = query.toLowerCase();
|
|
61
|
+
function highlight(text: string, query: string, locale?: string): ReactNode {
|
|
50
62
|
const parts: ReactNode[] = [];
|
|
51
63
|
let from = 0;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (at > from) parts.push(text.slice(from, at));
|
|
64
|
+
for (const [start, end] of matchRanges(text, query, { locale })) {
|
|
65
|
+
parts.push(text.slice(from, start));
|
|
55
66
|
parts.push(
|
|
56
|
-
<mark key={
|
|
57
|
-
{text.slice(
|
|
67
|
+
<mark key={start} className="rounded-sm bg-warning/30 text-foreground">
|
|
68
|
+
{text.slice(start, end)}
|
|
58
69
|
</mark>,
|
|
59
70
|
);
|
|
60
|
-
from =
|
|
61
|
-
at = lower.indexOf(q, from);
|
|
71
|
+
from = end;
|
|
62
72
|
}
|
|
63
|
-
|
|
73
|
+
parts.push(text.slice(from));
|
|
64
74
|
return parts;
|
|
65
75
|
}
|
|
66
76
|
|
|
@@ -75,7 +85,8 @@ function lineText(line: LogLine) {
|
|
|
75
85
|
*/
|
|
76
86
|
export function LogViewer({
|
|
77
87
|
lines = defaultLines,
|
|
78
|
-
title
|
|
88
|
+
title: titleProp,
|
|
89
|
+
labels,
|
|
79
90
|
height = 360,
|
|
80
91
|
rowHeight = 24,
|
|
81
92
|
overscan = 8,
|
|
@@ -88,6 +99,8 @@ export function LogViewer({
|
|
|
88
99
|
titleAs: TitleTag = 'h3',
|
|
89
100
|
className,
|
|
90
101
|
}: LogViewerProps) {
|
|
102
|
+
const { locale, t } = useI18n();
|
|
103
|
+
const title = titleProp ?? labels?.title ?? t('logViewer.title');
|
|
91
104
|
const titleId = useId();
|
|
92
105
|
const viewport = useRef<HTMLDivElement>(null);
|
|
93
106
|
const copyTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
@@ -103,14 +116,24 @@ export function LogViewer({
|
|
|
103
116
|
return c;
|
|
104
117
|
}, [lines]);
|
|
105
118
|
|
|
119
|
+
const foldedLines = useMemo(
|
|
120
|
+
() =>
|
|
121
|
+
lines.map((line) => ({
|
|
122
|
+
line,
|
|
123
|
+
message: foldText(line.message, locale),
|
|
124
|
+
source: foldText(line.source ?? '', locale),
|
|
125
|
+
})),
|
|
126
|
+
[lines, locale],
|
|
127
|
+
);
|
|
106
128
|
const visible = useMemo(() => {
|
|
107
|
-
const q = query.trim()
|
|
108
|
-
return
|
|
109
|
-
(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
129
|
+
const q = foldText(query.trim(), locale);
|
|
130
|
+
return foldedLines
|
|
131
|
+
.filter(
|
|
132
|
+
({ line, message, source }) =>
|
|
133
|
+
levels.includes(line.level) && (!q || message.indexOf(q) !== -1 || source.indexOf(q) !== -1),
|
|
134
|
+
)
|
|
135
|
+
.map(({ line }) => line);
|
|
136
|
+
}, [foldedLines, levels, query, locale]);
|
|
114
137
|
|
|
115
138
|
const total = visible.length * rowHeight;
|
|
116
139
|
const maxScroll = Math.max(0, total - height);
|
|
@@ -151,11 +174,18 @@ export function LogViewer({
|
|
|
151
174
|
{title}
|
|
152
175
|
</TitleTag>
|
|
153
176
|
<span className="font-mono text-[11px] text-muted-foreground">
|
|
154
|
-
{visible.length
|
|
177
|
+
{labels?.count?.(visible.length, lines.length) ??
|
|
178
|
+
t('logViewer.count', { visible: visible.length, total: lines.length })}
|
|
155
179
|
</span>
|
|
156
180
|
</div>
|
|
157
181
|
<div className="flex flex-wrap items-center gap-2 lg:ms-auto">
|
|
158
|
-
<ToggleGroup
|
|
182
|
+
<ToggleGroup
|
|
183
|
+
aria-label={labels?.levelFilter ?? t('logViewer.levelFilter')}
|
|
184
|
+
size="sm"
|
|
185
|
+
multiple
|
|
186
|
+
value={levels}
|
|
187
|
+
onValueChange={(v) => setLevels(v)}
|
|
188
|
+
>
|
|
159
189
|
{LOG_LEVELS.map((lv) => (
|
|
160
190
|
<Toggle key={lv} value={lv}>
|
|
161
191
|
{lv}
|
|
@@ -166,14 +196,19 @@ export function LogViewer({
|
|
|
166
196
|
<Input
|
|
167
197
|
size="sm"
|
|
168
198
|
type="search"
|
|
169
|
-
aria-label=
|
|
170
|
-
placeholder=
|
|
199
|
+
aria-label={labels?.searchLabel ?? t('logViewer.searchLabel')}
|
|
200
|
+
placeholder={labels?.searchPlaceholder ?? t('logViewer.searchPlaceholder')}
|
|
171
201
|
leadingIcon={Search}
|
|
172
202
|
value={query}
|
|
173
203
|
onValueChange={(v) => setQuery(String(v))}
|
|
174
204
|
className="w-full sm:w-48"
|
|
175
205
|
/>
|
|
176
|
-
<Switch
|
|
206
|
+
<Switch
|
|
207
|
+
size="sm"
|
|
208
|
+
label={labels?.follow ?? t('logViewer.follow')}
|
|
209
|
+
checked={follow}
|
|
210
|
+
onCheckedChange={setFollow}
|
|
211
|
+
/>
|
|
177
212
|
</div>
|
|
178
213
|
</div>
|
|
179
214
|
<div
|
|
@@ -188,7 +223,7 @@ export function LogViewer({
|
|
|
188
223
|
>
|
|
189
224
|
{visible.length === 0 ? (
|
|
190
225
|
<p className="px-4 py-6 text-center font-sans text-[13px] text-muted-foreground">
|
|
191
|
-
|
|
226
|
+
{labels?.empty ?? t('logViewer.empty')}
|
|
192
227
|
</p>
|
|
193
228
|
) : (
|
|
194
229
|
<div className="relative w-full" style={{ height: total }}>
|
|
@@ -213,17 +248,17 @@ export function LogViewer({
|
|
|
213
248
|
</span>
|
|
214
249
|
{line.source && (
|
|
215
250
|
<span className="hidden shrink-0 text-muted-foreground sm:inline">
|
|
216
|
-
[{highlight(line.source, query
|
|
251
|
+
[{highlight(line.source, query, locale)}]
|
|
217
252
|
</span>
|
|
218
253
|
)}
|
|
219
254
|
<span className="min-w-0 flex-1 truncate text-foreground">
|
|
220
|
-
{highlight(line.message, query
|
|
255
|
+
{highlight(line.message, query, locale)}
|
|
221
256
|
</span>
|
|
222
257
|
{onSelectLine && (
|
|
223
258
|
<IconButton
|
|
224
259
|
size="sm"
|
|
225
260
|
icon={Eye}
|
|
226
|
-
label={
|
|
261
|
+
label={labels?.inspect?.(line.timestamp) ?? t('logViewer.inspect', { timestamp: line.timestamp })}
|
|
227
262
|
aria-pressed={line.id === selectedLineId}
|
|
228
263
|
onClick={(event) => {
|
|
229
264
|
event.stopPropagation();
|
|
@@ -235,7 +270,11 @@ export function LogViewer({
|
|
|
235
270
|
<IconButton
|
|
236
271
|
size="sm"
|
|
237
272
|
icon={copied === line.id ? Check : Copy}
|
|
238
|
-
label={
|
|
273
|
+
label={
|
|
274
|
+
copied === line.id
|
|
275
|
+
? (labels?.copied ?? t('common.copied'))
|
|
276
|
+
: (labels?.copy?.(line.timestamp) ?? t('logViewer.copy', { timestamp: line.timestamp }))
|
|
277
|
+
}
|
|
239
278
|
onClick={(event) => {
|
|
240
279
|
if (onSelectLine) event.stopPropagation();
|
|
241
280
|
copy(line);
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import type { BlockMeta } from '../../meta';
|
|
2
|
+
import type { LogViewerLabels } from './LogViewer';
|
|
2
3
|
|
|
3
4
|
export const meta: BlockMeta = {
|
|
4
5
|
name: 'Log viewer',
|
|
5
6
|
family: 'builders',
|
|
6
7
|
status: 'beta',
|
|
7
8
|
description:
|
|
8
|
-
'Windowed log stream (role="log"): level filter, search with highlighted matches, follow-tail and per-line copy. Renders only the visible rows.',
|
|
9
|
+
'Windowed log stream (role="log"): level filter, search with highlighted matches, follow-tail and per-line copy. Renders only the visible rows. Optional labels?: Partial<LogViewerLabels> overrides each built-in label. Explicit content props win over labels, then I18nProvider (en/es); no provider keeps English. Imported fixtures and machine data stay unchanged. See the Catalog labels live preview.',
|
|
10
|
+
labels: [
|
|
11
|
+
{ key: 'title', type: 'string', state: 'Visible heading and log region name; title prop wins' },
|
|
12
|
+
{ key: 'levelFilter', type: 'string', state: 'Level filter group name' },
|
|
13
|
+
{ key: 'searchLabel', type: 'string', state: 'Searchbox name' },
|
|
14
|
+
{ key: 'searchPlaceholder', type: 'string', state: 'Searchbox placeholder' },
|
|
15
|
+
{ key: 'follow', type: 'string', state: 'Follow switch name' },
|
|
16
|
+
{ key: 'count', type: '(visible: number, total: number) => string', state: 'Filtered line count' },
|
|
17
|
+
{ key: 'empty', type: 'string', state: 'No matching lines' },
|
|
18
|
+
{ key: 'inspect', type: '(timestamp: string) => string', state: 'Inspect button name when onSelectLine exists' },
|
|
19
|
+
{ key: 'copy', type: '(timestamp: string) => string', state: 'Copy button before copying' },
|
|
20
|
+
{ key: 'copied', type: 'string', state: 'Copy button after copying' },
|
|
21
|
+
] satisfies Array<{ key: keyof LogViewerLabels; type: string; state: string }>,
|
|
9
22
|
uses: ['ToggleGroup', 'Toggle', 'Input', 'Switch', 'IconButton'],
|
|
10
23
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { I18nProvider, Stack } from '@gntik-ai/ui';
|
|
2
|
+
import { LogViewer } from '../LogViewer';
|
|
3
|
+
import { makeLogLines } from '../fixtures';
|
|
4
|
+
const lines = makeLogLines(3);
|
|
5
|
+
export default function Spanish() {
|
|
6
|
+
return (
|
|
7
|
+
<I18nProvider locale="es">
|
|
8
|
+
<Stack gap={6}>
|
|
9
|
+
<LogViewer lines={lines} height={100} onSelectLine={() => {}} />
|
|
10
|
+
<LogViewer
|
|
11
|
+
lines={lines}
|
|
12
|
+
height={100}
|
|
13
|
+
onSelectLine={() => {}}
|
|
14
|
+
labels={{
|
|
15
|
+
title: 'Application logs',
|
|
16
|
+
levelFilter: 'Severity',
|
|
17
|
+
searchLabel: 'Find log messages',
|
|
18
|
+
searchPlaceholder: 'Find…',
|
|
19
|
+
follow: 'Follow stream',
|
|
20
|
+
count: (visible, total) => `${visible}/${total} lines`,
|
|
21
|
+
empty: 'Nothing matched',
|
|
22
|
+
inspect: (timestamp) => `Open ${timestamp}`,
|
|
23
|
+
copy: (timestamp) => `Copy ${timestamp}`,
|
|
24
|
+
copied: 'Line copied',
|
|
25
|
+
}}
|
|
26
|
+
/>
|
|
27
|
+
</Stack>
|
|
28
|
+
</I18nProvider>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import LocalizedCharts from '../../../../charts/src/examples/LocalizedCharts';
|
|
4
|
+
import { expectNoAxeViolations } from '../../test/a11y';
|
|
5
|
+
|
|
6
|
+
it.each(['dark', 'light', 'high_contrast'])('keeps the localised chart example accessible in %s', async (theme) => {
|
|
7
|
+
document.documentElement.className = theme;
|
|
8
|
+
const { container } = render(<LocalizedCharts />);
|
|
9
|
+
expect(screen.getByRole('status', { name: 'Cargando gráfico' })).toBeInTheDocument();
|
|
10
|
+
await expectNoAxeViolations(container);
|
|
11
|
+
await userEvent.selectOptions(screen.getByRole('combobox', { name: 'Chart language' }), 'en');
|
|
12
|
+
expect(screen.getByRole('status', { name: 'Loading chart' })).toBeInTheDocument();
|
|
13
|
+
expect(screen.getByText('Nada que mostrar')).toBeInTheDocument();
|
|
14
|
+
expect(screen.getByText('Explicit empty message')).toBeInTheDocument();
|
|
15
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
2
3
|
import userEvent from '@testing-library/user-event';
|
|
3
4
|
import { expectNoAxeViolations } from '../../test/a11y';
|
|
4
5
|
import { ChartCard } from './ChartCard';
|
|
@@ -6,6 +7,14 @@ import HeatmapChartCard from './examples/heatmap';
|
|
|
6
7
|
import { TRAFFIC_BY_RANGE } from './fixtures';
|
|
7
8
|
|
|
8
9
|
describe('ChartCard', () => {
|
|
10
|
+
it('uses the kit locale for the loading chart', () => {
|
|
11
|
+
render(
|
|
12
|
+
<I18nProvider locale="es">
|
|
13
|
+
<ChartCard state="loading" />
|
|
14
|
+
</I18nProvider>,
|
|
15
|
+
);
|
|
16
|
+
expect(screen.getByRole('status', { name: 'Cargando gráfico' })).toBeInTheDocument();
|
|
17
|
+
});
|
|
9
18
|
it('renders title, legend and chart for the first range', async () => {
|
|
10
19
|
const { container } = render(<ChartCard />);
|
|
11
20
|
expect(screen.getByRole('heading', { name: 'Infrastructure cost' })).toBeInTheDocument();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AreaChart,
|
|
3
|
+
ChartLocaleProvider,
|
|
3
4
|
BarChart,
|
|
4
5
|
Heatmap,
|
|
5
6
|
LineChart,
|
|
@@ -9,7 +10,17 @@ import {
|
|
|
9
10
|
type HeatmapProps,
|
|
10
11
|
type ValueFormatter,
|
|
11
12
|
} from '@gntik-ai/charts';
|
|
12
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
Card,
|
|
15
|
+
CardAction,
|
|
16
|
+
CardDescription,
|
|
17
|
+
CardHeader,
|
|
18
|
+
CardTitle,
|
|
19
|
+
useI18n,
|
|
20
|
+
cn,
|
|
21
|
+
Toggle,
|
|
22
|
+
ToggleGroup,
|
|
23
|
+
} from '@gntik-ai/ui';
|
|
13
24
|
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
14
25
|
import { TrendDelta, type KpiDelta } from '../shared/TrendDelta';
|
|
15
26
|
import { COST_BY_RANGE, COST_RANGES, type CostPoint } from './fixtures';
|
|
@@ -146,73 +157,76 @@ export function ChartCard<T extends object = CostPoint>({
|
|
|
146
157
|
'aria-label': chartLabel,
|
|
147
158
|
...states,
|
|
148
159
|
};
|
|
160
|
+
const { locale } = useI18n();
|
|
149
161
|
return (
|
|
150
|
-
<
|
|
151
|
-
<
|
|
152
|
-
<
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
{r.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
<
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
<div className={cn('px-3 pb-4 pt-3 sm:px-4', !footer && 'pb-5')}>
|
|
193
|
-
{kind === 'heatmap' ? (
|
|
194
|
-
<Heatmap
|
|
195
|
-
data={data}
|
|
196
|
-
index={index}
|
|
197
|
-
categories={categories}
|
|
198
|
-
color={colors[0] ?? 'primary'}
|
|
199
|
-
valueFormatter={valueFormatter}
|
|
200
|
-
showScale={showLegend}
|
|
201
|
-
height={height}
|
|
202
|
-
aria-label={chartLabel}
|
|
203
|
-
{...heatmap}
|
|
204
|
-
{...states}
|
|
205
|
-
dataTable={dataTable ?? true}
|
|
206
|
-
/>
|
|
207
|
-
) : kind === 'bar' ? (
|
|
208
|
-
<BarChart {...common} stacked={stacked} />
|
|
209
|
-
) : kind === 'line' ? (
|
|
210
|
-
<LineChart {...common} />
|
|
211
|
-
) : (
|
|
212
|
-
<AreaChart {...common} stacked={stacked} />
|
|
162
|
+
<ChartLocaleProvider locale={locale}>
|
|
163
|
+
<Card className={className}>
|
|
164
|
+
<CardHeader className="pb-2">
|
|
165
|
+
<CardTitle as={titleAs}>{title}</CardTitle>
|
|
166
|
+
{description && <CardDescription>{description}</CardDescription>}
|
|
167
|
+
<CardAction className="flex items-center gap-2">
|
|
168
|
+
{showRangeToggle && ranges.length > 1 && (
|
|
169
|
+
<ToggleGroup
|
|
170
|
+
aria-label={`${title} range`}
|
|
171
|
+
size="sm"
|
|
172
|
+
value={active ? [active.value] : []}
|
|
173
|
+
onFocus={(event) => {
|
|
174
|
+
// Tab enters at the pressed option; pointer and restored focus stay on their original option.
|
|
175
|
+
if (!tabEntry.current) return;
|
|
176
|
+
if (event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget)) return;
|
|
177
|
+
const selected = event.currentTarget.querySelector<HTMLButtonElement>('[aria-pressed="true"]');
|
|
178
|
+
selected?.focus();
|
|
179
|
+
}}
|
|
180
|
+
onValueChange={(v) => {
|
|
181
|
+
const next = v[0];
|
|
182
|
+
if (!next) return;
|
|
183
|
+
if (rangeProp === undefined) setInner(next);
|
|
184
|
+
onRangeChange?.(next);
|
|
185
|
+
}}
|
|
186
|
+
>
|
|
187
|
+
{ranges.map((r) => (
|
|
188
|
+
<Toggle key={r.value} value={r.value} className="font-mono">
|
|
189
|
+
{r.label}
|
|
190
|
+
</Toggle>
|
|
191
|
+
))}
|
|
192
|
+
</ToggleGroup>
|
|
193
|
+
)}
|
|
194
|
+
{action}
|
|
195
|
+
</CardAction>
|
|
196
|
+
</CardHeader>
|
|
197
|
+
{active?.summary && (
|
|
198
|
+
<p className="flex flex-wrap items-baseline gap-x-2 px-5" aria-live="polite">
|
|
199
|
+
<span className="text-[24px] font-semibold tracking-tight text-foreground tabular-nums">
|
|
200
|
+
{active.summary.value}
|
|
201
|
+
</span>
|
|
202
|
+
{active.summary.delta && <TrendDelta {...active.summary.delta} />}
|
|
203
|
+
</p>
|
|
213
204
|
)}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
205
|
+
<div className={cn('px-3 pb-4 pt-3 sm:px-4', !footer && 'pb-5')}>
|
|
206
|
+
{kind === 'heatmap' ? (
|
|
207
|
+
<Heatmap
|
|
208
|
+
data={data}
|
|
209
|
+
index={index}
|
|
210
|
+
categories={categories}
|
|
211
|
+
color={colors[0] ?? 'primary'}
|
|
212
|
+
valueFormatter={valueFormatter}
|
|
213
|
+
showScale={showLegend}
|
|
214
|
+
height={height}
|
|
215
|
+
aria-label={chartLabel}
|
|
216
|
+
{...heatmap}
|
|
217
|
+
{...states}
|
|
218
|
+
dataTable={dataTable ?? true}
|
|
219
|
+
/>
|
|
220
|
+
) : kind === 'bar' ? (
|
|
221
|
+
<BarChart {...common} stacked={stacked} />
|
|
222
|
+
) : kind === 'line' ? (
|
|
223
|
+
<LineChart {...common} />
|
|
224
|
+
) : (
|
|
225
|
+
<AreaChart {...common} stacked={stacked} />
|
|
226
|
+
)}
|
|
227
|
+
</div>
|
|
228
|
+
{footer && <div className="border-t border-border px-5 py-3 text-[12.5px] text-muted-foreground">{footer}</div>}
|
|
229
|
+
</Card>
|
|
230
|
+
</ChartLocaleProvider>
|
|
217
231
|
);
|
|
218
232
|
}
|
|
@@ -5,6 +5,6 @@ export const meta: BlockMeta = {
|
|
|
5
5
|
family: 'data-display',
|
|
6
6
|
status: 'beta',
|
|
7
7
|
description:
|
|
8
|
-
'A Card with chart and legend: default 7d/30d/90d or custom ranges via ranges, controlled range/onRangeChange, and showRangeToggle={false} when a toolbar owns the range (pass its window as range). Supports title, optional headline and delta, area/line/bar/heatmap charts, and loading, empty and error states. Supply matching dataByRange keys and use defaultRange for initial uncontrolled selection; the toolbar is the only range control when the toggle is hidden. Unknown range/defaultRange keys fall back to the first option for selection, data and label, with a development-only warning.',
|
|
8
|
+
'A Card with chart and legend: default 7d/30d/90d or custom ranges via ranges, controlled range/onRangeChange, and showRangeToggle={false} when a toolbar owns the range (pass its window as range). Supports title, optional headline and delta, area/line/bar/heatmap charts, and loading, empty and error states. Supply matching dataByRange keys and use defaultRange for initial uncontrolled selection; the toolbar is the only range control when the toggle is hidden. Unknown range/defaultRange keys fall back to the first option for selection, data and label, with a development-only warning. Chart states follow the kit I18nProvider locale automatically through ChartLocaleProvider; standalone charts need their own ChartLocaleProvider (en/es, per-key labels overrides). Number/date formatting stays caller-controlled.',
|
|
9
9
|
uses: ['Card', 'ToggleGroup', 'AreaChart', 'LineChart', 'BarChart', 'Heatmap', 'ChartLegend'],
|
|
10
10
|
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { I18nProvider, es } from '@gntik-ai/ui';
|
|
4
|
+
import { DescriptionListCard, type DescriptionListCardLabels } from './DescriptionListCard';
|
|
5
|
+
import { DEPLOYMENT_DETAILS } from './fixtures';
|
|
6
|
+
|
|
7
|
+
it('localizes card defaults, copy names and announcements while retaining fixture fields', async () => {
|
|
8
|
+
const user = userEvent.setup();
|
|
9
|
+
render(
|
|
10
|
+
<I18nProvider locale="es">
|
|
11
|
+
<DescriptionListCard onEdit={() => {}} />
|
|
12
|
+
</I18nProvider>,
|
|
13
|
+
);
|
|
14
|
+
expect(screen.getByRole('heading', { name: es['descriptionList.title'] })).toHaveTextContent('Configuración');
|
|
15
|
+
expect(screen.getByText(es['descriptionList.description'])).toBeVisible();
|
|
16
|
+
expect(screen.getByRole('button', { name: es['descriptionList.edit'] })).toBeVisible();
|
|
17
|
+
for (const item of DEPLOYMENT_DETAILS) {
|
|
18
|
+
expect(screen.getByText(item.label)).toBeVisible();
|
|
19
|
+
if (item.value && !item.status && !item.render) expect(screen.getByText(item.value)).toBeVisible();
|
|
20
|
+
}
|
|
21
|
+
await user.click(screen.getByRole('button', { name: 'Copiar Deployment ID' }));
|
|
22
|
+
expect(screen.getByRole('button', { name: 'Deployment ID copiado' })).toBeVisible();
|
|
23
|
+
expect(screen.getByText(es['common.copiedToClipboard'])).toBeInTheDocument();
|
|
24
|
+
expect(await navigator.clipboard.readText()).toBe('dep_7f3c9a21');
|
|
25
|
+
expect(document.body.textContent).not.toContain('{');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('keeps English defaults and lets explicit props win over every override', async () => {
|
|
29
|
+
const user = userEvent.setup();
|
|
30
|
+
const { rerender } = render(<DescriptionListCard onEdit={() => {}} />);
|
|
31
|
+
expect(screen.getByRole('heading', { name: 'Configuration' })).toBeVisible();
|
|
32
|
+
expect(screen.getByText('Settings of this deployment.')).toBeVisible();
|
|
33
|
+
expect(screen.getByRole('button', { name: 'Edit' })).toBeVisible();
|
|
34
|
+
await user.click(screen.getByRole('button', { name: 'Copy Deployment ID' }));
|
|
35
|
+
expect(screen.getByRole('button', { name: 'Deployment ID copied' })).toBeVisible();
|
|
36
|
+
expect(screen.getByText('Copied to clipboard')).toBeInTheDocument();
|
|
37
|
+
const labels: DescriptionListCardLabels = {
|
|
38
|
+
title: 'Title override',
|
|
39
|
+
description: 'Description override',
|
|
40
|
+
edit: 'Edit override',
|
|
41
|
+
copy: (label) => `Copy override ${label}`,
|
|
42
|
+
copied: (label) => `Copied override ${label}`,
|
|
43
|
+
copiedToClipboard: 'Announce override',
|
|
44
|
+
};
|
|
45
|
+
const view = (overrides: Partial<DescriptionListCardLabels>, explicit = false) => (
|
|
46
|
+
<I18nProvider locale="es">
|
|
47
|
+
<DescriptionListCard
|
|
48
|
+
labels={overrides}
|
|
49
|
+
onEdit={() => {}}
|
|
50
|
+
title={explicit ? 'Explicit title' : undefined}
|
|
51
|
+
description={explicit ? 'Explicit description' : undefined}
|
|
52
|
+
editLabel={explicit ? 'Explicit edit' : undefined}
|
|
53
|
+
/>
|
|
54
|
+
</I18nProvider>
|
|
55
|
+
);
|
|
56
|
+
rerender(view(labels));
|
|
57
|
+
expect(screen.getByRole('heading', { name: labels.title })).toBeVisible();
|
|
58
|
+
expect(screen.getByText(labels.description)).toBeVisible();
|
|
59
|
+
expect(screen.getByRole('button', { name: labels.edit })).toBeVisible();
|
|
60
|
+
await user.click(screen.getByRole('button', { name: 'Copy override Deployment ID' }));
|
|
61
|
+
expect(screen.getByRole('button', { name: 'Copied override Deployment ID' })).toBeVisible();
|
|
62
|
+
expect(screen.getByText(labels.copiedToClipboard)).toBeInTheDocument();
|
|
63
|
+
await user.click(screen.getByRole('button', { name: 'Copy override Endpoint' }));
|
|
64
|
+
expect(screen.getByRole('button', { name: 'Copied override Endpoint' })).toBeVisible();
|
|
65
|
+
rerender(view(labels, true));
|
|
66
|
+
expect(screen.getByRole('heading', { name: 'Explicit title' })).toBeVisible();
|
|
67
|
+
expect(screen.getByText('Explicit description')).toBeVisible();
|
|
68
|
+
expect(screen.getByRole('button', { name: 'Explicit edit' })).toBeVisible();
|
|
69
|
+
rerender(view({ edit: 'Only edit' }));
|
|
70
|
+
expect(screen.getByRole('heading', { name: es['descriptionList.title'] })).toBeVisible();
|
|
71
|
+
expect(screen.getByText(es['descriptionList.description'])).toBeVisible();
|
|
72
|
+
expect(screen.getByRole('button', { name: 'Deployment ID copiado' })).toBeVisible();
|
|
73
|
+
});
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
cn,
|
|
10
10
|
IconButton,
|
|
11
11
|
StatusTag,
|
|
12
|
+
useI18n,
|
|
12
13
|
} from '@gntik-ai/ui';
|
|
13
14
|
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
14
15
|
import { DEPLOYMENT_DETAILS } from './fixtures';
|
|
@@ -29,7 +30,18 @@ export interface DescriptionItem {
|
|
|
29
30
|
copyValue?: string;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
export interface DescriptionListCardLabels {
|
|
34
|
+
title: string;
|
|
35
|
+
description: string;
|
|
36
|
+
edit: string;
|
|
37
|
+
copy: (label: string) => string;
|
|
38
|
+
copied: (label: string) => string;
|
|
39
|
+
copiedToClipboard: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
32
42
|
export interface DescriptionListCardProps {
|
|
43
|
+
/** Per-key copy overrides; explicit props take precedence, then labels, then the active catalog. */
|
|
44
|
+
labels?: Partial<DescriptionListCardLabels>;
|
|
33
45
|
title?: string;
|
|
34
46
|
description?: string;
|
|
35
47
|
items?: readonly DescriptionItem[];
|
|
@@ -43,7 +55,16 @@ export interface DescriptionListCardProps {
|
|
|
43
55
|
className?: string;
|
|
44
56
|
}
|
|
45
57
|
|
|
46
|
-
function CopyButton({
|
|
58
|
+
function CopyButton({
|
|
59
|
+
item,
|
|
60
|
+
onCopy,
|
|
61
|
+
labels,
|
|
62
|
+
}: {
|
|
63
|
+
item: DescriptionItem;
|
|
64
|
+
onCopy?: (item: DescriptionItem) => void;
|
|
65
|
+
labels?: Partial<DescriptionListCardLabels>;
|
|
66
|
+
}) {
|
|
67
|
+
const { t } = useI18n();
|
|
47
68
|
const [copied, setCopied] = useState(false);
|
|
48
69
|
const timer = useRef<number | undefined>(undefined);
|
|
49
70
|
useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
@@ -61,14 +82,18 @@ function CopyButton({ item, onCopy }: { item: DescriptionItem; onCopy?: (item: D
|
|
|
61
82
|
<>
|
|
62
83
|
<IconButton
|
|
63
84
|
icon={copied ? Check : Copy}
|
|
64
|
-
label={
|
|
85
|
+
label={
|
|
86
|
+
copied
|
|
87
|
+
? (labels?.copied?.(item.label) ?? t('descriptionList.copied', { label: item.label }))
|
|
88
|
+
: (labels?.copy?.(item.label) ?? t('descriptionList.copy', { label: item.label }))
|
|
89
|
+
}
|
|
65
90
|
size="sm"
|
|
66
91
|
variant="ghost"
|
|
67
92
|
className={cn('size-7 shrink-0', copied && 'text-success-text')}
|
|
68
93
|
onClick={copy}
|
|
69
94
|
/>
|
|
70
95
|
<span className="sr-only" aria-live="polite">
|
|
71
|
-
{copied ?
|
|
96
|
+
{copied ? (labels?.copiedToClipboard ?? t('common.copiedToClipboard')) : ''}
|
|
72
97
|
</span>
|
|
73
98
|
</>
|
|
74
99
|
);
|
|
@@ -76,15 +101,20 @@ function CopyButton({ item, onCopy }: { item: DescriptionItem; onCopy?: (item: D
|
|
|
76
101
|
|
|
77
102
|
/** Key–value detail card: label column, values (mono, status or rich), copy buttons and an Edit action. */
|
|
78
103
|
export function DescriptionListCard({
|
|
79
|
-
title
|
|
80
|
-
|
|
104
|
+
title: titleProp,
|
|
105
|
+
labels,
|
|
106
|
+
description: descriptionProp,
|
|
81
107
|
items = DEPLOYMENT_DETAILS,
|
|
82
108
|
onEdit,
|
|
83
|
-
editLabel
|
|
109
|
+
editLabel: editLabelProp,
|
|
84
110
|
onCopy,
|
|
85
111
|
titleAs = 'h3',
|
|
86
112
|
className,
|
|
87
113
|
}: DescriptionListCardProps) {
|
|
114
|
+
const { t } = useI18n();
|
|
115
|
+
const title = titleProp ?? labels?.title ?? t('descriptionList.title');
|
|
116
|
+
const description = descriptionProp ?? labels?.description ?? t('descriptionList.description');
|
|
117
|
+
const editLabel = editLabelProp ?? labels?.edit ?? t('descriptionList.edit');
|
|
88
118
|
return (
|
|
89
119
|
<Card className={className}>
|
|
90
120
|
<CardHeader divided>
|
|
@@ -110,7 +140,7 @@ export function DescriptionListCard({
|
|
|
110
140
|
{item.render ?? item.value}
|
|
111
141
|
</span>
|
|
112
142
|
)}
|
|
113
|
-
{item.copyable && <CopyButton item={item} onCopy={onCopy} />}
|
|
143
|
+
{item.copyable && <CopyButton item={item} onCopy={onCopy} labels={labels} />}
|
|
114
144
|
</dd>
|
|
115
145
|
</div>
|
|
116
146
|
))}
|