@applica-software-guru/react-admin 1.5.312 → 1.5.313
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 +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/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 +17900 -15923
- 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/src/components/ra-buttons/DeleteWithConfirmButton.tsx +177 -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
|
@@ -0,0 +1,177 @@
|
|
|
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 = defaultIcon,
|
|
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
|
+
typeof confirmContent === 'string' ? (
|
|
127
|
+
translate(confirmContent)
|
|
128
|
+
) : (
|
|
129
|
+
confirmContent
|
|
130
|
+
)
|
|
131
|
+
) : (
|
|
132
|
+
<Typography maxWidth="300px" variant="h4" align="center">
|
|
133
|
+
{translate('ra.message.delete_content')}
|
|
134
|
+
</Typography>
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
confirmColor={confirmColor}
|
|
138
|
+
translateOptions={{
|
|
139
|
+
name: translate(`resources.${resource}.forcedCaseName`, {
|
|
140
|
+
smart_count: 1,
|
|
141
|
+
_: inflection.humanize(
|
|
142
|
+
translate(`resources.${resource}.name`, {
|
|
143
|
+
smart_count: 1,
|
|
144
|
+
_: inflection.singularize(resource)
|
|
145
|
+
}),
|
|
146
|
+
true
|
|
147
|
+
)
|
|
148
|
+
}),
|
|
149
|
+
id: record?.id,
|
|
150
|
+
...translateOptions
|
|
151
|
+
}}
|
|
152
|
+
onConfirm={handleDelete}
|
|
153
|
+
onClose={handleDialogClose}
|
|
154
|
+
/>
|
|
155
|
+
</>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
DeleteWithConfirmButton.propTypes = {
|
|
160
|
+
basePath: PropTypes.string,
|
|
161
|
+
className: PropTypes.string,
|
|
162
|
+
confirmColor: PropTypes.string,
|
|
163
|
+
confirmContent: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
164
|
+
confirmTitle: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
165
|
+
icon: PropTypes.element,
|
|
166
|
+
label: PropTypes.string,
|
|
167
|
+
mutationMode: PropTypes.oneOf(['pessimistic', 'optimistic', 'undoable']),
|
|
168
|
+
onClick: PropTypes.func,
|
|
169
|
+
record: PropTypes.any,
|
|
170
|
+
redirect: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.func]),
|
|
171
|
+
resource: PropTypes.string,
|
|
172
|
+
translateOptions: PropTypes.object
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const defaultIcon = <ActionDelete />;
|
|
176
|
+
|
|
177
|
+
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
|
|