muffin-admin 1.36.4 → 1.36.6

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.
Files changed (68) hide show
  1. package/dist/esm/admin.js +71 -0
  2. package/dist/esm/authprovider.js +191 -0
  3. package/dist/esm/buttons/ActionButton.js +81 -0
  4. package/dist/esm/buttons/LinkButton.js +23 -0
  5. package/dist/esm/dashboard.js +60 -0
  6. package/dist/esm/dataprovider.js +296 -0
  7. package/dist/esm/fields/AvatarField.js +29 -0
  8. package/dist/esm/fields/FKField.js +27 -0
  9. package/dist/esm/fields/JsonField.js +28 -0
  10. package/dist/esm/hooks/useAction.js +8 -0
  11. package/dist/esm/index.js +40 -0
  12. package/dist/esm/inputs/FKInput.js +33 -0
  13. package/dist/esm/inputs/JsonInput.js +63 -0
  14. package/dist/esm/resources.js +38 -0
  15. package/dist/esm/ui.js +71 -0
  16. package/dist/esm/utils.js +38 -0
  17. package/dist/esm/views/create.js +16 -0
  18. package/dist/esm/views/edit.js +37 -0
  19. package/dist/esm/views/list.js +64 -0
  20. package/dist/esm/views/show.js +26 -0
  21. package/dist/esm/web.js +2 -0
  22. package/package.json +7 -11
  23. package/src/admin.jsx +78 -0
  24. package/src/authprovider.js +85 -0
  25. package/src/buttons/ActionButton.jsx +99 -0
  26. package/src/buttons/LinkButton.jsx +20 -0
  27. package/src/dashboard.jsx +74 -0
  28. package/src/dataprovider.js +94 -0
  29. package/src/fields/AvatarField.jsx +33 -0
  30. package/src/fields/FKField.jsx +27 -0
  31. package/src/fields/JsonField.jsx +26 -0
  32. package/src/hooks/useAction.js +9 -0
  33. package/src/index.js +14 -0
  34. package/src/inputs/FKInput.jsx +41 -0
  35. package/src/inputs/JsonInput.jsx +62 -0
  36. package/src/resources.jsx +36 -0
  37. package/src/ui.jsx +107 -0
  38. package/src/utils.js +38 -0
  39. package/src/views/create.jsx +30 -0
  40. package/src/views/edit.jsx +41 -0
  41. package/src/views/list.jsx +86 -0
  42. package/src/views/show.jsx +42 -0
  43. package/src/web.js +3 -0
  44. package/.eslintrc.json +0 -44
  45. package/Makefile +0 -18
  46. package/jsconfig.json +0 -9
  47. package/webpack.config.js +0 -45
  48. /package/dist/{admin.js → cjs/admin.js} +0 -0
  49. /package/dist/{authprovider.js → cjs/authprovider.js} +0 -0
  50. /package/dist/{buttons → cjs/buttons}/ActionButton.js +0 -0
  51. /package/dist/{buttons → cjs/buttons}/LinkButton.js +0 -0
  52. /package/dist/{dashboard.js → cjs/dashboard.js} +0 -0
  53. /package/dist/{dataprovider.js → cjs/dataprovider.js} +0 -0
  54. /package/dist/{fields → cjs/fields}/AvatarField.js +0 -0
  55. /package/dist/{fields → cjs/fields}/FKField.js +0 -0
  56. /package/dist/{fields → cjs/fields}/JsonField.js +0 -0
  57. /package/dist/{hooks → cjs/hooks}/useAction.js +0 -0
  58. /package/dist/{index.js → cjs/index.js} +0 -0
  59. /package/dist/{inputs → cjs/inputs}/FKInput.js +0 -0
  60. /package/dist/{inputs → cjs/inputs}/JsonInput.js +0 -0
  61. /package/dist/{resources.js → cjs/resources.js} +0 -0
  62. /package/dist/{ui.js → cjs/ui.js} +0 -0
  63. /package/dist/{utils.js → cjs/utils.js} +0 -0
  64. /package/dist/{views → cjs/views}/create.js +0 -0
  65. /package/dist/{views → cjs/views}/edit.js +0 -0
  66. /package/dist/{views → cjs/views}/list.js +0 -0
  67. /package/dist/{views → cjs/views}/show.js +0 -0
  68. /package/dist/{web.js → cjs/web.js} +0 -0
@@ -0,0 +1,71 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React from "react";
3
+ import { Admin, AppBar, Layout, Login, ToggleThemeButton, defaultTheme } from "react-admin";
4
+ import { IconButton, SvgIcon, Tooltip, Typography, createTheme } from "@mui/material";
5
+ import * as icons from "@mui/icons-material";
6
+ import authProvider from "./authprovider";
7
+ import dataProvider from "./dataprovider";
8
+ import { processAdmin, setupAdmin } from "./utils";
9
+ import "./dashboard";
10
+ import "./resources";
11
+ var darkTheme = createTheme({
12
+ palette: {
13
+ mode: "dark"
14
+ }
15
+ });
16
+
17
+ // Initialize the admin
18
+ setupAdmin("admin", function (props) {
19
+ var apiUrl = props.apiUrl,
20
+ auth = props.auth,
21
+ adminProps = props.adminProps,
22
+ appBarLinks = props.appBarLinks,
23
+ dashboard = props.dashboard,
24
+ resources = props.resources;
25
+ var appBar = function appBar(props) {
26
+ return /*#__PURE__*/React.createElement(AppBar, props, /*#__PURE__*/React.createElement(Typography, {
27
+ variant: "h6",
28
+ color: "inherit",
29
+ id: "react-admin-title",
30
+ style: {
31
+ flex: 1,
32
+ textOverflow: "ellipsis",
33
+ whiteSpace: "nowrap",
34
+ overflow: "hidden"
35
+ }
36
+ }), /*#__PURE__*/React.createElement(ToggleThemeButton, {
37
+ lightTheme: defaultTheme,
38
+ darkTheme: darkTheme
39
+ }), appBarLinks.map(function (info) {
40
+ return /*#__PURE__*/React.createElement(Tooltip, {
41
+ key: info.url,
42
+ title: info.title
43
+ }, /*#__PURE__*/React.createElement(IconButton, {
44
+ color: "inherit",
45
+ href: info.url
46
+ }, /*#__PURE__*/React.createElement(SvgIcon, {
47
+ component: icons[info.icon]
48
+ })));
49
+ }));
50
+ };
51
+ return /*#__PURE__*/React.createElement(Admin, _extends({
52
+ authProvider: processAdmin("auth", auth),
53
+ dataProvider: processAdmin("data", apiUrl),
54
+ dashboard: processAdmin("dashboard", dashboard),
55
+ loginPage: processAdmin("login", auth),
56
+ layout: function layout(props) {
57
+ return /*#__PURE__*/React.createElement(Layout, _extends({
58
+ appBar: appBar
59
+ }, props));
60
+ }
61
+ }, adminProps), processAdmin("resources", resources));
62
+ });
63
+
64
+ // Initialize authentication and data providers
65
+ setupAdmin("auth", authProvider);
66
+ setupAdmin("data", dataProvider);
67
+
68
+ // Initialize login page
69
+ setupAdmin("login", function () {
70
+ return Login;
71
+ });
@@ -0,0 +1,191 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import Cookies from "js-cookie";
4
+ import { makeRequest, processAdmin, requestHeaders, setupAdmin } from "./utils";
5
+ setupAdmin("auth-get", function (_ref) {
6
+ var storage = _ref.storage;
7
+ return function (name) {
8
+ return storage == "localstorage" ? localStorage.getItem(name) : Cookies.get(name);
9
+ };
10
+ });
11
+ setupAdmin("auth-set", function (_ref2) {
12
+ var storage = _ref2.storage;
13
+ return function (name, value) {
14
+ if (storage == "localstorage") {
15
+ localStorage.setItem(name, value);
16
+ requestHeaders["Authorization"] = value;
17
+ } else Cookies.set(name, value);
18
+ };
19
+ });
20
+ export default (function (props) {
21
+ var identityURL = props.identityURL,
22
+ authorizeURL = props.authorizeURL,
23
+ logoutURL = props.logoutURL,
24
+ required = props.required,
25
+ storage_name = props.storage_name;
26
+ var authGet = processAdmin("auth-get", props);
27
+ var authSet = processAdmin("auth-set", props);
28
+
29
+ // Initialize request headers
30
+ authSet(storage_name, authGet(storage_name));
31
+ var getIdentity = /*#__PURE__*/function () {
32
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
33
+ var _yield$makeRequest, json;
34
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
35
+ while (1) switch (_context.prev = _context.next) {
36
+ case 0:
37
+ if (!identityURL) {
38
+ _context.next = 6;
39
+ break;
40
+ }
41
+ _context.next = 3;
42
+ return makeRequest(identityURL);
43
+ case 3:
44
+ _yield$makeRequest = _context.sent;
45
+ json = _yield$makeRequest.json;
46
+ return _context.abrupt("return", json);
47
+ case 6:
48
+ case "end":
49
+ return _context.stop();
50
+ }
51
+ }, _callee);
52
+ }));
53
+ return function getIdentity() {
54
+ return _ref3.apply(this, arguments);
55
+ };
56
+ }();
57
+ if (required) return {
58
+ login: function () {
59
+ var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(data) {
60
+ var _yield$makeRequest2, json;
61
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
62
+ while (1) switch (_context2.prev = _context2.next) {
63
+ case 0:
64
+ if (authorizeURL) {
65
+ _context2.next = 2;
66
+ break;
67
+ }
68
+ throw {
69
+ message: "Authorization is not supported"
70
+ };
71
+ case 2:
72
+ _context2.next = 4;
73
+ return makeRequest(authorizeURL, {
74
+ data: data,
75
+ method: "POST"
76
+ });
77
+ case 4:
78
+ _yield$makeRequest2 = _context2.sent;
79
+ json = _yield$makeRequest2.json;
80
+ authSet(storage_name, json);
81
+ case 7:
82
+ case "end":
83
+ return _context2.stop();
84
+ }
85
+ }, _callee2);
86
+ }));
87
+ function login(_x) {
88
+ return _login.apply(this, arguments);
89
+ }
90
+ return login;
91
+ }(),
92
+ checkError: function () {
93
+ var _checkError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(error) {
94
+ var status;
95
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
96
+ while (1) switch (_context3.prev = _context3.next) {
97
+ case 0:
98
+ status = error.status;
99
+ if (!(status == 401 || status == 403)) {
100
+ _context3.next = 4;
101
+ break;
102
+ }
103
+ // Clean storage
104
+ authSet(storage_name, "");
105
+ throw {
106
+ message: "Invalid authorization",
107
+ redirectTo: logoutURL,
108
+ logoutUser: !logoutURL
109
+ };
110
+ case 4:
111
+ case "end":
112
+ return _context3.stop();
113
+ }
114
+ }, _callee3);
115
+ }));
116
+ function checkError(_x2) {
117
+ return _checkError.apply(this, arguments);
118
+ }
119
+ return checkError;
120
+ }(),
121
+ checkAuth: function () {
122
+ var _checkAuth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
123
+ var auth, user;
124
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
125
+ while (1) switch (_context4.prev = _context4.next) {
126
+ case 0:
127
+ auth = authGet(storage_name);
128
+ if (auth) {
129
+ _context4.next = 3;
130
+ break;
131
+ }
132
+ throw {
133
+ message: "Authorization required"
134
+ };
135
+ case 3:
136
+ if (identityURL) {
137
+ _context4.next = 5;
138
+ break;
139
+ }
140
+ return _context4.abrupt("return", auth);
141
+ case 5:
142
+ _context4.next = 7;
143
+ return getIdentity();
144
+ case 7:
145
+ user = _context4.sent;
146
+ if (user) {
147
+ _context4.next = 10;
148
+ break;
149
+ }
150
+ throw {
151
+ message: "Authorization required"
152
+ };
153
+ case 10:
154
+ return _context4.abrupt("return", user);
155
+ case 11:
156
+ case "end":
157
+ return _context4.stop();
158
+ }
159
+ }, _callee4);
160
+ }));
161
+ function checkAuth() {
162
+ return _checkAuth.apply(this, arguments);
163
+ }
164
+ return checkAuth;
165
+ }(),
166
+ logout: function () {
167
+ var _logout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
168
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
169
+ while (1) switch (_context5.prev = _context5.next) {
170
+ case 0:
171
+ // Clean storage
172
+ authSet(storage_name, "");
173
+ if (logoutURL) window.location = logoutURL;
174
+ case 2:
175
+ case "end":
176
+ return _context5.stop();
177
+ }
178
+ }, _callee5);
179
+ }));
180
+ function logout() {
181
+ return _logout.apply(this, arguments);
182
+ }
183
+ return logout;
184
+ }(),
185
+ getIdentity: getIdentity,
186
+ getPermissions: function getPermissions() {
187
+ var role = authGet(storage_name + "_role");
188
+ return role ? Promise.resolve(role) : Promise.reject();
189
+ }
190
+ };
191
+ });
@@ -0,0 +1,81 @@
1
+ import React from "react";
2
+ import { Button, useRefresh, useUnselectAll, useNotify, useRecordContext } from "react-admin";
3
+ import * as icons from "@mui/icons-material";
4
+ import useAction from "../hooks/useAction";
5
+ export var BulkActionButton = function BulkActionButton(_ref) {
6
+ var label = _ref.label,
7
+ icon = _ref.icon,
8
+ title = _ref.title,
9
+ action = _ref.action,
10
+ resource = _ref.resource,
11
+ selectedIds = _ref.selectedIds;
12
+ var refresh = useRefresh(),
13
+ unselectAll = useUnselectAll(resource),
14
+ notify = useNotify(),
15
+ Icon = icons[icon];
16
+ var mutation = useAction(resource, action);
17
+ var onClick = function onClick() {
18
+ mutation.mutate({
19
+ action: action,
20
+ ids: selectedIds
21
+ }, {
22
+ onSuccess: function onSuccess(_ref2) {
23
+ var data = _ref2.data;
24
+ if (data && data.message) notify(data.message, {
25
+ type: "success"
26
+ });
27
+ refresh();
28
+ unselectAll();
29
+ },
30
+ onError: function onError(err) {
31
+ notify(typeof err === "string" ? err : err.message, {
32
+ type: "error"
33
+ });
34
+ }
35
+ });
36
+ };
37
+ return /*#__PURE__*/React.createElement(Button, {
38
+ label: label,
39
+ title: title,
40
+ onClick: onClick,
41
+ disabled: mutation.isLoading
42
+ }, Icon && /*#__PURE__*/React.createElement(Icon, null));
43
+ };
44
+ export var ActionButton = function ActionButton(props) {
45
+ var icon = props.icon,
46
+ label = props.label,
47
+ title = props.title,
48
+ resource = props.resource,
49
+ action = props.action;
50
+ var record = useRecordContext();
51
+ var mutation = useAction(resource, action);
52
+ var refresh = useRefresh(),
53
+ notify = useNotify(),
54
+ Icon = icons[icon];
55
+ var onClick = function onClick() {
56
+ mutation.mutate({
57
+ record: record
58
+ }, {
59
+ onSuccess: function onSuccess(_ref3) {
60
+ var data = _ref3.data;
61
+ refresh();
62
+ if (data && data.redirectTo) window.location = data.redirectTo;
63
+ if (data && data.message) notify(data.message, {
64
+ type: "success"
65
+ });
66
+ },
67
+ onError: function onError(error) {
68
+ notify(typeof error === "string" ? error : error.message, {
69
+ type: "error"
70
+ });
71
+ }
72
+ });
73
+ };
74
+ return /*#__PURE__*/React.createElement(Button, {
75
+ label: label,
76
+ title: title,
77
+ onClick: onClick,
78
+ disabled: mutation.isLoading
79
+ }, Icon && /*#__PURE__*/React.createElement(Icon, null));
80
+ };
81
+ export default ActionButton;
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import { Button } from "react-admin";
3
+ import { Link } from "react-router-dom";
4
+ import * as icons from "@mui/icons-material";
5
+ var LinkButton = function LinkButton(_ref) {
6
+ var label = _ref.label,
7
+ icon = _ref.icon,
8
+ title = _ref.title,
9
+ resource = _ref.resource,
10
+ filters = _ref.filters;
11
+ var Icon = icons[icon] || icon;
12
+ var linkParams = {
13
+ pathname: "/".concat(resource),
14
+ search: filters ? "filter=".concat(JSON.stringify(filters)) : undefined
15
+ };
16
+ return /*#__PURE__*/React.createElement(Button, {
17
+ label: label,
18
+ title: title,
19
+ component: Link,
20
+ to: linkParams
21
+ }, Icon && /*#__PURE__*/React.createElement(Icon, null));
22
+ };
23
+ export default LinkButton;
@@ -0,0 +1,60 @@
1
+ import React from "react";
2
+ import { Grid, Card, CardContent, Typography, Table, TableBody, TableRow, TableCell } from "@mui/material";
3
+ import { setupAdmin } from "./utils";
4
+ var AdminTableView = function AdminTableView(_ref) {
5
+ var src = _ref.src;
6
+ return /*#__PURE__*/React.createElement(Table, null, /*#__PURE__*/React.createElement(TableBody, null, src.map(function (row, idx) {
7
+ return /*#__PURE__*/React.createElement(TableRow, {
8
+ key: idx,
9
+ hover: true
10
+ }, row.map(function (cell, idx) {
11
+ return /*#__PURE__*/React.createElement(TableCell, {
12
+ key: idx
13
+ }, cell);
14
+ }));
15
+ })));
16
+ };
17
+ var AdminCard = function AdminCard(_ref2) {
18
+ var src = _ref2.src;
19
+ if (Array.isArray(src)) {
20
+ return /*#__PURE__*/React.createElement(Grid, {
21
+ container: true,
22
+ item: true,
23
+ spacing: 2
24
+ }, src.map(function (card, idx) {
25
+ return /*#__PURE__*/React.createElement(AdminCard, {
26
+ key: idx,
27
+ src: card
28
+ });
29
+ }));
30
+ }
31
+ var title = src.title,
32
+ value = src.value;
33
+ return /*#__PURE__*/React.createElement(Grid, {
34
+ item: true,
35
+ xs: true
36
+ }, /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(CardContent, null, /*#__PURE__*/React.createElement(Typography, {
37
+ variant: "h5",
38
+ component: "h2",
39
+ m: 2,
40
+ style: {
41
+ textAlign: "center"
42
+ }
43
+ }, title), Array.isArray(value) && /*#__PURE__*/React.createElement(AdminTableView, {
44
+ src: value
45
+ }) || /*#__PURE__*/React.createElement("pre", null, JSON.stringify(value, null, 2)))));
46
+ };
47
+
48
+ // Process dashboard
49
+ setupAdmin("dashboard", function (props) {
50
+ if (!props) return;
51
+ var Dashboard = function Dashboard() {
52
+ return /*#__PURE__*/React.createElement(Grid, {
53
+ container: true,
54
+ spacing: 1
55
+ }, /*#__PURE__*/React.createElement(AdminCard, {
56
+ src: props
57
+ }));
58
+ };
59
+ return Dashboard;
60
+ });