@applica-software-guru/react-admin 1.5.312 → 1.5.314
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/BulkDeleteWithConfirmButton.d.ts +3 -0
- package/dist/components/ra-buttons/BulkDeleteWithConfirmButton.d.ts.map +1 -1
- package/dist/components/ra-buttons/DeleteWithConfirmButton.d.ts +28 -0
- package/dist/components/ra-buttons/DeleteWithConfirmButton.d.ts.map +1 -0
- package/dist/components/ra-buttons/index.d.ts +1 -0
- package/dist/components/ra-buttons/index.d.ts.map +1 -1
- package/dist/components/ra-fields/ActionsField.d.ts.map +1 -1
- package/dist/components/ra-forms/SimpleForm.d.ts.map +1 -1
- package/dist/components/ra-forms/TabbedForm.d.ts.map +1 -1
- package/dist/i18n/messages.json +1 -1
- package/dist/i18n/messages.json.gz +0 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/react-admin.cjs.js +68 -66
- package/dist/react-admin.cjs.js.gz +0 -0
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +18122 -16067
- package/dist/react-admin.es.js.gz +0 -0
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +69 -67
- package/dist/react-admin.umd.js.gz +0 -0
- package/dist/react-admin.umd.js.map +1 -1
- package/package.json +1 -1
- package/public/i18n/messages.json +1 -1
- package/src/components/ra-buttons/BulkDeleteWithConfirmButton.tsx +89 -5
- package/src/components/ra-buttons/DeleteWithConfirmButton.tsx +182 -0
- package/src/components/ra-buttons/index.ts +1 -0
- package/src/components/ra-fields/ActionsField.tsx +2 -1
- package/src/components/ra-forms/SimpleForm.tsx +1 -1
- package/src/components/ra-forms/TabbedForm.tsx +2 -7
- package/src/index.ts +0 -1
package/package.json
CHANGED
|
@@ -645,7 +645,7 @@
|
|
|
645
645
|
"id": "en.ra.message.bulk_delete_content",
|
|
646
646
|
"code": "ra.message.bulk_delete_content",
|
|
647
647
|
"lang": "en",
|
|
648
|
-
"text": "Sei sicuro di voler cancellare questo %{name}? |||| Sei sicuro di voler eliminare questi %{smart_count}?"
|
|
648
|
+
"text": "Sei sicuro di voler cancellare questo %{name}? |||| Sei sicuro di voler eliminare questi %{smart_count} %{name}?"
|
|
649
649
|
},
|
|
650
650
|
{
|
|
651
651
|
"id": "en.ra.message.bulk_delete_title",
|
|
@@ -3,7 +3,7 @@ import { ReactElement } from 'react';
|
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import ActionDelete from '@mui/icons-material/Delete';
|
|
5
5
|
import inflection from 'inflection';
|
|
6
|
-
import { alpha, styled } from '@mui/material/styles';
|
|
6
|
+
import { SxProps, alpha, styled, useTheme } from '@mui/material/styles';
|
|
7
7
|
import {
|
|
8
8
|
DeleteManyParams,
|
|
9
9
|
MutationMode,
|
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
import { BulkActionProps, Button, ButtonProps, Confirm } from 'react-admin';
|
|
20
20
|
import { UseMutationOptions } from 'react-query';
|
|
21
21
|
import _ from 'lodash';
|
|
22
|
+
import { Box, Typography } from '@mui/material';
|
|
23
|
+
import { DeleteFilled } from '@ant-design/icons';
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* BulkDeleteWithConfirmButton component allows you to delete multiple records with a confirmation dialog.
|
|
@@ -39,9 +41,10 @@ import _ from 'lodash';
|
|
|
39
41
|
*/
|
|
40
42
|
function BulkDeleteWithConfirmButton(props: BulkDeleteWithConfirmButtonProps) {
|
|
41
43
|
const {
|
|
42
|
-
confirmTitle
|
|
43
|
-
confirmContent
|
|
44
|
+
confirmTitle,
|
|
45
|
+
confirmContent,
|
|
44
46
|
confirmColor = 'primary',
|
|
47
|
+
dialogSx,
|
|
45
48
|
icon = defaultIcon,
|
|
46
49
|
label = 'ra.action.delete',
|
|
47
50
|
mutationMode = 'pessimistic',
|
|
@@ -58,6 +61,7 @@ function BulkDeleteWithConfirmButton(props: BulkDeleteWithConfirmButtonProps) {
|
|
|
58
61
|
const resource = useResourceContext(props);
|
|
59
62
|
const refresh = useRefresh();
|
|
60
63
|
const translate = useTranslate();
|
|
64
|
+
const theme = useTheme();
|
|
61
65
|
const [deleteMany, { isLoading }] = useDeleteMany(
|
|
62
66
|
resource,
|
|
63
67
|
{ ids: selectedIds, meta: mutationMeta },
|
|
@@ -119,8 +123,86 @@ function BulkDeleteWithConfirmButton(props: BulkDeleteWithConfirmButtonProps) {
|
|
|
119
123
|
<Confirm
|
|
120
124
|
isOpen={isOpen}
|
|
121
125
|
loading={isLoading}
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
sx={
|
|
127
|
+
dialogSx || {
|
|
128
|
+
'& .MuiPaper-root': {
|
|
129
|
+
p: 2
|
|
130
|
+
},
|
|
131
|
+
'& .MuiDialogActions-root': {
|
|
132
|
+
display: 'flex',
|
|
133
|
+
justifyContent: 'space-between',
|
|
134
|
+
width: '100%',
|
|
135
|
+
'& .RaConfirm-confirmPrimary': {
|
|
136
|
+
backgroundColor: theme.palette.primary.main,
|
|
137
|
+
color: theme.palette.primary.contrastText,
|
|
138
|
+
ml: 2,
|
|
139
|
+
'&:hover': {
|
|
140
|
+
backgroundColor: theme.palette.primary.dark
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
'& .MuiButtonBase-root': {
|
|
144
|
+
width: '50%',
|
|
145
|
+
border: `1px solid ${theme.palette.action.disabled}`
|
|
146
|
+
},
|
|
147
|
+
'& .MuiButton-icon': {
|
|
148
|
+
display: 'none'
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
title={
|
|
154
|
+
confirmTitle ? (
|
|
155
|
+
typeof confirmTitle === 'string' ? (
|
|
156
|
+
translate(confirmTitle)
|
|
157
|
+
) : (
|
|
158
|
+
confirmTitle
|
|
159
|
+
)
|
|
160
|
+
) : (
|
|
161
|
+
<Box
|
|
162
|
+
sx={{
|
|
163
|
+
display: 'flex',
|
|
164
|
+
alignItems: 'center',
|
|
165
|
+
justifyContent: 'center'
|
|
166
|
+
}}
|
|
167
|
+
>
|
|
168
|
+
<Box
|
|
169
|
+
sx={{
|
|
170
|
+
color: 'primary.main',
|
|
171
|
+
fontSize: '28px',
|
|
172
|
+
borderRadius: '50%',
|
|
173
|
+
backgroundColor: 'primary.lighter',
|
|
174
|
+
width: '56px',
|
|
175
|
+
height: '56px',
|
|
176
|
+
display: 'flex',
|
|
177
|
+
alignItems: 'center',
|
|
178
|
+
justifyContent: 'center'
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
<DeleteFilled />
|
|
182
|
+
</Box>
|
|
183
|
+
</Box>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
content={
|
|
187
|
+
confirmContent || (
|
|
188
|
+
<Typography maxWidth="300px" variant="h4" align="center">
|
|
189
|
+
{translate('ra.message.bulk_delete_content', {
|
|
190
|
+
_: 'ra.message.bulk_delete_content',
|
|
191
|
+
smart_count: selectedIds.length,
|
|
192
|
+
name: translate(`resources.${resource}.forcedCaseName`, {
|
|
193
|
+
smart_count: selectedIds.length,
|
|
194
|
+
_: inflection.humanize(
|
|
195
|
+
translate(`resources.${resource}.name`, {
|
|
196
|
+
smart_count: selectedIds.length,
|
|
197
|
+
_: inflection.inflect(resource, selectedIds.length)
|
|
198
|
+
}),
|
|
199
|
+
true
|
|
200
|
+
)
|
|
201
|
+
})
|
|
202
|
+
})}
|
|
203
|
+
</Typography>
|
|
204
|
+
)
|
|
205
|
+
}
|
|
124
206
|
confirmColor={confirmColor}
|
|
125
207
|
translateOptions={{
|
|
126
208
|
smart_count: selectedIds.length,
|
|
@@ -158,6 +240,7 @@ interface BulkDeleteWithConfirmButtonProps<RecordType extends RaRecord = any, Mu
|
|
|
158
240
|
confirmContent?: React.ReactNode;
|
|
159
241
|
confirmTitle?: React.ReactNode;
|
|
160
242
|
confirmColor?: 'primary' | 'warning';
|
|
243
|
+
dialogSx?: SxProps;
|
|
161
244
|
icon?: ReactElement;
|
|
162
245
|
mutationMode: MutationMode;
|
|
163
246
|
mutationOptions?: UseMutationOptions<RecordType, MutationOptionsError, DeleteManyParams<RecordType>> & {
|
|
@@ -197,6 +280,7 @@ BulkDeleteWithConfirmButton.propTypes = {
|
|
|
197
280
|
confirmTitle: PropTypes.node,
|
|
198
281
|
confirmContent: PropTypes.node,
|
|
199
282
|
confirmColor: PropTypes.string,
|
|
283
|
+
dialogSx: PropTypes.object,
|
|
200
284
|
icon: PropTypes.element,
|
|
201
285
|
label: PropTypes.string,
|
|
202
286
|
mutationMode: PropTypes.oneOf(['pessimistic', 'optimistic', 'undoable']),
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import ActionDelete from '@mui/icons-material/Delete';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import inflection from 'inflection';
|
|
5
|
+
import { RaRecord, useDeleteWithConfirmController, useRecordContext, useResourceContext, useTranslate } from 'ra-core';
|
|
6
|
+
import { Button } from './Button';
|
|
7
|
+
import { Confirm, DeleteWithConfirmButtonProps as RaDeleteWithConfirmButtonProps } from 'ra-ui-materialui';
|
|
8
|
+
import { Box, SxProps, Typography, useTheme } from '@mui/material';
|
|
9
|
+
import { DeleteFilled } from '@ant-design/icons';
|
|
10
|
+
|
|
11
|
+
type DeleteWithConfirmButtonProps<RecordType extends RaRecord = RaRecord> =
|
|
12
|
+
RaDeleteWithConfirmButtonProps<RecordType> & {
|
|
13
|
+
dialogSx?: SxProps;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function DeleteWithConfirmButton<RecordType extends RaRecord = any>(
|
|
17
|
+
props: DeleteWithConfirmButtonProps<RecordType>
|
|
18
|
+
): JSX.Element {
|
|
19
|
+
const {
|
|
20
|
+
className,
|
|
21
|
+
confirmTitle,
|
|
22
|
+
confirmContent,
|
|
23
|
+
confirmColor = 'primary',
|
|
24
|
+
color = 'error',
|
|
25
|
+
dialogSx,
|
|
26
|
+
icon = <ActionDelete />,
|
|
27
|
+
label = 'ra.action.delete',
|
|
28
|
+
mutationMode = 'pessimistic',
|
|
29
|
+
mutationOptions,
|
|
30
|
+
onClick,
|
|
31
|
+
redirect = 'list',
|
|
32
|
+
translateOptions = {},
|
|
33
|
+
...rest
|
|
34
|
+
} = props;
|
|
35
|
+
const translate = useTranslate();
|
|
36
|
+
const record = useRecordContext(props);
|
|
37
|
+
const resource = useResourceContext(props);
|
|
38
|
+
const theme = useTheme();
|
|
39
|
+
|
|
40
|
+
const { open, isLoading, handleDialogOpen, handleDialogClose, handleDelete } = useDeleteWithConfirmController({
|
|
41
|
+
record,
|
|
42
|
+
redirect,
|
|
43
|
+
mutationMode,
|
|
44
|
+
onClick,
|
|
45
|
+
mutationOptions,
|
|
46
|
+
resource
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<Button
|
|
52
|
+
onClick={handleDialogOpen}
|
|
53
|
+
label={label}
|
|
54
|
+
className={clsx('ra-delete-button', className)}
|
|
55
|
+
key="button"
|
|
56
|
+
color={color}
|
|
57
|
+
{...rest}
|
|
58
|
+
>
|
|
59
|
+
{icon}
|
|
60
|
+
</Button>
|
|
61
|
+
<Confirm
|
|
62
|
+
isOpen={open}
|
|
63
|
+
loading={isLoading}
|
|
64
|
+
sx={
|
|
65
|
+
dialogSx || {
|
|
66
|
+
'& .MuiPaper-root': {
|
|
67
|
+
p: 2
|
|
68
|
+
},
|
|
69
|
+
'& .MuiDialogActions-root': {
|
|
70
|
+
display: 'flex',
|
|
71
|
+
justifyContent: 'space-between',
|
|
72
|
+
width: '100%',
|
|
73
|
+
'& .RaConfirm-confirmPrimary': {
|
|
74
|
+
backgroundColor: theme.palette.primary.main,
|
|
75
|
+
color: theme.palette.primary.contrastText,
|
|
76
|
+
ml: 2,
|
|
77
|
+
'&:hover': {
|
|
78
|
+
backgroundColor: theme.palette.primary.dark
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
'& .MuiButtonBase-root': {
|
|
82
|
+
width: '50%',
|
|
83
|
+
border: `1px solid ${theme.palette.action.disabled}`
|
|
84
|
+
},
|
|
85
|
+
'& .MuiButton-icon': {
|
|
86
|
+
display: 'none'
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
title={
|
|
92
|
+
confirmTitle ? (
|
|
93
|
+
typeof confirmTitle === 'string' ? (
|
|
94
|
+
translate(confirmTitle)
|
|
95
|
+
) : (
|
|
96
|
+
confirmTitle
|
|
97
|
+
)
|
|
98
|
+
) : (
|
|
99
|
+
<Box
|
|
100
|
+
sx={{
|
|
101
|
+
display: 'flex',
|
|
102
|
+
alignItems: 'center',
|
|
103
|
+
justifyContent: 'center'
|
|
104
|
+
}}
|
|
105
|
+
>
|
|
106
|
+
<Box
|
|
107
|
+
sx={{
|
|
108
|
+
color: 'primary.main',
|
|
109
|
+
fontSize: '28px',
|
|
110
|
+
borderRadius: '50%',
|
|
111
|
+
backgroundColor: 'primary.lighter',
|
|
112
|
+
width: '56px',
|
|
113
|
+
height: '56px',
|
|
114
|
+
display: 'flex',
|
|
115
|
+
alignItems: 'center',
|
|
116
|
+
justifyContent: 'center'
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
<DeleteFilled />
|
|
120
|
+
</Box>
|
|
121
|
+
</Box>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
content={
|
|
125
|
+
confirmContent || (
|
|
126
|
+
<Typography maxWidth="300px" variant="h4" align="center">
|
|
127
|
+
{translate('ra.message.delete_content', {
|
|
128
|
+
_: 'ra.message.delete_content',
|
|
129
|
+
name: translate(`resources.${resource}.forcedCaseName`, {
|
|
130
|
+
smart_count: 1,
|
|
131
|
+
_: inflection.humanize(
|
|
132
|
+
translate(`resources.${resource}.name`, {
|
|
133
|
+
smart_count: 1,
|
|
134
|
+
_: inflection.singularize(resource)
|
|
135
|
+
}),
|
|
136
|
+
true
|
|
137
|
+
)
|
|
138
|
+
}),
|
|
139
|
+
id: record?.id
|
|
140
|
+
})}
|
|
141
|
+
</Typography>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
confirmColor={confirmColor}
|
|
145
|
+
translateOptions={{
|
|
146
|
+
name: translate(`resources.${resource}.forcedCaseName`, {
|
|
147
|
+
smart_count: 1,
|
|
148
|
+
_: inflection.humanize(
|
|
149
|
+
translate(`resources.${resource}.name`, {
|
|
150
|
+
smart_count: 1,
|
|
151
|
+
_: inflection.singularize(resource)
|
|
152
|
+
}),
|
|
153
|
+
true
|
|
154
|
+
)
|
|
155
|
+
}),
|
|
156
|
+
id: record?.id,
|
|
157
|
+
...translateOptions
|
|
158
|
+
}}
|
|
159
|
+
onConfirm={handleDelete}
|
|
160
|
+
onClose={handleDialogClose}
|
|
161
|
+
/>
|
|
162
|
+
</>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
DeleteWithConfirmButton.propTypes = {
|
|
167
|
+
basePath: PropTypes.string,
|
|
168
|
+
className: PropTypes.string,
|
|
169
|
+
confirmColor: PropTypes.string,
|
|
170
|
+
confirmContent: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
171
|
+
confirmTitle: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
172
|
+
icon: PropTypes.element,
|
|
173
|
+
label: PropTypes.string,
|
|
174
|
+
mutationMode: PropTypes.oneOf(['pessimistic', 'optimistic', 'undoable']),
|
|
175
|
+
onClick: PropTypes.func,
|
|
176
|
+
record: PropTypes.any,
|
|
177
|
+
redirect: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.func]),
|
|
178
|
+
resource: PropTypes.string,
|
|
179
|
+
translateOptions: PropTypes.object
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export { DeleteWithConfirmButton };
|
|
@@ -2,5 +2,6 @@ export * from './BulkDeleteWithConfirmButton';
|
|
|
2
2
|
export * from './Button';
|
|
3
3
|
export * from './CreateButton';
|
|
4
4
|
export * from './CreateInDialogButton';
|
|
5
|
+
export * from './DeleteWithConfirmButton';
|
|
5
6
|
export * from './EditInDialogButton';
|
|
6
7
|
export * from './ImpersonateUserButton';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ActionsMenu } from '@/components/ActionsMenu';
|
|
2
|
-
import { CloneButton,
|
|
2
|
+
import { CloneButton, EditButton } from 'react-admin';
|
|
3
|
+
import { DeleteWithConfirmButton } from '@/components/ra-buttons';
|
|
3
4
|
|
|
4
5
|
function ActionsField({ canEdit = true, canDelete = true, canClone = false }: ActionsFieldProps): JSX.Element | null {
|
|
5
6
|
if (!canEdit && !canDelete && !canClone) {
|
|
@@ -4,12 +4,12 @@ import { Toolbar } from '@/components/ra-forms/Toolbar';
|
|
|
4
4
|
import { useResourceTitle } from '@/hooks';
|
|
5
5
|
import { styled, useTheme } from '@mui/system';
|
|
6
6
|
import {
|
|
7
|
-
DeleteWithConfirmButton,
|
|
8
7
|
SimpleForm as RaSimpleForm,
|
|
9
8
|
SimpleFormProps as RaSimpleFormProps,
|
|
10
9
|
SaveButton,
|
|
11
10
|
useRecordContext
|
|
12
11
|
} from 'react-admin';
|
|
12
|
+
import { DeleteWithConfirmButton } from '@/components/ra-buttons';
|
|
13
13
|
|
|
14
14
|
const StyledSimpleForm = styled(RaSimpleForm, { slot: 'Root' })(({ theme }: { theme: any }) => ({
|
|
15
15
|
[theme.breakpoints.down('sm')]: {
|
|
@@ -5,13 +5,8 @@ import { useResourceTitle } from '@/hooks';
|
|
|
5
5
|
import { Box, useTheme } from '@mui/material';
|
|
6
6
|
import { styled } from '@mui/system';
|
|
7
7
|
import { PropsWithChildren } from 'react';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
TabbedForm as RaTabbedForm,
|
|
11
|
-
TabbedFormProps as RaTabbedFormProps,
|
|
12
|
-
SaveButton,
|
|
13
|
-
TabProps
|
|
14
|
-
} from 'react-admin';
|
|
8
|
+
import { TabbedForm as RaTabbedForm, TabbedFormProps as RaTabbedFormProps, SaveButton, TabProps } from 'react-admin';
|
|
9
|
+
import { DeleteWithConfirmButton } from '@/components/ra-buttons';
|
|
15
10
|
|
|
16
11
|
type StackTabProps = TabProps & PropsWithChildren<Record<string, never>>;
|
|
17
12
|
|