Skip to content

Commit

Permalink
feat: add readOnly support to React Material array and list with detail
Browse files Browse the repository at this point in the history
Closes #1901
  • Loading branch information
LukasBoll authored Jun 20, 2023
1 parent a5fdca6 commit fa055c2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 41 deletions.
1 change: 1 addition & 0 deletions packages/core/src/util/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ export interface OwnPropsOfMasterListItem {
index: number;
selected: boolean;
path: string;
enabled: boolean;
schema: JsonSchema;
handleSelect(index: number): () => void;
removeItem(path: string, value: number): () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const ListWithDetailMasterItem = ({
index,
childLabel,
selected,
enabled,
handleSelect,
removeItem,
path,
Expand All @@ -50,15 +51,17 @@ export const ListWithDetailMasterItem = ({
<Avatar aria-label='Index'>{index + 1}</Avatar>
</ListItemAvatar>
<ListItemText primary={childLabel} />
<ListItemSecondaryAction>
<IconButton
aria-label={translations.removeAriaLabel}
onClick={removeItem(path, index)}
size='large'
>
<DeleteIcon />
</IconButton>
</ListItemSecondaryAction>
{enabled && (
<ListItemSecondaryAction>
<IconButton
aria-label={translations.removeAriaLabel}
onClick={removeItem(path, index)}
size='large'
>
<DeleteIcon />
</IconButton>
</ListItemSecondaryAction>
)}
</ListItem>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const MaterialListWithDetailRenderer = ({
schema,
uischema,
path,
enabled,
errors,
visible,
label,
Expand Down Expand Up @@ -114,6 +115,7 @@ export const MaterialListWithDetailRenderer = ({
)}
errors={errors}
path={path}
enabled={enabled}
addItem={addItem}
createDefault={handleCreateDefaultValue}
/>
Expand All @@ -126,6 +128,7 @@ export const MaterialListWithDetailRenderer = ({
index={index}
path={path}
schema={schema}
enabled={enabled}
handleSelect={handleListItemClick}
removeItem={handleRemoveItem}
selected={selectedIndex === index}
Expand Down
60 changes: 39 additions & 21 deletions packages/material-renderers/src/layouts/ArrayToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface ArrayLayoutToolbarProps {
label: string;
errors: string;
path: string;
enabled: boolean;
addItem(path: string, data: any): () => void;
createDefault(): any;
translations: ArrayTranslations;
Expand All @@ -16,39 +17,56 @@ export const ArrayLayoutToolbar = React.memo(function ArrayLayoutToolbar({
errors,
addItem,
path,
enabled,
createDefault,
translations,
}: ArrayLayoutToolbarProps) {
return (
<Toolbar disableGutters={true}>
<Grid container alignItems='center' justifyContent='space-between'>
<Grid item>
<Typography variant={'h6'}>{label}</Typography>
<Grid
container
justifyContent={'flex-start'}
alignItems={'center'}
spacing={2}
>
<Grid item>
<Typography variant={'h6'}>{label}</Typography>
</Grid>
<Grid item>
{errors.length !== 0 && (
<Grid item>
<ValidationIcon
id='tooltip-validation'
errorMessages={errors}
/>
</Grid>
)}
</Grid>
</Grid>
</Grid>
{errors.length !== 0 && (
{enabled && (
<Grid item>
<ValidationIcon id='tooltip-validation' errorMessages={errors} />
</Grid>
)}
<Grid item>
<Grid container>
<Grid item>
<Tooltip
id='tooltip-add'
title={translations.addTooltip}
placement='bottom'
>
<IconButton
aria-label={translations.addAriaLabel}
onClick={addItem(path, createDefault())}
size='large'
<Grid container>
<Grid item>
<Tooltip
id='tooltip-add'
title={translations.addTooltip}
placement='bottom'
>
<AddIcon />
</IconButton>
</Tooltip>
<IconButton
aria-label={translations.addTooltip}
onClick={addItem(path, createDefault())}
size='large'
>
<AddIcon />
</IconButton>
</Tooltip>
</Grid>
</Grid>
</Grid>
</Grid>
)}
</Grid>
</Toolbar>
);
Expand Down
24 changes: 13 additions & 11 deletions packages/material-renderers/src/layouts/ExpandPanelRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const ExpandPanelRendererComponent = (props: ExpandPanelProps) => {
justifyContent='center'
alignItems='center'
>
{showSortButtons ? (
{showSortButtons && enabled ? (
<Fragment>
<Grid item>
<IconButton
Expand Down Expand Up @@ -192,16 +192,18 @@ const ExpandPanelRendererComponent = (props: ExpandPanelProps) => {
) : (
''
)}
<Grid item>
<IconButton
onClick={removeItems(path, [index])}
style={iconStyle}
aria-label={translations.removeAriaLabel}
size='large'
>
<DeleteIcon />
</IconButton>
</Grid>
{enabled && (
<Grid item>
<IconButton
onClick={removeItems(path, [index])}
style={iconStyle}
aria-label={translations.removeAriaLabel}
size='large'
>
<DeleteIcon />
</IconButton>
</Grid>
)}
</Grid>
</Grid>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps) => {
)}
errors={errors}
path={path}
enabled={enabled}
addItem={addItem}
createDefault={innerCreateDefaultValue}
/>
Expand Down

0 comments on commit fa055c2

Please sign in to comment.