@applica-software-guru/react-admin 1.1.113 → 1.1.114
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-forms/TableForm/TableFormIterator.d.ts +2 -0
- package/dist/components/ra-forms/TableForm/TableFormIterator.d.ts.map +1 -1
- package/dist/react-admin.cjs.js +37 -37
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +476 -461
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +37 -37
- package/dist/react-admin.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ra-forms/TableForm/TableFormIterator.tsx +32 -11
package/package.json
CHANGED
|
@@ -31,7 +31,7 @@ import get from 'lodash/get';
|
|
|
31
31
|
* <Grid container>
|
|
32
32
|
* <Grid item xs={12}>
|
|
33
33
|
* <ArrayInput label={false} source="descriptor.fields">
|
|
34
|
-
* <TableFormIterator label="Catalogo proprietà">
|
|
34
|
+
* <TableFormIterator template={{ property: 'FIELD' }} label="Catalogo proprietà"> // template: default value for new row
|
|
35
35
|
* <TextInput label="Name" source={'name'} validate={required()} />
|
|
36
36
|
* <TextInput source={'denomination'} helperText={false} />
|
|
37
37
|
* <SelectInput choices={FieldTypes} source={'type'} helperText={false} />
|
|
@@ -44,7 +44,7 @@ import get from 'lodash/get';
|
|
|
44
44
|
* @returns
|
|
45
45
|
*/
|
|
46
46
|
const TableFormIterator = (props: TableFormIteratorProps) => {
|
|
47
|
-
const { children, resource, source, label, disableActions = false, disableAdd = false, disableRemove = false, className, empty } = props;
|
|
47
|
+
const { children, resource, source, label, disableActions = false, disableAdd = false, disableRemove = false, className, empty, template = {} } = props;
|
|
48
48
|
const [confirmIsOpen, setConfirmIsOpen] = useState<boolean>(false);
|
|
49
49
|
const { fields, remove, replace } = useArrayInput(props);
|
|
50
50
|
const theme = useTheme();
|
|
@@ -90,8 +90,13 @@ const TableFormIterator = (props: TableFormIteratorProps) => {
|
|
|
90
90
|
// @ts-ignore
|
|
91
91
|
<TableFormIteratorContext.Provider value={context}>
|
|
92
92
|
<div className={className}>
|
|
93
|
-
{
|
|
94
|
-
|
|
93
|
+
{React.cloneElement(<AddTableRow />, {
|
|
94
|
+
label,
|
|
95
|
+
source,
|
|
96
|
+
disableAdd,
|
|
97
|
+
template,
|
|
98
|
+
addButton: props?.addButton,
|
|
99
|
+
})}
|
|
95
100
|
|
|
96
101
|
<TableContainer component={Paper} sx={{ mt: 2, border: `1px solid ${tableBorderColor}` }}>
|
|
97
102
|
<Table>
|
|
@@ -172,20 +177,33 @@ const TableFormIterator = (props: TableFormIteratorProps) => {
|
|
|
172
177
|
};
|
|
173
178
|
|
|
174
179
|
const AddTableRow = (props: any) => {
|
|
175
|
-
const { label, disableAdd } = props;
|
|
180
|
+
const { label, disableAdd, template = {} } = props;
|
|
176
181
|
const { append } = useArrayInput(props);
|
|
177
182
|
const theme = useTheme();
|
|
178
183
|
// @ts-ignore
|
|
179
184
|
const tableBorderColor = theme.palette.mode === 'dark' ? theme.palette.grey.A400 : theme.palette.grey.A800;
|
|
180
185
|
const iconColor = theme.palette.mode === 'light' ? '#000000' : '#FFFFFF';
|
|
181
186
|
|
|
187
|
+
const handleAddButtonClick = useCallback((
|
|
188
|
+
originalOnClickHandler: React.MouseEventHandler<Element>
|
|
189
|
+
) => (event: React.MouseEvent<Element, MouseEvent>) => {
|
|
190
|
+
append(template);
|
|
191
|
+
originalOnClickHandler && originalOnClickHandler(event);
|
|
192
|
+
}, [append, template]);
|
|
193
|
+
|
|
182
194
|
return (
|
|
183
195
|
<Stack justifyContent={'space-between'} alignItems={'center'} flexDirection={'row'}>
|
|
184
196
|
<Typography>{label}</Typography>
|
|
185
197
|
{!disableAdd && (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
198
|
+
React.isValidElement(props?.addButton) ?
|
|
199
|
+
React.cloneElement(props?.addButton, {
|
|
200
|
+
onClick: handleAddButtonClick(
|
|
201
|
+
props?.addButton?.props.onClick
|
|
202
|
+
),
|
|
203
|
+
}) :
|
|
204
|
+
<IconButton size="small" color="secondary" sx={{ border: `1px solid ${tableBorderColor}` }} onClick={() => append(template)}>
|
|
205
|
+
<PlusCircleOutlined style={{ color: iconColor }} />
|
|
206
|
+
</IconButton>
|
|
189
207
|
)}
|
|
190
208
|
</Stack>
|
|
191
209
|
);
|
|
@@ -204,8 +222,9 @@ const StyledTableFormIterator = styled(TableFormIterator, {
|
|
|
204
222
|
}));
|
|
205
223
|
|
|
206
224
|
AddTableRow.propTypes = {
|
|
207
|
-
label: PropTypes.string
|
|
208
|
-
source: PropTypes.string
|
|
225
|
+
label: PropTypes.string,
|
|
226
|
+
source: PropTypes.string,
|
|
227
|
+
defaultValue: PropTypes.any
|
|
209
228
|
};
|
|
210
229
|
|
|
211
230
|
TableFormIterator.propTypes = {
|
|
@@ -224,7 +243,8 @@ TableFormIterator.propTypes = {
|
|
|
224
243
|
disableAdd: PropTypes.bool,
|
|
225
244
|
disableRemove: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
|
|
226
245
|
TransitionProps: PropTypes.shape({}),
|
|
227
|
-
empty: PropTypes.oneOfType([PropTypes.node, PropTypes.string])
|
|
246
|
+
empty: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
|
|
247
|
+
template: PropTypes.object
|
|
228
248
|
};
|
|
229
249
|
|
|
230
250
|
export interface TableFormIteratorProps extends Partial<UseFieldArrayReturn> {
|
|
@@ -234,6 +254,7 @@ export interface TableFormIteratorProps extends Partial<UseFieldArrayReturn> {
|
|
|
234
254
|
disableAdd?: boolean;
|
|
235
255
|
disableActions?: boolean;
|
|
236
256
|
disableRemove?: boolean;
|
|
257
|
+
template?: object;
|
|
237
258
|
meta?: {
|
|
238
259
|
// the type defined in FieldArrayRenderProps says error is boolean, which is wrong.
|
|
239
260
|
error?: any;
|