react-admin-base-bootstrap 0.9.11 → 0.9.12
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.
|
@@ -7,9 +7,10 @@ type ModalEntityEditorParams = {
|
|
|
7
7
|
url?: string;
|
|
8
8
|
onReload?: any;
|
|
9
9
|
disabled?: Boolean;
|
|
10
|
+
beforeSave?: () => Promise<Boolean> | Boolean;
|
|
10
11
|
children: React.ReactNode;
|
|
11
12
|
};
|
|
12
|
-
export declare function ModalEntityEditor({ entity, title, size, url, onReload, disabled, children }: ModalEntityEditorParams): React.JSX.Element;
|
|
13
|
+
export declare function ModalEntityEditor({ entity, title, size, url, onReload, disabled, beforeSave, children }: ModalEntityEditorParams): React.JSX.Element;
|
|
13
14
|
type CrudActionProps = {
|
|
14
15
|
id: any;
|
|
15
16
|
edit?: Boolean;
|
|
@@ -27,7 +27,7 @@ import LoadingButton from '../Components/LoadingButton';
|
|
|
27
27
|
import BootstrapDataTable, { Actions } from './BootstrapDataTable';
|
|
28
28
|
import BootstrapModal from './BootstrapModal';
|
|
29
29
|
import { useBootstrapOptions } from "./BootstrapOptions";
|
|
30
|
-
export function ModalEntityEditor({ entity, title, size, url, onReload, disabled, children }) {
|
|
30
|
+
export function ModalEntityEditor({ entity, title, size, url, onReload, disabled, beforeSave, children }) {
|
|
31
31
|
const [data, , save, loading, dirty] = entity;
|
|
32
32
|
const bsOptions = useBootstrapOptions();
|
|
33
33
|
const [open, setOpen] = useState(true);
|
|
@@ -44,12 +44,14 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
44
44
|
setError(null);
|
|
45
45
|
}
|
|
46
46
|
try {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
if (!beforeSave || (yield beforeSave())) {
|
|
48
|
+
let data = yield save();
|
|
49
|
+
if (onReload) {
|
|
50
|
+
yield onReload(data);
|
|
51
|
+
}
|
|
52
|
+
if (url) {
|
|
53
|
+
setSaved(true);
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
catch (e) {
|
|
@@ -59,7 +61,7 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
59
61
|
finally {
|
|
60
62
|
}
|
|
61
63
|
});
|
|
62
|
-
}, [save, saved, error, onReload, url]);
|
|
64
|
+
}, [save, saved, error, onReload, url, beforeSave]);
|
|
63
65
|
const check = bsOptions.noCloseOnSave && dirty;
|
|
64
66
|
const intl = useIntl();
|
|
65
67
|
const checkConfirmText = intl.formatMessage({ id: 'CANCEL_ENTITY_SAVE' });
|
package/package.json
CHANGED
package/src/Components/CRUD.tsx
CHANGED
|
@@ -15,10 +15,11 @@ type ModalEntityEditorParams = {
|
|
|
15
15
|
url?: string;
|
|
16
16
|
onReload?: any;
|
|
17
17
|
disabled?: Boolean;
|
|
18
|
+
beforeSave?: () => Promise<Boolean> | Boolean;
|
|
18
19
|
children: React.ReactNode;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export function ModalEntityEditor({ entity, title, size, url, onReload, disabled, children } : ModalEntityEditorParams) {
|
|
22
|
+
export function ModalEntityEditor({ entity, title, size, url, onReload, disabled, beforeSave, children } : ModalEntityEditorParams) {
|
|
22
23
|
const [ data, , save, loading, dirty ] = entity;
|
|
23
24
|
const bsOptions = useBootstrapOptions();
|
|
24
25
|
|
|
@@ -30,7 +31,6 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
30
31
|
e.stopPropagation();
|
|
31
32
|
e.preventDefault();
|
|
32
33
|
|
|
33
|
-
|
|
34
34
|
if (saved) {
|
|
35
35
|
setSaved(false);
|
|
36
36
|
}
|
|
@@ -40,6 +40,7 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
try {
|
|
43
|
+
if (!beforeSave || await beforeSave()) {
|
|
43
44
|
let data = await save();
|
|
44
45
|
if (onReload) {
|
|
45
46
|
await onReload(data);
|
|
@@ -48,6 +49,7 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
48
49
|
if (url) {
|
|
49
50
|
setSaved(true);
|
|
50
51
|
}
|
|
52
|
+
}
|
|
51
53
|
} catch(e) {
|
|
52
54
|
console.error(e);
|
|
53
55
|
setError((e.response && e.response.data && e.response.data.message) || (error.data && error.data.message) || e.data || e.message || e);
|
|
@@ -56,7 +58,7 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
56
58
|
{
|
|
57
59
|
|
|
58
60
|
}
|
|
59
|
-
}, [save, saved, error, onReload, url]);
|
|
61
|
+
}, [save, saved, error, onReload, url, beforeSave]);
|
|
60
62
|
|
|
61
63
|
const check = bsOptions.noCloseOnSave && dirty;
|
|
62
64
|
const intl = useIntl();
|