muffin-admin 6.1.3 → 7.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/MuffinResource.js +5 -1
- package/dist/MuffinResourceEdit.d.ts +2 -0
- package/dist/MuffinResourceEdit.js +21 -7
- package/dist/MuffinResourceList.js +11 -7
- package/dist/MuffinResourceShow.js +3 -3
- package/dist/buildRA.js +14 -12
- package/dist/dataprovider.d.ts +1 -1
- package/dist/dataprovider.js +7 -3
- package/dist/inputs/FilterInput.d.ts +1 -0
- package/dist/inputs/FilterInput.js +42 -0
- package/dist/inputs/index.d.ts +1 -0
- package/dist/inputs/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +3 -2
- package/src/MuffinResource.tsx +9 -4
- package/src/MuffinResourceEdit.tsx +33 -20
- package/src/MuffinResourceList.tsx +17 -14
- package/src/MuffinResourceShow.tsx +3 -3
- package/src/buildRA.tsx +15 -12
- package/src/dataprovider.ts +9 -2
- package/src/i18n/ru.ts +2 -2
- package/src/inputs/FilterInput.tsx +67 -0
- package/src/inputs/index.ts +1 -0
- package/src/types.ts +7 -6
package/dist/MuffinResource.js
CHANGED
|
@@ -19,6 +19,10 @@ export function MuffinResource(_a) {
|
|
|
19
19
|
const opts = adminOpts === null || adminOpts === void 0 ? void 0 : adminOpts.resources.find((r) => r.name == name);
|
|
20
20
|
if (!opts)
|
|
21
21
|
return null;
|
|
22
|
-
|
|
22
|
+
const Create = findBuilder(["create", name]);
|
|
23
|
+
const Edit = findBuilder(["edit", name]);
|
|
24
|
+
const List = findBuilder(["list", name]);
|
|
25
|
+
const Show = findBuilder(["show", name]);
|
|
26
|
+
return (_jsx(Resource, Object.assign({ name: name, icon: findIcon(opts.icon), create: Create, edit: Edit, list: List, show: Show }, props), name));
|
|
23
27
|
}
|
|
24
28
|
setupAdmin(["resource"], MuffinResource);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
2
|
export declare function MuffinEdit({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare function MuffinEditFormToolbar(): import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export declare function MuffinEditInputs(): import("react/jsx-runtime").JSX.Element;
|
|
3
5
|
export declare function MuffinEditToolbar({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
4
6
|
export declare function MuffinEditActions({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,20 +3,34 @@ import { DeleteButton, Edit, ListButton, SaveButton, ShowButton, SimpleForm, Too
|
|
|
3
3
|
import { buildRA } from "./buildRA";
|
|
4
4
|
import { ActionButton } from "./buttons";
|
|
5
5
|
import { useMuffinAdminOpts, useMuffinResourceOpts } from "./hooks";
|
|
6
|
-
import {
|
|
6
|
+
import { findBuilder, setupAdmin } from "./utils";
|
|
7
7
|
export function MuffinEdit({ children }) {
|
|
8
8
|
const { adminProps: { mutationMode = "optimistic" }, } = useMuffinAdminOpts();
|
|
9
9
|
const { edit, name } = useMuffinResourceOpts();
|
|
10
10
|
if (!edit)
|
|
11
11
|
return null;
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} }))] }), children: buildAdmin(["edit-inputs", name], inputs) })] }));
|
|
12
|
+
const Actions = findBuilder(["edit-toolbar", name]);
|
|
13
|
+
const Inputs = findBuilder(["edit-inputs", name]);
|
|
14
|
+
const FormToolbar = findBuilder(["edit-form-toolbar", name]);
|
|
15
|
+
return (_jsxs(Edit, { actions: _jsx(Actions, {}), mutationMode: mutationMode, children: [children, _jsx(SimpleForm, { toolbar: _jsx(FormToolbar, {}), children: _jsx(Inputs, {}) })] }));
|
|
17
16
|
}
|
|
18
17
|
setupAdmin(["edit"], MuffinEdit);
|
|
19
|
-
|
|
18
|
+
export function MuffinEditFormToolbar() {
|
|
19
|
+
const { edit } = useMuffinResourceOpts();
|
|
20
|
+
if (!edit)
|
|
21
|
+
return null;
|
|
22
|
+
const { remove } = edit;
|
|
23
|
+
return (_jsxs(Toolbar, { children: [_jsx(SaveButton, {}), remove && _jsx(DeleteButton, { sx: { marginLeft: "auto" } })] }));
|
|
24
|
+
}
|
|
25
|
+
setupAdmin(["edit-form-toolbar"], MuffinEditFormToolbar);
|
|
26
|
+
export function MuffinEditInputs() {
|
|
27
|
+
const { edit } = useMuffinResourceOpts();
|
|
28
|
+
if (!edit)
|
|
29
|
+
return null;
|
|
30
|
+
const { inputs } = edit;
|
|
31
|
+
return _jsx(_Fragment, { children: buildRA(inputs) });
|
|
32
|
+
}
|
|
33
|
+
setupAdmin(["edit-inputs"], MuffinEditInputs);
|
|
20
34
|
export function MuffinEditToolbar({ children }) {
|
|
21
35
|
const resource = useResourceContext();
|
|
22
36
|
const Actions = findBuilder(["edit-actions", resource]);
|
|
@@ -2,21 +2,28 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import sortBy from "lodash/sortBy";
|
|
3
3
|
import uniq from "lodash/uniq";
|
|
4
4
|
import { BulkDeleteButton, BulkExportButton, CreateButton, DatagridConfigurable, EditButton, ExportButton, FilterButton, InfiniteList, List, Pagination, SelectColumnsButton, TopToolbar, } from "react-admin";
|
|
5
|
-
import { buildRA } from "./buildRA";
|
|
5
|
+
import { buildRA, buildRAComponent } from "./buildRA";
|
|
6
6
|
import { BulkActionButton, ListActionButton } from "./buttons";
|
|
7
7
|
import { HelpLink } from "./common/HelpLink";
|
|
8
8
|
import { useMuffinResourceOpts } from "./hooks";
|
|
9
9
|
import { buildAdmin, findBuilder, setupAdmin } from "./utils";
|
|
10
10
|
export function MuffinList({ children }) {
|
|
11
11
|
const { name, list } = useMuffinResourceOpts();
|
|
12
|
-
const { limit, limitMax, limitTotal,
|
|
12
|
+
const { limit, limitMax, limitTotal, sort, filters } = list;
|
|
13
13
|
const DataGrid = findBuilder(["list-grid", name]);
|
|
14
14
|
const Toolbar = findBuilder(["list-toolbar", name]);
|
|
15
|
-
|
|
15
|
+
const raFilters = buildAdmin(["list-filters", name], filters);
|
|
16
|
+
return limitTotal ? (_jsxs(List, { sort: sort, perPage: limit, filters: raFilters, actions: _jsx(Toolbar, {}), pagination: _jsx(Pagination, { rowsPerPageOptions: sortBy(uniq([10, 25, 50, 100, limit, limitMax])) }), children: [children, _jsx(DataGrid, {})] })) : (_jsxs(InfiniteList, { sort: sort, perPage: limit, actions: _jsx(Toolbar, {}), filters: raFilters, children: [children, _jsx(DataGrid, {})] }));
|
|
16
17
|
}
|
|
17
18
|
setupAdmin(["list"], MuffinList);
|
|
18
19
|
setupAdmin(["list-fields"], buildRA);
|
|
19
|
-
|
|
20
|
+
function muffinListFilters(filters) {
|
|
21
|
+
return filters.map((props) => {
|
|
22
|
+
const [rtype, opts] = props;
|
|
23
|
+
return buildRAComponent(rtype, Object.assign(Object.assign({}, opts), { variant: "outlined" }));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
setupAdmin(["list-filters"], muffinListFilters);
|
|
20
27
|
function MuffinListDatagrid() {
|
|
21
28
|
const { name, list } = useMuffinResourceOpts();
|
|
22
29
|
const { fields, edit, show } = list;
|
|
@@ -47,6 +54,3 @@ function MuffinListActions() {
|
|
|
47
54
|
return (_jsxs(_Fragment, { children: [actions.map((props) => (_jsx(BulkActionButton, Object.assign({}, props), props.id))), _jsx(BulkExportButton, {}), remove && _jsx(BulkDeleteButton, {})] }));
|
|
48
55
|
}
|
|
49
56
|
setupAdmin(["list-actions"], MuffinListActions);
|
|
50
|
-
function MuffinPagination() {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
@@ -7,10 +7,10 @@ import { useMuffinResourceOpts } from "./hooks";
|
|
|
7
7
|
import { buildAdmin, findBuilder, setupAdmin } from "./utils";
|
|
8
8
|
export function MuffinShow({ children }) {
|
|
9
9
|
const { show, name } = useMuffinResourceOpts();
|
|
10
|
-
const
|
|
11
|
-
return (_jsxs(Show, { actions: _jsx(
|
|
10
|
+
const ShowToolbar = findBuilder(["show-toolbar", name]);
|
|
11
|
+
return (_jsxs(Show, { actions: _jsx(ShowToolbar, {}), children: [children, _jsx(SimpleShowLayout, { children: buildAdmin(["show-fields", name], show) })] }));
|
|
12
12
|
}
|
|
13
|
-
setupAdmin(["show"],
|
|
13
|
+
setupAdmin(["show"], MuffinShow);
|
|
14
14
|
setupAdmin(["show-fields"], ({ fields }) => buildRA(fields));
|
|
15
15
|
export function MuffinShowToolbar({ children }) {
|
|
16
16
|
const { show, name } = useMuffinResourceOpts();
|
package/dist/buildRA.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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,
|
|
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, required, RichTextField, SelectArrayInput, SelectField, SelectInput, TextField, TextInput, UrlField, } from "react-admin";
|
|
3
3
|
import { AvatarField, EditableBooleanField, FKField, JsonField } from "./fields";
|
|
4
|
-
import { FKInput, JsonInput } from "./inputs";
|
|
4
|
+
import { FilterInput, FKInput, JsonInput } from "./inputs";
|
|
5
5
|
const UI = {
|
|
6
6
|
// Fields
|
|
7
7
|
BooleanField,
|
|
@@ -24,25 +24,27 @@ const UI = {
|
|
|
24
24
|
FKField,
|
|
25
25
|
JsonField,
|
|
26
26
|
// Inputs
|
|
27
|
+
ArrayInput,
|
|
28
|
+
AutocompleteArrayInput,
|
|
29
|
+
AutocompleteInput,
|
|
27
30
|
BooleanInput,
|
|
28
|
-
|
|
31
|
+
CheckboxGroupInput,
|
|
29
32
|
DateInput,
|
|
33
|
+
FilterInput,
|
|
30
34
|
DateTimeInput,
|
|
31
|
-
|
|
35
|
+
FKInput,
|
|
32
36
|
FileInput,
|
|
37
|
+
ImageInput,
|
|
38
|
+
JsonInput,
|
|
39
|
+
NullableBooleanInput,
|
|
33
40
|
NumberInput,
|
|
34
41
|
PasswordInput,
|
|
35
|
-
TextInput,
|
|
36
|
-
AutocompleteInput,
|
|
37
42
|
RadioButtonGroupInput,
|
|
38
|
-
SelectInput,
|
|
39
|
-
ArrayInput,
|
|
40
|
-
AutocompleteArrayInput,
|
|
41
|
-
CheckboxGroupInput,
|
|
42
43
|
ReferenceArrayInput,
|
|
43
44
|
ReferenceInput,
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
SelectInput,
|
|
46
|
+
TextInput,
|
|
47
|
+
SelectArrayInput,
|
|
46
48
|
};
|
|
47
49
|
export function buildRAComponent(name, props) {
|
|
48
50
|
const Item = UI[name];
|
package/dist/dataprovider.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ export declare function MuffinDataprovider(apiUrl: string): {
|
|
|
85
85
|
total?: undefined;
|
|
86
86
|
pageInfo?: undefined;
|
|
87
87
|
}>;
|
|
88
|
-
runAction: (
|
|
88
|
+
runAction: (_: string, action: string, props: TActionProps) => Promise<{
|
|
89
89
|
data: any;
|
|
90
90
|
}>;
|
|
91
91
|
};
|
package/dist/dataprovider.js
CHANGED
|
@@ -33,8 +33,12 @@ export function MuffinDataprovider(apiUrl) {
|
|
|
33
33
|
getList: (resource, params) => __awaiter(this, void 0, void 0, function* () {
|
|
34
34
|
const { filter, pagination, sort } = params;
|
|
35
35
|
const query = {};
|
|
36
|
-
if (filter)
|
|
37
|
-
query.where = JSON.stringify(filter)
|
|
36
|
+
if (filter) {
|
|
37
|
+
query.where = JSON.stringify(Object.entries(filter).reduce((acc, [key, value]) => {
|
|
38
|
+
acc[key] = Array.isArray(value) ? { $in: value } : value;
|
|
39
|
+
return acc;
|
|
40
|
+
}, {}));
|
|
41
|
+
}
|
|
38
42
|
if (pagination) {
|
|
39
43
|
const { page, perPage: limit } = pagination;
|
|
40
44
|
query.limit = limit;
|
|
@@ -97,7 +101,7 @@ export function MuffinDataprovider(apiUrl) {
|
|
|
97
101
|
filter[target] = id;
|
|
98
102
|
return yield methods.getList(resource, Object.assign({ filter }, opts));
|
|
99
103
|
}),
|
|
100
|
-
runAction: (
|
|
104
|
+
runAction: (_, action, props) => __awaiter(this, void 0, void 0, function* () {
|
|
101
105
|
const { payload, ids, record } = props;
|
|
102
106
|
action = action.replace(/^\/+/, "");
|
|
103
107
|
if (record) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function FilterInput({ type, ...props }: any): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
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, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import Button from "@mui/material/Button";
|
|
14
|
+
import FormGroup from "@mui/material/FormGroup";
|
|
15
|
+
import Menu from "@mui/material/Menu";
|
|
16
|
+
import MenuItem from "@mui/material/MenuItem";
|
|
17
|
+
import TextField from "@mui/material/TextField";
|
|
18
|
+
import { useState } from "react";
|
|
19
|
+
import { useInput } from "react-admin";
|
|
20
|
+
const OPERATORS = {
|
|
21
|
+
$eq: "=",
|
|
22
|
+
$ne: "≠",
|
|
23
|
+
$gt: ">",
|
|
24
|
+
$ge: "≥",
|
|
25
|
+
$lt: "<",
|
|
26
|
+
$le: "≤",
|
|
27
|
+
};
|
|
28
|
+
export function FilterInput(_a) {
|
|
29
|
+
var { type = "text" } = _a, props = __rest(_a, ["type"]);
|
|
30
|
+
const { field } = useInput(Object.assign({ format: (value) => (value ? value[Object.keys(value)[0]] : "") }, props));
|
|
31
|
+
const [op, setOp] = useState((field.value && Object.keys(field.value)[0]) || "$eq");
|
|
32
|
+
const onChange = function (e) {
|
|
33
|
+
field.onChange({ [op]: e.target.value });
|
|
34
|
+
};
|
|
35
|
+
const [menuEl, setMenuEl] = useState(null);
|
|
36
|
+
const open = Boolean(menuEl);
|
|
37
|
+
return (_jsxs(_Fragment, { children: [_jsxs(FormGroup, { row: true, sx: { flexWrap: "nowrap" }, children: [_jsx(Button, { size: "small", disableElevation: true, sx: { minWidth: 30 }, onClick: (e) => setMenuEl(e.currentTarget), children: _jsx("span", { style: { fontSize: "1.5em" }, children: OPERATORS[op] }) }), _jsx(TextField, Object.assign({}, field, { onChange: onChange, value: field.value, variant: "outlined", type: type }))] }), _jsx(Menu, { open: open, onClose: () => setMenuEl(null), anchorEl: menuEl, children: Object.entries(OPERATORS).map(([key, value]) => (_jsx(MenuItem, { selected: op === value, onClick: () => {
|
|
38
|
+
setOp(key);
|
|
39
|
+
setMenuEl(null);
|
|
40
|
+
field.onChange({ [key]: field.value });
|
|
41
|
+
}, children: value }, key))) })] }));
|
|
42
|
+
}
|
package/dist/inputs/index.d.ts
CHANGED
package/dist/inputs/index.js
CHANGED