muffin-admin 6.2.0 → 7.0.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/MuffinResourceList.js +11 -7
- package/dist/buildRA.js +14 -12
- package/dist/dataprovider.d.ts +1 -1
- package/dist/dataprovider.js +7 -3
- package/dist/inputs/FKInput.js +1 -1
- 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/package.json +3 -2
- package/src/MuffinResourceList.tsx +17 -14
- package/src/buildRA.tsx +15 -12
- package/src/dataprovider.ts +9 -2
- package/src/i18n/ru.ts +2 -2
- package/src/inputs/FKInput.tsx +7 -1
- package/src/inputs/FilterInput.tsx +67 -0
- package/src/inputs/index.ts +1 -0
- package/src/types.ts +6 -6
|
@@ -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
|
-
}
|
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) {
|
package/dist/inputs/FKInput.js
CHANGED
|
@@ -26,5 +26,5 @@ export function FKInput(_a) {
|
|
|
26
26
|
return `#${pk}`;
|
|
27
27
|
return (pk && `${record[refSource]} (#${pk})`) || "";
|
|
28
28
|
};
|
|
29
|
-
return (_jsx(ReferenceInput, { reference: reference, source: source, children: _jsx(AutocompleteInput, Object.assign({ source: refKey, optionText: renderText, fullWidth: fullWidth }, props)) }));
|
|
29
|
+
return (_jsx(ReferenceInput, { reference: reference, source: source, children: _jsx(AutocompleteInput, Object.assign({ source: refKey, optionText: renderText, fullWidth: fullWidth, sx: { minWidth: 300 } }, props)) }));
|
|
30
30
|
}
|
|
@@ -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