react-admin-base-bootstrap 0.9.11 → 0.9.13
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.
|
@@ -41,7 +41,8 @@ export function Actions({ edit, del, rowSpan, children }) {
|
|
|
41
41
|
showCancelButton: true,
|
|
42
42
|
confirmButtonColor: '#3085d6',
|
|
43
43
|
cancelButtonColor: '#d33',
|
|
44
|
-
confirmButtonText: intl.formatMessage({ id: 'ACTIONS.DELETE.CONFIRM' })
|
|
44
|
+
confirmButtonText: intl.formatMessage({ id: 'ACTIONS.DELETE.CONFIRM' }),
|
|
45
|
+
cancelButtonText: intl.formatMessage({ id: 'ENTITY.CANCEL' }),
|
|
45
46
|
});
|
|
46
47
|
if (val.value) {
|
|
47
48
|
setLoading(true);
|
|
@@ -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
|
@@ -45,9 +45,10 @@ export function Actions({edit, del, rowSpan, children}: ActionsProp) {
|
|
|
45
45
|
showCancelButton: true,
|
|
46
46
|
confirmButtonColor: '#3085d6',
|
|
47
47
|
cancelButtonColor: '#d33',
|
|
48
|
-
confirmButtonText: intl.formatMessage({ id: 'ACTIONS.DELETE.CONFIRM' })
|
|
48
|
+
confirmButtonText: intl.formatMessage({ id: 'ACTIONS.DELETE.CONFIRM' }),
|
|
49
|
+
cancelButtonText: intl.formatMessage({ id: 'ENTITY.CANCEL' }),
|
|
49
50
|
});
|
|
50
|
-
|
|
51
|
+
|
|
51
52
|
if (val.value) {
|
|
52
53
|
setLoading(true);
|
|
53
54
|
try {
|
|
@@ -148,7 +149,7 @@ export default function BootstrapTable({url, bordered, noStrip, defaultParams, a
|
|
|
148
149
|
};
|
|
149
150
|
}
|
|
150
151
|
}, [setParams, innerRef]);
|
|
151
|
-
|
|
152
|
+
|
|
152
153
|
const fetchData = useCallback(async function(extraParams) {
|
|
153
154
|
if (body) {
|
|
154
155
|
const data = await api.tokenized.post(url, body, { params: { ...params, ...(extraParams || {}) } });
|
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();
|