muffin-admin 11.7.2 → 12.0.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/MuffinResourceEdit.js +35 -3
- package/dist/MuffinResourceList.js +8 -2
- package/dist/MuffinResourceShow.d.ts +1 -1
- package/dist/MuffinResourceShow.js +42 -5
- package/dist/buttons/LinkButton.js +8 -2
- package/dist/common/AdminModal.d.ts +4 -2
- package/dist/common/AdminModal.js +2 -2
- package/dist/fields/FKField.js +11 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/MuffinResourceEdit.tsx +72 -11
- package/src/MuffinResourceList.tsx +15 -1
- package/src/MuffinResourceShow.tsx +92 -14
- package/src/buttons/LinkButton.tsx +10 -2
- package/src/common/AdminModal.tsx +6 -3
- package/src/fields/FKField.tsx +13 -1
- package/src/index.tsx +1 -1
|
@@ -1,18 +1,48 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Box, Typography } from "@mui/material";
|
|
3
|
+
import { DeleteButton, Edit, ListButton, SaveButton, ShowButton, SimpleForm, Toolbar, TopToolbar, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
|
|
4
|
+
import { useLocation, useNavigate } from "react-router-dom";
|
|
3
5
|
import { buildRA } from "./buildRA";
|
|
4
6
|
import { ActionButton } from "./buttons";
|
|
7
|
+
import { AdminModal } from "./common";
|
|
5
8
|
import { useMuffinAdminOpts, useMuffinResourceOpts } from "./hooks";
|
|
6
9
|
import { findBuilder, setupAdmin } from "./utils";
|
|
7
10
|
export function MuffinEdit({ children }) {
|
|
8
11
|
const { adminProps: { mutationMode = "optimistic" }, } = useMuffinAdminOpts();
|
|
9
12
|
const { edit, name, key } = useMuffinResourceOpts();
|
|
13
|
+
const location = useLocation();
|
|
14
|
+
const navigate = useNavigate();
|
|
15
|
+
const returnTo = new URLSearchParams(location.search).get("returnTo");
|
|
10
16
|
if (!edit)
|
|
11
17
|
return null;
|
|
18
|
+
const handleClose = () => {
|
|
19
|
+
if (returnTo) {
|
|
20
|
+
navigate(returnTo);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (window.history.length > 1) {
|
|
24
|
+
navigate(-1);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
navigate(`/${name}`);
|
|
28
|
+
};
|
|
12
29
|
const Actions = findBuilder(["edit-toolbar", name]);
|
|
13
30
|
const Inputs = findBuilder(["edit-inputs", name]);
|
|
14
31
|
const FormToolbar = findBuilder(["edit-form-toolbar", name]);
|
|
15
|
-
return (
|
|
32
|
+
return (_jsx(Edit, { actions: false, title: false, component: "div", mutationMode: mutationMode, queryOptions: { meta: { key } }, sx: {
|
|
33
|
+
"& .RaEdit-main": {
|
|
34
|
+
padding: 0,
|
|
35
|
+
},
|
|
36
|
+
}, children: _jsxs(AdminModal, { open: true, onClose: handleClose, title: _jsx(Actions, {}), maxWidth: "xl", contentSx: {
|
|
37
|
+
paddingTop: "8px !important",
|
|
38
|
+
paddingBottom: "12px !important",
|
|
39
|
+
paddingLeft: "16px !important",
|
|
40
|
+
paddingRight: "16px !important",
|
|
41
|
+
}, sx: {
|
|
42
|
+
"& .MuiDialog-paper": {
|
|
43
|
+
width: "min(1400px, 96vw)",
|
|
44
|
+
},
|
|
45
|
+
}, children: [children, _jsx(SimpleForm, { toolbar: _jsx(FormToolbar, {}), children: _jsx(Inputs, {}) })] }) }));
|
|
16
46
|
}
|
|
17
47
|
setupAdmin(["edit"], MuffinEdit);
|
|
18
48
|
export function MuffinEditFormToolbar() {
|
|
@@ -33,8 +63,10 @@ export function MuffinEditInputs() {
|
|
|
33
63
|
setupAdmin(["edit-inputs"], MuffinEditInputs);
|
|
34
64
|
export function MuffinEditToolbar({ children }) {
|
|
35
65
|
const resource = useResourceContext();
|
|
66
|
+
const record = useRecordContext();
|
|
67
|
+
const translate = useTranslate();
|
|
36
68
|
const Actions = findBuilder(["edit-actions", resource]);
|
|
37
|
-
return (_jsxs(TopToolbar, { children: [_jsx(Actions, {}), children, _jsx(
|
|
69
|
+
return (_jsx(Box, { sx: { display: "flex", flexDirection: "column", width: "100%" }, children: _jsxs(TopToolbar, { sx: { pl: 0, pr: 0, width: "100%", justifyContent: "space-between" }, children: [_jsxs(Typography, { variant: "h6", sx: { mr: 2 }, children: [translate(`resources.${resource}.name`, { smart_count: 1, _: resource }), (record === null || record === void 0 ? void 0 : record.id) ? ` #${record.id}` : ""] }), _jsxs(Box, { sx: { display: "flex", alignItems: "center" }, children: [_jsx(Actions, {}), children, _jsx(ShowButton, {}), _jsx(ListButton, {})] })] }) }));
|
|
38
70
|
}
|
|
39
71
|
setupAdmin(["edit-toolbar"], MuffinEditToolbar);
|
|
40
72
|
export function MuffinEditActions({ children }) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import sortBy from "lodash/sortBy";
|
|
3
3
|
import uniq from "lodash/uniq";
|
|
4
|
-
import { BulkDeleteButton, BulkExportButton, CreateButton, DatagridConfigurable, EditButton, ExportButton, FilterButton, InfiniteList, List, Pagination, SelectColumnsButton, TopToolbar, } from "react-admin";
|
|
4
|
+
import { BulkDeleteButton, BulkExportButton, CreateButton, DatagridConfigurable, EditButton, ExportButton, FilterButton, InfiniteList, List, Pagination, SelectColumnsButton, TopToolbar, useTranslate, } from "react-admin";
|
|
5
5
|
import { buildRA, buildRAComponent } from "./buildRA";
|
|
6
6
|
import { BulkActionButton, ListActionButton } from "./buttons";
|
|
7
7
|
import { HelpLink } from "./common/HelpLink";
|
|
@@ -33,10 +33,16 @@ function MuffinListDatagrid() {
|
|
|
33
33
|
setupAdmin(["list-grid"], MuffinListDatagrid);
|
|
34
34
|
function MuffinListGridButtons() {
|
|
35
35
|
const { list } = useMuffinResourceOpts();
|
|
36
|
+
const translate = useTranslate();
|
|
36
37
|
const { edit } = list;
|
|
37
38
|
if (!edit)
|
|
38
39
|
return null;
|
|
39
|
-
return _jsx(EditButton, {})
|
|
40
|
+
return (_jsx(EditButton, { label: "", title: translate("ra.action.edit", { _: "Edit" }), sx: {
|
|
41
|
+
minWidth: "auto",
|
|
42
|
+
width: "100%",
|
|
43
|
+
justifyContent: "flex-end",
|
|
44
|
+
"& .MuiButton-startIcon": { margin: 0 },
|
|
45
|
+
} }));
|
|
40
46
|
}
|
|
41
47
|
setupAdmin(["list-grid-buttons"], MuffinListGridButtons);
|
|
42
48
|
function MuffinListToolbar() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
2
|
export declare function MuffinShow({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
3
|
-
export declare function MuffinShowToolbar(
|
|
3
|
+
export declare function MuffinShowToolbar(): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
export declare function MuffinShowActions({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
export declare function MuffinShowLinks({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,23 +1,60 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Box, Typography } from "@mui/material";
|
|
3
|
+
import { EditButton, ListButton, Show, SimpleShowLayout, TopToolbar, useRecordContext, useTranslate, } from "react-admin";
|
|
4
|
+
import { useLocation, useNavigate } from "react-router-dom";
|
|
3
5
|
import { LinkAction } from "./actions";
|
|
4
6
|
import { buildRA } from "./buildRA";
|
|
5
7
|
import { ActionButton } from "./buttons";
|
|
8
|
+
import { AdminModal } from "./common";
|
|
6
9
|
import { useMuffinResourceOpts } from "./hooks";
|
|
7
10
|
import { buildAdmin, findBuilder, setupAdmin } from "./utils";
|
|
8
11
|
export function MuffinShow({ children }) {
|
|
9
12
|
const { show, name, key } = useMuffinResourceOpts();
|
|
13
|
+
const location = useLocation();
|
|
14
|
+
const navigate = useNavigate();
|
|
10
15
|
const ShowToolbar = findBuilder(["show-toolbar", name]);
|
|
11
|
-
|
|
16
|
+
const returnTo = new URLSearchParams(location.search).get("returnTo");
|
|
17
|
+
const handleClose = () => {
|
|
18
|
+
if (returnTo) {
|
|
19
|
+
navigate(returnTo);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (window.history.length > 1) {
|
|
23
|
+
navigate(-1);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
navigate(`/${name}`);
|
|
27
|
+
};
|
|
28
|
+
return (_jsx(Show, { actions: false, title: false, component: "div", queryOptions: { meta: { key } }, sx: {
|
|
29
|
+
"& .RaShow-main": {
|
|
30
|
+
padding: 0,
|
|
31
|
+
},
|
|
32
|
+
}, children: _jsxs(AdminModal, { open: true, onClose: handleClose, title: _jsx(ShowToolbar, {}), maxWidth: "xl", hideBackdrop: true, disableScrollLock: true, contentSx: {
|
|
33
|
+
paddingTop: "8px !important",
|
|
34
|
+
paddingBottom: "12px !important",
|
|
35
|
+
paddingLeft: "16px !important",
|
|
36
|
+
paddingRight: "16px !important",
|
|
37
|
+
}, sx: {
|
|
38
|
+
"& .MuiDialog-paper": {
|
|
39
|
+
width: "min(1400px, 96vw)",
|
|
40
|
+
},
|
|
41
|
+
}, children: [_jsx(SimpleShowLayout, { sx: {
|
|
42
|
+
padding: 0,
|
|
43
|
+
"& .RaSimpleShowLayout-stack": {
|
|
44
|
+
rowGap: 1,
|
|
45
|
+
},
|
|
46
|
+
}, children: buildAdmin(["show-fields", name], show) }), children] }) }));
|
|
12
47
|
}
|
|
13
48
|
setupAdmin(["show"], MuffinShow);
|
|
14
49
|
setupAdmin(["show-fields"], ({ fields }) => buildRA(fields));
|
|
15
|
-
export function MuffinShowToolbar(
|
|
50
|
+
export function MuffinShowToolbar() {
|
|
16
51
|
const { show, name } = useMuffinResourceOpts();
|
|
52
|
+
const record = useRecordContext();
|
|
53
|
+
const translate = useTranslate();
|
|
17
54
|
const { edit } = show;
|
|
18
55
|
const Links = findBuilder(["show-links", name]);
|
|
19
56
|
const Actions = findBuilder(["show-actions", name]);
|
|
20
|
-
return (_jsxs(TopToolbar, { children: [
|
|
57
|
+
return (_jsxs(Box, { sx: { display: "flex", flexDirection: "column", width: "100%" }, children: [_jsxs(TopToolbar, { sx: { pl: 0, pr: 0, width: "100%", justifyContent: "space-between" }, children: [_jsxs(Typography, { variant: "h6", sx: { mr: 2 }, children: [translate(`resources.${name}.name`, { smart_count: 1, _: name }), (record === null || record === void 0 ? void 0 : record.id) ? ` #${record.id}` : ""] }), _jsxs(Box, { sx: { display: "flex", alignItems: "center" }, children: [_jsx(Actions, {}), edit && _jsx(EditButton, {}), _jsx(ListButton, {})] })] }), _jsx(Box, { sx: { mt: 0.5 }, children: _jsx(Links, {}) })] }));
|
|
21
58
|
}
|
|
22
59
|
setupAdmin(["show-toolbar"], MuffinShowToolbar);
|
|
23
60
|
export function MuffinShowActions({ children }) {
|
|
@@ -29,6 +66,6 @@ setupAdmin(["show-actions"], MuffinShowActions);
|
|
|
29
66
|
export function MuffinShowLinks({ children }) {
|
|
30
67
|
const { show } = useMuffinResourceOpts();
|
|
31
68
|
const { links } = show;
|
|
32
|
-
return (_jsxs(
|
|
69
|
+
return (_jsxs(Box, { sx: { display: "flex", flexWrap: "wrap", gap: 1 }, children: [links.map(([key, props]) => (_jsx(LinkAction, Object.assign({ resource: key }, props), key))), children] }));
|
|
33
70
|
}
|
|
34
71
|
setupAdmin(["show-links"], MuffinShowLinks);
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Button } from "react-admin";
|
|
3
|
-
import { Link } from "react-router-dom";
|
|
3
|
+
import { Link, useLocation } from "react-router-dom";
|
|
4
4
|
import { buildIcon } from "../utils";
|
|
5
5
|
const LinkButton = ({ filters, icon, label, resource, id, title, }) => {
|
|
6
|
+
const location = useLocation();
|
|
7
|
+
const searchParams = new URLSearchParams();
|
|
8
|
+
searchParams.set("returnTo", `${location.pathname}${location.search}`);
|
|
9
|
+
if (filters) {
|
|
10
|
+
searchParams.set("filter", JSON.stringify(filters));
|
|
11
|
+
}
|
|
6
12
|
const linkParams = {
|
|
7
13
|
pathname: `/${resource}`,
|
|
8
|
-
search:
|
|
14
|
+
search: `?${searchParams.toString()}`,
|
|
9
15
|
};
|
|
10
16
|
if (id)
|
|
11
17
|
linkParams.pathname += `/${id}/show`;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { DialogProps } from "@mui/material";
|
|
2
2
|
import { PropsWithChildren } from "react";
|
|
3
|
-
|
|
3
|
+
import { SxProps, Theme } from "@mui/material/styles";
|
|
4
|
+
interface IProps extends Omit<DialogProps, "title" | "open" | "onClose"> {
|
|
4
5
|
open: boolean;
|
|
5
6
|
onClose: () => void;
|
|
6
7
|
title?: React.ReactNode;
|
|
7
8
|
actions?: React.ReactNode;
|
|
9
|
+
contentSx?: SxProps<Theme>;
|
|
8
10
|
}
|
|
9
|
-
export declare function AdminModal({ open, onClose, children, title, actions, ...props }: PropsWithChildren<IProps
|
|
11
|
+
export declare function AdminModal({ open, onClose, children, title, actions, contentSx, ...props }: PropsWithChildren<IProps>): import("react/jsx-runtime").JSX.Element;
|
|
10
12
|
export {};
|
|
@@ -12,6 +12,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { Dialog, DialogActions, DialogContent, DialogTitle } from "@mui/material";
|
|
14
14
|
export function AdminModal(_a) {
|
|
15
|
-
var { open, onClose, children, title, actions } = _a, props = __rest(_a, ["open", "onClose", "children", "title", "actions"]);
|
|
16
|
-
return (_jsxs(Dialog, Object.assign({ open: open, onClose: onClose, fullWidth: true, maxWidth: "md" }, props, { children: [title && _jsx(DialogTitle, { children: title }), _jsx(DialogContent, { children: children }), actions && _jsx(DialogActions, { children: actions })] })));
|
|
15
|
+
var { open, onClose, children, title, actions, contentSx } = _a, props = __rest(_a, ["open", "onClose", "children", "title", "actions", "contentSx"]);
|
|
16
|
+
return (_jsxs(Dialog, Object.assign({ open: open, onClose: onClose, fullWidth: true, maxWidth: "md" }, props, { children: [title && _jsx(DialogTitle, { children: title }), _jsx(DialogContent, { sx: contentSx, children: children }), actions && _jsx(DialogActions, { children: actions })] })));
|
|
17
17
|
}
|
package/dist/fields/FKField.js
CHANGED
|
@@ -11,10 +11,20 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
13
|
import { ReferenceField, TextField, useFieldValue } from "react-admin";
|
|
14
|
+
import { useLocation } from "react-router-dom";
|
|
14
15
|
export function FKField(_a) {
|
|
15
16
|
var { reference, refSource, refKey, link, source } = _a, props = __rest(_a, ["reference", "refSource", "refKey", "link", "source"]);
|
|
17
|
+
const location = useLocation();
|
|
16
18
|
refKey = refKey || "id";
|
|
17
|
-
|
|
19
|
+
const returnTo = `${location.pathname}${location.search}`;
|
|
20
|
+
const resolveLink = link ||
|
|
21
|
+
((record) => {
|
|
22
|
+
const id = record === null || record === void 0 ? void 0 : record[refKey];
|
|
23
|
+
if (id === undefined || id === null)
|
|
24
|
+
return false;
|
|
25
|
+
return `/${reference}/${id}/show?returnTo=${encodeURIComponent(returnTo)}`;
|
|
26
|
+
});
|
|
27
|
+
return (_jsxs(ReferenceField, Object.assign({ source: source, link: resolveLink, reference: reference, queryOptions: { meta: { key: refKey } } }, props, { children: [_jsx(TextField, { source: refSource }), refSource !== refKey && _jsx(FKFieldValue, { source: refKey })] })));
|
|
18
28
|
}
|
|
19
29
|
function FKFieldValue(props) {
|
|
20
30
|
const value = useFieldValue(props);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED