@applica-software-guru/react-admin 1.5.329 → 1.5.330
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-buttons/DeleteWithConfirmButton.d.ts +8 -0
- package/dist/components/ra-buttons/DeleteWithConfirmButton.d.ts.map +1 -1
- package/dist/components/ra-forms/TableForm/TableFormIterator.d.ts.map +1 -1
- package/dist/components/ra-forms/TableForm/TableFormIteratorItem.d.ts.map +1 -1
- package/dist/react-admin.cjs.js +50 -50
- package/dist/react-admin.cjs.js.gz +0 -0
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +5649 -5651
- package/dist/react-admin.es.js.gz +0 -0
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +50 -50
- package/dist/react-admin.umd.js.gz +0 -0
- package/dist/react-admin.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ra-buttons/DeleteWithConfirmButton.tsx +26 -6
- package/src/components/ra-forms/TableForm/TableFormIterator.tsx +7 -17
- package/src/components/ra-forms/TableForm/TableFormIteratorItem.tsx +7 -18
package/package.json
CHANGED
|
@@ -7,10 +7,19 @@ import { Button } from './Button';
|
|
|
7
7
|
import { Confirm, DeleteWithConfirmButtonProps as RaDeleteWithConfirmButtonProps } from 'ra-ui-materialui';
|
|
8
8
|
import { Box, SxProps, Typography, useTheme } from '@mui/material';
|
|
9
9
|
import { DeleteFilled } from '@ant-design/icons';
|
|
10
|
+
import { useCallback } from 'react';
|
|
10
11
|
|
|
11
12
|
type DeleteWithConfirmButtonProps<RecordType extends RaRecord = RaRecord> =
|
|
12
13
|
RaDeleteWithConfirmButtonProps<RecordType> & {
|
|
13
14
|
dialogSx?: SxProps;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated confirmTitle prop is deprecated, please use confirmContent instead.
|
|
17
|
+
*/
|
|
18
|
+
confirmTitle?: React.ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* onConfirm {callback} is used to handle a custom delete action when user confirms the deletion.
|
|
21
|
+
*/
|
|
22
|
+
onConfirm?: () => void;
|
|
14
23
|
};
|
|
15
24
|
|
|
16
25
|
function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
|
|
@@ -30,6 +39,7 @@ function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
|
|
|
30
39
|
onClick,
|
|
31
40
|
redirect = 'list',
|
|
32
41
|
translateOptions = {},
|
|
42
|
+
onConfirm,
|
|
33
43
|
...rest
|
|
34
44
|
} = props;
|
|
35
45
|
const translate = useTranslate();
|
|
@@ -46,6 +56,17 @@ function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
|
|
|
46
56
|
resource
|
|
47
57
|
});
|
|
48
58
|
|
|
59
|
+
const handleOnConfirm = useCallback(
|
|
60
|
+
(event: any) => {
|
|
61
|
+
if (onConfirm) {
|
|
62
|
+
onConfirm();
|
|
63
|
+
} else {
|
|
64
|
+
handleDelete(event);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
[handleDelete, onConfirm]
|
|
68
|
+
);
|
|
69
|
+
|
|
49
70
|
return (
|
|
50
71
|
<>
|
|
51
72
|
<Button
|
|
@@ -122,9 +143,9 @@ function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
|
|
|
122
143
|
)
|
|
123
144
|
}
|
|
124
145
|
content={
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
146
|
+
<Typography maxWidth="300px" variant="h4" align="center">
|
|
147
|
+
{confirmContent ||
|
|
148
|
+
translate('ra.message.delete_content', {
|
|
128
149
|
_: 'ra.message.delete_content',
|
|
129
150
|
name: translate(`resources.${resource}.forcedCaseName`, {
|
|
130
151
|
smart_count: 1,
|
|
@@ -138,8 +159,7 @@ function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
|
|
|
138
159
|
}),
|
|
139
160
|
id: record?.id
|
|
140
161
|
})}
|
|
141
|
-
|
|
142
|
-
)
|
|
162
|
+
</Typography>
|
|
143
163
|
}
|
|
144
164
|
confirmColor={confirmColor}
|
|
145
165
|
translateOptions={{
|
|
@@ -156,7 +176,7 @@ function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
|
|
|
156
176
|
id: record?.id,
|
|
157
177
|
...translateOptions
|
|
158
178
|
}}
|
|
159
|
-
onConfirm={
|
|
179
|
+
onConfirm={handleOnConfirm}
|
|
160
180
|
onClose={handleDialogClose}
|
|
161
181
|
/>
|
|
162
182
|
</>
|
|
@@ -19,10 +19,11 @@ import {
|
|
|
19
19
|
import { styled, useTheme } from '@mui/material/styles';
|
|
20
20
|
import { FormDataConsumer, RaRecord, useTranslate, useTranslateLabel } from 'ra-core';
|
|
21
21
|
import * as React from 'react';
|
|
22
|
-
import { Children, ReactElement, ReactNode, useCallback, useMemo, useRef
|
|
23
|
-
import {
|
|
22
|
+
import { Children, ReactElement, ReactNode, useCallback, useMemo, useRef } from 'react';
|
|
23
|
+
import { useArrayInput } from 'react-admin';
|
|
24
24
|
import { UseFieldArrayReturn, useFormContext } from 'react-hook-form';
|
|
25
25
|
import { Tooltip } from '@/components/@extended';
|
|
26
|
+
import { DeleteWithConfirmButton } from '@/components/ra-buttons';
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* How to use TableFormIterator:
|
|
@@ -57,7 +58,6 @@ function RawTableFormIterator(props: TableFormIteratorProps): ReactElement | nul
|
|
|
57
58
|
inset,
|
|
58
59
|
sx
|
|
59
60
|
} = props;
|
|
60
|
-
const [confirmIsOpen, setConfirmIsOpen] = useState<boolean>(false);
|
|
61
61
|
const { fields, remove, replace, append } = useArrayInput(props);
|
|
62
62
|
const { resetField } = useFormContext();
|
|
63
63
|
const theme = useTheme();
|
|
@@ -129,7 +129,6 @@ function RawTableFormIterator(props: TableFormIteratorProps): ReactElement | nul
|
|
|
129
129
|
|
|
130
130
|
const handleArrayClear = useCallback(() => {
|
|
131
131
|
replace([]);
|
|
132
|
-
setConfirmIsOpen(false);
|
|
133
132
|
}, [replace]);
|
|
134
133
|
|
|
135
134
|
const context = useMemo(
|
|
@@ -217,9 +216,10 @@ function RawTableFormIterator(props: TableFormIteratorProps): ReactElement | nul
|
|
|
217
216
|
{!disableRemove && showClearAllButton ? (
|
|
218
217
|
<TableCell key="actions" sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
|
|
219
218
|
<ActionsMenu horizontal>
|
|
220
|
-
<
|
|
221
|
-
{
|
|
222
|
-
|
|
219
|
+
<DeleteWithConfirmButton
|
|
220
|
+
onConfirm={handleArrayClear}
|
|
221
|
+
confirmContent={translate('ra.message.clear_array_input')}
|
|
222
|
+
/>
|
|
223
223
|
</ActionsMenu>
|
|
224
224
|
</TableCell>
|
|
225
225
|
) : (
|
|
@@ -264,16 +264,6 @@ function RawTableFormIterator(props: TableFormIteratorProps): ReactElement | nul
|
|
|
264
264
|
</TableBody>
|
|
265
265
|
</Table>
|
|
266
266
|
</TableContainer>
|
|
267
|
-
|
|
268
|
-
{fields.length > 0 && (
|
|
269
|
-
<Confirm
|
|
270
|
-
isOpen={confirmIsOpen}
|
|
271
|
-
title={translate('ra.action.clear_array_input')}
|
|
272
|
-
content={translate('ra.message.clear_array_input')}
|
|
273
|
-
onConfirm={handleArrayClear}
|
|
274
|
-
onClose={() => setConfirmIsOpen(false)}
|
|
275
|
-
/>
|
|
276
|
-
)}
|
|
277
267
|
</div>
|
|
278
268
|
</TableFormIteratorContext.Provider>
|
|
279
269
|
) : null;
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { EditButton } from './EditButton';
|
|
2
2
|
import { ActionsMenu } from '@/components/ActionsMenu';
|
|
3
|
+
import { DeleteWithConfirmButton } from '@/components/ra-buttons';
|
|
3
4
|
import { useTableFormIterator } from '@/components/ra-forms/TableForm/TableFormIteratorContext';
|
|
4
5
|
import {
|
|
5
6
|
TableFormIteratorItemContext,
|
|
6
7
|
TableFormIteratorItemContextValue
|
|
7
8
|
} from '@/components/ra-forms/TableForm/TableFormIteratorItemContext';
|
|
8
|
-
import {
|
|
9
|
+
import { Stack, TableCell } from '@mui/material';
|
|
9
10
|
import { RaRecord } from 'ra-core';
|
|
10
11
|
import { Children, ReactElement, ReactNode, cloneElement, isValidElement, useMemo } from 'react';
|
|
11
12
|
import * as React from 'react';
|
|
12
|
-
import {
|
|
13
|
+
import { useTranslate } from 'react-admin';
|
|
13
14
|
|
|
14
15
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
15
16
|
const TableFormIteratorItem = React.forwardRef((props: TableFormIteratorItemProps, _: any) => {
|
|
16
17
|
const { children, disabled, disableRemove = false, index, member, resource, record } = props;
|
|
17
18
|
const translate = useTranslate();
|
|
18
|
-
const [confirmIsOpen, setConfirmIsOpen] = React.useState<boolean>(false);
|
|
19
19
|
const { total, remove } = useTableFormIterator();
|
|
20
20
|
|
|
21
21
|
const handleRowDelete = React.useCallback(() => {
|
|
22
|
-
setConfirmIsOpen(false);
|
|
23
22
|
remove(index);
|
|
24
23
|
}, [index, remove]);
|
|
25
24
|
|
|
@@ -75,9 +74,10 @@ const TableFormIteratorItem = React.forwardRef((props: TableFormIteratorItemProp
|
|
|
75
74
|
<TableCell>
|
|
76
75
|
<Stack direction="row" spacing={1} justifyContent="center" alignItems="center">
|
|
77
76
|
<ActionsMenu horizontal>
|
|
78
|
-
<
|
|
79
|
-
{
|
|
80
|
-
|
|
77
|
+
<DeleteWithConfirmButton
|
|
78
|
+
onConfirm={handleRowDelete}
|
|
79
|
+
confirmContent={translate('ra.message.remove_item')}
|
|
80
|
+
/>
|
|
81
81
|
{renderEditButton}
|
|
82
82
|
</ActionsMenu>
|
|
83
83
|
</Stack>
|
|
@@ -90,17 +90,6 @@ const TableFormIteratorItem = React.forwardRef((props: TableFormIteratorItemProp
|
|
|
90
90
|
</Stack>
|
|
91
91
|
</TableCell>
|
|
92
92
|
) : null}
|
|
93
|
-
|
|
94
|
-
{/** @ts-ignore */}
|
|
95
|
-
{children.length > 0 && (
|
|
96
|
-
<Confirm
|
|
97
|
-
isOpen={confirmIsOpen}
|
|
98
|
-
title={translate('ra.action.remove_item')}
|
|
99
|
-
content={translate('ra.message.remove_item')}
|
|
100
|
-
onConfirm={handleRowDelete}
|
|
101
|
-
onClose={() => setConfirmIsOpen(false)}
|
|
102
|
-
/>
|
|
103
|
-
)}
|
|
104
93
|
</TableFormIteratorItemContext.Provider>
|
|
105
94
|
);
|
|
106
95
|
});
|