react-admin-base-bootstrap 0.8.15 → 0.8.17
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/lib/esm/Components/BootstrapDataTable.d.ts +2 -1
- package/lib/esm/Components/BootstrapDataTable.js +2 -2
- package/lib/esm/Components/BootstrapOptions.d.ts +3 -1
- package/lib/esm/Components/BootstrapOptions.js +5 -3
- package/lib/esm/Components/CRUD.js +9 -3
- package/package.json +2 -2
- package/src/Components/BootstrapDataTable.tsx +4 -3
- package/src/Components/BootstrapOptions.tsx +7 -3
- package/src/Components/CRUD.tsx +9 -7
|
@@ -21,11 +21,12 @@ export interface BootstrapTableProps {
|
|
|
21
21
|
add?: string;
|
|
22
22
|
children: any;
|
|
23
23
|
innerRef?: any;
|
|
24
|
+
noSearch?: boolean;
|
|
24
25
|
}
|
|
25
26
|
interface RowRendererProps<Row = any> {
|
|
26
27
|
render: (row: Row) => React.ReactNode;
|
|
27
28
|
}
|
|
28
29
|
export declare function RowRenderer<Row = any>({ render }: RowRendererProps<Row>): React.JSX.Element;
|
|
29
30
|
export declare function CustomRenderer<Row = any>({ render }: RowRendererProps<Row>): React.JSX.Element;
|
|
30
|
-
export default function BootstrapTable({ url, bordered, noStrip, defaultParams, add, children, innerRef, body }: BootstrapTableProps): React.JSX.Element;
|
|
31
|
+
export default function BootstrapTable({ url, bordered, noStrip, defaultParams, add, noSearch, children, innerRef, body }: BootstrapTableProps): React.JSX.Element;
|
|
31
32
|
export {};
|
|
@@ -90,7 +90,7 @@ export function CustomRenderer({ render }) {
|
|
|
90
90
|
const rows = useContext(RowDatasContext);
|
|
91
91
|
return React.createElement(React.Fragment, null, rows.map(render));
|
|
92
92
|
}
|
|
93
|
-
export default function BootstrapTable({ url, bordered, noStrip, defaultParams, add, children, innerRef, body }) {
|
|
93
|
+
export default function BootstrapTable({ url, bordered, noStrip, defaultParams, add, noSearch = false, children, innerRef, body }) {
|
|
94
94
|
const state = useState(Object.assign({ sort: 'id' }, defaultParams));
|
|
95
95
|
const [params, setParams] = state;
|
|
96
96
|
const [page, lastPage, setPage, data, itemPerPage, setItemPerPage, update, count] = useDataTable(url, params, body);
|
|
@@ -141,7 +141,7 @@ export default function BootstrapTable({ url, bordered, noStrip, defaultParams,
|
|
|
141
141
|
React.createElement("option", { value: "200" }, "200"),
|
|
142
142
|
React.createElement("option", { value: "-1" }, intl.formatMessage({ id: "ALL" })))),
|
|
143
143
|
children[2],
|
|
144
|
-
React.createElement(Col, { md: "3", className: "ms-auto" },
|
|
144
|
+
!noSearch && React.createElement(Col, { md: "3", className: "ms-auto" },
|
|
145
145
|
React.createElement(Input, { placeholder: intl.formatMessage({ id: "SEARCH" }), type: "text", value: params.query || '', onChange: e => setParams(Object.assign(Object.assign({}, params), { query: e.currentTarget.value })) }))),
|
|
146
146
|
children[3]),
|
|
147
147
|
data === null ? React.createElement(Alert, { className: "text-center mb-0 mx-3 ", color: "warning" },
|
|
@@ -2,10 +2,12 @@ import React, { ReactNode } from "react";
|
|
|
2
2
|
import BootstrapOptions from "./BootstrapOptions";
|
|
3
3
|
interface BootstrapOptions {
|
|
4
4
|
noCloseModal: boolean;
|
|
5
|
+
noCloseOnSave: boolean;
|
|
6
|
+
onlySaveOnDirty: boolean;
|
|
5
7
|
}
|
|
6
8
|
interface BootstrapOptionsProviderProps extends BootstrapOptions {
|
|
7
9
|
children: ReactNode;
|
|
8
10
|
}
|
|
9
11
|
export declare function useBootstrapOptions(): BootstrapOptions;
|
|
10
|
-
export default function BootstrapOptionsProvider({ children, noCloseModal }: BootstrapOptionsProviderProps): React.JSX.Element;
|
|
12
|
+
export default function BootstrapOptionsProvider({ children, noCloseModal, noCloseOnSave, onlySaveOnDirty }: BootstrapOptionsProviderProps): React.JSX.Element;
|
|
11
13
|
export {};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React, { createContext, useContext, useMemo } from "react";
|
|
2
2
|
const BootstrapOptionsContext = createContext({
|
|
3
|
-
noCloseModal: false
|
|
3
|
+
noCloseModal: false,
|
|
4
|
+
noCloseOnSave: false,
|
|
5
|
+
onlySaveOnDirty: false
|
|
4
6
|
});
|
|
5
7
|
export function useBootstrapOptions() {
|
|
6
8
|
return useContext(BootstrapOptionsContext);
|
|
7
9
|
}
|
|
8
|
-
export default function BootstrapOptionsProvider({ children, noCloseModal }) {
|
|
9
|
-
const options = useMemo(() => ({ noCloseModal }), [noCloseModal]);
|
|
10
|
+
export default function BootstrapOptionsProvider({ children, noCloseModal, noCloseOnSave, onlySaveOnDirty }) {
|
|
11
|
+
const options = useMemo(() => ({ noCloseModal, noCloseOnSave, onlySaveOnDirty }), [noCloseModal, noCloseOnSave]);
|
|
10
12
|
return React.createElement(BootstrapOptionsContext.Provider, { value: options }, children);
|
|
11
13
|
}
|
|
@@ -26,8 +26,10 @@ import { Alert, Button, Col, Form, ModalFooter, ModalHeader, Row } from "reactst
|
|
|
26
26
|
import LoadingButton from '../Components/LoadingButton';
|
|
27
27
|
import BootstrapDataTable, { Actions } from './BootstrapDataTable';
|
|
28
28
|
import BootstrapModal from './BootstrapModal';
|
|
29
|
+
import { useBootstrapOptions } from "./BootstrapOptions";
|
|
29
30
|
export function ModalEntityEditor({ entity, title, size, url, onReload, disabled, children }) {
|
|
30
|
-
const [, , save, loading] = entity;
|
|
31
|
+
const [, , save, loading, dirty] = entity;
|
|
32
|
+
const bsOptions = useBootstrapOptions();
|
|
31
33
|
const [open, setOpen] = useState(true);
|
|
32
34
|
const [saved, setSaved] = useState(false);
|
|
33
35
|
const [error, setError] = useState(false);
|
|
@@ -59,7 +61,7 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
59
61
|
});
|
|
60
62
|
}, [save, saved, error, onReload, url]);
|
|
61
63
|
return React.createElement(React.Fragment, null,
|
|
62
|
-
(saved || !open) && url && React.createElement(Navigate, { to: url, replace: true }),
|
|
64
|
+
((!bsOptions.noCloseOnSave && saved) || !open) && url && React.createElement(Navigate, { to: url, replace: true }),
|
|
63
65
|
React.createElement(BootstrapModal, { isOpen: true, size: size, toggle: () => url ? setOpen(false) : onReload(null), fade: false },
|
|
64
66
|
title && React.createElement(ModalHeader, { toggle: () => url ? setOpen(false) : onReload(null) },
|
|
65
67
|
React.createElement("b", null, title)),
|
|
@@ -68,9 +70,13 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
68
70
|
React.createElement("fieldset", { disabled: !!loading || !!disabled }, children),
|
|
69
71
|
React.createElement(ModalFooter, null,
|
|
70
72
|
error && React.createElement(Alert, { color: "danger", toggle: () => setError(null), style: { display: 'block', width: '100%' } }, error),
|
|
73
|
+
bsOptions.noCloseOnSave && !dirty && saved && React.createElement(Alert, { color: "success", style: { display: 'block', width: '100%' } },
|
|
74
|
+
React.createElement("i", { className: "fas fa-check-circle" }),
|
|
75
|
+
" ",
|
|
76
|
+
React.createElement(FormattedMessage, { id: "ENTITY.SAVED" })),
|
|
71
77
|
React.createElement(Row, { className: "w-100" },
|
|
72
78
|
React.createElement(Col, null,
|
|
73
|
-
React.createElement(LoadingButton, { block: true, loading: loading, type: "submit", color: "primary" },
|
|
79
|
+
React.createElement(LoadingButton, { block: true, loading: loading, disabled: bsOptions.onlySaveOnDirty && !dirty, type: "submit", color: "primary" },
|
|
74
80
|
React.createElement("i", { className: "fas fa-save" }),
|
|
75
81
|
' ',
|
|
76
82
|
React.createElement(FormattedMessage, { id: "ENTITY.SAVE" }))),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-admin-base-bootstrap",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"modal-cropper": "^1.2.3",
|
|
39
39
|
"nprogress": "^0.2.0",
|
|
40
40
|
"prettysize": "^2.0.0",
|
|
41
|
-
"react-admin-base": "^0.8.
|
|
41
|
+
"react-admin-base": "^0.8.10",
|
|
42
42
|
"react-dnd": "^16.0.1",
|
|
43
43
|
"react-dnd-html5-backend": "^16.0.1",
|
|
44
44
|
"react-password-strength-bar": "^0.4.1",
|
|
@@ -101,6 +101,7 @@ export interface BootstrapTableProps {
|
|
|
101
101
|
add?: string;
|
|
102
102
|
children: any;
|
|
103
103
|
innerRef?: any;
|
|
104
|
+
noSearch?: boolean;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
interface RowRendererProps<Row = any> {
|
|
@@ -123,7 +124,7 @@ export function CustomRenderer<Row = any>({render}: RowRendererProps<Row>) {
|
|
|
123
124
|
</>;
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
export default function BootstrapTable({url, bordered, noStrip, defaultParams, add, children, innerRef, body}: BootstrapTableProps) {
|
|
127
|
+
export default function BootstrapTable({url, bordered, noStrip, defaultParams, add, noSearch = false, children, innerRef, body}: BootstrapTableProps) {
|
|
127
128
|
const state = useState({sort: 'id', ...defaultParams});
|
|
128
129
|
const [params, setParams] = state;
|
|
129
130
|
const [page, lastPage, setPage, data, itemPerPage, setItemPerPage, update, count] = useDataTable(url, params, body);
|
|
@@ -178,13 +179,13 @@ export default function BootstrapTable({url, bordered, noStrip, defaultParams, a
|
|
|
178
179
|
</Input>
|
|
179
180
|
</Col>
|
|
180
181
|
{children[2]}
|
|
181
|
-
<Col md="3" className="ms-auto">
|
|
182
|
+
{!noSearch && <Col md="3" className="ms-auto">
|
|
182
183
|
<Input
|
|
183
184
|
placeholder={intl.formatMessage({id: "SEARCH"})} type="text"
|
|
184
185
|
value={params.query || ''}
|
|
185
186
|
onChange={e => setParams({...params, query: e.currentTarget.value})}
|
|
186
187
|
/>
|
|
187
|
-
</Col>
|
|
188
|
+
</Col>}
|
|
188
189
|
</Row>
|
|
189
190
|
{children[3]}
|
|
190
191
|
</CardHeader>
|
|
@@ -3,6 +3,8 @@ import BootstrapOptions from "./BootstrapOptions";
|
|
|
3
3
|
|
|
4
4
|
interface BootstrapOptions {
|
|
5
5
|
noCloseModal: boolean;
|
|
6
|
+
noCloseOnSave: boolean;
|
|
7
|
+
onlySaveOnDirty: boolean;
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
interface BootstrapOptionsProviderProps extends BootstrapOptions {
|
|
@@ -10,15 +12,17 @@ interface BootstrapOptionsProviderProps extends BootstrapOptions {
|
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
const BootstrapOptionsContext = createContext<BootstrapOptions>({
|
|
13
|
-
noCloseModal: false
|
|
15
|
+
noCloseModal: false,
|
|
16
|
+
noCloseOnSave: false,
|
|
17
|
+
onlySaveOnDirty: false
|
|
14
18
|
});
|
|
15
19
|
|
|
16
20
|
export function useBootstrapOptions() {
|
|
17
21
|
return useContext(BootstrapOptionsContext);
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
export default function BootstrapOptionsProvider({children,noCloseModal}: BootstrapOptionsProviderProps) {
|
|
21
|
-
const options = useMemo(() => ({noCloseModal}), [noCloseModal]);
|
|
24
|
+
export default function BootstrapOptionsProvider({children,noCloseModal,noCloseOnSave, onlySaveOnDirty}: BootstrapOptionsProviderProps) {
|
|
25
|
+
const options = useMemo(() => ({noCloseModal,noCloseOnSave,onlySaveOnDirty}), [noCloseModal, noCloseOnSave]);
|
|
22
26
|
return <BootstrapOptionsContext.Provider value={options}>
|
|
23
27
|
{ children }
|
|
24
28
|
</BootstrapOptionsContext.Provider>;
|
package/src/Components/CRUD.tsx
CHANGED
|
@@ -19,7 +19,8 @@ type ModalEntityEditorParams = {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function ModalEntityEditor({ entity, title, size, url, onReload, disabled, children } : ModalEntityEditorParams) {
|
|
22
|
-
const [ , , save, loading ] = entity;
|
|
22
|
+
const [ , , save, loading, dirty ] = entity;
|
|
23
|
+
const bsOptions = useBootstrapOptions();
|
|
23
24
|
|
|
24
25
|
const [ open, setOpen ] = useState(true);
|
|
25
26
|
const [ saved, setSaved ] = useState(false);
|
|
@@ -58,10 +59,10 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
58
59
|
}, [save, saved, error, onReload, url]);
|
|
59
60
|
|
|
60
61
|
return <>
|
|
61
|
-
{ (saved || !open) && url && <Navigate to={url} replace />}
|
|
62
|
+
{ ((!bsOptions.noCloseOnSave && saved) || !open) && url && <Navigate to={url} replace />}
|
|
62
63
|
<BootstrapModal isOpen size={size} toggle={() => url ? setOpen(false) : onReload(null)} fade={false}>
|
|
63
64
|
{ title && <ModalHeader toggle={() => url ? setOpen(false) : onReload(null)}>
|
|
64
|
-
|
|
65
|
+
<b>{ title }</b>
|
|
65
66
|
</ModalHeader> }
|
|
66
67
|
<ValidatorProvider>
|
|
67
68
|
<Form onSubmit={onSubmit} disabled={!!loading || disabled}>
|
|
@@ -69,12 +70,13 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
|
|
|
69
70
|
{ children }
|
|
70
71
|
</fieldset>
|
|
71
72
|
<ModalFooter>
|
|
72
|
-
|
|
73
|
+
{ error && <Alert color="danger" toggle={() => setError(null)} style={{ display: 'block', width: '100%' }}>{ error }</Alert>}
|
|
74
|
+
{ bsOptions.noCloseOnSave && !dirty && saved && <Alert color="success" style={{ display: 'block', width: '100%' }}><i className="fas fa-check-circle" /> <FormattedMessage id="ENTITY.SAVED" /></Alert>}
|
|
73
75
|
<Row className="w-100">
|
|
74
76
|
<Col>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
<LoadingButton block loading={loading} disabled={bsOptions.onlySaveOnDirty && !dirty} type="submit" color="primary">
|
|
78
|
+
<i className="fas fa-save" />{' '}<FormattedMessage id="ENTITY.SAVE" />
|
|
79
|
+
</LoadingButton>
|
|
78
80
|
</Col>
|
|
79
81
|
<Col>
|
|
80
82
|
<Button block outline color="danger" onClick={(e) => { e.preventDefault(); (url ? setOpen(false) : onReload(null)); }}>
|