Skip to content

Commit 2697126

Browse files
jaruesinkcodegen-sh[bot]
authored andcommitted
Add autodocs tags and enhance stories for client-side and server-driven DataTable components
- Added 'autodocs' tags to the metadata of both client-side and server-driven DataTable stories for improved documentation generation. - Included detailed source code examples in the stories to demonstrate client-side filtering and server-side data fetching with Bazza UI components. - Enhanced the clarity and maintainability of the DataTableWithClientSideFilters and DataTableWithBazzaFilters components.
1 parent 6d1e36e commit 2697126

2 files changed

Lines changed: 220 additions & 0 deletions

File tree

apps/docs/src/remix-hook-form/data-table/data-table-client-side.stories.tsx

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const meta: Meta<typeof DataTableWithClientSideFilters> = {
125125
},
126126
},
127127
},
128+
tags: ['autodocs'],
128129
};
129130

130131
export default meta;
@@ -138,6 +139,94 @@ export const ClientSide: Story = {
138139
story:
139140
'Demonstrates client-side filtering using Bazza UI components and real-time filtering without server requests. All filtering happens in the browser for immediate response.',
140141
},
142+
source: {
143+
code: `
144+
import { useMemo, useState } from 'react';
145+
import {
146+
DataTable,
147+
DataTableFilter,
148+
useDataTableFilters,
149+
useFilterSync,
150+
useReactTable,
151+
getCoreRowModel,
152+
getPaginationRowModel,
153+
getSortedRowModel,
154+
} from './data-table-stories.helpers';
155+
156+
function DataTableWithClientSideFilters() {
157+
// --- Client-side data state ---
158+
const [data] = useState<MockIssue[]>(mockDatabase);
159+
160+
// --- Bazza UI Filter Setup ---
161+
const [filters, setFilters] = useFilterSync();
162+
163+
// --- Pagination and Sorting State ---
164+
const [pagination, setPagination] = useState<PaginationState>({
165+
pageIndex: 0,
166+
pageSize: 10,
167+
});
168+
const [sorting, setSorting] = useState<SortingState>([]);
169+
170+
// --- Event Handlers ---
171+
const handlePaginationChange: OnChangeFn<PaginationState> = (updaterOrValue) => {
172+
setPagination(typeof updaterOrValue === 'function' ? updaterOrValue(pagination) : updaterOrValue);
173+
};
174+
175+
const handleSortingChange: OnChangeFn<SortingState> = (updaterOrValue) => {
176+
setSorting(typeof updaterOrValue === 'function' ? updaterOrValue(sorting) : updaterOrValue);
177+
};
178+
179+
// --- Bazza UI Filter Setup ---
180+
const bazzaProcessedColumns = useMemo(() => columnConfigs, []);
181+
const filterStrategy = 'client' as const;
182+
183+
// Setup filter actions and strategy (controlled mode)
184+
const {
185+
columns: filterColumns,
186+
actions,
187+
strategy,
188+
data: filteredData,
189+
} = useDataTableFilters({
190+
columnsConfig: bazzaProcessedColumns,
191+
filters,
192+
onFiltersChange: setFilters,
193+
strategy: filterStrategy,
194+
data,
195+
});
196+
197+
// --- TanStack Table Setup ---
198+
const table = useReactTable({
199+
data: filteredData,
200+
columns,
201+
state: {
202+
pagination,
203+
sorting,
204+
},
205+
onPaginationChange: handlePaginationChange,
206+
onSortingChange: handleSortingChange,
207+
getCoreRowModel: getCoreRowModel(),
208+
getPaginationRowModel: getPaginationRowModel(),
209+
getSortedRowModel: getSortedRowModel(),
210+
manualPagination: false, // Client-side pagination
211+
manualSorting: false, // Client-side sorting
212+
});
213+
214+
return (
215+
<div className="space-y-4">
216+
{/* Bazza UI Filter Interface */}
217+
<DataTableFilter columns={filterColumns} filters={filters} actions={actions} strategy={strategy} />
218+
219+
{/* Data Table */}
220+
<DataTable
221+
table={table}
222+
columns={columns.length}
223+
pageCount={table.getPageCount()}
224+
onPaginationChange={handleDataTablePagination}
225+
/>
226+
</div>
227+
);
228+
}`,
229+
},
141230
},
142231
},
143232
decorators: [

apps/docs/src/remix-hook-form/data-table/data-table-server-driven.stories.tsx

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ const meta: Meta<typeof DataTableWithBazzaFilters> = {
269269
},
270270
},
271271
},
272+
tags: ['autodocs'],
272273
};
273274

274275
export default meta;
@@ -282,6 +283,136 @@ export const ServerDriven: Story = {
282283
story:
283284
'Demonstrates server-side filtering (via loader), pagination, and sorting with Bazza UI components and URL state synchronization.',
284285
},
286+
source: {
287+
code: `
288+
import { useMemo } from 'react';
289+
import { type LoaderFunctionArgs, useLoaderData } from 'react-router';
290+
import { useSearchParams } from 'react-router-dom';
291+
import {
292+
DataTable,
293+
DataTableFilter,
294+
useDataTableFilters,
295+
useFilterSync,
296+
useReactTable,
297+
getCoreRowModel,
298+
getPaginationRowModel,
299+
getSortedRowModel,
300+
} from './data-table-stories.helpers';
301+
302+
// --- Data Fetch Handler ---
303+
const handleDataFetch = async ({ request }: LoaderFunctionArgs): Promise<DataResponse> => {
304+
const url = new URL(request.url);
305+
const params = url.searchParams;
306+
307+
// Parse pagination, sorting, and filters from URL
308+
const page = dataTableRouterParsers.page.parse(params.get('page')) ?? 0;
309+
const pageSize = dataTableRouterParsers.pageSize.parse(params.get('pageSize')) ?? 10;
310+
const sortField = params.get('sortField');
311+
const sortOrder = (params.get('sortOrder') || 'asc') as 'asc' | 'desc';
312+
const filtersParam = params.get('filters');
313+
314+
// Parse filters
315+
let parsedFilters = [];
316+
try {
317+
if (filtersParam) {
318+
parsedFilters = filtersArraySchema.parse(JSON.parse(filtersParam));
319+
}
320+
} catch (error) {
321+
console.error('Filter parsing error:', error);
322+
}
323+
324+
// Apply filtering, sorting, pagination to data
325+
let processedData = [...mockDatabase];
326+
327+
// Apply filters, sorting, and pagination logic here...
328+
329+
return {
330+
data: paginatedData,
331+
meta: { total, page, pageSize, pageCount },
332+
facetedCounts,
333+
};
334+
};
335+
336+
function DataTableWithBazzaFilters() {
337+
const loaderData = useLoaderData<DataResponse>();
338+
const [searchParams, setSearchParams] = useSearchParams();
339+
340+
const data = loaderData?.data ?? [];
341+
const pageCount = loaderData?.meta.pageCount ?? 0;
342+
const facetedCounts = loaderData?.facetedCounts ?? {};
343+
344+
// --- Bazza UI Filter Setup ---
345+
const [filters, setFilters] = useFilterSync();
346+
347+
// Read pagination and sorting from URL
348+
const pageIndex = Number.parseInt(searchParams.get('page') ?? '0', 10);
349+
const pageSize = Number.parseInt(searchParams.get('pageSize') ?? '10', 10);
350+
const sortField = searchParams.get('sortField');
351+
const sortOrder = (searchParams.get('sortOrder') || 'asc') as 'asc' | 'desc';
352+
353+
const pagination = { pageIndex, pageSize };
354+
const sorting = sortField ? [{ id: sortField, desc: sortOrder === 'desc' }] : [];
355+
356+
// Event handlers update URL directly
357+
const handlePaginationChange = (updaterOrValue) => {
358+
const next = typeof updaterOrValue === 'function' ? updaterOrValue(pagination) : updaterOrValue;
359+
searchParams.set('page', next.pageIndex.toString());
360+
searchParams.set('pageSize', next.pageSize.toString());
361+
setSearchParams(searchParams);
362+
};
363+
364+
const handleSortingChange = (updaterOrValue) => {
365+
const next = typeof updaterOrValue === 'function' ? updaterOrValue(sorting) : updaterOrValue;
366+
if (next.length > 0) {
367+
searchParams.set('sortField', next[0].id);
368+
searchParams.set('sortOrder', next[0].desc ? 'desc' : 'asc');
369+
} else {
370+
searchParams.delete('sortField');
371+
searchParams.delete('sortOrder');
372+
}
373+
setSearchParams(searchParams);
374+
};
375+
376+
// Setup filter actions and strategy
377+
const {
378+
columns: filterColumns,
379+
actions,
380+
strategy,
381+
} = useDataTableFilters({
382+
columnsConfig: bazzaProcessedColumns,
383+
filters,
384+
onFiltersChange: setFilters,
385+
faceted: facetedOptionCounts,
386+
strategy: 'server',
387+
data,
388+
});
389+
390+
// TanStack Table Setup
391+
const table = useReactTable({
392+
data,
393+
columns,
394+
pageCount,
395+
state: { pagination, sorting },
396+
onPaginationChange: handlePaginationChange,
397+
onSortingChange: handleSortingChange,
398+
getCoreRowModel: getCoreRowModel(),
399+
getPaginationRowModel: getPaginationRowModel(),
400+
getSortedRowModel: getSortedRowModel(),
401+
manualPagination: true,
402+
manualSorting: true,
403+
});
404+
405+
return (
406+
<div className="space-y-4">
407+
{/* Bazza UI Filter Interface */}
408+
<DataTableFilter columns={filterColumns} filters={filters} actions={actions} strategy={strategy} />
409+
410+
{/* Data Table */}
411+
<DataTable table={table} columns={columns.length} pageCount={pageCount} />
412+
</div>
413+
);
414+
}`,
415+
},
285416
},
286417
},
287418
render: () => <DataTableWithBazzaFilters />,

0 commit comments

Comments
 (0)