react-admin-base-bootstrap 0.8.16 → 0.8.18

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.
@@ -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" },
@@ -20,7 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  };
21
21
  import React, { useCallback, useContext, useRef, useState } from 'react';
22
22
  import { ValidatorProvider } from "react-admin-base";
23
- import { FormattedMessage } from 'react-intl';
23
+ import { FormattedMessage, useIntl } from 'react-intl';
24
24
  import { Navigate, Routes, useParams, Route } from 'react-router-dom';
25
25
  import { Alert, Button, Col, Form, ModalFooter, ModalHeader, Row } from "reactstrap";
26
26
  import LoadingButton from '../Components/LoadingButton';
@@ -60,10 +60,26 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
60
60
  }
61
61
  });
62
62
  }, [save, saved, error, onReload, url]);
63
+ const check = bsOptions.noCloseOnSave && dirty;
64
+ const intl = useIntl();
65
+ const checkConfirmText = intl.formatMessage({ id: 'CANCEL_ENTITY_SAVE' });
66
+ const onClose = useCallback(function () {
67
+ if (check) {
68
+ const ok = confirm(checkConfirmText);
69
+ if (!ok)
70
+ return;
71
+ }
72
+ if (url) {
73
+ setOpen(false);
74
+ }
75
+ else {
76
+ onReload(null);
77
+ }
78
+ }, [setOpen, onReload, url, check, checkConfirmText]);
63
79
  return React.createElement(React.Fragment, null,
64
80
  ((!bsOptions.noCloseOnSave && saved) || !open) && url && React.createElement(Navigate, { to: url, replace: true }),
65
- React.createElement(BootstrapModal, { isOpen: true, size: size, toggle: () => url ? setOpen(false) : onReload(null), fade: false },
66
- title && React.createElement(ModalHeader, { toggle: () => url ? setOpen(false) : onReload(null) },
81
+ React.createElement(BootstrapModal, { isOpen: true, size: size, toggle: onClose, fade: false },
82
+ title && React.createElement(ModalHeader, { toggle: onClose },
67
83
  React.createElement("b", null, title)),
68
84
  React.createElement(ValidatorProvider, null,
69
85
  React.createElement(Form, { onSubmit: onSubmit, disabled: !!loading || disabled },
@@ -81,7 +97,7 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
81
97
  ' ',
82
98
  React.createElement(FormattedMessage, { id: "ENTITY.SAVE" }))),
83
99
  React.createElement(Col, null,
84
- React.createElement(Button, { block: true, outline: true, color: "danger", onClick: (e) => { e.preventDefault(); (url ? setOpen(false) : onReload(null)); } },
100
+ React.createElement(Button, { block: true, outline: true, color: "danger", onClick: (e) => { e.preventDefault(); onClose(); } },
85
101
  React.createElement("i", { className: "fas fa-times-circle" }),
86
102
  ' ',
87
103
  React.createElement(FormattedMessage, { id: "ENTITY.CANCEL" })))))))));
@@ -38,5 +38,6 @@
38
38
  "ACTIONS.DELETE.CONFIRM": "Ja, löschen!",
39
39
  "PLEASE_WAIT": "Warten Sie mal.",
40
40
  "AUTHORIZATION_CODE": "Zugangscode",
41
- "RECORDS": "{count, plural, =0 {kein eintrag} one {# datensatz} other {# datensätze}}"
41
+ "RECORDS": "{count, plural, =0 {kein eintrag} one {# datensatz} other {# datensätze}}",
42
+ "CANCEL_ENTITY_SAVE": "Es gibt Änderungen auf der Seite. Sind Sie sicher, dass Sie sie rückgängig machen wollen?"
42
43
  }
@@ -40,5 +40,6 @@
40
40
  "ACTIONS.DELETE.CONFIRM": "Yes, delete it!",
41
41
  "PLEASE_WAIT": "Please wait.",
42
42
  "AUTHORIZATION_CODE": "Authorization Code",
43
- "RECORDS": "{count, plural, =0 {no records} one {# record} other {# records}}"
43
+ "RECORDS": "{count, plural, =0 {no records} one {# record} other {# records}}",
44
+ "CANCEL_ENTITY_SAVE": "There are changes on the page. Are you sure you want to undo them?"
44
45
  }
@@ -39,5 +39,6 @@
39
39
  "ACTIONS.DELETE.CONFIRM": "Evet, sil!",
40
40
  "PLEASE_WAIT": "Lütfen bekleyiniz.",
41
41
  "AUTHORIZATION_CODE": "Yetki Kodu",
42
- "RECORDS": "{count, plural, =0 {Kayıt yok} one {# kayıt} other {# kayıt}}"
42
+ "RECORDS": "{count, plural, =0 {Kayıt yok} one {# kayıt} other {# kayıt}}",
43
+ "CANCEL_ENTITY_SAVE": "Sayfada değişiklikler var. Geri almak istediğinizden emin misiniz?"
43
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-admin-base-bootstrap",
3
- "version": "0.8.16",
3
+ "version": "0.8.18",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 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>
@@ -1,6 +1,6 @@
1
1
  import React, { useCallback, useContext, useRef, useState } from 'react';
2
2
  import { ValidatorProvider } from "react-admin-base";
3
- import { FormattedMessage } from 'react-intl';
3
+ import {FormattedMessage, useIntl} from 'react-intl';
4
4
  import { Navigate, Routes, useParams, Route } from 'react-router-dom';
5
5
  import { Alert, Button, Col, Form, Modal, ModalFooter, ModalHeader, Row } from "reactstrap";
6
6
  import LoadingButton from '../Components/LoadingButton';
@@ -58,11 +58,28 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
58
58
  }
59
59
  }, [save, saved, error, onReload, url]);
60
60
 
61
+ const check = bsOptions.noCloseOnSave && dirty;
62
+ const intl = useIntl();
63
+ const checkConfirmText = intl.formatMessage({ id: 'CANCEL_ENTITY_SAVE' });
64
+ const onClose = useCallback(function() {
65
+ if (check) {
66
+ const ok = confirm(checkConfirmText);
67
+ if (!ok)
68
+ return ;
69
+ }
70
+
71
+ if (url) {
72
+ setOpen(false);
73
+ } else {
74
+ onReload(null);
75
+ }
76
+ }, [ setOpen, onReload, url, check, checkConfirmText ]);
77
+
61
78
  return <>
62
79
  { ((!bsOptions.noCloseOnSave && saved) || !open) && url && <Navigate to={url} replace />}
63
- <BootstrapModal isOpen size={size} toggle={() => url ? setOpen(false) : onReload(null)} fade={false}>
64
- { title && <ModalHeader toggle={() => url ? setOpen(false) : onReload(null)}>
65
- <b>{ title }</b>
80
+ <BootstrapModal isOpen size={size} toggle={onClose} fade={false}>
81
+ { title && <ModalHeader toggle={onClose}>
82
+ <b>{ title }</b>
66
83
  </ModalHeader> }
67
84
  <ValidatorProvider>
68
85
  <Form onSubmit={onSubmit} disabled={!!loading || disabled}>
@@ -79,7 +96,7 @@ export function ModalEntityEditor({ entity, title, size, url, onReload, disabled
79
96
  </LoadingButton>
80
97
  </Col>
81
98
  <Col>
82
- <Button block outline color="danger" onClick={(e) => { e.preventDefault(); (url ? setOpen(false) : onReload(null)); }}>
99
+ <Button block outline color="danger" onClick={(e) => { e.preventDefault(); onClose(); }}>
83
100
  <i className="fas fa-times-circle" />{' '}<FormattedMessage id="ENTITY.CANCEL" />
84
101
  </Button>
85
102
  </Col>
package/src/i18n/de.json CHANGED
@@ -38,5 +38,6 @@
38
38
  "ACTIONS.DELETE.CONFIRM": "Ja, löschen!",
39
39
  "PLEASE_WAIT": "Warten Sie mal.",
40
40
  "AUTHORIZATION_CODE": "Zugangscode",
41
- "RECORDS": "{count, plural, =0 {kein eintrag} one {# datensatz} other {# datensätze}}"
41
+ "RECORDS": "{count, plural, =0 {kein eintrag} one {# datensatz} other {# datensätze}}",
42
+ "CANCEL_ENTITY_SAVE": "Es gibt Änderungen auf der Seite. Sind Sie sicher, dass Sie sie rückgängig machen wollen?"
42
43
  }
package/src/i18n/en.json CHANGED
@@ -40,5 +40,6 @@
40
40
  "ACTIONS.DELETE.CONFIRM": "Yes, delete it!",
41
41
  "PLEASE_WAIT": "Please wait.",
42
42
  "AUTHORIZATION_CODE": "Authorization Code",
43
- "RECORDS": "{count, plural, =0 {no records} one {# record} other {# records}}"
43
+ "RECORDS": "{count, plural, =0 {no records} one {# record} other {# records}}",
44
+ "CANCEL_ENTITY_SAVE": "There are changes on the page. Are you sure you want to undo them?"
44
45
  }
package/src/i18n/tr.json CHANGED
@@ -39,5 +39,6 @@
39
39
  "ACTIONS.DELETE.CONFIRM": "Evet, sil!",
40
40
  "PLEASE_WAIT": "Lütfen bekleyiniz.",
41
41
  "AUTHORIZATION_CODE": "Yetki Kodu",
42
- "RECORDS": "{count, plural, =0 {Kayıt yok} one {# kayıt} other {# kayıt}}"
42
+ "RECORDS": "{count, plural, =0 {Kayıt yok} one {# kayıt} other {# kayıt}}",
43
+ "CANCEL_ENTITY_SAVE": "Sayfada değişiklikler var. Geri almak istediğinizden emin misiniz?"
43
44
  }