@applica-software-guru/react-admin 1.1.104 → 1.1.107
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/components/ra-forms/Create.d.ts +8 -21
- package/dist/components/ra-forms/Create.d.ts.map +1 -1
- package/dist/components/ra-forms/index.d.ts +2 -1
- package/dist/components/ra-forms/index.d.ts.map +1 -1
- package/dist/components/ra-lists/List.d.ts.map +1 -1
- package/dist/react-admin.cjs.js +50 -50
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +4018 -4000
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +51 -51
- package/dist/react-admin.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ra-forms/Create.tsx +66 -2
- package/src/components/ra-forms/index.jsx +2 -1
- package/src/components/ra-lists/List.tsx +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,69 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { useCallback, createContext, useContext } from 'react';
|
|
3
|
+
import { CreateProps, Identifier, Create as RaCreate, RaRecord, useDataProvider, useResourceContext } from 'react-admin';
|
|
2
4
|
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { useLocation } from 'react-router';
|
|
6
|
+
import { useQuery } from 'react-query';
|
|
7
|
+
import { Stack, CircularProgress } from '@mui/material';
|
|
3
8
|
|
|
4
|
-
|
|
9
|
+
type ICreateProps<
|
|
10
|
+
RecordType extends Omit<RaRecord, 'id'> = any,
|
|
11
|
+
ResultRecordType extends RaRecord = RecordType & { id: Identifier }
|
|
12
|
+
> = CreateProps<RecordType, Error, ResultRecordType> & {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
useDefaults?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type IResourceDefaultValue = object;
|
|
18
|
+
const ResourceDefaultValueContext = createContext<IResourceDefaultValue>({});
|
|
19
|
+
|
|
20
|
+
function Create(props: ICreateProps) {
|
|
21
|
+
const { useDefaults = false } = props,
|
|
22
|
+
resource = useResourceContext(),
|
|
23
|
+
dataProvider = useDataProvider(),
|
|
24
|
+
{ search } = useLocation(),
|
|
25
|
+
url = `${resource}/new`,
|
|
26
|
+
fetch = useCallback(() => {
|
|
27
|
+
if (!useDefaults || !_.isFunction(dataProvider.get)) {
|
|
28
|
+
return Promise.resolve({});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const params: { [key in string]: string } = {};
|
|
32
|
+
new URLSearchParams(search ?? '').forEach((v, k) => {
|
|
33
|
+
params[k] = v;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return dataProvider
|
|
37
|
+
.get(url, params)
|
|
38
|
+
.then((response: { data: object }) => response.data)
|
|
39
|
+
.then((data: { responseCode: string; value: object }) => {
|
|
40
|
+
const { responseCode, value } = data;
|
|
41
|
+
if (responseCode === 'ok') {
|
|
42
|
+
return value;
|
|
43
|
+
} else {
|
|
44
|
+
return Promise.reject(data);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}, [resource, useDefaults, search, dataProvider]),
|
|
48
|
+
{ data, isLoading } = useQuery({ queryKey: [resource, search], queryFn: fetch }),
|
|
49
|
+
passProps = _.omit(props, ['useDefaults']);
|
|
50
|
+
|
|
51
|
+
return isLoading ? (
|
|
52
|
+
<Stack alignItems={'center'} justifyContent="center" flex={1} p={2}>
|
|
53
|
+
<CircularProgress />
|
|
54
|
+
</Stack>
|
|
55
|
+
) : (
|
|
56
|
+
<ResourceDefaultValueContext.Provider value={data ?? {}}>
|
|
57
|
+
<RaCreate {...passProps} />
|
|
58
|
+
</ResourceDefaultValueContext.Provider>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function useResourceDefaultValues(): IResourceDefaultValue {
|
|
63
|
+
return useContext(ResourceDefaultValueContext);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const StyledCreate = styled(Create, {
|
|
5
67
|
name: 'RaApplicaEdit',
|
|
6
68
|
slot: 'root'
|
|
7
69
|
})(({ theme }) => ({
|
|
@@ -14,3 +76,5 @@ const StyledCreate = styled(RaCreate, {
|
|
|
14
76
|
}));
|
|
15
77
|
|
|
16
78
|
export default StyledCreate;
|
|
79
|
+
|
|
80
|
+
export { useResourceDefaultValues };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import CardForm from './CardForm';
|
|
2
2
|
import ChangePasswordForm from './ChangePasswordForm';
|
|
3
|
-
import Create from './Create';
|
|
3
|
+
import Create, { useResourceDefaultValues } from './Create';
|
|
4
4
|
import Edit from './Edit';
|
|
5
5
|
import FormHeader from './FormHeader';
|
|
6
6
|
import LongForm from './LongForm';
|
|
@@ -11,6 +11,7 @@ import TableFormIterator from './TableForm';
|
|
|
11
11
|
import Toolbar from './Toolbar';
|
|
12
12
|
export {
|
|
13
13
|
Create,
|
|
14
|
+
useResourceDefaultValues,
|
|
14
15
|
CardForm,
|
|
15
16
|
ChangePasswordForm,
|
|
16
17
|
Edit,
|