muffin-admin 1.28.1 → 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/.babelrc +5 -0
- package/.eslintrc.json +44 -0
- package/admin.jsx +50 -46
- package/authprovider.js +53 -48
- package/buttons/ActionButton.jsx +76 -45
- package/buttons/LinkButton.jsx +12 -12
- package/dashboard.jsx +46 -29
- package/dataprovider.js +62 -49
- package/fields/AvatarField.jsx +28 -19
- package/fields/FKField.jsx +16 -12
- package/fields/JsonField.jsx +25 -0
- package/hooks/useAction.js +9 -0
- package/index.js +7 -4
- package/inputs/FKInput.jsx +29 -17
- package/inputs/JsonInput.jsx +62 -0
- package/jsconfig.json +9 -0
- package/package.json +15 -12
- package/resources.jsx +25 -15
- package/ui.jsx +89 -33
- package/utils.js +23 -19
- package/views/create.jsx +22 -18
- package/views/edit.jsx +34 -26
- package/views/list.jsx +62 -32
- package/views/show.jsx +35 -26
- package/webpack.config.js +19 -18
package/utils.js
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
|
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 ||
|
|
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
|
-
|
|
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 (
|
|
21
|
-
if (
|
|
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 = {
|
|
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
|
|
1
|
+
import React from 'react'
|
|
2
2
|
|
|
3
|
-
import { Create, SimpleForm, TopToolbar, ListButton } from
|
|
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(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
1
|
+
import React from 'react'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
import
|
|
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(
|
|
24
|
-
|
|
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=
|
|
36
|
+
children = processAdmin('list-fields', children, res)
|
|
37
|
+
if (edit) children.push(<EditButton key='edit-button' />)
|
|
28
38
|
|
|
29
|
-
pagination = pagination ||
|
|
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) =>
|
|
33
|
-
|
|
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
|
|
38
|
-
|
|
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(
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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
|
|
1
|
+
import React from 'react'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const path = require('path'),
|
|
1
|
+
const path = require('path'),
|
|
2
|
+
webpack = require('webpack'),
|
|
3
|
+
mode = process.env.NODE_ENV
|
|
2
4
|
|
|
3
5
|
module.exports = {
|
|
4
|
-
|
|
5
6
|
entry: '.',
|
|
6
7
|
|
|
7
8
|
output: {
|
|
@@ -15,29 +16,29 @@ module.exports = {
|
|
|
15
16
|
{
|
|
16
17
|
test: /\.jsx$/,
|
|
17
18
|
use: {
|
|
18
|
-
loader:
|
|
19
|
+
loader: 'babel-loader',
|
|
19
20
|
options: {
|
|
20
|
-
presets: [
|
|
21
|
-
plugins: [
|
|
21
|
+
presets: ['@babel/preset-env', '@babel/preset-react'],
|
|
22
|
+
plugins: ['@babel/plugin-transform-runtime'],
|
|
22
23
|
},
|
|
23
24
|
},
|
|
24
25
|
},
|
|
25
|
-
]
|
|
26
|
+
],
|
|
26
27
|
},
|
|
27
28
|
|
|
28
|
-
plugins: [
|
|
29
|
-
new webpack.EnvironmentPlugin({NODE_ENV: 'production'}),
|
|
30
|
-
],
|
|
29
|
+
plugins: [new webpack.EnvironmentPlugin({ NODE_ENV: 'production' })],
|
|
31
30
|
|
|
32
|
-
mode: mode ||
|
|
33
|
-
devtool: mode ==
|
|
31
|
+
mode: mode || 'production',
|
|
32
|
+
devtool: mode == 'development' && 'inline-source-map',
|
|
34
33
|
|
|
35
34
|
devServer: {
|
|
36
35
|
hot: true,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
open: true,
|
|
37
|
+
proxy: [
|
|
38
|
+
{
|
|
39
|
+
context: ['!*.js'],
|
|
40
|
+
target: 'http://localhost:5000',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
}
|