muffin-admin 8.2.0 → 8.4.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 +8 -0
- package/dist/MuffinRecordList.js +13 -0
- package/dist/buildRA.js +2 -1
- package/dist/buttons/CopyButton.d.ts +3 -0
- package/dist/buttons/CopyButton.js +13 -0
- package/dist/buttons/index.d.ts +1 -0
- package/dist/buttons/index.js +1 -0
- package/dist/fields/CopyField.d.ts +4 -0
- package/dist/fields/CopyField.js +23 -0
- package/dist/fields/index.d.ts +1 -0
- package/dist/fields/index.js +1 -0
- package/dist/hooks/useMuffinResourceOpts.d.ts +1 -1
- package/dist/hooks/useMuffinResourceOpts.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/MuffinRecordList.tsx +29 -0
- package/src/buildRA.tsx +2 -1
- package/src/buttons/CopyButton.tsx +24 -0
- package/src/buttons/index.ts +1 -0
- package/src/fields/CopyField.tsx +17 -0
- package/src/fields/index.ts +1 -0
- package/src/hooks/useMuffinResourceOpts.ts +2 -2
- package/src/index.tsx +2 -1
package/package.json
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Box from "@mui/material/Box"
|
|
2
|
+
import Typography from "@mui/material/Typography"
|
|
3
|
+
import { Datagrid, SortPayload, useGetList, useRecordContext, useTranslate } from "react-admin"
|
|
4
|
+
import { useMuffinResourceOpts } from "./hooks"
|
|
5
|
+
import { buildAdmin } from "./utils"
|
|
6
|
+
|
|
7
|
+
type TProps = {
|
|
8
|
+
resource: string
|
|
9
|
+
filter: (record: any) => Record<string, any>
|
|
10
|
+
sort?: SortPayload
|
|
11
|
+
}
|
|
12
|
+
export function MuffinRecordList({ resource, filter, sort }: TProps) {
|
|
13
|
+
const record = useRecordContext()
|
|
14
|
+
const translate = useTranslate()
|
|
15
|
+
const {
|
|
16
|
+
list: { fields },
|
|
17
|
+
} = useMuffinResourceOpts(resource)
|
|
18
|
+
const { data, isPending } = useGetList(resource, { sort, filter: filter(record) })
|
|
19
|
+
return (
|
|
20
|
+
<Box p={2}>
|
|
21
|
+
<Typography variant="h6">
|
|
22
|
+
{translate(`resources.${resource}.name`, { smart_count: 2 })}
|
|
23
|
+
</Typography>
|
|
24
|
+
<Datagrid resource={resource} bulkActionButtons={false} isPending={isPending} data={data}>
|
|
25
|
+
{buildAdmin(["list-fields", resource], fields)}
|
|
26
|
+
</Datagrid>
|
|
27
|
+
</Box>
|
|
28
|
+
)
|
|
29
|
+
}
|
package/src/buildRA.tsx
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
UrlField,
|
|
36
36
|
} from "react-admin"
|
|
37
37
|
|
|
38
|
-
import { AvatarField, EditableBooleanField, FKField, JsonField } from "./fields"
|
|
38
|
+
import { AvatarField, CopyField, EditableBooleanField, FKField, JsonField } from "./fields"
|
|
39
39
|
import { FilterInput, FKInput, JsonInput, TimestampInput } from "./inputs"
|
|
40
40
|
|
|
41
41
|
const UI: Record<string, JSX.ElementType> = {
|
|
@@ -59,6 +59,7 @@ const UI: Record<string, JSX.ElementType> = {
|
|
|
59
59
|
EditableBooleanField,
|
|
60
60
|
FKField,
|
|
61
61
|
JsonField,
|
|
62
|
+
CopyField,
|
|
62
63
|
|
|
63
64
|
// Inputs
|
|
64
65
|
ArrayInput,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import CopyIcon from "@mui/icons-material/FileCopy"
|
|
2
|
+
|
|
3
|
+
import { Snackbar } from "@mui/material"
|
|
4
|
+
import { useState } from "react"
|
|
5
|
+
|
|
6
|
+
export function CopyButton({ value }) {
|
|
7
|
+
const [open, setOpen] = useState(false)
|
|
8
|
+
const handleClick = (e: any) => {
|
|
9
|
+
setOpen(true)
|
|
10
|
+
navigator.clipboard.writeText(value)
|
|
11
|
+
e.stopPropagation()
|
|
12
|
+
}
|
|
13
|
+
return (
|
|
14
|
+
<span title="Copy to clipboard">
|
|
15
|
+
<CopyIcon color="info" fontSize="small" onClick={handleClick} style={{ cursor: "pointer" }} />
|
|
16
|
+
<Snackbar
|
|
17
|
+
open={open}
|
|
18
|
+
autoHideDuration={2000}
|
|
19
|
+
onClose={() => setOpen(false)}
|
|
20
|
+
message={`Copied to clipboard: ${value}`}
|
|
21
|
+
/>
|
|
22
|
+
</span>
|
|
23
|
+
)
|
|
24
|
+
}
|
package/src/buttons/index.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import get from "lodash/get"
|
|
2
|
+
|
|
3
|
+
import { useRecordContext } from "react-admin"
|
|
4
|
+
import { CopyButton } from "../buttons"
|
|
5
|
+
|
|
6
|
+
export function CopyField({ source, ...props }) {
|
|
7
|
+
const record = useRecordContext(props)
|
|
8
|
+
const value = get(record, source)
|
|
9
|
+
|
|
10
|
+
if (!value) return null
|
|
11
|
+
return (
|
|
12
|
+
<div style={{ display: "flex", alignItems: "center" }}>
|
|
13
|
+
<span>{value}</span>
|
|
14
|
+
<CopyButton value={value} />
|
|
15
|
+
</div>
|
|
16
|
+
)
|
|
17
|
+
}
|
package/src/fields/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useResourceContext } from "react-admin"
|
|
2
2
|
import { useMuffinAdminOpts } from "./useMuffinAdminOpts"
|
|
3
3
|
|
|
4
|
-
export function useMuffinResourceOpts() {
|
|
5
|
-
|
|
4
|
+
export function useMuffinResourceOpts(resource?) {
|
|
5
|
+
resource = useResourceContext({ resource })
|
|
6
6
|
const { resources } = useMuffinAdminOpts()
|
|
7
7
|
return resources.find((r) => r.name === resource)
|
|
8
8
|
}
|
package/src/index.tsx
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./utils"
|
|
|
6
6
|
|
|
7
7
|
export * from "./MuffinAdmin"
|
|
8
8
|
export * from "./MuffinDashboard"
|
|
9
|
+
export * from "./MuffinRecordList"
|
|
9
10
|
export * from "./MuffinResource"
|
|
10
11
|
export * from "./MuffinResourceCreate"
|
|
11
12
|
export * from "./MuffinResourceEdit"
|
|
@@ -35,4 +36,4 @@ export async function initAdmin(prefix = "", containerId: string = "root") {
|
|
|
35
36
|
)
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export const VERSION = "8.
|
|
39
|
+
export const VERSION = "8.4.0"
|