feat(create-role): make isCreator condition checked by default (#1276)
This commit is contained in:
@@ -4,9 +4,12 @@ import Checkbox, { CheckboxProps } from '@mui/material/Checkbox';
|
|||||||
|
|
||||||
type ControlledCheckboxProps = {
|
type ControlledCheckboxProps = {
|
||||||
name: string;
|
name: string;
|
||||||
} & CheckboxProps;
|
defaultValue?: boolean;
|
||||||
|
} & Omit<CheckboxProps, 'defaultValue'>;
|
||||||
|
|
||||||
export default function ControlledCheckbox(props: ControlledCheckboxProps): React.ReactElement {
|
export default function ControlledCheckbox(
|
||||||
|
props: ControlledCheckboxProps
|
||||||
|
): React.ReactElement {
|
||||||
const { control } = useFormContext();
|
const { control } = useFormContext();
|
||||||
const {
|
const {
|
||||||
required,
|
required,
|
||||||
@@ -34,24 +37,25 @@ export default function ControlledCheckbox(props: ControlledCheckboxProps): Reac
|
|||||||
...field
|
...field
|
||||||
},
|
},
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
{...checkboxProps}
|
{...checkboxProps}
|
||||||
{...field}
|
{...field}
|
||||||
checked={!!value}
|
checked={!!value}
|
||||||
name={name}
|
name={name}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onChange={(...args) => {
|
onChange={(...args) => {
|
||||||
controllerOnChange(...args);
|
controllerOnChange(...args);
|
||||||
onChange?.(...args);
|
onChange?.(...args);
|
||||||
}}
|
}}
|
||||||
onBlur={(...args) => {
|
onBlur={(...args) => {
|
||||||
controllerOnBlur();
|
controllerOnBlur();
|
||||||
onBlur?.(...args);
|
onBlur?.(...args);
|
||||||
}}
|
}}
|
||||||
inputRef={ref}
|
inputRef={ref}
|
||||||
/>
|
/>
|
||||||
)}}
|
);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -22,18 +22,14 @@ type PermissionSettingsProps = {
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
fieldPrefix: string;
|
fieldPrefix: string;
|
||||||
subject: string;
|
subject: string;
|
||||||
|
defaultChecked?: boolean;
|
||||||
actions: IPermissionCatalog['actions'];
|
actions: IPermissionCatalog['actions'];
|
||||||
conditions: IPermissionCatalog['conditions'];
|
conditions: IPermissionCatalog['conditions'];
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function PermissionSettings(props: PermissionSettingsProps) {
|
export default function PermissionSettings(props: PermissionSettingsProps) {
|
||||||
const {
|
const { onClose, fieldPrefix, subject, actions, conditions, defaultChecked } =
|
||||||
onClose,
|
props;
|
||||||
fieldPrefix,
|
|
||||||
subject,
|
|
||||||
actions,
|
|
||||||
conditions,
|
|
||||||
} = props;
|
|
||||||
|
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const { getValues, resetField } = useFormContext();
|
const { getValues, resetField } = useFormContext();
|
||||||
@@ -47,7 +43,7 @@ export default function PermissionSettings(props: PermissionSettingsProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
}
|
};
|
||||||
|
|
||||||
const apply = () => {
|
const apply = () => {
|
||||||
for (const action of actions) {
|
for (const action of actions) {
|
||||||
@@ -59,13 +55,11 @@ export default function PermissionSettings(props: PermissionSettingsProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open onClose={cancel}>
|
<Dialog open onClose={cancel}>
|
||||||
<DialogTitle>
|
<DialogTitle>{formatMessage('permissionSettings.title')}</DialogTitle>
|
||||||
{formatMessage('permissionSettings.title')}
|
|
||||||
</DialogTitle>
|
|
||||||
|
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<TableContainer component={Paper}>
|
<TableContainer component={Paper}>
|
||||||
@@ -74,14 +68,14 @@ export default function PermissionSettings(props: PermissionSettingsProps) {
|
|||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell component="th" />
|
<TableCell component="th" />
|
||||||
|
|
||||||
{actions.map(action => (
|
{actions.map((action) => (
|
||||||
<TableCell component="th" key={action.key}>
|
<TableCell component="th" key={action.key}>
|
||||||
<Typography
|
<Typography
|
||||||
variant="subtitle1"
|
variant="subtitle1"
|
||||||
align="center"
|
align="center"
|
||||||
sx={{
|
sx={{
|
||||||
color: 'text.secondary',
|
color: 'text.secondary',
|
||||||
fontWeight: 700
|
fontWeight: 700,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{action.label}
|
{action.label}
|
||||||
@@ -97,9 +91,7 @@ export default function PermissionSettings(props: PermissionSettingsProps) {
|
|||||||
sx={{ '&:last-child td': { border: 0 } }}
|
sx={{ '&:last-child td': { border: 0 } }}
|
||||||
>
|
>
|
||||||
<TableCell scope="row">
|
<TableCell scope="row">
|
||||||
<Typography
|
<Typography variant="subtitle2">
|
||||||
variant="subtitle2"
|
|
||||||
>
|
|
||||||
{condition.label}
|
{condition.label}
|
||||||
</Typography>
|
</Typography>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
@@ -109,13 +101,16 @@ export default function PermissionSettings(props: PermissionSettingsProps) {
|
|||||||
key={`${action.key}.${condition.key}`}
|
key={`${action.key}.${condition.key}`}
|
||||||
align="center"
|
align="center"
|
||||||
>
|
>
|
||||||
<Typography
|
<Typography variant="subtitle2">
|
||||||
variant="subtitle2"
|
|
||||||
>
|
|
||||||
{action.subjects.includes(subject) && (
|
{action.subjects.includes(subject) && (
|
||||||
<ControlledCheckbox
|
<ControlledCheckbox
|
||||||
name={`${fieldPrefix}.${action.key}.conditions.${condition.key}`}
|
name={`${fieldPrefix}.${action.key}.conditions.${condition.key}`}
|
||||||
disabled={getValues(`${fieldPrefix}.${action.key}.value`) !== true}
|
defaultValue={defaultChecked}
|
||||||
|
disabled={
|
||||||
|
getValues(
|
||||||
|
`${fieldPrefix}.${action.key}.value`
|
||||||
|
) !== true
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -131,12 +126,14 @@ export default function PermissionSettings(props: PermissionSettingsProps) {
|
|||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={cancel}>{formatMessage('permissionSettings.cancel')}</Button>
|
<Button onClick={cancel}>
|
||||||
|
{formatMessage('permissionSettings.cancel')}
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button onClick={apply} color="error">
|
<Button onClick={apply} color="error">
|
||||||
{formatMessage('permissionSettings.apply')}
|
{formatMessage('permissionSettings.apply')}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
@@ -19,11 +19,13 @@ import PermissionCatalogFieldLoader from './PermissionCatalogFieldLoader';
|
|||||||
type PermissionCatalogFieldProps = {
|
type PermissionCatalogFieldProps = {
|
||||||
name?: string;
|
name?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
defaultChecked?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const PermissionCatalogField = ({
|
const PermissionCatalogField = ({
|
||||||
name = 'permissions',
|
name = 'permissions',
|
||||||
disabled = false,
|
disabled = false,
|
||||||
|
defaultChecked = false,
|
||||||
}: PermissionCatalogFieldProps) => {
|
}: PermissionCatalogFieldProps) => {
|
||||||
const { permissionCatalog, loading } = usePermissionCatalog();
|
const { permissionCatalog, loading } = usePermissionCatalog();
|
||||||
const [dialogName, setDialogName] = React.useState<string>();
|
const [dialogName, setDialogName] = React.useState<string>();
|
||||||
@@ -98,6 +100,7 @@ const PermissionCatalogField = ({
|
|||||||
subject={subject.key}
|
subject={subject.key}
|
||||||
actions={permissionCatalog.actions}
|
actions={permissionCatalog.actions}
|
||||||
conditions={permissionCatalog.conditions}
|
conditions={permissionCatalog.conditions}
|
||||||
|
defaultChecked={defaultChecked}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
@@ -74,7 +74,10 @@ export default function CreateRole(): React.ReactElement {
|
|||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PermissionCatalogField name="computedPermissions" />
|
<PermissionCatalogField
|
||||||
|
name="computedPermissions"
|
||||||
|
defaultChecked={true}
|
||||||
|
/>
|
||||||
|
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
type="submit"
|
type="submit"
|
||||||
|
Reference in New Issue
Block a user