@umituz/web-dashboard 11.0.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.0.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",
@@ -38,6 +38,8 @@
38
38
  "./organization": "./src/domains/organization/index.ts",
39
39
  "./organization/components": "./src/domains/organization/components/index.ts",
40
40
  "./package.json": "./package.json",
41
+ "./pages": "./src/domains/pages/index.ts",
42
+ "./pages/components": "./src/domains/pages/components/index.ts",
41
43
  "./permissions": "./src/domains/permissions/index.ts",
42
44
  "./settings": "./src/domains/settings/index.ts",
43
45
  "./settings/components": "./src/domains/settings/components/index.ts",
@@ -0,0 +1,140 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import { MemoryRouter, Route, Routes, useLocation } from 'react-router';
4
+ import type { Column } from '@umituz/web-design-system/organisms';
5
+ import { ListPage } from './ListPage';
6
+
7
+ interface Device {
8
+ id: string;
9
+ name: string;
10
+ status: 'online' | 'offline';
11
+ site: string;
12
+ }
13
+
14
+ const DEVICES: readonly Device[] = [
15
+ { id: 'dev-1', name: 'North Gate Reader', status: 'online', site: 'HQ' },
16
+ { id: 'dev-2', name: 'Server Door Sensor', status: 'offline', site: 'DC' },
17
+ { id: 'dev-3', name: 'Lobby Camera', status: 'online', site: 'HQ' },
18
+ ];
19
+
20
+ const COLUMNS: readonly Column<Device>[] = [
21
+ { id: 'name', header: 'Device', accessor: 'name' },
22
+ { id: 'status', header: 'Status', accessor: 'status' },
23
+ ];
24
+
25
+ function LocationProbe() {
26
+ const location = useLocation();
27
+ return <output data-testid="location">{location.pathname}</output>;
28
+ }
29
+
30
+ function mount(props: Partial<Parameters<typeof ListPage<Device>>[0]> = {}) {
31
+ return render(
32
+ <MemoryRouter>
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>
49
+ </MemoryRouter>,
50
+ );
51
+ }
52
+
53
+ describe('ListPage', () => {
54
+ it('renders header and every row', () => {
55
+ mount();
56
+ expect(screen.getByText('Devices')).toBeDefined();
57
+ expect(screen.getByText('North Gate Reader')).toBeDefined();
58
+ expect(screen.getByText('Server Door Sensor')).toBeDefined();
59
+ expect(screen.getByText('Lobby Camera')).toBeDefined();
60
+ });
61
+
62
+ it('filters rows by search terms', () => {
63
+ mount({ search: { terms: (row) => [row.name, row.site] } });
64
+ fireEvent.change(screen.getByPlaceholderText('Search…'), { target: { value: 'camera' } });
65
+ expect(screen.getByText('Lobby Camera')).toBeDefined();
66
+ expect(screen.queryByText('North Gate Reader')).toBeNull();
67
+ });
68
+
69
+ it('filters rows by select default matcher and custom matcher', () => {
70
+ mount({
71
+ filters: [{ id: 'status', label: 'Status', options: [{ value: 'online', label: 'Online' }] }],
72
+ });
73
+ fireEvent.change(screen.getByLabelText('Status'), { target: { value: 'online' } });
74
+ expect(screen.queryByText('Server Door Sensor')).toBeNull();
75
+ expect(screen.getByText('Lobby Camera')).toBeDefined();
76
+ });
77
+
78
+ it('honours a custom matchFilter', () => {
79
+ mount({
80
+ filters: [{ id: 'campus', label: 'Campus', options: [{ value: 'hq', label: 'HQ' }] }],
81
+ matchFilter: (row, id, value) => id === 'campus' && row.site.toLowerCase() === value,
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 } });
90
+ fireEvent.change(screen.getByPlaceholderText('Search…'), { target: { value: 'gate' } });
91
+ expect(screen.getByTestId('list-page-count').textContent).toBe('1 of 3');
92
+ });
93
+
94
+ it('navigates via rowLink on row click', () => {
95
+ mount({ rowLink: (row) => `/devices/${row.id}` });
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);
108
+ });
109
+
110
+ it('renders custom cells from column config', () => {
111
+ mount({
112
+ columns: [
113
+ { id: 'name', header: 'Device', cell: (row) => `${row.name}!` },
114
+ { id: 'status', header: 'Status', cell: (row) => <em>{row.status}</em> },
115
+ ],
116
+ });
117
+ expect(screen.getByText('Lobby Camera!')).toBeDefined();
118
+ expect(screen.getAllByText('online', { selector: 'em' }).length).toBe(2);
119
+ });
120
+
121
+ it('shows the DataTable empty state when no row matches', () => {
122
+ mount({
123
+ search: { terms: (row) => row.name },
124
+ table: { emptyState: { title: 'No devices', description: 'Try another search' } },
125
+ });
126
+ fireEvent.change(screen.getByPlaceholderText('Search…'), { target: { value: 'zzz' } });
127
+ expect(screen.getByText('No devices')).toBeDefined();
128
+ expect(screen.getByText('Try another search')).toBeDefined();
129
+ expect(screen.queryByText('Lobby Camera')).toBeNull();
130
+ });
131
+
132
+ it('honours label overrides', () => {
133
+ mount({
134
+ search: { terms: (row) => row.name },
135
+ labels: { searchPlaceholder: 'Cihaz ara', countShown: () => 'üç' },
136
+ });
137
+ expect(screen.getByPlaceholderText('Cihaz ara')).toBeDefined();
138
+ expect(screen.getByTestId('list-page-count').textContent).toBe('üç');
139
+ });
140
+ });
@@ -0,0 +1,120 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { useNavigate } from 'react-router';
3
+ import { PageHeader } from '@umituz/web-design-system/templates';
4
+ import { DataTable, FilterBar } from '@umituz/web-design-system/organisms';
5
+ import { FilterSelect } from '@umituz/web-design-system/molecules';
6
+ import {
7
+ defaultListPageLabels,
8
+ type ListPageFilter,
9
+ type ListPageLabels,
10
+ type ListPageProps,
11
+ } from '../types';
12
+
13
+ const matchesFilterDefault = <T,>(row: T, filterId: string, value: string): boolean =>
14
+ String((row as Record<string, unknown>)[filterId] ?? '') === value;
15
+
16
+ const toSearchTerms = (value: string | readonly string[]): readonly string[] =>
17
+ typeof value === 'string' ? [value] : value;
18
+
19
+ export function ListPage<T>({
20
+ title,
21
+ description,
22
+ kicker,
23
+ meta,
24
+ actions,
25
+ data,
26
+ columns,
27
+ search,
28
+ filters,
29
+ matchFilter,
30
+ rowLink,
31
+ toolbar,
32
+ footer,
33
+ labels,
34
+ table,
35
+ }: ListPageProps<T>) {
36
+ const merged: ListPageLabels = { ...defaultListPageLabels, ...labels };
37
+ const navigate = useNavigate();
38
+ const [query, setQuery] = useState('');
39
+ const [values, setValues] = useState<Record<string, string>>({});
40
+
41
+ const rows = useMemo(() => {
42
+ let list = data as readonly T[];
43
+ for (const filter of filters ?? []) {
44
+ const value = values[filter.id] ?? '';
45
+ if (value === '') continue;
46
+ const match = matchFilter ?? matchesFilterDefault;
47
+ list = list.filter((row) => match(row, filter.id, value));
48
+ }
49
+ const q = query.trim().toLowerCase();
50
+ if (q !== '' && search) {
51
+ list = list.filter((row) =>
52
+ toSearchTerms(search.terms(row)).some((term) => term.toLowerCase().includes(q)),
53
+ );
54
+ }
55
+ return list;
56
+ }, [data, filters, values, query, search, matchFilter]);
57
+
58
+ const hasToolbar = Boolean(search || (filters && filters.length > 0) || toolbar);
59
+
60
+ return (
61
+ <div className="flex w-full flex-col gap-6">
62
+ <PageHeader
63
+ kicker={kicker}
64
+ title={title}
65
+ description={description}
66
+ meta={meta}
67
+ actions={actions}
68
+ />
69
+
70
+ {hasToolbar && (
71
+ <FilterBar
72
+ search={
73
+ search
74
+ ? {
75
+ value: query,
76
+ onChange: setQuery,
77
+ placeholder: search.placeholder ?? merged.searchPlaceholder,
78
+ }
79
+ : undefined
80
+ }
81
+ actions={
82
+ <>
83
+ {toolbar}
84
+ <span className="text-sm text-muted-foreground" data-testid="list-page-count">
85
+ {merged.countShown(rows.length, data.length)}
86
+ </span>
87
+ </>
88
+ }
89
+ >
90
+ {(filters ?? []).map((filter: ListPageFilter) => (
91
+ <FilterSelect
92
+ key={filter.id}
93
+ value={values[filter.id] ?? ''}
94
+ onChange={(value) => setValues((prev) => ({ ...prev, [filter.id]: value }))}
95
+ options={filter.options}
96
+ ariaLabel={filter.label}
97
+ allLabel={merged.filterAll}
98
+ />
99
+ ))}
100
+ </FilterBar>
101
+ )}
102
+
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
+ />
116
+
117
+ {footer}
118
+ </div>
119
+ );
120
+ }
@@ -0,0 +1 @@
1
+ export { ListPage } from './ListPage';
@@ -0,0 +1,9 @@
1
+ export { ListPage } from './components';
2
+ export {
3
+ defaultListPageLabels,
4
+ type ListPageFilter,
5
+ type ListPageFilterOption,
6
+ type ListPageLabels,
7
+ type ListPageProps,
8
+ type ListPageSearchConfig,
9
+ } from './types';
@@ -0,0 +1,48 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { Column, DataTableProps } from '@umituz/web-design-system/organisms';
3
+
4
+ export interface ListPageFilterOption {
5
+ value: string;
6
+ label: string;
7
+ }
8
+
9
+ export interface ListPageFilter {
10
+ id: string;
11
+ label: string;
12
+ options: readonly ListPageFilterOption[];
13
+ }
14
+
15
+ export interface ListPageSearchConfig<T> {
16
+ terms: (row: T) => string | readonly string[];
17
+ placeholder?: string;
18
+ }
19
+
20
+ export interface ListPageLabels {
21
+ searchPlaceholder: string;
22
+ filterAll: string;
23
+ countShown: (shown: number, total: number) => string;
24
+ }
25
+
26
+ export interface ListPageProps<T> {
27
+ title: ReactNode;
28
+ description?: ReactNode;
29
+ kicker?: ReactNode;
30
+ meta?: ReactNode;
31
+ actions?: ReactNode;
32
+ data: readonly T[];
33
+ columns: readonly Column<T>[];
34
+ search?: ListPageSearchConfig<T>;
35
+ filters?: readonly ListPageFilter[];
36
+ matchFilter?: (row: T, filterId: string, value: string) => boolean;
37
+ rowLink?: (row: T) => string | undefined;
38
+ toolbar?: ReactNode;
39
+ footer?: ReactNode;
40
+ labels?: Partial<ListPageLabels>;
41
+ table?: Omit<DataTableProps<T>, 'data' | 'columns'>;
42
+ }
43
+
44
+ export const defaultListPageLabels: ListPageLabels = {
45
+ searchPlaceholder: 'Search…',
46
+ filterAll: 'All',
47
+ countShown: (shown, total) => `${shown} of ${total}`,
48
+ };
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './domains/layouts';
2
+ export * from './domains/pages';
2
3
  export * from './domains/settings';
3
4
  export * from './domains/calendar';
4
5
  export * from './domains/permissions';