muffin-admin 1.29.0 → 1.30.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/utils.js CHANGED
@@ -1,35 +1,39 @@
1
- import React from "react";
1
+ /* eslint-disable no-console */
2
2
 
3
- import { fetchUtils } from 'ra-core';
4
- import { stringify } from 'query-string';
5
- import { required } from 'react-admin';
3
+ import { isValidElement } from 'react'
6
4
 
5
+ import { fetchUtils } from 'ra-core'
6
+ import { stringify } from 'query-string'
7
7
 
8
- const admin = globalThis.admin = globalThis.admin || {};
8
+ const parts = {}
9
+
10
+ export const setupAdmin = (part, gen) => (parts[part] = gen)
9
11
 
10
- export const setupAdmin = globalThis.setupAdmin = (type, fn) => admin[type] = fn
11
12
  export const checkParams = (fn) => (props, res) => {
12
- if (!props || React.isValidElement(props)) return props;
13
- return fn(props, res);
13
+ if (!props || isValidElement(props)) return props
14
+ return fn(props, res)
14
15
  }
15
- export const processAdmin = (type, props, res) => {
16
- let callbacks = [], result = props;
17
16
 
18
- if (process.env.NODE_ENV == 'development') console.log(`${type}${ res ? '-' + res : ''}`, props);
17
+ export const processAdmin = (type, props, res) => {
18
+ if (process.env.NODE_ENV == 'development')
19
+ console.log(`${type}${res ? '-' + res : ''}`, props)
19
20
 
20
- if (admin[`${type}-${res}`]) return admin[`${type}-${res}`](props, res);
21
- if (admin[type]) return admin[type](props, res);
21
+ if (parts[`${type}-${res}`]) return parts[`${type}-${res}`](props, res)
22
+ if (parts[type]) return parts[type](props, res)
22
23
  }
23
24
 
24
- export const requestHeaders = {};
25
+ export const requestHeaders = {}
25
26
 
26
27
  export const makeRequest = (url, params) => {
27
- let {data, query, ...opts} = params || {};
28
+ let { data, query, ...opts } = params || {}
28
29
 
29
- if (data) opts.body = JSON.stringify(data);
30
- if (query) url = `${url}?${stringify(query)}`;
30
+ if (data) opts.body = JSON.stringify(data)
31
+ if (query) url = `${url}?${stringify(query)}`
31
32
 
32
- opts = {...opts, headers: new Headers({...requestHeaders, ...opts.headers})}
33
+ opts = {
34
+ ...opts,
35
+ headers: new Headers({ ...requestHeaders, ...opts.headers }),
36
+ }
33
37
 
34
- return fetchUtils.fetchJson(url, opts);
38
+ return fetchUtils.fetchJson(url, opts)
35
39
  }
package/views/create.jsx CHANGED
@@ -1,26 +1,30 @@
1
- import React from "react";
1
+ import React from 'react'
2
2
 
3
- import { Create, SimpleForm, TopToolbar, ListButton } from "react-admin";
3
+ import { Create, SimpleForm, TopToolbar, ListButton } from 'react-admin'
4
4
 
5
5
  import initRAItems from '../ui.jsx'
6
6
  import { checkParams, processAdmin, setupAdmin } from '../utils'
7
7
 
8
-
9
8
  // Initialize a create component
10
- setupAdmin('create', checkParams((inputs, res) => props => {
11
-
12
- const Actions = ({basePath}) => (
13
- <TopToolbar>
14
- <ListButton basePath={ basePath } />
15
- </TopToolbar>
16
- )
9
+ setupAdmin(
10
+ 'create',
11
+ checkParams(
12
+ (inputs, res) =>
13
+ function MACreate(props) {
14
+ const Actions = (
15
+ <TopToolbar>
16
+ <ListButton />
17
+ </TopToolbar>
18
+ )
17
19
 
18
- return (
19
- <Create actions={ <Actions /> } {...props}>
20
- <SimpleForm children={ processAdmin('create-inputs', inputs, res) } />
21
- </Create>
20
+ return (
21
+ <Create actions={Actions} {...props}>
22
+ <SimpleForm>
23
+ {processAdmin('create-inputs', inputs, res)}
24
+ </SimpleForm>
25
+ </Create>
26
+ )
27
+ }
22
28
  )
23
- }
24
- ));
25
- setupAdmin('create-inputs', initRAItems);
26
-
29
+ )
30
+ setupAdmin('create-inputs', initRAItems)
package/views/edit.jsx CHANGED
@@ -1,34 +1,42 @@
1
- import React from "react";
1
+ import React from 'react'
2
2
 
3
- import { Edit, ListButton, ShowButton, SimpleForm, TopToolbar } from "react-admin";
3
+ import {
4
+ Edit,
5
+ ListButton,
6
+ ShowButton,
7
+ SimpleForm,
8
+ TopToolbar,
9
+ } from 'react-admin'
4
10
 
5
11
  import initRAItems from '../ui.jsx'
6
12
  import { checkParams, processAdmin, setupAdmin } from '../utils'
7
13
 
8
14
  import { ActionButton } from '../buttons/ActionButton.jsx'
9
15
 
10
-
11
16
  // Initialize an edit component
12
- setupAdmin('edit', checkParams(({actions, inputs}, res) => props => {
13
-
14
- const Actions = ({basePath, data, resource, ...baseProps}) => (
15
- <TopToolbar>
16
- {
17
- actions.map((props, idx) => {
18
- let aProps = {resource, basePath, ...baseProps, ...props};
19
- return <ActionButton key={ idx } {...aProps} />
20
- })
21
- }
22
- <ListButton basePath={ basePath } />
23
- <ShowButton basePath={basePath} record={data} />
24
- </TopToolbar>
25
- )
26
-
27
- return (
28
- <Edit actions={ <Actions /> } { ...props }>
29
- <SimpleForm children={ processAdmin('edit-inputs', inputs, res) } />
30
- </Edit>
31
- )
32
- }));
33
-
34
- setupAdmin('edit-inputs', initRAItems);
17
+ setupAdmin(
18
+ 'edit',
19
+ checkParams(
20
+ ({ actions, inputs }, res) =>
21
+ function MAEdit(props) {
22
+ const Actions = ({ basePath, resource, ...baseProps }) => (
23
+ <TopToolbar>
24
+ {actions.map((props, idx) => {
25
+ let aProps = { resource, basePath, ...baseProps, ...props }
26
+ return <ActionButton key={idx} {...aProps} />
27
+ })}
28
+ <ListButton />
29
+ <ShowButton />
30
+ </TopToolbar>
31
+ )
32
+
33
+ return (
34
+ <Edit actions={<Actions />} {...props}>
35
+ <SimpleForm>{processAdmin('edit-inputs', inputs, res)}</SimpleForm>
36
+ </Edit>
37
+ )
38
+ }
39
+ )
40
+ )
41
+
42
+ setupAdmin('edit-inputs', initRAItems)
package/views/list.jsx CHANGED
@@ -1,56 +1,86 @@
1
- import React from "react";
1
+ import React from 'react'
2
2
 
3
- import {
3
+ import {
4
4
  BulkDeleteButton,
5
5
  Datagrid,
6
6
  EditButton,
7
7
  Filter,
8
8
  List,
9
9
  Pagination,
10
- Show,
11
- } from "react-admin";
12
- import uniq from "lodash/uniq";
13
- import sortBy from "lodash/sortBy";
10
+ } from 'react-admin'
11
+ import uniq from 'lodash/uniq'
12
+ import sortBy from 'lodash/sortBy'
14
13
 
15
14
  import initRAItems from '../ui.jsx'
16
15
  import { checkParams, processAdmin, setupAdmin } from '../utils'
17
16
  import { BulkActionButton } from '../buttons/ActionButton.jsx'
18
17
 
19
-
20
- const defaultPagination = <Pagination rowsPerPageOptions={[10, 25, 50, 100]} />;
18
+ const defaultPagination = <Pagination rowsPerPageOptions={[10, 25, 50, 100]} />
21
19
 
22
20
  // Initiliaze a list component
23
- setupAdmin('list', checkParams((props, res) => {
24
- let {children, filters, edit, pagination, show, limit, limitMax, actions, ...listProps } = props;
21
+ setupAdmin(
22
+ 'list',
23
+ checkParams((props, res) => {
24
+ let {
25
+ children,
26
+ filters,
27
+ edit,
28
+ pagination,
29
+ show,
30
+ limit,
31
+ limitMax,
32
+ actions,
33
+ ...listProps
34
+ } = props
25
35
 
26
- children = processAdmin('list-fields', children, res);
27
- if (edit) children.push(<EditButton key="edit-button" />);
36
+ children = processAdmin('list-fields', children, res)
37
+ if (edit) children.push(<EditButton key='edit-button' />)
28
38
 
29
- pagination = pagination || <Pagination rowsPerPageOptions={sortBy(uniq([10, 25, 50, 100, limit, limitMax]))} />
39
+ pagination = pagination || (
40
+ <Pagination
41
+ rowsPerPageOptions={sortBy(uniq([10, 25, 50, 100, limit, limitMax]))}
42
+ />
43
+ )
30
44
 
31
- return props => {
32
- let Filters = (props) => <Filter { ...props } children={ processAdmin('list-filters', filters, res) } />
33
- let Actions = processAdmin('list-bulkActions', actions);
45
+ return function MAList(props) {
46
+ let Filters = (props) => (
47
+ <Filter {...props}>{processAdmin('list-filters', filters, res)}</Filter>
48
+ )
49
+ let Actions = processAdmin('list-bulkActions', actions)
34
50
 
35
- props = { ...props, ...listProps };
51
+ props = { ...props, ...listProps }
36
52
  return (
37
- <List filters={ <Filters /> } bulkActionButtons={ <Actions /> } perPage={ limit } pagination={ pagination || defaultPagination } { ...props }>
38
- <Datagrid rowClick={ show ? "show" : null } children={ children } />
53
+ <List
54
+ filters={<Filters />}
55
+ bulkActionButtons={<Actions />}
56
+ perPage={limit}
57
+ pagination={pagination || defaultPagination}
58
+ {...props}
59
+ >
60
+ <Datagrid rowClick={show ? 'show' : null}>{children}</Datagrid>
39
61
  </List>
40
62
  )
41
- };
42
- }));
63
+ }
64
+ })
65
+ )
43
66
 
44
- setupAdmin('list-bulkActions', actions => props => {
45
- let buttons = actions.map((action, idx) => {
46
- let aProps = { ...action, ...props };
67
+ setupAdmin(
68
+ 'list-bulkActions',
69
+ (actions) =>
70
+ function MABulkActions(props) {
71
+ let buttons = actions.map((action, idx) => {
72
+ let aProps = { ...action, ...props }
47
73
  return <BulkActionButton key={idx} {...aProps} />
48
- })
74
+ })
75
+
76
+ return (
77
+ <>
78
+ {buttons}
79
+ <BulkDeleteButton {...props} />
80
+ </>
81
+ )
82
+ }
83
+ )
49
84
 
50
- return <>
51
- { buttons }
52
- <BulkDeleteButton {...props} />
53
- </>
54
- });
55
- setupAdmin('list-filters', initRAItems);
56
- setupAdmin('list-fields', initRAItems);
85
+ setupAdmin('list-filters', initRAItems)
86
+ setupAdmin('list-fields', initRAItems)
package/views/show.jsx CHANGED
@@ -1,34 +1,43 @@
1
- import React from "react";
1
+ import React from 'react'
2
2
 
3
- import { ListButton, EditButton, Show, SimpleShowLayout, TopToolbar } from "react-admin";
3
+ import {
4
+ ListButton,
5
+ EditButton,
6
+ Show,
7
+ SimpleShowLayout,
8
+ TopToolbar,
9
+ } from 'react-admin'
4
10
 
5
11
  import initRAItems from '../ui.jsx'
6
12
  import { checkParams, processAdmin, setupAdmin } from '../utils'
7
13
 
8
14
  import { ActionButton } from '../buttons/ActionButton.jsx'
9
15
 
10
-
11
16
  // Initiliaze a show component
12
- setupAdmin('show', checkParams(({actions, fields}, res) => props => {
13
-
14
- const Actions = ({basePath, data, resource, ...baseProps}) => (
15
- <TopToolbar>
16
- {
17
- actions.map((props, idx) => {
18
- let aProps = {resource, basePath, record: data, ...baseProps, ...props};
19
- return <ActionButton key={ idx } {...aProps} />
20
- })
21
- }
22
- <ListButton basePath={ basePath } />
23
- <EditButton basePath={basePath} record={data} />
24
- </TopToolbar>
25
- )
26
-
27
- return (
28
- <Show actions={ <Actions /> } {...props}>
29
- <SimpleShowLayout children={ processAdmin('show-fields', fields, res) } />
30
- </Show>
31
- )
32
- }));
33
-
34
- setupAdmin('show-fields', initRAItems);
17
+ setupAdmin(
18
+ 'show',
19
+ checkParams(
20
+ ({ actions, fields }, resource) =>
21
+ function MAShow(props) {
22
+ const Actions = () => (
23
+ <TopToolbar>
24
+ {actions.map((props, idx) => {
25
+ return <ActionButton key={idx} resource={resource} {...props} />
26
+ })}
27
+ <ListButton />
28
+ <EditButton />
29
+ </TopToolbar>
30
+ )
31
+
32
+ return (
33
+ <Show actions={<Actions />} {...props}>
34
+ <SimpleShowLayout>
35
+ {processAdmin('show-fields', fields, resource)}
36
+ </SimpleShowLayout>
37
+ </Show>
38
+ )
39
+ }
40
+ )
41
+ )
42
+
43
+ setupAdmin('show-fields', initRAItems)
package/webpack.config.js CHANGED
@@ -33,6 +33,7 @@ module.exports = {
33
33
 
34
34
  devServer: {
35
35
  hot: true,
36
+ open: true,
36
37
  proxy: [
37
38
  {
38
39
  context: ['!*.js'],