MCPcopy
hub / github.com/refinedev/refine / PostList

Function PostList

examples/multi-level-menu/src/pages/posts/list.tsx:15–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13import type { IPost, ICategory } from "../../interfaces";
14
15export const PostList = () => {
16 const { tableProps, filters } = useTable<IPost>();
17
18 const categoryIds =
19 tableProps?.dataSource?.map((item) => item.category.id) ?? [];
20 const { data, isLoading } = useMany<ICategory>({
21 resource: "categories",
22 ids: categoryIds,
23 queryOptions: {
24 enabled: categoryIds.length > 0,
25 },
26 });
27
28 const { selectProps: categorySelectProps } = useSelect<ICategory>({
29 resource: "categories",
30 optionLabel: "title",
31 optionValue: "id",
32 defaultValue: getDefaultFilter("category.id", filters, "in"),
33 });
34
35 return (
36 <List>
37 <Table {...tableProps} rowKey="id">
38 <Table.Column dataIndex="id" title="ID" />
39 <Table.Column dataIndex="title" title="Title" />
40 <Table.Column
41 dataIndex={["category", "id"]}
42 title="Category"
43 render={(value) => {
44 if (isLoading) {
45 return <TextField value="Loading..." />;
46 }
47
48 return (
49 <TextField
50 value={data?.data.find((item) => item.id === value)?.title}
51 />
52 );
53 }}
54 filterDropdown={(props) => (
55 <FilterDropdown
56 {...props}
57 mapValue={(selectedKeys) => selectedKeys.map(Number)}
58 >
59 <Select
60 style={{ minWidth: 200 }}
61 mode="multiple"
62 placeholder="Select Category"
63 {...categorySelectProps}
64 />
65 </FilterDropdown>
66 )}
67 defaultFilteredValue={getDefaultFilter("category.id", filters, "in")}
68 />
69 <Table.Column
70 dataIndex="status"
71 title="Status"
72 render={(value: string) => <TagField value={value} />}

Callers

nothing calls this directly

Calls 4

useTableFunction · 0.90
useManyFunction · 0.90
useSelectFunction · 0.90
getDefaultFilterFunction · 0.90

Tested by

no test coverage detected