muffin-admin 3.3.12 → 3.4.1
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 +4 -4
- package/dist/buttons/ActionButton.d.ts +7 -2
- package/dist/buttons/ActionButton.js +52 -8
- package/dist/common/AdminModal.d.ts +10 -0
- package/dist/common/AdminModal.js +17 -0
- package/dist/common/ConfirmationProvider.d.ts +13 -0
- package/dist/common/ConfirmationProvider.js +36 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.js +2 -0
- package/dist/i18n/index.d.ts +0 -0
- package/dist/i18n/index.js +0 -0
- package/dist/i18n/provider.d.ts +0 -0
- package/dist/i18n/provider.js +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/MuffinAdmin.tsx +58 -14
- package/src/buttons/ActionButton.tsx +56 -10
- package/src/common/AdminModal.tsx +26 -0
- package/src/common/ConfirmationProvider.tsx +75 -0
- package/src/common/index.ts +2 -0
- package/src/i18n/index.ts +0 -0
- package/src/i18n/provider.ts +0 -0
- package/src/index.tsx +1 -0
- package/src/types.ts +1 -0
package/dist/MuffinAdmin.js
CHANGED
|
@@ -3,16 +3,16 @@ import IconButton from "@mui/material/IconButton";
|
|
|
3
3
|
import SvgIcon from "@mui/material/SvgIcon";
|
|
4
4
|
import Tooltip from "@mui/material/Tooltip";
|
|
5
5
|
import Typography from "@mui/material/Typography";
|
|
6
|
-
import {
|
|
6
|
+
import { AdminContext, AdminUI, AppBar, defaultI18nProvider, Layout, localStorageStore, Login, } from "react-admin";
|
|
7
|
+
import { ConfirmationProvider } from "./common";
|
|
7
8
|
import { useMuffinAdminOpts } from "./hooks";
|
|
8
9
|
import { buildAdmin, findBuilder, findIcon, setupAdmin } from "./utils";
|
|
9
10
|
export function MuffinAdmin(props) {
|
|
10
11
|
const opts = useMuffinAdminOpts();
|
|
11
12
|
const { resources = [], auth, adminProps, apiUrl } = opts;
|
|
12
13
|
document.title = (adminProps === null || adminProps === void 0 ? void 0 : adminProps.title) || "Muffin Admin";
|
|
13
|
-
const authProvider = findBuilder(["authprovider"])(auth);
|
|
14
|
-
|
|
15
|
-
return (_jsx(Admin, Object.assign({ requireAuth: auth.required, authProvider: authProvider, dataProvider: dataProvider, layout: findBuilder(["layout"]), loginPage: findBuilder(["loginpage"]), dashboard: findBuilder(["dashboard"]), darkTheme: { palette: { mode: "dark" } } }, props, { children: resources === null || resources === void 0 ? void 0 : resources.map(({ name }) => buildAdmin(["resource", name], { name })) })));
|
|
14
|
+
const { basename, authProvider = findBuilder(["authprovider"])(auth), dataProvider = findBuilder(["dataprovider"])(apiUrl), catchAll, dashboard = findBuilder(["dashboard"]), disableTelemetry, error, i18nProvider = defaultI18nProvider, layout = findBuilder(["layout"]), loading, loginPage = findBuilder(["loginpage"]), authCallbackPage, notification, queryClient, requireAuth = auth.required, store = localStorageStore(), ready, theme, lightTheme, darkTheme, defaultTheme, title = "React Admin", } = props;
|
|
15
|
+
return (_jsx(AdminContext, { authProvider: authProvider, basename: basename, dataProvider: dataProvider, i18nProvider: i18nProvider, store: store, queryClient: queryClient, theme: theme, lightTheme: lightTheme, darkTheme: darkTheme, defaultTheme: defaultTheme, children: _jsx(ConfirmationProvider, { children: _jsx(AdminUI, { layout: layout, dashboard: dashboard, disableTelemetry: disableTelemetry, catchAll: catchAll, error: error, title: title, loading: loading, loginPage: loginPage, authCallbackPage: authCallbackPage, notification: notification, requireAuth: requireAuth, ready: ready, children: resources === null || resources === void 0 ? void 0 : resources.map(({ name }) => buildAdmin(["resource", name], { name })) }) }) }));
|
|
16
16
|
}
|
|
17
17
|
setupAdmin(["admin"], MuffinAdmin);
|
|
18
18
|
export function MuffinAdminLayout(props) {
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { AdminAction } from "../types";
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export type ActionPayloadProps = {
|
|
3
|
+
active: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
onHandle: (payload: any) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function ActionButton({ icon, label, title, action, id, confirm }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare function BulkActionButton({ label, icon, title, action, id, confirm }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,21 +1,65 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, useListContext, useRecordContext, useResourceContext } from "react-admin";
|
|
3
|
-
import { useState } from "react";
|
|
11
|
+
import { Button, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
|
|
12
|
+
import { useMemo, useState } from "react";
|
|
13
|
+
import { useConfirmation } from "../common";
|
|
4
14
|
import { useAction } from "../hooks/useAction";
|
|
5
15
|
import { buildIcon, findBuilder } from "../utils";
|
|
6
|
-
export function ActionButton({ icon, label, title, action, id }) {
|
|
7
|
-
const
|
|
16
|
+
export function ActionButton({ icon, label, title, action, id, confirm }) {
|
|
17
|
+
const translate = useTranslate();
|
|
8
18
|
const record = useRecordContext();
|
|
9
19
|
const resource = useResourceContext();
|
|
10
|
-
const
|
|
20
|
+
const confirmation = useConfirmation();
|
|
21
|
+
const { mutate, isPending } = useAction(action);
|
|
22
|
+
const [payloadActive, setPayloadActive] = useState(false);
|
|
23
|
+
const [payloadResolver, setPayloadResolver] = useState();
|
|
11
24
|
const PayloadBuilder = findBuilder(["action", "payload", id, resource]);
|
|
12
|
-
|
|
25
|
+
const buildPayload = useMemo(() => {
|
|
26
|
+
if (PayloadBuilder) {
|
|
27
|
+
return new Promise((resolve) => setPayloadResolver(() => resolve));
|
|
28
|
+
}
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
}, [PayloadBuilder]);
|
|
31
|
+
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
32
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
if (PayloadBuilder)
|
|
34
|
+
setPayloadActive(true);
|
|
35
|
+
const payload = yield buildPayload;
|
|
36
|
+
const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
|
|
37
|
+
if (process)
|
|
38
|
+
yield mutate({ record, payload });
|
|
39
|
+
}), disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: payloadResolver, onClose: () => setPayloadActive(false) }))] }));
|
|
13
40
|
}
|
|
14
|
-
export function BulkActionButton({ label, icon, title, action, id }) {
|
|
41
|
+
export function BulkActionButton({ label, icon, title, action, id, confirm }) {
|
|
42
|
+
const translate = useTranslate();
|
|
15
43
|
const { selectedIds } = useListContext();
|
|
16
44
|
const { mutate, isPending } = useAction(action);
|
|
45
|
+
const confirmation = useConfirmation();
|
|
17
46
|
const resource = useResourceContext();
|
|
18
47
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
48
|
+
const [payloadResolver, setPayloadResolver] = useState();
|
|
19
49
|
const PayloadBuilder = findBuilder(["action", "payload", id, resource]);
|
|
20
|
-
|
|
50
|
+
const buildPayload = useMemo(() => {
|
|
51
|
+
if (PayloadBuilder) {
|
|
52
|
+
return new Promise((resolve) => setPayloadResolver(() => resolve));
|
|
53
|
+
}
|
|
54
|
+
return Promise.resolve();
|
|
55
|
+
}, [PayloadBuilder]);
|
|
56
|
+
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
57
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
if (PayloadBuilder)
|
|
59
|
+
setPayloadActive(true);
|
|
60
|
+
const payload = yield buildPayload;
|
|
61
|
+
const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
|
|
62
|
+
if (process)
|
|
63
|
+
yield mutate({ ids: selectedIds, payload });
|
|
64
|
+
}), disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: payloadResolver, onClose: () => setPayloadActive(false) }))] }));
|
|
21
65
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DialogProps } from "@mui/material";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
interface IProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
title?: string;
|
|
7
|
+
actions?: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function AdminModal({ open, onClose, children, title, actions, ...props }: PropsWithChildren<IProps & DialogProps>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Dialog, DialogActions, DialogContent, DialogTitle } from "@mui/material";
|
|
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 })] })));
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
type TConfirmProps = {
|
|
3
|
+
title?: string;
|
|
4
|
+
message: string;
|
|
5
|
+
actions?: React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
type TConfirmContext = {
|
|
8
|
+
confirm: (props: TConfirmProps) => Promise<boolean>;
|
|
9
|
+
};
|
|
10
|
+
export declare const ConfirmContext: import("react").Context<TConfirmContext>;
|
|
11
|
+
export declare function ConfirmationProvider({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare const useConfirmation: () => TConfirmContext;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Typography } from "@mui/material";
|
|
3
|
+
import { createContext, useContext, useState } from "react";
|
|
4
|
+
import { useTranslate } from "react-admin";
|
|
5
|
+
import { AdminModal } from "./AdminModal";
|
|
6
|
+
export const ConfirmContext = createContext({});
|
|
7
|
+
export function ConfirmationProvider({ children }) {
|
|
8
|
+
const translate = useTranslate();
|
|
9
|
+
const [open, setOpen] = useState(false);
|
|
10
|
+
const [title, setTitle] = useState(translate("ra.message.are_you_sure"));
|
|
11
|
+
const [message, setMessage] = useState(null);
|
|
12
|
+
const [resolver, setResolve] = useState(null);
|
|
13
|
+
function handleConfirm({ title, message }) {
|
|
14
|
+
setOpen(true);
|
|
15
|
+
if (title)
|
|
16
|
+
setTitle(title);
|
|
17
|
+
if (message)
|
|
18
|
+
setMessage(message);
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
setResolve(() => resolve);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const confirmContext = {
|
|
24
|
+
confirm: handleConfirm,
|
|
25
|
+
};
|
|
26
|
+
return (_jsxs(ConfirmContext.Provider, { value: confirmContext, children: [children, _jsx(AdminModal, { open: open, onClose: () => setOpen(false), title: title, maxWidth: "xs", actions: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "contained", onClick: () => {
|
|
27
|
+
setOpen(false);
|
|
28
|
+
resolver(true);
|
|
29
|
+
}, children: translate("ra.action.confirm") }), _jsx(Button, { variant: "outlined", onClick: () => {
|
|
30
|
+
setOpen(false);
|
|
31
|
+
resolver(false);
|
|
32
|
+
}, children: translate("ra.action.cancel") })] }), children: _jsx(Typography, { children: message }) })] }));
|
|
33
|
+
}
|
|
34
|
+
export const useConfirmation = () => {
|
|
35
|
+
return useContext(ConfirmContext);
|
|
36
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED