muffin-admin 3.19.0 → 3.20.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/MuffinAdmin.js +1 -1
- package/dist/authprovider.js +1 -1
- package/dist/buildRA.d.ts +2 -2
- package/dist/buttons/ActionButton.js +1 -1
- package/dist/dataprovider.d.ts +20 -16
- package/dist/dataprovider.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/utils.d.ts +4 -3
- package/package.json +2 -1
- package/src/MuffinAdmin.tsx +2 -2
- package/src/MuffinDashboard.tsx +2 -2
- package/src/authprovider.ts +1 -1
- package/src/buildRA.tsx +2 -2
- package/src/buttons/ActionButton.tsx +2 -3
- package/src/dataprovider.ts +10 -9
- package/src/fields/AvatarField.tsx +1 -1
- package/src/types.ts +38 -0
- package/src/utils.tsx +5 -4
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
export type TID = string | number;
|
|
1
2
|
export type TProps = {
|
|
2
3
|
[key: string]: any;
|
|
3
4
|
};
|
|
5
|
+
export type TAdminType = "action-payload" | "admin" | "appbar" | "auth-provider" | "auth-storage-get" | "auth-storage-set" | "create" | "create-inputs" | "create-toolbar" | "dashboard" | "dashboard-actions" | "dashboard-content" | "data-provider" | "edit" | "edit-actions" | "edit-inputs" | "edit-toolbar" | "layout" | "list" | "list-toolbar" | "list-grid" | "list-grid-buttons" | "list-filters" | "list-fields" | "list-bulk-actions" | "locale" | "loginpage" | "resource" | "show" | "show-actions" | "show-toolbar" | "show-fields" | "show-links";
|
|
6
|
+
export type TAdminPath = [type: TAdminType, ...ids: string[]];
|
|
4
7
|
export type AdminAction = {
|
|
5
8
|
view?: ("show" | "edit" | "list" | "bulk")[];
|
|
6
9
|
help?: string;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
1
|
+
import { TAdminPath } from "./types";
|
|
2
|
+
export declare function setupAdmin<T>(adminType: TAdminPath, fc: (props: any) => T): void;
|
|
3
|
+
export declare function buildAdmin(adminType: TAdminPath, props?: {}): any;
|
|
4
|
+
export declare function findBuilder(adminType: TAdminPath): (props: any) => any;
|
|
4
5
|
export type APIParams = {
|
|
5
6
|
method?: string;
|
|
6
7
|
query?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muffin-admin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.20.0",
|
|
4
4
|
"description": "NPM package for https://github.com/klen/muffin-admin",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"validator": "^13.12.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"@types/lodash": "^4.17.10",
|
|
34
35
|
"@types/node": "20.14.2",
|
|
35
36
|
"@types/react": "18.3.3",
|
|
36
37
|
"@types/react-dom": "18.3.0",
|
package/src/MuffinAdmin.tsx
CHANGED
|
@@ -37,8 +37,8 @@ export function MuffinAdmin(props: AdminProps) {
|
|
|
37
37
|
|
|
38
38
|
const {
|
|
39
39
|
basename,
|
|
40
|
-
authProvider = findBuilder(["
|
|
41
|
-
dataProvider = findBuilder(["
|
|
40
|
+
authProvider = findBuilder(["auth-provider"])(auth),
|
|
41
|
+
dataProvider = findBuilder(["data-provider"])(apiUrl),
|
|
42
42
|
catchAll,
|
|
43
43
|
dashboard = findBuilder(["dashboard"]),
|
|
44
44
|
disableTelemetry,
|
package/src/MuffinDashboard.tsx
CHANGED
|
@@ -65,9 +65,9 @@ function DashboardCard({ title, value }: AdminDashboardBlock) {
|
|
|
65
65
|
const AdminTableView = ({ src }) => (
|
|
66
66
|
<Table>
|
|
67
67
|
<TableBody>
|
|
68
|
-
{src.map((row, idx) => (
|
|
68
|
+
{src.map((row: any, idx: number) => (
|
|
69
69
|
<TableRow key={idx} hover>
|
|
70
|
-
{row.map((cell, idx) => (
|
|
70
|
+
{row.map((cell: any, idx: number) => (
|
|
71
71
|
<TableCell key={idx}>{cell}</TableCell>
|
|
72
72
|
))}
|
|
73
73
|
</TableRow>
|
package/src/authprovider.ts
CHANGED
package/src/buildRA.tsx
CHANGED
|
@@ -81,7 +81,7 @@ const UI: Record<string, JSX.ElementType> = {
|
|
|
81
81
|
FKInput,
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
export function buildRAComponent(name, props) {
|
|
84
|
+
export function buildRAComponent(name: string, props: any) {
|
|
85
85
|
const Item = UI[name]
|
|
86
86
|
if (!Item) return null
|
|
87
87
|
|
|
@@ -99,6 +99,6 @@ export function buildRA(items: [string, Record<string, any>][]) {
|
|
|
99
99
|
return items.map((item) => buildRAComponent(item[0], item[1]))
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
export function registerUI(name, component) {
|
|
102
|
+
export function registerUI(name: string, component: JSX.ElementType) {
|
|
103
103
|
UI[name] = component
|
|
104
104
|
}
|
|
@@ -76,7 +76,7 @@ export function BulkActionButton({ paths, confirm, ...props }: AdminAction) {
|
|
|
76
76
|
const confirmMessage =
|
|
77
77
|
typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?"
|
|
78
78
|
|
|
79
|
-
const onHandle = async (payload
|
|
79
|
+
const onHandle = async (payload?: any) => {
|
|
80
80
|
const process = confirm ? await confirmation.confirm({ message: confirmMessage }) : true
|
|
81
81
|
if (process) await mutate({ ids: selectedIds, payload })
|
|
82
82
|
}
|
|
@@ -100,8 +100,7 @@ function ActionButtonBase({
|
|
|
100
100
|
const resource = useResourceContext()
|
|
101
101
|
const [payloadActive, setPayloadActive] = useState(false)
|
|
102
102
|
|
|
103
|
-
const PayloadBuilder =
|
|
104
|
-
findBuilder(["action", "payload", id, resource]) || (schema && CommonPayload)
|
|
103
|
+
const PayloadBuilder = findBuilder(["action-payload", id, resource]) || (schema && CommonPayload)
|
|
105
104
|
|
|
106
105
|
return (
|
|
107
106
|
<>
|
package/src/dataprovider.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TID } from "./types"
|
|
1
2
|
import { APIParams, makeRequest, setupAdmin } from "./utils"
|
|
2
3
|
|
|
3
4
|
export function MuffinDataprovider(apiUrl: string) {
|
|
@@ -26,35 +27,35 @@ export function MuffinDataprovider(apiUrl: string) {
|
|
|
26
27
|
return { data, total: parseInt(headers.get("x-total"), 10) }
|
|
27
28
|
},
|
|
28
29
|
|
|
29
|
-
getOne: async (resource, { id }) => {
|
|
30
|
+
getOne: async (resource: string, { id }: { id: TID }) => {
|
|
30
31
|
return await request(`${resource}/${id}`)
|
|
31
32
|
},
|
|
32
33
|
|
|
33
|
-
create: async (resource, { data }) => {
|
|
34
|
+
create: async (resource: string, { data }) => {
|
|
34
35
|
return await request(resource, {
|
|
35
36
|
data,
|
|
36
37
|
method: "POST",
|
|
37
38
|
})
|
|
38
39
|
},
|
|
39
40
|
|
|
40
|
-
update: async (resource, { id, data }) => {
|
|
41
|
+
update: async (resource: string, { id, data }: { id: TID; data: any }) => {
|
|
41
42
|
return await makeRequest(`${apiUrl}/${resource}/${id}`, {
|
|
42
43
|
data,
|
|
43
44
|
method: "PUT",
|
|
44
45
|
}).then(({ json }) => ({ data: json }))
|
|
45
46
|
},
|
|
46
47
|
|
|
47
|
-
updateMany: async (resource, { ids, data }) => {
|
|
48
|
+
updateMany: async (resource: string, { ids, data }: { ids: TID[]; data: any }) => {
|
|
48
49
|
await Promise.all(ids.map((id) => methods.update(resource, { id, data })))
|
|
49
50
|
return { data: ids }
|
|
50
51
|
},
|
|
51
52
|
|
|
52
|
-
delete: async (resource, { id }) => {
|
|
53
|
+
delete: async (resource: string, { id }: { id: TID }) => {
|
|
53
54
|
await request(`${resource}/${id}`, { method: "DELETE" })
|
|
54
55
|
return { data: { id } }
|
|
55
56
|
},
|
|
56
57
|
|
|
57
|
-
deleteMany: async (resource, { ids }) => {
|
|
58
|
+
deleteMany: async (resource: string, { ids }: { ids: TID[][] }) => {
|
|
58
59
|
await request(resource, {
|
|
59
60
|
data: ids,
|
|
60
61
|
method: "DELETE",
|
|
@@ -62,13 +63,13 @@ export function MuffinDataprovider(apiUrl: string) {
|
|
|
62
63
|
return { data: ids }
|
|
63
64
|
},
|
|
64
65
|
|
|
65
|
-
getMany: (resource, props) => {
|
|
66
|
+
getMany: (resource: string, props: { ids: TID[]; meta: any }) => {
|
|
66
67
|
const { ids, meta } = props
|
|
67
68
|
const key = meta?.key || "id"
|
|
68
69
|
return methods.getList(resource, { filter: { [key]: { $in: ids } } })
|
|
69
70
|
},
|
|
70
71
|
|
|
71
|
-
getManyReference: async (resource, { target, id, filter, ...opts }) => {
|
|
72
|
+
getManyReference: async (resource: string, { target, id, filter, ...opts }) => {
|
|
72
73
|
filter = filter || {}
|
|
73
74
|
filter[target] = id
|
|
74
75
|
return await methods.getList(resource, { filter, ...opts })
|
|
@@ -96,4 +97,4 @@ export type TActionProps<T = any> = {
|
|
|
96
97
|
ids?: string[]
|
|
97
98
|
record?: T
|
|
98
99
|
}
|
|
99
|
-
setupAdmin(["
|
|
100
|
+
setupAdmin(["data-provider"], MuffinDataprovider)
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
|
+
export type TID = string | number
|
|
2
|
+
|
|
1
3
|
export type TProps = {
|
|
2
4
|
[key: string]: any
|
|
3
5
|
}
|
|
4
6
|
|
|
7
|
+
export type TAdminType =
|
|
8
|
+
| "action-payload"
|
|
9
|
+
| "admin"
|
|
10
|
+
| "appbar"
|
|
11
|
+
| "auth-provider"
|
|
12
|
+
| "auth-storage-get"
|
|
13
|
+
| "auth-storage-set"
|
|
14
|
+
| "create"
|
|
15
|
+
| "create-inputs"
|
|
16
|
+
| "create-toolbar"
|
|
17
|
+
| "dashboard"
|
|
18
|
+
| "dashboard-actions"
|
|
19
|
+
| "dashboard-content"
|
|
20
|
+
| "data-provider"
|
|
21
|
+
| "edit"
|
|
22
|
+
| "edit-actions"
|
|
23
|
+
| "edit-inputs"
|
|
24
|
+
| "edit-toolbar"
|
|
25
|
+
| "layout"
|
|
26
|
+
| "list"
|
|
27
|
+
| "list-toolbar"
|
|
28
|
+
| "list-grid"
|
|
29
|
+
| "list-grid-buttons"
|
|
30
|
+
| "list-filters"
|
|
31
|
+
| "list-fields"
|
|
32
|
+
| "list-bulk-actions"
|
|
33
|
+
| "locale"
|
|
34
|
+
| "loginpage"
|
|
35
|
+
| "resource"
|
|
36
|
+
| "show"
|
|
37
|
+
| "show-actions"
|
|
38
|
+
| "show-toolbar"
|
|
39
|
+
| "show-fields"
|
|
40
|
+
| "show-links"
|
|
41
|
+
export type TAdminPath = [type: TAdminType, ...ids: string[]]
|
|
42
|
+
|
|
5
43
|
export type AdminAction = {
|
|
6
44
|
view?: ("show" | "edit" | "list" | "bulk")[]
|
|
7
45
|
help?: string
|
package/src/utils.tsx
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import * as icons from "@mui/icons-material"
|
|
2
2
|
import { stringify } from "query-string"
|
|
3
3
|
import { fetchUtils } from "ra-core"
|
|
4
|
+
import { TAdminPath } from "./types"
|
|
4
5
|
|
|
5
|
-
const builders = new Map<string, (props) => any>()
|
|
6
|
+
const builders = new Map<string, (props: any) => any>()
|
|
6
7
|
|
|
7
|
-
export function setupAdmin<T>(adminType:
|
|
8
|
+
export function setupAdmin<T>(adminType: TAdminPath, fc: (props: any) => T) {
|
|
8
9
|
const key = adminType.join("/")
|
|
9
10
|
builders.set(key, fc)
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export function buildAdmin(adminType:
|
|
13
|
+
export function buildAdmin(adminType: TAdminPath, props = {}) {
|
|
13
14
|
const builder = findBuilder(adminType)
|
|
14
15
|
if (process.env.NODE_ENV == "development") console.log(props)
|
|
15
16
|
if (builder) return builder(props)
|
|
@@ -18,7 +19,7 @@ export function buildAdmin(adminType: string[], props = {}) {
|
|
|
18
19
|
return null
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export function findBuilder(adminType:
|
|
22
|
+
export function findBuilder(adminType: TAdminPath): (props: any) => any {
|
|
22
23
|
if (process.env.NODE_ENV == "development") console.log(adminType)
|
|
23
24
|
const key = [...adminType]
|
|
24
25
|
while (key.length) {
|