muffin-admin 13.1.0 → 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.
@@ -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 {};
@@ -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
- 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, children: buildAdmin(["list-fields", resource], fields) })] }));
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
  }
@@ -21,5 +21,7 @@ export function LinkAction(_a) {
21
21
  if (!record)
22
22
  return null;
23
23
  const resource = resources.find((r) => r.name === props.resource);
24
- return (_jsx(LinkButton, Object.assign({}, props, { icon: icon || (resource === null || resource === void 0 ? void 0 : resource.icon), label: label || `resources.${props.resource}.name`, filters: { [filter || currentResource]: encodeURIComponent(record[field || "id"]) } })));
24
+ return (_jsx(LinkButton, Object.assign({}, props, { icon: icon || (resource === null || resource === void 0 ? void 0 : resource.icon), label: label || `resources.${props.resource}.name`, filters: {
25
+ [filter || currentResource]: record[field || "id"],
26
+ } })));
25
27
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "13.1.0";
1
+ export declare const VERSION = "13.2.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "13.1.0";
1
+ export const VERSION = "13.2.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "13.1.0",
3
+ "version": "13.2.0",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -23,6 +23,8 @@
23
23
  },
24
24
  "homepage": "https://github.com/klen/muffin-admin#readme",
25
25
  "dependencies": {
26
+ "@mui/icons-material": "^9.2.0",
27
+ "@mui/material": "^9.2.0",
26
28
  "date-fns": "^4.1.0",
27
29
  "js-cookie": "^3.0.5",
28
30
  "ra-language-russian": "^5.4.4",
@@ -1,6 +1,13 @@
1
1
  import Box from "@mui/material/Box"
2
2
  import Typography from "@mui/material/Typography"
3
- import { Datagrid, type SortPayload, useGetList, useRecordContext, useTranslate } from "react-admin"
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 resource={resource} bulkActionButtons={false} isPending={isPending} data={data}>
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>
@@ -23,7 +23,9 @@ export function LinkAction({
23
23
  {...props}
24
24
  icon={icon || resource?.icon}
25
25
  label={label || `resources.${props.resource}.name`}
26
- filters={{ [filter || currentResource]: encodeURIComponent(record[field || "id"]) }}
26
+ filters={{
27
+ [filter || currentResource]: record[field || "id"],
28
+ }}
27
29
  />
28
30
  )
29
31
  }
@@ -13,6 +13,7 @@ const LinkButton = ({
13
13
  }: AdminShowLink & { resource: string; filters?: any; id?: string }) => {
14
14
  const location = useLocation()
15
15
  const searchParams = new URLSearchParams()
16
+
16
17
  searchParams.set("returnTo", `${location.pathname}${location.search}`)
17
18
 
18
19
  if (filters) {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = "13.1.0"
1
+ export const VERSION = "13.2.0"