@umituz/web-dashboard 11.1.0 → 11.3.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-dashboard",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.3.0",
|
|
4
4
|
"description": "Installable app skeleton for the fleet — layouts, analytics (dependency-free SVG charts), calendar, onboarding flow permissions/module registry; udb-* stylesheet on design-system tokens",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
-
import { MemoryRouter } from 'react-router';
|
|
3
|
+
import { MemoryRouter, Route, Routes, useLocation } from 'react-router';
|
|
4
|
+
import type { Column } from '@umituz/web-design-system/organisms';
|
|
4
5
|
import { ListPage } from './ListPage';
|
|
5
6
|
|
|
6
7
|
interface Device {
|
|
@@ -16,22 +17,35 @@ const DEVICES: readonly Device[] = [
|
|
|
16
17
|
{ id: 'dev-3', name: 'Lobby Camera', status: 'online', site: 'HQ' },
|
|
17
18
|
];
|
|
18
19
|
|
|
19
|
-
const COLUMNS = [
|
|
20
|
-
{
|
|
21
|
-
{
|
|
20
|
+
const COLUMNS: readonly Column<Device>[] = [
|
|
21
|
+
{ id: 'name', header: 'Device', accessor: 'name' },
|
|
22
|
+
{ id: 'status', header: 'Status', accessor: 'status' },
|
|
22
23
|
];
|
|
23
24
|
|
|
25
|
+
function LocationProbe() {
|
|
26
|
+
const location = useLocation();
|
|
27
|
+
return <output data-testid="location">{location.pathname}</output>;
|
|
28
|
+
}
|
|
29
|
+
|
|
24
30
|
function mount(props: Partial<Parameters<typeof ListPage<Device>>[0]> = {}) {
|
|
25
31
|
return render(
|
|
26
32
|
<MemoryRouter>
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
<LocationProbe />
|
|
34
|
+
<Routes>
|
|
35
|
+
<Route
|
|
36
|
+
path="/"
|
|
37
|
+
element={
|
|
38
|
+
<ListPage<Device>
|
|
39
|
+
title="Devices"
|
|
40
|
+
description="Field hardware"
|
|
41
|
+
data={DEVICES}
|
|
42
|
+
columns={COLUMNS}
|
|
43
|
+
{...props}
|
|
44
|
+
/>
|
|
45
|
+
}
|
|
46
|
+
/>
|
|
47
|
+
<Route path="/devices/:id" element={<output>detail</output>} />
|
|
48
|
+
</Routes>
|
|
35
49
|
</MemoryRouter>,
|
|
36
50
|
);
|
|
37
51
|
}
|
|
@@ -46,11 +60,8 @@ describe('ListPage', () => {
|
|
|
46
60
|
});
|
|
47
61
|
|
|
48
62
|
it('filters rows by search terms', () => {
|
|
49
|
-
mount({
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
const input = screen.getByPlaceholderText('Search…');
|
|
53
|
-
fireEvent.change(input, { target: { value: 'camera' } });
|
|
63
|
+
mount({ search: { terms: (row) => [row.name, row.site] } });
|
|
64
|
+
fireEvent.change(screen.getByPlaceholderText('Search…'), { target: { value: 'camera' } });
|
|
54
65
|
expect(screen.getByText('Lobby Camera')).toBeDefined();
|
|
55
66
|
expect(screen.queryByText('North Gate Reader')).toBeNull();
|
|
56
67
|
});
|
|
@@ -64,37 +75,53 @@ describe('ListPage', () => {
|
|
|
64
75
|
expect(screen.getByText('Lobby Camera')).toBeDefined();
|
|
65
76
|
});
|
|
66
77
|
|
|
67
|
-
it('
|
|
78
|
+
it('honours a custom matchFilter', () => {
|
|
68
79
|
mount({
|
|
69
|
-
|
|
80
|
+
filters: [{ id: 'campus', label: 'Campus', options: [{ value: 'hq', label: 'HQ' }] }],
|
|
81
|
+
matchFilter: (row, id, value) => id === 'campus' && row.site.toLowerCase() === value,
|
|
70
82
|
});
|
|
83
|
+
fireEvent.change(screen.getByLabelText('Campus'), { target: { value: 'hq' } });
|
|
84
|
+
expect(screen.getByText('Lobby Camera')).toBeDefined();
|
|
85
|
+
expect(screen.queryByText('Server Door Sensor')).toBeNull();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('shows the count of shown vs total', () => {
|
|
89
|
+
mount({ search: { terms: (row) => row.name } });
|
|
71
90
|
fireEvent.change(screen.getByPlaceholderText('Search…'), { target: { value: 'gate' } });
|
|
72
91
|
expect(screen.getByTestId('list-page-count').textContent).toBe('1 of 3');
|
|
73
92
|
});
|
|
74
93
|
|
|
75
|
-
it('
|
|
94
|
+
it('navigates via rowLink on row click', () => {
|
|
76
95
|
mount({ rowLink: (row) => `/devices/${row.id}` });
|
|
77
|
-
|
|
78
|
-
expect(
|
|
96
|
+
fireEvent.click(screen.getByText('Lobby Camera'));
|
|
97
|
+
expect(screen.getByTestId('location').textContent).toBe('/devices/dev-3');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('keeps table passthrough escape hatches working', () => {
|
|
101
|
+
const onRowClick = vi.fn();
|
|
102
|
+
mount({
|
|
103
|
+
columns: [{ id: 'name', header: 'Device', accessor: 'name' }],
|
|
104
|
+
table: { onRowClick, sortable: true },
|
|
105
|
+
});
|
|
106
|
+
fireEvent.click(screen.getByText('Lobby Camera'));
|
|
107
|
+
expect(onRowClick).toHaveBeenCalledTimes(1);
|
|
79
108
|
});
|
|
80
109
|
|
|
81
|
-
it('renders custom cells
|
|
110
|
+
it('renders custom cells from column config', () => {
|
|
82
111
|
mount({
|
|
83
112
|
columns: [
|
|
84
|
-
{
|
|
85
|
-
{
|
|
113
|
+
{ id: 'name', header: 'Device', cell: (row) => `${row.name}!` },
|
|
114
|
+
{ id: 'status', header: 'Status', cell: (row) => <em>{row.status}</em> },
|
|
86
115
|
],
|
|
87
|
-
rowActions: (row) => <button type="button">open-{row.id}</button>,
|
|
88
116
|
});
|
|
89
117
|
expect(screen.getByText('Lobby Camera!')).toBeDefined();
|
|
90
118
|
expect(screen.getAllByText('online', { selector: 'em' }).length).toBe(2);
|
|
91
|
-
expect(screen.getByText('open-dev-3')).toBeDefined();
|
|
92
119
|
});
|
|
93
120
|
|
|
94
|
-
it('shows the empty state when no row matches', () => {
|
|
121
|
+
it('shows the DataTable empty state when no row matches', () => {
|
|
95
122
|
mount({
|
|
96
123
|
search: { terms: (row) => row.name },
|
|
97
|
-
|
|
124
|
+
table: { emptyState: { title: 'No devices', description: 'Try another search' } },
|
|
98
125
|
});
|
|
99
126
|
fireEvent.change(screen.getByPlaceholderText('Search…'), { target: { value: 'zzz' } });
|
|
100
127
|
expect(screen.getByText('No devices')).toBeDefined();
|
|
@@ -102,10 +129,9 @@ describe('ListPage', () => {
|
|
|
102
129
|
expect(screen.queryByText('Lobby Camera')).toBeNull();
|
|
103
130
|
});
|
|
104
131
|
|
|
105
|
-
it('renders
|
|
106
|
-
|
|
107
|
-
expect(screen.
|
|
108
|
-
expect(container.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0);
|
|
132
|
+
it('renders the notice slot between header and toolbar', () => {
|
|
133
|
+
mount({ notice: <div role="alert">offline note</div> });
|
|
134
|
+
expect(screen.getByRole('alert').textContent).toBe('offline note');
|
|
109
135
|
});
|
|
110
136
|
|
|
111
137
|
it('honours label overrides', () => {
|
|
@@ -116,14 +142,4 @@ describe('ListPage', () => {
|
|
|
116
142
|
expect(screen.getByPlaceholderText('Cihaz ara')).toBeDefined();
|
|
117
143
|
expect(screen.getByTestId('list-page-count').textContent).toBe('üç');
|
|
118
144
|
});
|
|
119
|
-
|
|
120
|
-
it('fires the empty action onClick', () => {
|
|
121
|
-
const onClick = vi.fn();
|
|
122
|
-
mount({
|
|
123
|
-
data: [],
|
|
124
|
-
empty: { title: 'No devices', action: { label: 'Add device', onClick } },
|
|
125
|
-
});
|
|
126
|
-
fireEvent.click(screen.getByText('Add device'));
|
|
127
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
128
|
-
});
|
|
129
145
|
});
|
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
import { useMemo, useState
|
|
2
|
-
import {
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
import { useNavigate } from 'react-router';
|
|
3
3
|
import { PageHeader } from '@umituz/web-design-system/templates';
|
|
4
|
-
import {
|
|
5
|
-
EmptyState,
|
|
6
|
-
FilterBar,
|
|
7
|
-
Table,
|
|
8
|
-
TableBody,
|
|
9
|
-
TableCell,
|
|
10
|
-
TableHead,
|
|
11
|
-
TableHeader,
|
|
12
|
-
TableRow,
|
|
13
|
-
} from '@umituz/web-design-system/organisms';
|
|
4
|
+
import { DataTable, FilterBar } from '@umituz/web-design-system/organisms';
|
|
14
5
|
import { FilterSelect } from '@umituz/web-design-system/molecules';
|
|
15
|
-
import { Skeleton } from '@umituz/web-design-system/atoms';
|
|
16
6
|
import {
|
|
17
7
|
defaultListPageLabels,
|
|
18
|
-
type ListPageColumn,
|
|
19
8
|
type ListPageFilter,
|
|
20
9
|
type ListPageLabels,
|
|
21
10
|
type ListPageProps,
|
|
@@ -33,55 +22,41 @@ export function ListPage<T>({
|
|
|
33
22
|
kicker,
|
|
34
23
|
meta,
|
|
35
24
|
actions,
|
|
25
|
+
notice,
|
|
36
26
|
data,
|
|
37
|
-
getRowId,
|
|
38
27
|
columns,
|
|
39
28
|
search,
|
|
40
29
|
filters,
|
|
41
30
|
matchFilter,
|
|
42
31
|
rowLink,
|
|
43
|
-
rowActions,
|
|
44
|
-
loading = false,
|
|
45
|
-
empty,
|
|
46
32
|
toolbar,
|
|
47
33
|
footer,
|
|
48
34
|
labels,
|
|
35
|
+
table,
|
|
49
36
|
}: ListPageProps<T>) {
|
|
50
37
|
const merged: ListPageLabels = { ...defaultListPageLabels, ...labels };
|
|
38
|
+
const navigate = useNavigate();
|
|
51
39
|
const [query, setQuery] = useState('');
|
|
52
40
|
const [values, setValues] = useState<Record<string, string>>({});
|
|
53
41
|
|
|
54
|
-
const activeFilters = useMemo(
|
|
55
|
-
() => Object.entries(values).filter(([, value]) => value !== ''),
|
|
56
|
-
[values],
|
|
57
|
-
);
|
|
58
|
-
|
|
59
42
|
const rows = useMemo(() => {
|
|
60
43
|
let list = data as readonly T[];
|
|
61
|
-
for (const
|
|
44
|
+
for (const filter of filters ?? []) {
|
|
45
|
+
const value = values[filter.id] ?? '';
|
|
46
|
+
if (value === '') continue;
|
|
62
47
|
const match = matchFilter ?? matchesFilterDefault;
|
|
63
|
-
list = list.filter((row) => match(row, id, value));
|
|
48
|
+
list = list.filter((row) => match(row, filter.id, value));
|
|
64
49
|
}
|
|
65
50
|
const q = query.trim().toLowerCase();
|
|
66
51
|
if (q !== '' && search) {
|
|
67
52
|
list = list.filter((row) =>
|
|
68
|
-
toSearchTerms(search.terms(row)).some((term) =>
|
|
69
|
-
term.toLowerCase().includes(q),
|
|
70
|
-
),
|
|
53
|
+
toSearchTerms(search.terms(row)).some((term) => term.toLowerCase().includes(q)),
|
|
71
54
|
);
|
|
72
55
|
}
|
|
73
56
|
return list;
|
|
74
|
-
}, [data,
|
|
57
|
+
}, [data, filters, values, query, search, matchFilter]);
|
|
75
58
|
|
|
76
59
|
const hasToolbar = Boolean(search || (filters && filters.length > 0) || toolbar);
|
|
77
|
-
const showEmpty = !loading && rows.length === 0;
|
|
78
|
-
|
|
79
|
-
const renderCell = (column: ListPageColumn<T>, row: T, isFirst: boolean): ReactNode => {
|
|
80
|
-
const content = column.render ? column.render(row) : String((row as Record<string, unknown>)[column.key] ?? '');
|
|
81
|
-
const href = isFirst && rowLink ? rowLink(row) : undefined;
|
|
82
|
-
if (href === undefined) return content;
|
|
83
|
-
return <Link to={href}>{content}</Link>;
|
|
84
|
-
};
|
|
85
60
|
|
|
86
61
|
return (
|
|
87
62
|
<div className="flex w-full flex-col gap-6">
|
|
@@ -93,6 +68,8 @@ export function ListPage<T>({
|
|
|
93
68
|
actions={actions}
|
|
94
69
|
/>
|
|
95
70
|
|
|
71
|
+
{notice}
|
|
72
|
+
|
|
96
73
|
{hasToolbar && (
|
|
97
74
|
<FilterBar
|
|
98
75
|
search={
|
|
@@ -117,9 +94,7 @@ export function ListPage<T>({
|
|
|
117
94
|
<FilterSelect
|
|
118
95
|
key={filter.id}
|
|
119
96
|
value={values[filter.id] ?? ''}
|
|
120
|
-
onChange={(value) =>
|
|
121
|
-
setValues((prev) => ({ ...prev, [filter.id]: value }))
|
|
122
|
-
}
|
|
97
|
+
onChange={(value) => setValues((prev) => ({ ...prev, [filter.id]: value }))}
|
|
123
98
|
options={filter.options}
|
|
124
99
|
ariaLabel={filter.label}
|
|
125
100
|
allLabel={merged.filterAll}
|
|
@@ -128,65 +103,19 @@ export function ListPage<T>({
|
|
|
128
103
|
</FilterBar>
|
|
129
104
|
)}
|
|
130
105
|
|
|
131
|
-
<
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
? Array.from({ length: 5 }, (_, rowIndex) => (
|
|
145
|
-
<TableRow key={`skeleton-${rowIndex}`}>
|
|
146
|
-
{columns.map((column) => (
|
|
147
|
-
<TableCell key={column.key}>
|
|
148
|
-
<Skeleton variant="text" />
|
|
149
|
-
</TableCell>
|
|
150
|
-
))}
|
|
151
|
-
{rowActions && <TableCell />}
|
|
152
|
-
</TableRow>
|
|
153
|
-
))
|
|
154
|
-
: showEmpty
|
|
155
|
-
? (
|
|
156
|
-
<TableRow>
|
|
157
|
-
<TableCell colSpan={columns.length + (rowActions ? 1 : 0)}>
|
|
158
|
-
<EmptyState
|
|
159
|
-
title={empty?.title ?? merged.emptyTitle}
|
|
160
|
-
description={empty?.description}
|
|
161
|
-
icon={empty?.icon}
|
|
162
|
-
action={
|
|
163
|
-
empty?.action ? (
|
|
164
|
-
empty.action.to ? (
|
|
165
|
-
<Link to={empty.action.to}>{empty.action.label}</Link>
|
|
166
|
-
) : empty.action.onClick ? (
|
|
167
|
-
{
|
|
168
|
-
label: empty.action.label,
|
|
169
|
-
onClick: empty.action.onClick,
|
|
170
|
-
}
|
|
171
|
-
) : undefined
|
|
172
|
-
) : undefined
|
|
173
|
-
}
|
|
174
|
-
/>
|
|
175
|
-
</TableCell>
|
|
176
|
-
</TableRow>
|
|
177
|
-
)
|
|
178
|
-
: rows.map((row) => (
|
|
179
|
-
<TableRow key={getRowId(row)}>
|
|
180
|
-
{columns.map((column, columnIndex) => (
|
|
181
|
-
<TableCell key={column.key} className={column.className}>
|
|
182
|
-
{renderCell(column, row, columnIndex === 0)}
|
|
183
|
-
</TableCell>
|
|
184
|
-
))}
|
|
185
|
-
{rowActions && <TableCell>{rowActions(row)}</TableCell>}
|
|
186
|
-
</TableRow>
|
|
187
|
-
))}
|
|
188
|
-
</TableBody>
|
|
189
|
-
</Table>
|
|
106
|
+
<DataTable
|
|
107
|
+
{...table}
|
|
108
|
+
data={[...rows]}
|
|
109
|
+
columns={[...columns]}
|
|
110
|
+
onRowClick={
|
|
111
|
+
rowLink
|
|
112
|
+
? (row) => {
|
|
113
|
+
const href = rowLink(row);
|
|
114
|
+
if (href !== undefined) navigate(href);
|
|
115
|
+
}
|
|
116
|
+
: table?.onRowClick
|
|
117
|
+
}
|
|
118
|
+
/>
|
|
190
119
|
|
|
191
120
|
{footer}
|
|
192
121
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Column, DataTableProps } from '@umituz/web-design-system/organisms';
|
|
3
3
|
|
|
4
4
|
export interface ListPageFilterOption {
|
|
5
5
|
value: string;
|
|
@@ -12,36 +12,14 @@ export interface ListPageFilter {
|
|
|
12
12
|
options: readonly ListPageFilterOption[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export interface ListPageColumn<T> {
|
|
16
|
-
key: string;
|
|
17
|
-
header: ReactNode;
|
|
18
|
-
render?: (row: T) => ReactNode;
|
|
19
|
-
headerClassName?: string;
|
|
20
|
-
className?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
15
|
export interface ListPageSearchConfig<T> {
|
|
24
16
|
terms: (row: T) => string | readonly string[];
|
|
25
17
|
placeholder?: string;
|
|
26
18
|
}
|
|
27
19
|
|
|
28
|
-
export interface ListPageEmptyAction {
|
|
29
|
-
label: string;
|
|
30
|
-
to?: string;
|
|
31
|
-
onClick?: () => void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ListPageEmpty {
|
|
35
|
-
title: string;
|
|
36
|
-
description?: string;
|
|
37
|
-
icon?: EmptyStateProps['icon'];
|
|
38
|
-
action?: ListPageEmptyAction;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
20
|
export interface ListPageLabels {
|
|
42
21
|
searchPlaceholder: string;
|
|
43
22
|
filterAll: string;
|
|
44
|
-
emptyTitle: string;
|
|
45
23
|
countShown: (shown: number, total: number) => string;
|
|
46
24
|
}
|
|
47
25
|
|
|
@@ -51,24 +29,21 @@ export interface ListPageProps<T> {
|
|
|
51
29
|
kicker?: ReactNode;
|
|
52
30
|
meta?: ReactNode;
|
|
53
31
|
actions?: ReactNode;
|
|
32
|
+
notice?: ReactNode;
|
|
54
33
|
data: readonly T[];
|
|
55
|
-
|
|
56
|
-
columns: readonly ListPageColumn<T>[];
|
|
34
|
+
columns: readonly Column<T>[];
|
|
57
35
|
search?: ListPageSearchConfig<T>;
|
|
58
36
|
filters?: readonly ListPageFilter[];
|
|
59
37
|
matchFilter?: (row: T, filterId: string, value: string) => boolean;
|
|
60
38
|
rowLink?: (row: T) => string | undefined;
|
|
61
|
-
rowActions?: (row: T) => ReactNode;
|
|
62
|
-
loading?: boolean;
|
|
63
|
-
empty?: ListPageEmpty;
|
|
64
39
|
toolbar?: ReactNode;
|
|
65
40
|
footer?: ReactNode;
|
|
66
41
|
labels?: Partial<ListPageLabels>;
|
|
42
|
+
table?: Omit<DataTableProps<T>, 'data' | 'columns'>;
|
|
67
43
|
}
|
|
68
44
|
|
|
69
45
|
export const defaultListPageLabels: ListPageLabels = {
|
|
70
46
|
searchPlaceholder: 'Search…',
|
|
71
47
|
filterAll: 'All',
|
|
72
|
-
emptyTitle: 'Nothing here yet',
|
|
73
48
|
countShown: (shown, total) => `${shown} of ${total}`,
|
|
74
49
|
};
|