Skip to content

Commit b9b1de3

Browse files
authored
fix(dashboard): Forward transformQueryKey and view options from ListPage (#5066)
1 parent 54ee8d3 commit b9b1de3

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { renderToStaticMarkup } from 'react-dom/server';
2+
import { beforeEach, describe, expect, it, vi } from 'vitest';
3+
4+
import { ListPage } from './list-page.js';
5+
6+
// Capture the props ListPage forwards to PaginatedListDataTable.
7+
const captured: { props?: Record<string, any> } = {};
8+
9+
vi.mock('@/vdb/components/shared/paginated-list-data-table.js', () => ({
10+
PaginatedListDataTable: (props: Record<string, any>) => {
11+
captured.props = props;
12+
return null;
13+
},
14+
}));
15+
16+
vi.mock('../layout-engine/page-layout.js', () => ({
17+
Page: ({ children }: any) => <>{children}</>,
18+
PageTitle: ({ children }: any) => <>{children}</>,
19+
PageActionBar: ({ children }: any) => <>{children}</>,
20+
PageLayout: ({ children }: any) => <>{children}</>,
21+
FullWidthPageBlock: ({ children }: any) => <>{children}</>,
22+
}));
23+
24+
vi.mock('@/vdb/hooks/use-user-settings.js', () => ({
25+
useUserSettings: () => ({ setTableSettings: vi.fn(), settings: {} }),
26+
}));
27+
28+
vi.mock('@tanstack/react-router', () => ({
29+
useNavigate: () => vi.fn(),
30+
}));
31+
32+
describe('ListPage prop forwarding', () => {
33+
const baseProps = {
34+
route: { useSearch: () => ({}), fullPath: '/' } as any,
35+
title: 'Test',
36+
listQuery: {} as any,
37+
};
38+
39+
beforeEach(() => {
40+
captured.props = undefined;
41+
});
42+
43+
it('forwards transformQueryKey, disableViewOptions and includeSelectionColumn to PaginatedListDataTable', () => {
44+
const transformQueryKey = (queryKey: any[]) => [...queryKey, 'extra'];
45+
46+
renderToStaticMarkup(
47+
<ListPage
48+
{...baseProps}
49+
transformQueryKey={transformQueryKey}
50+
disableViewOptions={true}
51+
// false is the non-default value, so this asserts the value is really forwarded
52+
// rather than coinciding with PaginatedListDataTable's own default of true.
53+
includeSelectionColumn={false}
54+
/>,
55+
);
56+
57+
expect(captured.props).toBeDefined();
58+
expect(captured.props?.transformQueryKey).toBe(transformQueryKey);
59+
expect(captured.props?.disableViewOptions).toBe(true);
60+
expect(captured.props?.includeSelectionColumn).toBe(false);
61+
});
62+
});

packages/dashboard/src/lib/framework/page/list-page.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,27 @@ export interface ListPageProps<
322322
* that is not often required.
323323
*/
324324
transformData?: (data: any[]) => any[];
325+
/**
326+
* @description
327+
* Allows the react-query cache key to be transformed. Use this together with the
328+
* `transformVariables` prop when a page injects extra state into the query
329+
* (e.g. a language selector or a status filter): the default key only reflects page, sorting,
330+
* column filters and the search term, so without transforming the key too, changing the injected
331+
* state serves a stale cached result instead of refetching.
332+
*/
333+
transformQueryKey?: (queryKey: any[]) => any[];
334+
/**
335+
* @description
336+
* When true, disables the view options (column visibility) control in the table toolbar.
337+
*/
338+
disableViewOptions?: boolean;
339+
/**
340+
* @description
341+
* When false, the row selection checkbox column will not be included.
342+
*
343+
* @default true
344+
*/
345+
includeSelectionColumn?: boolean;
325346
/**
326347
* @description
327348
* Allows you to directly manipulate the TanStack Table `TableOptions` object before the
@@ -500,6 +521,9 @@ export function ListPage<
500521
children,
501522
rowActions,
502523
transformData,
524+
transformQueryKey,
525+
disableViewOptions,
526+
includeSelectionColumn,
503527
setTableOptions,
504528
bulkActions,
505529
registerRefresher,
@@ -599,6 +623,9 @@ export function ListPage<
599623
bulkActions,
600624
setTableOptions,
601625
transformData,
626+
transformQueryKey,
627+
disableViewOptions,
628+
includeSelectionColumn,
602629
registerRefresher,
603630
};
604631

0 commit comments

Comments
 (0)