@jsonforms/material-renderers 3.3.0 → 3.4.0-alpha.0

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.
@@ -9,5 +9,6 @@ export interface ArrayLayoutToolbarProps {
9
9
  addItem(path: string, data: any): () => void;
10
10
  createDefault(): any;
11
11
  translations: ArrayTranslations;
12
+ disableAdd?: boolean;
12
13
  }
13
14
  export declare const ArrayLayoutToolbar: React.NamedExoticComponent<ArrayLayoutToolbarProps>;
@@ -18,6 +18,7 @@ interface OwnPropsOfExpandPanel {
18
18
  childLabelProp?: string;
19
19
  handleExpansion(panel: string): (event: any, expanded: boolean) => void;
20
20
  translations: ArrayTranslations;
21
+ disableRemove?: boolean;
21
22
  }
22
23
  interface StatePropsOfExpandPanel extends OwnPropsOfExpandPanel {
23
24
  childLabel: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonforms/material-renderers",
3
- "version": "3.3.0",
3
+ "version": "3.4.0-alpha.0",
4
4
  "description": "Material Renderer Set for JSON Forms",
5
5
  "repository": "https://github.com/eclipsesource/jsonforms",
6
6
  "bugs": "https://github.com/eclipsesource/jsonforms/issues",
@@ -73,8 +73,8 @@
73
73
  "peerDependencies": {
74
74
  "@emotion/react": "^11.4.1",
75
75
  "@emotion/styled": "^11.3.0",
76
- "@jsonforms/core": "3.3.0",
77
- "@jsonforms/react": "3.3.0",
76
+ "@jsonforms/core": "3.4.0-alpha.0",
77
+ "@jsonforms/react": "3.4.0-alpha.0",
78
78
  "@mui/icons-material": "^5.11.16",
79
79
  "@mui/material": "^5.13.0",
80
80
  "@mui/x-date-pickers": "^6.0.0",
@@ -126,8 +126,8 @@
126
126
  "webpack": "^5.78.0",
127
127
  "webpack-cli": "^5.1.4",
128
128
  "webpack-dev-server": "^4.15.1",
129
- "@jsonforms/core": "3.3.0",
130
- "@jsonforms/react": "3.3.0"
129
+ "@jsonforms/core": "3.4.0-alpha.0",
130
+ "@jsonforms/react": "3.4.0-alpha.0"
131
131
  },
132
132
  "scripts": {
133
133
  "build": "rollup -c rollup.config.js",
@@ -45,6 +45,7 @@ export const ListWithDetailMasterItem = ({
45
45
  removeItem,
46
46
  path,
47
47
  translations,
48
+ disableRemove,
48
49
  }: StatePropsOfMasterItem) => {
49
50
  return (
50
51
  <ListItem button selected={selected} onClick={handleSelect(index)}>
@@ -52,7 +53,7 @@ export const ListWithDetailMasterItem = ({
52
53
  <Avatar aria-label='Index'>{index + 1}</Avatar>
53
54
  </ListItemAvatar>
54
55
  <ListItemText primary={childLabel} />
55
- {enabled && (
56
+ {enabled && !disableRemove && (
56
57
  <ListItemSecondaryAction>
57
58
  <Tooltip
58
59
  id='tooltip-remove'
@@ -65,6 +65,8 @@ export const MaterialListWithDetailRenderer = ({
65
65
  rootSchema,
66
66
  translations,
67
67
  description,
68
+ disableAdd,
69
+ disableRemove,
68
70
  }: ArrayLayoutProps) => {
69
71
  const [selectedIndex, setSelectedIndex] = useState(undefined);
70
72
  const handleRemoveItem = useCallback(
@@ -100,6 +102,8 @@ export const MaterialListWithDetailRenderer = ({
100
102
  [uischemas, schema, uischema.scope, path, uischema, rootSchema]
101
103
  );
102
104
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
105
+ const doDisableAdd = disableAdd || appliedUiSchemaOptions.disableAdd;
106
+ const doDisableRemove = disableRemove || appliedUiSchemaOptions.disableRemove;
103
107
 
104
108
  React.useEffect(() => {
105
109
  setSelectedIndex(undefined);
@@ -124,6 +128,7 @@ export const MaterialListWithDetailRenderer = ({
124
128
  enabled={enabled}
125
129
  addItem={addItem}
126
130
  createDefault={handleCreateDefaultValue}
131
+ disableAdd={doDisableAdd}
127
132
  />
128
133
  <Grid container direction='row' spacing={2}>
129
134
  <Grid item xs={3}>
@@ -142,6 +147,7 @@ export const MaterialListWithDetailRenderer = ({
142
147
  uischema={foundUISchema}
143
148
  childLabelProp={appliedUiSchemaOptions.elementLabelProp}
144
149
  translations={translations}
150
+ disableRemove={doDisableRemove}
145
151
  />
146
152
  ))
147
153
  ) : (
@@ -278,6 +278,7 @@ interface NonEmptyRowProps {
278
278
  cells?: JsonFormsCellRendererRegistryEntry[];
279
279
  path: string;
280
280
  translations: ArrayTranslations;
281
+ disableRemove?: boolean;
281
282
  }
282
283
 
283
284
  const NonEmptyRowComponent = ({
@@ -294,6 +295,7 @@ const NonEmptyRowComponent = ({
294
295
  cells,
295
296
  path,
296
297
  translations,
298
+ disableRemove,
297
299
  }: NonEmptyRowProps & WithDeleteDialogSupport) => {
298
300
  const moveUp = useMemo(
299
301
  () => moveUpCreator(path, rowIndex),
@@ -354,21 +356,23 @@ const NonEmptyRowComponent = ({
354
356
  </Grid>
355
357
  </Fragment>
356
358
  ) : null}
357
- <Grid item>
358
- <Tooltip
359
- id='tooltip-remove'
360
- title={translations.removeTooltip}
361
- placement='bottom'
362
- >
363
- <IconButton
364
- aria-label={translations.removeAriaLabel}
365
- onClick={() => openDeleteDialog(childPath, rowIndex)}
366
- size='large'
359
+ {!disableRemove ? (
360
+ <Grid item>
361
+ <Tooltip
362
+ id='tooltip-remove'
363
+ title={translations.removeTooltip}
364
+ placement='bottom'
367
365
  >
368
- <DeleteIcon />
369
- </IconButton>
370
- </Tooltip>
371
- </Grid>
366
+ <IconButton
367
+ aria-label={translations.removeAriaLabel}
368
+ onClick={() => openDeleteDialog(childPath, rowIndex)}
369
+ size='large'
370
+ >
371
+ <DeleteIcon />
372
+ </IconButton>
373
+ </Tooltip>
374
+ </Grid>
375
+ ) : null}
372
376
  </Grid>
373
377
  </NoBorderTableCell>
374
378
  ) : null}
@@ -387,6 +391,7 @@ interface TableRowsProp {
387
391
  moveUp?(path: string, toMove: number): () => void;
388
392
  moveDown?(path: string, toMove: number): () => void;
389
393
  translations: ArrayTranslations;
394
+ disableRemove?: boolean;
390
395
  }
391
396
  const TableRows = ({
392
397
  data,
@@ -400,6 +405,7 @@ const TableRows = ({
400
405
  enabled,
401
406
  cells,
402
407
  translations,
408
+ disableRemove,
403
409
  }: TableRowsProp & WithDeleteDialogSupport) => {
404
410
  const isEmptyTable = data === 0;
405
411
 
@@ -438,6 +444,7 @@ const TableRows = ({
438
444
  cells={cells}
439
445
  path={path}
440
446
  translations={translations}
447
+ disableRemove={disableRemove}
441
448
  />
442
449
  );
443
450
  })}
@@ -464,8 +471,16 @@ export class MaterialTableControl extends React.Component<
464
471
  enabled,
465
472
  cells,
466
473
  translations,
474
+ disableAdd,
475
+ disableRemove,
476
+ config,
467
477
  } = this.props;
468
478
 
479
+ const appliedUiSchemaOptions = merge({}, config, uischema.options);
480
+ const doDisableAdd = disableAdd || appliedUiSchemaOptions.disableAdd;
481
+ const doDisableRemove =
482
+ disableRemove || appliedUiSchemaOptions.disableRemove;
483
+
469
484
  const controlElement = uischema as ControlElement;
470
485
  const isObjectSchema = schema.type === 'object';
471
486
  const headerCells: any = isObjectSchema
@@ -491,6 +506,7 @@ export class MaterialTableControl extends React.Component<
491
506
  rootSchema={rootSchema}
492
507
  enabled={enabled}
493
508
  translations={translations}
509
+ disableAdd={doDisableAdd}
494
510
  />
495
511
  {isObjectSchema && (
496
512
  <TableRow>
@@ -504,6 +520,7 @@ export class MaterialTableControl extends React.Component<
504
520
  openDeleteDialog={openDeleteDialog}
505
521
  translations={translations}
506
522
  {...this.props}
523
+ disableRemove={doDisableRemove}
507
524
  />
508
525
  </TableBody>
509
526
  </Table>
@@ -54,6 +54,7 @@ export interface MaterialTableToolbarProps {
54
54
  enabled: boolean;
55
55
  translations: ArrayTranslations;
56
56
  addItem(path: string, value: any): () => void;
57
+ disableAdd?: boolean;
57
58
  }
58
59
 
59
60
  const fixedCellSmall = {
@@ -72,6 +73,7 @@ const TableToolbar = React.memo(function TableToolbar({
72
73
  enabled,
73
74
  translations,
74
75
  rootSchema,
76
+ disableAdd,
75
77
  }: MaterialTableToolbarProps) {
76
78
  return (
77
79
  <TableRow>
@@ -100,7 +102,7 @@ const TableToolbar = React.memo(function TableToolbar({
100
102
  {description && <FormHelperText>{description}</FormHelperText>}
101
103
  </Stack>
102
104
  </NoBorderTableCell>
103
- {enabled ? (
105
+ {enabled && !disableAdd ? (
104
106
  <NoBorderTableCell align='right' style={fixedCellSmall}>
105
107
  <Tooltip
106
108
  id='tooltip-add'
@@ -20,6 +20,7 @@ export interface ArrayLayoutToolbarProps {
20
20
  addItem(path: string, data: any): () => void;
21
21
  createDefault(): any;
22
22
  translations: ArrayTranslations;
23
+ disableAdd?: boolean;
23
24
  }
24
25
  export const ArrayLayoutToolbar = React.memo(function ArrayLayoutToolbar({
25
26
  label,
@@ -30,6 +31,7 @@ export const ArrayLayoutToolbar = React.memo(function ArrayLayoutToolbar({
30
31
  enabled,
31
32
  createDefault,
32
33
  translations,
34
+ disableAdd,
33
35
  }: ArrayLayoutToolbarProps) {
34
36
  return (
35
37
  <Toolbar disableGutters={true}>
@@ -57,7 +59,7 @@ export const ArrayLayoutToolbar = React.memo(function ArrayLayoutToolbar({
57
59
  </Grid>
58
60
  </Grid>
59
61
  </Grid>
60
- {enabled && (
62
+ {enabled && !disableAdd && (
61
63
  <Grid item>
62
64
  <Grid container>
63
65
  <Grid item>
@@ -29,6 +29,7 @@ import {
29
29
  removeId,
30
30
  ArrayTranslations,
31
31
  computeChildLabel,
32
+ UpdateArrayContext,
32
33
  } from '@jsonforms/core';
33
34
  import {
34
35
  Accordion,
@@ -65,6 +66,7 @@ interface OwnPropsOfExpandPanel {
65
66
  childLabelProp?: string;
66
67
  handleExpansion(panel: string): (event: any, expanded: boolean) => void;
67
68
  translations: ArrayTranslations;
69
+ disableRemove?: boolean;
68
70
  }
69
71
 
70
72
  interface StatePropsOfExpandPanel extends OwnPropsOfExpandPanel {
@@ -117,6 +119,7 @@ const ExpandPanelRendererComponent = (props: ExpandPanelProps) => {
117
119
  cells,
118
120
  config,
119
121
  translations,
122
+ disableRemove,
120
123
  } = props;
121
124
 
122
125
  const foundUISchema = useMemo(
@@ -207,7 +210,7 @@ const ExpandPanelRendererComponent = (props: ExpandPanelProps) => {
207
210
  ) : (
208
211
  ''
209
212
  )}
210
- {enabled && (
213
+ {enabled && !disableRemove && (
211
214
  <Grid item>
212
215
  <Tooltip
213
216
  id='tooltip-remove'
@@ -262,13 +265,17 @@ export const ctxDispatchToExpandPanelProps: (
262
265
  (event: any): void => {
263
266
  event.stopPropagation();
264
267
  dispatch(
265
- update(path, (array) => {
266
- toDelete
267
- .sort()
268
- .reverse()
269
- .forEach((s) => array.splice(s, 1));
270
- return array;
271
- })
268
+ update(
269
+ path,
270
+ (array) => {
271
+ toDelete
272
+ .sort()
273
+ .reverse()
274
+ .forEach((s) => array.splice(s, 1));
275
+ return array;
276
+ },
277
+ { type: 'REMOVE', indices: toDelete } as UpdateArrayContext
278
+ )
272
279
  );
273
280
  },
274
281
  [dispatch]
@@ -278,10 +285,17 @@ export const ctxDispatchToExpandPanelProps: (
278
285
  (event: any): void => {
279
286
  event.stopPropagation();
280
287
  dispatch(
281
- update(path, (array) => {
282
- moveUp(array, toMove);
283
- return array;
284
- })
288
+ update(
289
+ path,
290
+ (array) => {
291
+ moveUp(array, toMove);
292
+ return array;
293
+ },
294
+ {
295
+ type: 'MOVE',
296
+ moves: [{ from: toMove, to: toMove - 1 }],
297
+ } as UpdateArrayContext
298
+ )
285
299
  );
286
300
  },
287
301
  [dispatch]
@@ -291,10 +305,17 @@ export const ctxDispatchToExpandPanelProps: (
291
305
  (event: any): void => {
292
306
  event.stopPropagation();
293
307
  dispatch(
294
- update(path, (array) => {
295
- moveDown(array, toMove);
296
- return array;
297
- })
308
+ update(
309
+ path,
310
+ (array) => {
311
+ moveDown(array, toMove);
312
+ return array;
313
+ },
314
+ {
315
+ type: 'MOVE',
316
+ moves: [{ from: toMove, to: toMove + 1 }],
317
+ } as UpdateArrayContext
318
+ )
298
319
  );
299
320
  },
300
321
  [dispatch]
@@ -67,8 +67,12 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps) => {
67
67
  uischemas,
68
68
  translations,
69
69
  description,
70
+ disableAdd,
71
+ disableRemove,
70
72
  } = props;
71
73
  const appliedUiSchemaOptions = merge({}, config, props.uischema.options);
74
+ const doDisableAdd = disableAdd || appliedUiSchemaOptions.disableAdd;
75
+ const doDisableRemove = disableRemove || appliedUiSchemaOptions.disableRemove;
72
76
 
73
77
  return (
74
78
  <div>
@@ -85,6 +89,7 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps) => {
85
89
  enabled={enabled}
86
90
  addItem={addItem}
87
91
  createDefault={innerCreateDefaultValue}
92
+ disableAdd={doDisableAdd}
88
93
  />
89
94
  <div>
90
95
  {data > 0 ? (
@@ -108,6 +113,7 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps) => {
108
113
  childLabelProp={appliedUiSchemaOptions.elementLabelProp}
109
114
  uischemas={uischemas}
110
115
  translations={translations}
116
+ disableRemove={doDisableRemove}
111
117
  />
112
118
  );
113
119
  })