@umituz/web-dashboard 11.1.0 → 11.2.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.1.0",
3
+ "version": "11.2.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
- { key: 'name', header: 'Device' },
21
- { key: 'status', header: 'Status' },
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
- <ListPage<Device>
28
- title="Devices"
29
- description="Field hardware"
30
- data={DEVICES}
31
- getRowId={(row) => row.id}
32
- columns={COLUMNS}
33
- {...props}
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
- search: { terms: (row) => [row.name, row.site] },
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('shows the count of shown vs total', () => {
78
+ it('honours a custom matchFilter', () => {
68
79
  mount({
69
- search: { terms: (row) => row.name },
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('renders first column as a link via rowLink', () => {
94
+ it('navigates via rowLink on row click', () => {
76
95
  mount({ rowLink: (row) => `/devices/${row.id}` });
77
- const link = screen.getByText('Lobby Camera').closest('a');
78
- expect(link?.getAttribute('href')).toBe('/devices/dev-3');
96
+ fireEvent.click(screen.getByText('Lobby Camera'));
97
+ expect(screen.getByTestId('location').textContent).toBe('/devices/dev-3');
79
98
  });
80
99
 
81
- it('renders custom cells and per-row actions', () => {
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);
108
+ });
109
+
110
+ it('renders custom cells from column config', () => {
82
111
  mount({
83
112
  columns: [
84
- { key: 'name', header: 'Device', render: (row) => `${row.name}!` },
85
- { key: 'status', header: 'Status', render: (row) => <em>{row.status}</em> },
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
- empty: { title: 'No devices', description: 'Try another search' },
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,12 +129,6 @@ describe('ListPage', () => {
102
129
  expect(screen.queryByText('Lobby Camera')).toBeNull();
103
130
  });
104
131
 
105
- it('renders skeleton rows while loading an empty dataset', () => {
106
- const { container } = mount({ data: [], loading: true, empty: { title: 'No devices' } });
107
- expect(screen.queryByText('No devices')).toBeNull();
108
- expect(container.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0);
109
- });
110
-
111
132
  it('honours label overrides', () => {
112
133
  mount({
113
134
  search: { terms: (row) => row.name },
@@ -116,14 +137,4 @@ describe('ListPage', () => {
116
137
  expect(screen.getByPlaceholderText('Cihaz ara')).toBeDefined();
117
138
  expect(screen.getByTestId('list-page-count').textContent).toBe('üç');
118
139
  });
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
140
  });
@@ -1,21 +1,10 @@
1
- import { useMemo, useState, type ReactNode } from 'react';
2
- import { Link } from 'react-router';
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,
@@ -34,54 +23,39 @@ export function ListPage<T>({
34
23
  meta,
35
24
  actions,
36
25
  data,
37
- getRowId,
38
26
  columns,
39
27
  search,
40
28
  filters,
41
29
  matchFilter,
42
30
  rowLink,
43
- rowActions,
44
- loading = false,
45
- empty,
46
31
  toolbar,
47
32
  footer,
48
33
  labels,
34
+ table,
49
35
  }: ListPageProps<T>) {
50
36
  const merged: ListPageLabels = { ...defaultListPageLabels, ...labels };
37
+ const navigate = useNavigate();
51
38
  const [query, setQuery] = useState('');
52
39
  const [values, setValues] = useState<Record<string, string>>({});
53
40
 
54
- const activeFilters = useMemo(
55
- () => Object.entries(values).filter(([, value]) => value !== ''),
56
- [values],
57
- );
58
-
59
41
  const rows = useMemo(() => {
60
42
  let list = data as readonly T[];
61
- for (const [id, value] of activeFilters) {
43
+ for (const filter of filters ?? []) {
44
+ const value = values[filter.id] ?? '';
45
+ if (value === '') continue;
62
46
  const match = matchFilter ?? matchesFilterDefault;
63
- list = list.filter((row) => match(row, id, value));
47
+ list = list.filter((row) => match(row, filter.id, value));
64
48
  }
65
49
  const q = query.trim().toLowerCase();
66
50
  if (q !== '' && search) {
67
51
  list = list.filter((row) =>
68
- toSearchTerms(search.terms(row)).some((term) =>
69
- term.toLowerCase().includes(q),
70
- ),
52
+ toSearchTerms(search.terms(row)).some((term) => term.toLowerCase().includes(q)),
71
53
  );
72
54
  }
73
55
  return list;
74
- }, [data, activeFilters, query, search, matchFilter]);
56
+ }, [data, filters, values, query, search, matchFilter]);
75
57
 
76
58
  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
59
 
86
60
  return (
87
61
  <div className="flex w-full flex-col gap-6">
@@ -117,9 +91,7 @@ export function ListPage<T>({
117
91
  <FilterSelect
118
92
  key={filter.id}
119
93
  value={values[filter.id] ?? ''}
120
- onChange={(value) =>
121
- setValues((prev) => ({ ...prev, [filter.id]: value }))
122
- }
94
+ onChange={(value) => setValues((prev) => ({ ...prev, [filter.id]: value }))}
123
95
  options={filter.options}
124
96
  ariaLabel={filter.label}
125
97
  allLabel={merged.filterAll}
@@ -128,65 +100,19 @@ export function ListPage<T>({
128
100
  </FilterBar>
129
101
  )}
130
102
 
131
- <Table>
132
- <TableHeader>
133
- <TableRow>
134
- {columns.map((column) => (
135
- <TableHead key={column.key} className={column.headerClassName}>
136
- {column.header}
137
- </TableHead>
138
- ))}
139
- {rowActions && <TableHead className="w-0" />}
140
- </TableRow>
141
- </TableHeader>
142
- <TableBody>
143
- {loading && data.length === 0
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>
103
+ <DataTable
104
+ {...table}
105
+ data={[...rows]}
106
+ columns={[...columns]}
107
+ onRowClick={
108
+ rowLink
109
+ ? (row) => {
110
+ const href = rowLink(row);
111
+ if (href !== undefined) navigate(href);
112
+ }
113
+ : table?.onRowClick
114
+ }
115
+ />
190
116
 
191
117
  {footer}
192
118
  </div>
@@ -1,9 +1,6 @@
1
1
  export { ListPage } from './components';
2
2
  export {
3
3
  defaultListPageLabels,
4
- type ListPageColumn,
5
- type ListPageEmpty,
6
- type ListPageEmptyAction,
7
4
  type ListPageFilter,
8
5
  type ListPageFilterOption,
9
6
  type ListPageLabels,
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
- import type { EmptyStateProps } from '@umituz/web-design-system/organisms';
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
 
@@ -52,23 +30,19 @@ export interface ListPageProps<T> {
52
30
  meta?: ReactNode;
53
31
  actions?: ReactNode;
54
32
  data: readonly T[];
55
- getRowId: (row: T) => string;
56
- columns: readonly ListPageColumn<T>[];
33
+ columns: readonly Column<T>[];
57
34
  search?: ListPageSearchConfig<T>;
58
35
  filters?: readonly ListPageFilter[];
59
36
  matchFilter?: (row: T, filterId: string, value: string) => boolean;
60
37
  rowLink?: (row: T) => string | undefined;
61
- rowActions?: (row: T) => ReactNode;
62
- loading?: boolean;
63
- empty?: ListPageEmpty;
64
38
  toolbar?: ReactNode;
65
39
  footer?: ReactNode;
66
40
  labels?: Partial<ListPageLabels>;
41
+ table?: Omit<DataTableProps<T>, 'data' | 'columns'>;
67
42
  }
68
43
 
69
44
  export const defaultListPageLabels: ListPageLabels = {
70
45
  searchPlaceholder: 'Search…',
71
46
  filterAll: 'All',
72
- emptyTitle: 'Nothing here yet',
73
47
  countShown: (shown, total) => `${shown} of ${total}`,
74
48
  };