Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eneufeld committed Jun 5, 2024
1 parent b2db7c1 commit 4384c79
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export const MaterialListWithDetailRenderer = ({
[uischemas, schema, uischema.scope, path, uischema, rootSchema]
);
const appliedUiSchemaOptions = merge({}, config, uischema.options);
const doDisableAdd = disableAdd || appliedUiSchemaOptions.disableAdd;
const doDisableRemove = disableRemove || appliedUiSchemaOptions.disableRemove;

React.useEffect(() => {
setSelectedIndex(undefined);
Expand All @@ -126,7 +128,7 @@ export const MaterialListWithDetailRenderer = ({
enabled={enabled}
addItem={addItem}
createDefault={handleCreateDefaultValue}
disableAdd={disableAdd}
disableAdd={doDisableAdd}
/>
<Grid container direction='row' spacing={2}>
<Grid item xs={3}>
Expand All @@ -145,7 +147,7 @@ export const MaterialListWithDetailRenderer = ({
uischema={foundUISchema}
childLabelProp={appliedUiSchemaOptions.elementLabelProp}
translations={translations}
disableRemove={disableRemove}
disableRemove={doDisableRemove}
/>
))
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,15 @@ export class MaterialTableControl extends React.Component<
cells,
translations,
disableAdd,
disableRemove,
config,
} = this.props;

const appliedUiSchemaOptions = merge({}, config, uischema.options);
const doDisableAdd = disableAdd || appliedUiSchemaOptions.disableAdd;
const doDisableRemove =
disableRemove || appliedUiSchemaOptions.disableRemove;

const controlElement = uischema as ControlElement;
const isObjectSchema = schema.type === 'object';
const headerCells: any = isObjectSchema
Expand All @@ -499,7 +506,7 @@ export class MaterialTableControl extends React.Component<
rootSchema={rootSchema}
enabled={enabled}
translations={translations}
disableAdd={disableAdd}
disableAdd={doDisableAdd}
/>
{isObjectSchema && (
<TableRow>
Expand All @@ -513,6 +520,7 @@ export class MaterialTableControl extends React.Component<
openDeleteDialog={openDeleteDialog}
translations={translations}
{...this.props}
disableRemove={doDisableRemove}
/>
</TableBody>
</Table>
Expand Down
30 changes: 22 additions & 8 deletions packages/material-renderers/src/layouts/ExpandPanelRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,17 @@ export const ctxDispatchToExpandPanelProps: (
(event: any): void => {
event.stopPropagation();
dispatch(
update(path, (array) => {
moveUp(array, toMove);
return array;
})
update(
path,
(array) => {
moveUp(array, toMove);
return array;
},
{
type: 'MOVE',
moves: [{ from: toMove, to: toMove - 1 }],
} as UpdateArrayContext
)
);
},
[dispatch]
Expand All @@ -299,10 +306,17 @@ export const ctxDispatchToExpandPanelProps: (
(event: any): void => {
event.stopPropagation();
dispatch(
update(path, (array) => {
moveDown(array, toMove);
return array;
})
update(
path,
(array) => {
moveDown(array, toMove);
return array;
},
{
type: 'MOVE',
moves: [{ from: toMove, to: toMove + 1 }],
} as UpdateArrayContext
)
);
},
[dispatch]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps) => {
disableRemove,
} = props;
const appliedUiSchemaOptions = merge({}, config, props.uischema.options);
const doDisableAdd = disableAdd || appliedUiSchemaOptions.disableAdd;
const doDisableRemove = disableRemove || appliedUiSchemaOptions.disableRemove;

return (
<div>
Expand All @@ -87,7 +89,7 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps) => {
enabled={enabled}
addItem={addItem}
createDefault={innerCreateDefaultValue}
disableAdd={disableAdd}
disableAdd={doDisableAdd}
/>
<div>
{data > 0 ? (
Expand All @@ -111,7 +113,7 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps) => {
childLabelProp={appliedUiSchemaOptions.elementLabelProp}
uischemas={uischemas}
translations={translations}
disableRemove={disableRemove}
disableRemove={doDisableRemove}
/>
);
})
Expand Down

0 comments on commit 4384c79

Please sign in to comment.