muffin-admin 13.1.1 → 13.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/dist/MuffinRecordList.d.ts +5 -1
- package/dist/MuffinRecordList.js +11 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/MuffinRecordList.tsx +24 -3
- package/src/version.ts +1 -1
|
@@ -3,6 +3,10 @@ type TProps = {
|
|
|
3
3
|
resource: string;
|
|
4
4
|
filter: (record: any) => Record<string, any>;
|
|
5
5
|
sort?: SortPayload;
|
|
6
|
+
highlightBy?: (record: any) => {
|
|
7
|
+
field: string;
|
|
8
|
+
value: string;
|
|
9
|
+
};
|
|
6
10
|
};
|
|
7
|
-
export declare function MuffinRecordList({ resource, filter, sort }: TProps): import("react").JSX.Element;
|
|
11
|
+
export declare function MuffinRecordList({ resource, filter, sort, highlightBy }: TProps): import("react").JSX.Element;
|
|
8
12
|
export {};
|
package/dist/MuffinRecordList.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import Box from "@mui/material/Box";
|
|
3
3
|
import Typography from "@mui/material/Typography";
|
|
4
|
-
import { Datagrid, useGetList, useRecordContext, useTranslate } from "react-admin";
|
|
4
|
+
import { Datagrid, useGetList, useRecordContext, useTheme, useTranslate, } from "react-admin";
|
|
5
5
|
import { useMuffinResourceOpts } from "./hooks";
|
|
6
6
|
import { buildAdmin } from "./utils";
|
|
7
|
-
export function MuffinRecordList({ resource, filter, sort }) {
|
|
7
|
+
export function MuffinRecordList({ resource, filter, sort, highlightBy }) {
|
|
8
8
|
const record = useRecordContext();
|
|
9
|
+
const theme = useTheme()[0];
|
|
9
10
|
const translate = useTranslate();
|
|
10
11
|
const { list: { fields }, } = useMuffinResourceOpts(resource);
|
|
11
12
|
const { data, isPending } = useGetList(resource, { sort, filter: filter(record) });
|
|
12
|
-
|
|
13
|
+
const rowSx = (row) => {
|
|
14
|
+
if (!highlightBy)
|
|
15
|
+
return {};
|
|
16
|
+
const { field, value } = highlightBy(record);
|
|
17
|
+
const selectColor = theme === "dark" ? "#646D7E" : "#B4CFEC";
|
|
18
|
+
return { backgroundColor: row[field] === value ? selectColor : "" };
|
|
19
|
+
};
|
|
20
|
+
return (_jsxs(Box, { sx: { p: 2 }, children: [_jsx(Typography, { variant: "h6", children: translate(`resources.${resource}.name`, { smart_count: 2 }) }), _jsx(Datagrid, { resource: resource, bulkActionButtons: false, isPending: isPending, data: data, rowSx: rowSx, children: buildAdmin(["list-fields", resource], fields) })] }));
|
|
13
21
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "13.
|
|
1
|
+
export declare const VERSION = "13.2.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "13.
|
|
1
|
+
export const VERSION = "13.2.0";
|
package/package.json
CHANGED
package/src/MuffinRecordList.tsx
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import Box from "@mui/material/Box"
|
|
2
2
|
import Typography from "@mui/material/Typography"
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Datagrid,
|
|
5
|
+
type SortPayload,
|
|
6
|
+
useGetList,
|
|
7
|
+
useRecordContext,
|
|
8
|
+
useTheme,
|
|
9
|
+
useTranslate,
|
|
10
|
+
} from "react-admin"
|
|
4
11
|
import { useMuffinResourceOpts } from "./hooks"
|
|
5
12
|
import { buildAdmin } from "./utils"
|
|
6
13
|
|
|
@@ -8,20 +15,34 @@ type TProps = {
|
|
|
8
15
|
resource: string
|
|
9
16
|
filter: (record: any) => Record<string, any>
|
|
10
17
|
sort?: SortPayload
|
|
18
|
+
highlightBy?: (record: any) => { field: string; value: string }
|
|
11
19
|
}
|
|
12
|
-
export function MuffinRecordList({ resource, filter, sort }: TProps) {
|
|
20
|
+
export function MuffinRecordList({ resource, filter, sort, highlightBy }: TProps) {
|
|
13
21
|
const record = useRecordContext()
|
|
22
|
+
const theme = useTheme()[0]
|
|
14
23
|
const translate = useTranslate()
|
|
15
24
|
const {
|
|
16
25
|
list: { fields },
|
|
17
26
|
} = useMuffinResourceOpts(resource)
|
|
18
27
|
const { data, isPending } = useGetList(resource, { sort, filter: filter(record) })
|
|
28
|
+
const rowSx = (row: any) => {
|
|
29
|
+
if (!highlightBy) return {}
|
|
30
|
+
const { field, value } = highlightBy(record)
|
|
31
|
+
const selectColor = theme === "dark" ? "#646D7E" : "#B4CFEC"
|
|
32
|
+
return { backgroundColor: row[field] === value ? selectColor : "" }
|
|
33
|
+
}
|
|
19
34
|
return (
|
|
20
35
|
<Box sx={{ p: 2 }}>
|
|
21
36
|
<Typography variant="h6">
|
|
22
37
|
{translate(`resources.${resource}.name`, { smart_count: 2 })}
|
|
23
38
|
</Typography>
|
|
24
|
-
<Datagrid
|
|
39
|
+
<Datagrid
|
|
40
|
+
resource={resource}
|
|
41
|
+
bulkActionButtons={false}
|
|
42
|
+
isPending={isPending}
|
|
43
|
+
data={data}
|
|
44
|
+
rowSx={rowSx}
|
|
45
|
+
>
|
|
25
46
|
{buildAdmin(["list-fields", resource], fields)}
|
|
26
47
|
</Datagrid>
|
|
27
48
|
</Box>
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "13.
|
|
1
|
+
export const VERSION = "13.2.0"
|