Skip to content

Commit

Permalink
Fix readonly mode for buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
nfour committed Sep 8, 2023
1 parent 5cacdd2 commit fa394da
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
92 changes: 47 additions & 45 deletions libs/jsonform/src/FormConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,51 +251,53 @@ export const FormConfigEditor = observer<{
</Alert>
)}
</Grid>
<Grid
container
css={css`
flex-grow: 1;
justify-content: space-between;
padding: 1em 1.5em;
box-shadow: 0 -2px 3px 0 #0002, 0 1px 1px 0 #0001;
position: relative;
`}
>
<div>
<ConfirmDropdown
trigger={{
button: {
variant: 'outlined',
disabled: !!readOnly,
},
icon: <DiscardIcon fontSize="small" />,
label: <>{text?.discardButton || 'Discard'}</>,
}}
confirm={{
icon: <DiscardIcon />,
label: <>{text?.discardButton || 'Discard'}</>,
onClick() {
operations?.onDiscard?.();
},
}}
/>
<Button
color="primary"
variant="outlined"
endIcon={<SaveIcon fontSize="small" />}
onClick={() => {
state.validateEntireForm();

if (state.hasValidationErrors) return;

operations?.onSave?.(state.data);
}}
disabled={!!readOnly || state.hasValidationErrors}
>
{text?.saveButton || 'Save'}
</Button>
</div>
</Grid>
{!readOnly && (
<Grid
container
css={css`
flex-grow: 1;
justify-content: space-between;
padding: 1em 1.5em;
box-shadow: 0 -2px 3px 0 #0002, 0 1px 1px 0 #0001;
position: relative;
`}
>
<div>
<ConfirmDropdown
trigger={{
button: {
variant: 'outlined',
disabled: !!readOnly,
},
icon: <DiscardIcon fontSize="small" />,
label: <>{text?.discardButton || 'Discard'}</>,
}}
confirm={{
icon: <DiscardIcon />,
label: <>{text?.discardButton || 'Discard'}</>,
onClick() {
operations?.onDiscard?.();
},
}}
/>
<Button
color="primary"
variant="outlined"
endIcon={<SaveIcon fontSize="small" />}
onClick={() => {
state.validateEntireForm();

if (state.hasValidationErrors) return;

operations?.onSave?.(state.data);
}}
disabled={!!readOnly || state.hasValidationErrors}
>
{text?.saveButton || 'Save'}
</Button>
</div>
</Grid>
)}
</Grid>
);
},
Expand Down
5 changes: 1 addition & 4 deletions libs/scenarios/src/editor/ScenarioConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const ScenarioConfigEditor = observer<{

updateScenario({ ...activeScenario, data });
},

...(editor.operations ?? {}),
}}
/>
Expand All @@ -91,7 +92,6 @@ export const ScenarioConfigEditor = observer<{
box-shadow: 0 2px 3px 0 #0002, 0 -1px 1px 0 #0001;
position: relative;
`}
disabled={!!editor.readOnly}
>
<ConfirmDropdown
css={css`
Expand All @@ -100,9 +100,6 @@ export const ScenarioConfigEditor = observer<{
trigger={{
icon: <DeleteIcon />,
label: <>Delete</>,
button: {
disabled: !!editor.readOnly,
},
}}
confirm={{
icon: <DeleteIcon />,
Expand Down

0 comments on commit fa394da

Please sign in to comment.