muffin-admin 1.44.4 → 1.45.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.d.ts +2 -0
- package/dist/MuffinAdmin.js +25 -0
- package/dist/MuffinDashboard.d.ts +2 -0
- package/dist/MuffinDashboard.js +16 -0
- package/dist/MuffinResource.d.ts +2 -0
- package/dist/MuffinResource.js +19 -0
- package/dist/MuffinResourceCreate.d.ts +4 -0
- package/dist/MuffinResourceCreate.js +11 -0
- package/dist/MuffinResourceEdit.d.ts +2 -0
- package/dist/MuffinResourceEdit.js +26 -0
- package/dist/MuffinResourceList.d.ts +2 -0
- package/dist/MuffinResourceList.js +16 -0
- package/dist/MuffinResourceShow.d.ts +2 -0
- package/dist/MuffinResourceShow.js +13 -0
- package/dist/actions/LinkAction.d.ts +4 -0
- package/dist/actions/LinkAction.js +10 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/index.js +1 -0
- package/dist/authprovider.d.ts +9 -0
- package/dist/authprovider.js +80 -0
- package/dist/buildRA.d.ts +2 -0
- package/dist/buildRA.js +63 -0
- package/dist/buttons/ActionButton.d.ts +7 -0
- package/dist/buttons/ActionButton.js +51 -0
- package/dist/buttons/LinkButton.d.ts +6 -0
- package/dist/buttons/LinkButton.js +12 -0
- package/dist/buttons/index.d.ts +2 -0
- package/dist/buttons/index.js +2 -0
- package/dist/dataprovider.d.ts +59 -0
- package/dist/dataprovider.js +106 -0
- package/dist/fields/AvatarField.d.ts +13 -0
- package/dist/fields/AvatarField.js +33 -0
- package/dist/fields/EditableBooleanField.d.ts +3 -0
- package/dist/fields/EditableBooleanField.js +5 -0
- package/dist/fields/FKField.d.ts +14 -0
- package/dist/fields/FKField.js +21 -0
- package/dist/fields/JsonField.d.ts +4 -0
- package/dist/fields/JsonField.js +11 -0
- package/dist/fields/index.d.ts +4 -0
- package/dist/fields/index.js +4 -0
- package/dist/hooks/useAction.d.ts +5 -0
- package/dist/hooks/useAction.js +6 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +35 -0
- package/dist/inputs/FKInput.d.ts +8 -0
- package/dist/inputs/FKInput.js +27 -0
- package/dist/inputs/JsonInput.d.ts +19 -0
- package/dist/inputs/JsonInput.js +69 -0
- package/dist/inputs/index.d.ts +2 -0
- package/dist/inputs/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +28 -0
- package/dist/utils.js +57 -0
- package/dist/web.d.ts +1 -0
- package/dist/web.js +3 -0
- package/package.json +31 -14
- package/src/MuffinAdmin.tsx +73 -0
- package/src/MuffinDashboard.tsx +52 -0
- package/src/MuffinResource.tsx +27 -0
- package/src/MuffinResourceCreate.tsx +24 -0
- package/src/MuffinResourceEdit.tsx +42 -0
- package/src/MuffinResourceList.tsx +46 -0
- package/src/MuffinResourceShow.tsx +39 -0
- package/src/actions/LinkAction.tsx +10 -0
- package/src/actions/index.ts +1 -0
- package/src/{authprovider.js → authprovider.ts} +27 -22
- package/src/{ui.jsx → buildRA.tsx} +30 -35
- package/src/buttons/{ActionButton.jsx → ActionButton.tsx} +18 -30
- package/src/buttons/{LinkButton.jsx → LinkButton.tsx} +11 -6
- package/src/buttons/index.ts +2 -0
- package/src/{dataprovider.js → dataprovider.ts} +8 -6
- package/src/fields/{AvatarField.jsx → AvatarField.tsx} +3 -7
- package/src/fields/EditableBooleanField.tsx +5 -0
- package/src/fields/{FKField.jsx → FKField.tsx} +2 -10
- package/src/fields/{JsonField.jsx → JsonField.tsx} +2 -3
- package/src/fields/index.ts +4 -0
- package/src/hooks/{useAction.js → useAction.ts} +2 -2
- package/src/index.tsx +25 -0
- package/src/inputs/FKInput.tsx +27 -0
- package/src/inputs/{JsonInput.jsx → JsonInput.tsx} +3 -4
- package/src/inputs/index.ts +2 -0
- package/src/types.ts +73 -0
- package/src/utils.tsx +69 -0
- package/src/web.ts +4 -0
- package/dist/cjs/admin.js +0 -80
- package/dist/cjs/authprovider.js +0 -214
- package/dist/cjs/buttons/ActionButton.js +0 -96
- package/dist/cjs/buttons/LinkButton.js +0 -34
- package/dist/cjs/dashboard.js +0 -63
- package/dist/cjs/dataprovider.js +0 -304
- package/dist/cjs/fields/AvatarField.js +0 -37
- package/dist/cjs/fields/EditableBooleanField.js +0 -25
- package/dist/cjs/fields/FKField.js +0 -35
- package/dist/cjs/fields/JsonField.js +0 -38
- package/dist/cjs/hooks/useAction.js +0 -14
- package/dist/cjs/index.js +0 -76
- package/dist/cjs/inputs/FKInput.js +0 -41
- package/dist/cjs/inputs/JsonInput.js +0 -70
- package/dist/cjs/resources.js +0 -52
- package/dist/cjs/ui.js +0 -76
- package/dist/cjs/utils.js +0 -49
- package/dist/cjs/views/create.js +0 -18
- package/dist/cjs/views/edit.js +0 -31
- package/dist/cjs/views/list.js +0 -67
- package/dist/cjs/views/show.js +0 -37
- package/dist/cjs/web.js +0 -4
- package/dist/esm/admin.js +0 -74
- package/dist/esm/authprovider.js +0 -206
- package/dist/esm/buttons/ActionButton.js +0 -83
- package/dist/esm/buttons/LinkButton.js +0 -23
- package/dist/esm/dashboard.js +0 -60
- package/dist/esm/dataprovider.js +0 -296
- package/dist/esm/fields/AvatarField.js +0 -29
- package/dist/esm/fields/EditableBooleanField.js +0 -17
- package/dist/esm/fields/FKField.js +0 -27
- package/dist/esm/fields/JsonField.js +0 -28
- package/dist/esm/hooks/useAction.js +0 -8
- package/dist/esm/index.js +0 -42
- package/dist/esm/inputs/FKInput.js +0 -33
- package/dist/esm/inputs/JsonInput.js +0 -63
- package/dist/esm/resources.js +0 -47
- package/dist/esm/ui.js +0 -70
- package/dist/esm/utils.js +0 -38
- package/dist/esm/views/create.js +0 -16
- package/dist/esm/views/edit.js +0 -29
- package/dist/esm/views/list.js +0 -64
- package/dist/esm/views/show.js +0 -35
- package/dist/esm/web.js +0 -2
- package/src/admin.jsx +0 -78
- package/src/dashboard.jsx +0 -74
- package/src/fields/EditableBooleanField.jsx +0 -11
- package/src/index.js +0 -16
- package/src/inputs/FKInput.jsx +0 -42
- package/src/resources.jsx +0 -39
- package/src/utils.js +0 -38
- package/src/views/create.jsx +0 -30
- package/src/views/edit.jsx +0 -48
- package/src/views/list.jsx +0 -86
- package/src/views/show.jsx +0 -51
- package/src/web.js +0 -3
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import IconButton from "@mui/material/IconButton";
|
|
3
|
+
import SvgIcon from "@mui/material/SvgIcon";
|
|
4
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
5
|
+
import Typography from "@mui/material/Typography";
|
|
6
|
+
import createTheme from "@mui/material/styles/createTheme";
|
|
7
|
+
import { Admin, AppBar, Layout, Login, ToggleThemeButton, defaultTheme, } from "react-admin";
|
|
8
|
+
import { AdminPropsContext, buildAdmin, findBuilder, findIcon, setupAdmin } from "./utils";
|
|
9
|
+
const darkTheme = createTheme({
|
|
10
|
+
palette: { mode: "dark" },
|
|
11
|
+
});
|
|
12
|
+
export function MuffinAdmin(props) {
|
|
13
|
+
const { resources, auth } = props;
|
|
14
|
+
const children = resources.map((resource) => buildAdmin(["resource", resource.name], Object.assign(Object.assign({}, resource), { key: resource.name })));
|
|
15
|
+
const appBar = (props) => (_jsxs(AppBar, Object.assign({}, props, { children: [_jsx(Typography, { variant: "h6", color: "inherit", id: "react-admin-title", style: {
|
|
16
|
+
flex: 1,
|
|
17
|
+
textOverflow: "ellipsis",
|
|
18
|
+
whiteSpace: "nowrap",
|
|
19
|
+
overflow: "hidden",
|
|
20
|
+
} }), _jsx(ToggleThemeButton, { lightTheme: defaultTheme, darkTheme: darkTheme }), props.appBarLinks.map((info) => (_jsx(Tooltip, { title: info.title, children: _jsx(IconButton, { color: "inherit", href: info.url, children: _jsx(SvgIcon, { component: findIcon(info.icon) }) }) }, info.url)))] })));
|
|
21
|
+
return (_jsx(AdminPropsContext.Provider, { value: props, children: _jsx(Admin, { requireAuth: auth.required, dashboard: buildAdmin(["dashboard"]), loginPage: findBuilder(["loginpage"]), authProvider: buildAdmin(["authprovider"], auth), layout: (props) => _jsx(Layout, Object.assign({}, props, { appBar: appBar })), dataProvider: buildAdmin(["dataprovider"], props), children: children }) }));
|
|
22
|
+
}
|
|
23
|
+
setupAdmin(["admin"], MuffinAdmin);
|
|
24
|
+
// Initialize login page
|
|
25
|
+
setupAdmin(["loginpage"], () => Login);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Card from "@mui/material/Card";
|
|
3
|
+
import CardContent from "@mui/material/CardContent";
|
|
4
|
+
import Grid from "@mui/material/Grid";
|
|
5
|
+
import Table from "@mui/material/Table";
|
|
6
|
+
import TableBody from "@mui/material/TableBody";
|
|
7
|
+
import TableCell from "@mui/material/TableCell";
|
|
8
|
+
import TableRow from "@mui/material/TableRow";
|
|
9
|
+
import Typography from "@mui/material/Typography";
|
|
10
|
+
export function MuffinDashboard(props) {
|
|
11
|
+
return (_jsx(Grid, { container: true, spacing: 1, children: Array.isArray(props) ? (props.map((card, idx) => _jsx(DashboardCard, Object.assign({}, card), idx))) : (_jsx(DashboardCard, Object.assign({}, props))) }));
|
|
12
|
+
}
|
|
13
|
+
function DashboardCard(title, value) {
|
|
14
|
+
return (_jsx(Grid, { item: true, xs: true, children: _jsx(Card, { children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h5", component: "h2", m: 2, style: { textAlign: "center" }, children: title }), (Array.isArray(value) && _jsx(AdminTableView, { src: value })) || (_jsx("pre", { children: JSON.stringify(value, null, 2) }))] }) }) }));
|
|
15
|
+
}
|
|
16
|
+
const AdminTableView = ({ src }) => (_jsx(Table, { children: _jsx(TableBody, { children: src.map((row, idx) => (_jsx(TableRow, { hover: true, children: row.map((cell, idx) => (_jsx(TableCell, { children: cell }, idx))) }, idx))) }) }));
|
|
@@ -0,0 +1,19 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
13
|
+
import { Resource } from "react-admin";
|
|
14
|
+
import { buildAdmin, findIcon, setupAdmin } from "./utils";
|
|
15
|
+
export function MuffinResource(_a) {
|
|
16
|
+
var { name, create: createProps, edit: editProps, list: listProps, show: showProps, icon } = _a, props = __rest(_a, ["name", "create", "edit", "list", "show", "icon"]);
|
|
17
|
+
return (_jsx(Resource, Object.assign({ name: name, icon: findIcon(icon), create: buildAdmin(["create", name], createProps), edit: buildAdmin(["edit", name], editProps), list: buildAdmin(["list", name], listProps), show: buildAdmin(["show", name], showProps) }, props)));
|
|
18
|
+
}
|
|
19
|
+
setupAdmin(["resource"], MuffinResource);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Create, ListButton, SimpleForm, TopToolbar, useResourceContext } from "react-admin";
|
|
3
|
+
import { buildRA } from "./buildRA";
|
|
4
|
+
import { buildAdmin, setupAdmin } from "./utils";
|
|
5
|
+
export function MuffinResourceCreate({ inputs }) {
|
|
6
|
+
const resourceName = useResourceContext();
|
|
7
|
+
return (_jsx(Create, { actions: buildAdmin(["create-actions", resourceName]), children: _jsx(SimpleForm, { children: buildAdmin(["create-inputs", resourceName], inputs) }) }));
|
|
8
|
+
}
|
|
9
|
+
setupAdmin(["create"], (inputs) => _jsx(MuffinResourceCreate, { inputs: inputs }));
|
|
10
|
+
setupAdmin(["create-actions"], () => (_jsx(TopToolbar, { children: _jsx(ListButton, {}) })));
|
|
11
|
+
setupAdmin(["create-inputs"], buildRA);
|
|
@@ -0,0 +1,26 @@
|
|
|
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 { useContext } from "react";
|
|
14
|
+
import { Edit, ListButton, ShowButton, SimpleForm, TopToolbar, useResourceContext, } from "react-admin";
|
|
15
|
+
import { buildRA } from "./buildRA";
|
|
16
|
+
import { ActionButton } from "./buttons";
|
|
17
|
+
import { AdminPropsContext, buildAdmin, setupAdmin } from "./utils";
|
|
18
|
+
export function MuffinResourceEdit(_a) {
|
|
19
|
+
var { actions, inputs } = _a, props = __rest(_a, ["actions", "inputs"]);
|
|
20
|
+
const resourceName = useResourceContext();
|
|
21
|
+
const { adminProps: { mutationMode }, } = useContext(AdminPropsContext);
|
|
22
|
+
return (_jsx(Edit, Object.assign({ actions: buildAdmin(["edit-actions", resourceName], actions), mutationMode: mutationMode || "optimistic" }, props, { children: _jsx(SimpleForm, { children: buildAdmin(["edit-inputs", resourceName], inputs) }) })));
|
|
23
|
+
}
|
|
24
|
+
setupAdmin(["edit"], (props) => _jsx(MuffinResourceEdit, Object.assign({}, props)));
|
|
25
|
+
setupAdmin(["edit-actions"], (actions) => (_jsxs(TopToolbar, { children: [actions.map((props, idx) => (_jsx(ActionButton, Object.assign({}, props), idx))), _jsx(ListButton, {}), _jsx(ShowButton, {})] })));
|
|
26
|
+
setupAdmin(["edit-inputs"], buildRA);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import sortBy from "lodash/sortBy";
|
|
3
|
+
import uniq from "lodash/uniq";
|
|
4
|
+
import { BulkDeleteButton, Datagrid, EditButton, List, Pagination, useResourceContext, } from "react-admin";
|
|
5
|
+
import { buildRA } from "./buildRA";
|
|
6
|
+
import { BulkActionButton } from "./buttons";
|
|
7
|
+
import { buildAdmin, setupAdmin } from "./utils";
|
|
8
|
+
export function MuffinResourceList(props) {
|
|
9
|
+
const resourceName = useResourceContext();
|
|
10
|
+
const { fields, edit, show, limit, limitMax, filters, actions } = props;
|
|
11
|
+
return (_jsx(List, { bulkActionButtons: buildAdmin(["list-actions", resourceName], actions), filters: buildAdmin(["list-filters", resourceName], filters) || undefined, perPage: limit, pagination: _jsx(Pagination, { rowsPerPageOptions: sortBy(uniq([10, 25, 50, 100, limit, limitMax])) }), children: _jsxs(Datagrid, { rowClick: show ? "show" : edit ? "edit" : false, children: [buildAdmin(["list-fields", resourceName], fields), edit && _jsx(EditButton, {})] }) }));
|
|
12
|
+
}
|
|
13
|
+
setupAdmin(["list"], (props) => _jsx(MuffinResourceList, Object.assign({}, props)));
|
|
14
|
+
setupAdmin(["list-fields"], buildRA);
|
|
15
|
+
setupAdmin(["list-filters"], buildRA);
|
|
16
|
+
setupAdmin(["list-actions"], (actions) => (_jsxs(_Fragment, { children: [actions.map((props, idx) => (_jsx(BulkActionButton, Object.assign({}, props), idx))), _jsx(BulkDeleteButton, {})] })));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { EditButton, ListButton, Show, SimpleShowLayout, TopToolbar, useResourceContext, } from "react-admin";
|
|
3
|
+
import { LinkAction } from "./actions";
|
|
4
|
+
import { buildRA } from "./buildRA";
|
|
5
|
+
import { ActionButton } from "./buttons";
|
|
6
|
+
import { buildAdmin, setupAdmin } from "./utils";
|
|
7
|
+
export function MuffinResourceShow(props) {
|
|
8
|
+
const resourceName = useResourceContext();
|
|
9
|
+
return (_jsx(Show, { actions: buildAdmin(["show-actions", resourceName], props), children: _jsx(SimpleShowLayout, { children: buildAdmin(["show-fields", resourceName], props) }) }));
|
|
10
|
+
}
|
|
11
|
+
setupAdmin(["show"], (props) => _jsx(MuffinResourceShow, Object.assign({}, props)));
|
|
12
|
+
setupAdmin(["show-fields"], ({ fields }) => buildRA(fields));
|
|
13
|
+
setupAdmin(["show-actions"], ({ actions, links }) => (_jsxs(TopToolbar, { children: [_jsx("div", { style: { marginRight: "auto" }, children: Object.keys(links).map((key) => (_jsx(LinkAction, Object.assign({ resource: key }, links[key]), key))) }), actions.map((props, idx) => (_jsx(ActionButton, Object.assign({}, props), idx))), _jsx(ListButton, {}), _jsx(EditButton, {})] })));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRecordContext, useResourceContext } from "react-admin";
|
|
3
|
+
import LinkButton from "../buttons/LinkButton";
|
|
4
|
+
export function LinkAction(props) {
|
|
5
|
+
const record = useRecordContext();
|
|
6
|
+
const currentResource = useResourceContext();
|
|
7
|
+
if (!record)
|
|
8
|
+
return null;
|
|
9
|
+
return _jsx(LinkButton, Object.assign({}, props, { filters: { [currentResource]: record.id } }));
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./LinkAction";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./LinkAction";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AdminOpts } from "./types";
|
|
2
|
+
export declare function MuffinAuthProvider(props: AdminOpts["auth"]): {
|
|
3
|
+
login: (data: any) => Promise<void>;
|
|
4
|
+
checkError: (error: any) => Promise<void>;
|
|
5
|
+
checkAuth: () => Promise<any>;
|
|
6
|
+
logout: () => Promise<void>;
|
|
7
|
+
getIdentity: () => Promise<any>;
|
|
8
|
+
getPermissions: () => Promise<any>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
};
|
|
10
|
+
import Cookies from "js-cookie";
|
|
11
|
+
import { buildAdmin, makeRequest, requestHeaders, setupAdmin } from ".";
|
|
12
|
+
setupAdmin(["auth-storage-get"], ({ storage, storageName }) => () => storage == "localstorage" ? localStorage.getItem(storageName) : Cookies.get(storageName));
|
|
13
|
+
setupAdmin(["auth-storage-set"], ({ storage }) => (name, value) => {
|
|
14
|
+
if (storage == "localstorage") {
|
|
15
|
+
localStorage.setItem(name, value);
|
|
16
|
+
requestHeaders["Authorization"] = value;
|
|
17
|
+
}
|
|
18
|
+
else
|
|
19
|
+
Cookies.set(name, value);
|
|
20
|
+
});
|
|
21
|
+
export function MuffinAuthProvider(props) {
|
|
22
|
+
const { identityURL, authorizeURL, logoutURL, required, storageName } = props;
|
|
23
|
+
const authGet = buildAdmin(["auth-storage-get"], props);
|
|
24
|
+
const authSet = buildAdmin(["auth-storage-set"], props);
|
|
25
|
+
// Initialize request headers
|
|
26
|
+
authSet(storageName, authGet(storageName));
|
|
27
|
+
const getIdentity = () => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
if (identityURL) {
|
|
29
|
+
const { json } = yield makeRequest(identityURL);
|
|
30
|
+
return json;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (required)
|
|
34
|
+
return {
|
|
35
|
+
login: (data) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
if (!authorizeURL)
|
|
37
|
+
throw { message: "Authorization is not supported" };
|
|
38
|
+
const { json } = yield makeRequest(authorizeURL, {
|
|
39
|
+
data,
|
|
40
|
+
method: "POST",
|
|
41
|
+
});
|
|
42
|
+
authSet(storageName, json);
|
|
43
|
+
}),
|
|
44
|
+
checkError: (error) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const { status } = error || {};
|
|
46
|
+
if (status == 401 || status == 403) {
|
|
47
|
+
// Clean storage
|
|
48
|
+
authSet(storageName, "");
|
|
49
|
+
throw {
|
|
50
|
+
message: "Invalid authorization",
|
|
51
|
+
redirectTo: logoutURL,
|
|
52
|
+
logoutUser: !logoutURL,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
checkAuth: () => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const auth = authGet(storageName);
|
|
58
|
+
if (!auth)
|
|
59
|
+
throw { message: "Authorization required" };
|
|
60
|
+
if (!identityURL)
|
|
61
|
+
return auth;
|
|
62
|
+
const user = yield getIdentity();
|
|
63
|
+
if (!user)
|
|
64
|
+
throw { message: "Authorization required" };
|
|
65
|
+
return user;
|
|
66
|
+
}),
|
|
67
|
+
logout: () => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
// Clean storage
|
|
69
|
+
authSet(storageName, "");
|
|
70
|
+
if (logoutURL)
|
|
71
|
+
window.location.href = logoutURL;
|
|
72
|
+
}),
|
|
73
|
+
getIdentity,
|
|
74
|
+
getPermissions: () => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const role = authGet(storageName + "_role");
|
|
76
|
+
return role || "";
|
|
77
|
+
}),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
setupAdmin(["authprovider"], MuffinAuthProvider);
|
package/dist/buildRA.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ArrayField, ArrayInput, AutocompleteArrayInput, AutocompleteInput, BooleanField, BooleanInput, CheckboxGroupInput, ChipField, DateField, DateInput, DateTimeInput, EmailField, FileField, FileInput, ImageField, ImageInput, NullableBooleanInput, NumberField, NumberInput, PasswordInput, RadioButtonGroupInput, ReferenceArrayField, ReferenceArrayInput, ReferenceField, ReferenceInput, ReferenceManyField, RichTextField, SelectField, SelectInput, TextField, TextInput, UrlField, required, } from "react-admin";
|
|
3
|
+
import { AvatarField, EditableBooleanField, FKField, JsonField } from "./fields";
|
|
4
|
+
import { FKInput, JsonInput } from "./inputs";
|
|
5
|
+
const UI = {
|
|
6
|
+
// Fields
|
|
7
|
+
BooleanField,
|
|
8
|
+
ChipField,
|
|
9
|
+
DateField,
|
|
10
|
+
EmailField,
|
|
11
|
+
ImageField,
|
|
12
|
+
FileField,
|
|
13
|
+
NumberField,
|
|
14
|
+
RichTextField,
|
|
15
|
+
TextField,
|
|
16
|
+
UrlField,
|
|
17
|
+
SelectField,
|
|
18
|
+
ArrayField,
|
|
19
|
+
ReferenceField,
|
|
20
|
+
ReferenceManyField,
|
|
21
|
+
ReferenceArrayField,
|
|
22
|
+
AvatarField,
|
|
23
|
+
EditableBooleanField,
|
|
24
|
+
FKField,
|
|
25
|
+
JsonField,
|
|
26
|
+
// Inputs
|
|
27
|
+
BooleanInput,
|
|
28
|
+
NullableBooleanInput,
|
|
29
|
+
DateInput,
|
|
30
|
+
DateTimeInput,
|
|
31
|
+
ImageInput,
|
|
32
|
+
FileInput,
|
|
33
|
+
NumberInput,
|
|
34
|
+
PasswordInput,
|
|
35
|
+
TextInput,
|
|
36
|
+
AutocompleteInput,
|
|
37
|
+
RadioButtonGroupInput,
|
|
38
|
+
SelectInput,
|
|
39
|
+
ArrayInput,
|
|
40
|
+
AutocompleteArrayInput,
|
|
41
|
+
CheckboxGroupInput,
|
|
42
|
+
ReferenceArrayInput,
|
|
43
|
+
ReferenceInput,
|
|
44
|
+
JsonInput,
|
|
45
|
+
FKInput,
|
|
46
|
+
};
|
|
47
|
+
export function buildRAComponent(name, props) {
|
|
48
|
+
var _a;
|
|
49
|
+
const Item = UI[name];
|
|
50
|
+
if (!Item)
|
|
51
|
+
return null;
|
|
52
|
+
if (props.required) {
|
|
53
|
+
props.validate = required();
|
|
54
|
+
delete props.required;
|
|
55
|
+
}
|
|
56
|
+
props.fullWidth = (_a = props.fullWidth) !== null && _a !== void 0 ? _a : true;
|
|
57
|
+
if (props.children)
|
|
58
|
+
props.children = buildRA(props.children)[0];
|
|
59
|
+
return _jsx(Item, Object.assign({}, props), props.source);
|
|
60
|
+
}
|
|
61
|
+
export function buildRA(items) {
|
|
62
|
+
return items.map((item) => buildRAComponent(item[0], item[1]));
|
|
63
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function BulkActionButton({ label, icon, title, action }: {
|
|
2
|
+
label: any;
|
|
3
|
+
icon: any;
|
|
4
|
+
title: any;
|
|
5
|
+
action: any;
|
|
6
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function ActionButton(props: any): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as icons from "@mui/icons-material";
|
|
3
|
+
import { Button, useListContext, useNotify, useRecordContext, useRefresh, useResourceContext, useUnselectAll, } from "react-admin";
|
|
4
|
+
import { useAction } from "../hooks/useAction";
|
|
5
|
+
import { buildIcon } from "../utils";
|
|
6
|
+
export function BulkActionButton({ label, icon, title, action }) {
|
|
7
|
+
const resource = useResourceContext();
|
|
8
|
+
const { selectedIds } = useListContext();
|
|
9
|
+
const refresh = useRefresh(), unselectAll = useUnselectAll(resource), notify = useNotify();
|
|
10
|
+
const mutation = useAction(resource, action);
|
|
11
|
+
const onClick = () => {
|
|
12
|
+
mutation.mutate({
|
|
13
|
+
action,
|
|
14
|
+
ids: selectedIds,
|
|
15
|
+
}, {
|
|
16
|
+
onSuccess: ({ data }) => {
|
|
17
|
+
if (data && data.message)
|
|
18
|
+
notify(data.message, { type: "success" });
|
|
19
|
+
refresh();
|
|
20
|
+
unselectAll();
|
|
21
|
+
},
|
|
22
|
+
onError: (err) => {
|
|
23
|
+
notify(typeof err === "string" ? err : err.message, { type: "error" });
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
return (_jsx(Button, { label: label, title: title, onClick: onClick, disabled: mutation.isLoading, children: buildIcon(icon) }));
|
|
28
|
+
}
|
|
29
|
+
export function ActionButton(props) {
|
|
30
|
+
const { icon, label, title, resource, action } = props;
|
|
31
|
+
const record = useRecordContext();
|
|
32
|
+
const { mutate, isLoading } = useAction(resource, action);
|
|
33
|
+
const refresh = useRefresh(), notify = useNotify(), Icon = icons[icon];
|
|
34
|
+
const onClick = () => {
|
|
35
|
+
mutate({ record }, {
|
|
36
|
+
onSuccess: ({ data }) => {
|
|
37
|
+
refresh();
|
|
38
|
+
if (data && data.redirectTo)
|
|
39
|
+
window.location = data.redirectTo;
|
|
40
|
+
if (data && data.message)
|
|
41
|
+
notify(data.message, { type: "success" });
|
|
42
|
+
},
|
|
43
|
+
onError: (err) => {
|
|
44
|
+
notify(typeof err === "string" ? err : err.message, {
|
|
45
|
+
type: "error",
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
return (_jsx(Button, { label: label, title: title, onClick: onClick, disabled: isLoading, children: Icon && _jsx(Icon, {}) }));
|
|
51
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "react-admin";
|
|
3
|
+
import { Link } from "react-router-dom";
|
|
4
|
+
import { buildIcon } from "../utils";
|
|
5
|
+
const LinkButton = ({ filters, icon, label, resource, title, }) => {
|
|
6
|
+
const linkParams = {
|
|
7
|
+
pathname: `/${resource}`,
|
|
8
|
+
search: filters ? `filter=${JSON.stringify(filters)}` : undefined,
|
|
9
|
+
};
|
|
10
|
+
return (_jsx(Button, { label: label, title: title, component: Link, to: linkParams, children: buildIcon(icon) }));
|
|
11
|
+
};
|
|
12
|
+
export default LinkButton;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { AdminOpts } from "./types";
|
|
2
|
+
export declare function MuffinDataprovider({ apiUrl }: AdminOpts): {
|
|
3
|
+
getList: (resource: string, params: any) => Promise<{
|
|
4
|
+
data: any;
|
|
5
|
+
total: number;
|
|
6
|
+
}>;
|
|
7
|
+
getOne: (resource: any, { id }: {
|
|
8
|
+
id: any;
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
data: any;
|
|
11
|
+
}>;
|
|
12
|
+
create: (resource: any, { data }: {
|
|
13
|
+
data: any;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
data: any;
|
|
16
|
+
}>;
|
|
17
|
+
update: (resource: any, { id, data }: {
|
|
18
|
+
id: any;
|
|
19
|
+
data: any;
|
|
20
|
+
}) => Promise<{
|
|
21
|
+
data: any;
|
|
22
|
+
}>;
|
|
23
|
+
updateMany: (resource: any, { ids, data }: {
|
|
24
|
+
ids: any;
|
|
25
|
+
data: any;
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
data: any;
|
|
28
|
+
}>;
|
|
29
|
+
delete: (resource: any, { id }: {
|
|
30
|
+
id: any;
|
|
31
|
+
}) => Promise<{
|
|
32
|
+
data: {
|
|
33
|
+
id: any;
|
|
34
|
+
};
|
|
35
|
+
}>;
|
|
36
|
+
deleteMany: (resource: any, { ids }: {
|
|
37
|
+
ids: any;
|
|
38
|
+
}) => Promise<{
|
|
39
|
+
data: any;
|
|
40
|
+
}>;
|
|
41
|
+
getMany: (resource: any, { ids }: {
|
|
42
|
+
ids: any;
|
|
43
|
+
}) => Promise<{
|
|
44
|
+
data: any;
|
|
45
|
+
total: number;
|
|
46
|
+
}>;
|
|
47
|
+
getManyReference: (resource: any, { target, id, filter, ...opts }: {
|
|
48
|
+
[x: string]: any;
|
|
49
|
+
target: any;
|
|
50
|
+
id: any;
|
|
51
|
+
filter: any;
|
|
52
|
+
}) => Promise<{
|
|
53
|
+
data: any;
|
|
54
|
+
total: number;
|
|
55
|
+
}>;
|
|
56
|
+
runAction: (resource: any, action: any, props: any) => Promise<{
|
|
57
|
+
data: any;
|
|
58
|
+
}>;
|
|
59
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { makeRequest, setupAdmin } from "./utils";
|
|
22
|
+
export function MuffinDataprovider({ apiUrl }) {
|
|
23
|
+
const methods = {
|
|
24
|
+
getList: (resource, params) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const { filter, pagination, sort } = params;
|
|
26
|
+
const query = {};
|
|
27
|
+
if (filter)
|
|
28
|
+
query.where = JSON.stringify(filter);
|
|
29
|
+
if (pagination) {
|
|
30
|
+
const { page, perPage: limit } = pagination;
|
|
31
|
+
query.limit = limit;
|
|
32
|
+
query.offset = limit * (page - 1);
|
|
33
|
+
}
|
|
34
|
+
if (sort) {
|
|
35
|
+
const { field, order } = sort;
|
|
36
|
+
query.sort = order == "ASC" ? field : `-${field}`;
|
|
37
|
+
}
|
|
38
|
+
const { headers, json } = yield makeRequest(`${apiUrl}/${resource}`, {
|
|
39
|
+
query,
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
data: json,
|
|
43
|
+
total: parseInt(headers.get("x-total"), 10),
|
|
44
|
+
};
|
|
45
|
+
}),
|
|
46
|
+
getOne: (resource, { id }) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const { json } = yield makeRequest(`${apiUrl}/${resource}/${id}`);
|
|
48
|
+
return { data: json };
|
|
49
|
+
}),
|
|
50
|
+
create: (resource, { data }) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const { json } = yield makeRequest(`${apiUrl}/${resource}`, {
|
|
52
|
+
data,
|
|
53
|
+
method: "POST",
|
|
54
|
+
});
|
|
55
|
+
return { data: json };
|
|
56
|
+
}),
|
|
57
|
+
update: (resource, { id, data }) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const { json } = yield makeRequest(`${apiUrl}/${resource}/${id}`, {
|
|
59
|
+
data,
|
|
60
|
+
method: "PUT",
|
|
61
|
+
});
|
|
62
|
+
return { data: json };
|
|
63
|
+
}),
|
|
64
|
+
updateMany: (resource, { ids, data }) => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
yield Promise.all(ids.map((id) => methods.update(resource, { id, data })));
|
|
66
|
+
return { data: ids };
|
|
67
|
+
}),
|
|
68
|
+
delete: (resource, { id }) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
yield makeRequest(`${apiUrl}/${resource}/${id}`, {
|
|
70
|
+
method: "DELETE",
|
|
71
|
+
});
|
|
72
|
+
return { data: { id } };
|
|
73
|
+
}),
|
|
74
|
+
deleteMany: (resource, { ids }) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
yield makeRequest(`${apiUrl}/${resource}`, {
|
|
76
|
+
data: ids,
|
|
77
|
+
method: "DELETE",
|
|
78
|
+
});
|
|
79
|
+
return { data: ids };
|
|
80
|
+
}),
|
|
81
|
+
getMany: (resource, { ids }) => {
|
|
82
|
+
return methods.getList(resource, { filter: { id: { $in: ids } } });
|
|
83
|
+
},
|
|
84
|
+
getManyReference: (resource, _a) => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
var { target, id, filter } = _a, opts = __rest(_a, ["target", "id", "filter"]);
|
|
86
|
+
filter = filter || {};
|
|
87
|
+
filter[target] = id;
|
|
88
|
+
return yield methods.getList(resource, Object.assign({ filter }, opts));
|
|
89
|
+
}),
|
|
90
|
+
runAction: (resource, action, props) => __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const { payload, ids, record } = props;
|
|
92
|
+
action = action.replace(/^\/+/, "");
|
|
93
|
+
if (record) {
|
|
94
|
+
action = action.replace(/\{([^}]+)\}/, (_, field) => record[field]);
|
|
95
|
+
}
|
|
96
|
+
const { json } = yield makeRequest(`${apiUrl}/${action}`, {
|
|
97
|
+
query: { ids },
|
|
98
|
+
method: "POST",
|
|
99
|
+
data: payload,
|
|
100
|
+
});
|
|
101
|
+
return { data: json };
|
|
102
|
+
}),
|
|
103
|
+
};
|
|
104
|
+
return methods;
|
|
105
|
+
}
|
|
106
|
+
setupAdmin(["dataprovider"], MuffinDataprovider);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function AvatarField({ source, alt, style, nameProp, ...props }: {
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
source: any;
|
|
4
|
+
alt: any;
|
|
5
|
+
style: any;
|
|
6
|
+
nameProp: any;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare namespace AvatarField {
|
|
9
|
+
var displayName: string;
|
|
10
|
+
var defaultProps: {
|
|
11
|
+
addLabel: boolean;
|
|
12
|
+
};
|
|
13
|
+
}
|