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.
@@ -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, filters, sort } = list;
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
- return limitTotal ? (_jsxs(List, { sort: sort, perPage: limit, actions: _jsx(Toolbar, {}), filters: buildAdmin(["list-filters", name], filters), 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: buildAdmin(["list-filters", name], filters), children: [children, _jsx(DataGrid, {})] }));
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
- setupAdmin(["list-filters"], buildRA);
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, required, } from "react-admin";
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
- NullableBooleanInput,
31
+ CheckboxGroupInput,
29
32
  DateInput,
33
+ FilterInput,
30
34
  DateTimeInput,
31
- ImageInput,
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
- JsonInput,
45
- FKInput,
45
+ SelectInput,
46
+ TextInput,
47
+ SelectArrayInput,
46
48
  };
47
49
  export function buildRAComponent(name, props) {
48
50
  const Item = UI[name];
@@ -85,7 +85,7 @@ export declare function MuffinDataprovider(apiUrl: string): {
85
85
  total?: undefined;
86
86
  pageInfo?: undefined;
87
87
  }>;
88
- runAction: (resource: string, action: string, props: TActionProps) => Promise<{
88
+ runAction: (_: string, action: string, props: TActionProps) => Promise<{
89
89
  data: any;
90
90
  }>;
91
91
  };
@@ -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: (resource, action, props) => __awaiter(this, void 0, void 0, function* () {
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) {
@@ -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
+ }
@@ -1,2 +1,3 @@
1
+ export * from "./FilterInput";
1
2
  export * from "./FKInput";
2
3
  export * from "./JsonInput";
@@ -1,2 +1,3 @@
1
+ export * from "./FilterInput";
1
2
  export * from "./FKInput";
2
3
  export * from "./JsonInput";