Skip to content

Commit

Permalink
[frontend] disable field to edit default value in settings if needed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lndrtrbn authored Feb 26, 2024
1 parent c00c894 commit d212280
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const AutocompleteField = (props) => {
/>
{typeof openCreate === 'function' && (
<IconButton
disabled={fieldProps.disabled}
onClick={() => openCreate()}
edge="end"
style={{ position: 'absolute', top: 5, right: 35 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ interface DefaultValueFieldProps {
},
setFieldValue: (field: string, value: string) => void,
entityType?: string
disabled?: boolean
}

const DefaultValueField = ({
attribute,
setFieldValue,
entityType,
name,
disabled = false,
}: DefaultValueFieldProps) => {
const { t_i18n } = useFormatter();
const label = t_i18n('Default value');
Expand All @@ -51,6 +53,7 @@ const DefaultValueField = ({
label={t_i18n('Activate/Deactivate default values')}
fullWidth={true}
containerstyle={{ marginTop: 20 }}
disabled={disabled}
/>
<Alert
severity="info"
Expand All @@ -69,6 +72,7 @@ const DefaultValueField = ({
<KillChainPhasesField
name={name}
style={fieldSpacingContainerStyle}
disabled={disabled}
/>
);
}
Expand All @@ -80,6 +84,7 @@ const DefaultValueField = ({
name={name}
style={fieldSpacingContainerStyle}
setFieldValue={setFieldValue}
disabled={disabled}
/>
);
}
Expand All @@ -90,6 +95,7 @@ const DefaultValueField = ({
label={label}
name={name}
style={fieldSpacingContainerStyle}
disabled={disabled}
/>
);
}
Expand All @@ -100,6 +106,7 @@ const DefaultValueField = ({
label={label}
name={name}
style={fieldSpacingContainerStyle}
disabled={disabled}
/>
);
}
Expand All @@ -113,6 +120,7 @@ const DefaultValueField = ({
showAllMembersLine
showCreatorLine
canDeactivate
disabled={disabled}
/>
);
}
Expand All @@ -122,6 +130,7 @@ const DefaultValueField = ({
name={name}
label={label}
style={fieldSpacingContainerStyle}
disabled={disabled}
/>
);
}
Expand All @@ -134,6 +143,7 @@ const DefaultValueField = ({
name={name}
multiple={attribute.multiple ?? false}
containerStyle={fieldSpacingContainerStyle}
disabled={disabled}
/>
);
}
Expand All @@ -152,6 +162,7 @@ const DefaultValueField = ({
style: { marginTop: 20 },
},
}}
disabled={disabled}
/>
);
}
Expand All @@ -164,6 +175,7 @@ const DefaultValueField = ({
name={name}
label={label}
containerstyle={fieldSpacingContainerStyle}
disabled={disabled}
/>
);
}
Expand All @@ -178,6 +190,7 @@ const DefaultValueField = ({
label={label}
fullWidth={true}
style={{ marginTop: 20 }}
disabled={disabled}
/>
);
}
Expand All @@ -192,6 +205,7 @@ const DefaultValueField = ({
multiline={true}
rows="4"
style={{ marginTop: 20 }}
disabled={disabled}
/>
);
}
Expand All @@ -203,6 +217,7 @@ const DefaultValueField = ({
name={name}
label={label}
fullWidth={true}
disabled={disabled}
style={{
...fieldSpacingContainerStyle,
minHeight: 200,
Expand All @@ -219,6 +234,7 @@ const DefaultValueField = ({
label={label}
fullWidth={true}
style={{ marginTop: 20 }}
disabled={disabled}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ class KillChainPhasesField extends Component {
}

render() {
const { t, name, style, classes, onChange, helpertext } = this.props;
const { t, name, style, classes, onChange, helpertext, disabled } = this.props;
return (
<Field
component={AutocompleteField}
style={style}
name={name}
multiple={true}
disabled={disabled}
textfieldprops={{
variant: 'standard',
label: t('Kill chain phases'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ interface ObservableTypesFieldProps {
multiple?: boolean;
onChange?: (name: string, value: string | string[]) => void;
style?: Record<string, string | number>;
disabled?: boolean;
}
const ObservableTypesField: FunctionComponent<ObservableTypesFieldProps> = ({
name,
label,
multiple,
onChange,
style,
disabled,
}) => {
const classes = useStyles();
const { t_i18n } = useFormatter();
Expand All @@ -44,6 +46,7 @@ const ObservableTypesField: FunctionComponent<ObservableTypesFieldProps> = ({
name={name}
multiple={multiple || false}
fullWidth={true}
disabled={disabled}
textfieldprops={{
variant: 'standard',
label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface OpenVocabProps {
onFocus?: (name: string, value: Option) => void;
containerStyle?: Record<string, string | number>;
editContext?: unknown;
disabled?: boolean;
queryRef: PreloadedQuery<OpenVocabFieldQuery>;
onChange?: (name: string, value: string | string[]) => void;
onSubmit?: (name: string, value: string | string[]) => void;
Expand Down Expand Up @@ -60,6 +61,7 @@ Omit<OpenVocabProps, 'type'>
containerStyle,
editContext,
queryRef,
disabled = false,
}) => {
const { vocabularies } = usePreloadedQuery<OpenVocabFieldQuery>(
vocabularyQuery,
Expand Down Expand Up @@ -113,6 +115,7 @@ Omit<OpenVocabProps, 'type'>
fullWidth={true}
multiple={multiple}
style={containerStyle}
disabled={disabled}
options={openVocabList}
renderOption={renderOption}
isOptionEqualToValue={(option: Option, value: string) => option.value === value
Expand All @@ -132,6 +135,7 @@ Omit<OpenVocabProps, 'type'>
name={name}
onChange={internalOnChange}
fullWidth={true}
disabled={disabled}
multiple={multiple}
style={containerStyle}
options={openVocabList}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ const EntitySettingAttributeEdition = ({
setFieldValue={setFieldValue}
entityType={entitySetting.target_type}
name="default_values"
disabled={!attribute.editDefault}
/>

{attribute.scale && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const entitySettingAttributeLineFragment = graphql`
multiple
mandatory
mandatoryType
editDefault
defaultValues {
id
name
Expand Down Expand Up @@ -80,16 +81,17 @@ const EntitySettingAttributeLine: FunctionComponent<EntitySettingAttributeLinePr
const handleCloseUpdate = () => setDisplayUpdate(false);

const needEE = attribute.name === INPUT_AUTHORIZED_MEMBERS && !isEnterpriseEdition;
const nothingToUpdate = attribute.mandatoryType !== 'customizable' && !attribute.editDefault;

return (
<>
<ListItemButton
key={attribute.name}
divider={true}
classes={{ root: classes.item }}
onClick={() => !needEE && handleOpenUpdate()}
disableRipple={needEE}
sx={needEE
onClick={() => !needEE && !nothingToUpdate && handleOpenUpdate()}
disableRipple={needEE || nothingToUpdate}
sx={needEE || nothingToUpdate
? {
'&:hover': {
cursor: 'default',
Expand Down Expand Up @@ -125,7 +127,7 @@ const EntitySettingAttributeLine: FunctionComponent<EntitySettingAttributeLinePr
}
/>
<ListItemIcon classes={{ root: classes.goIcon }}>
{!needEE && <NorthEastOutlined />}
{!needEE && !nothingToUpdate && <NorthEastOutlined />}
</ListItemIcon>
</ListItemButton>
<EntitySettingAttributeEdition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ const EntitySettingAttributes = ({
isSortable: false,
render: (data: EntitySettingAttributeLine_attribute$data) => {
return isNotEmptyField(data.defaultValues) ? (
<CheckCircleOutlined fontSize="small" color="success" />
<CheckCircleOutlined
fontSize="small"
color={data.editDefault ? 'success' : 'disabled'}
/>
) : (
<DoNotDisturbOnOutlined fontSize="small" color="primary" />
<DoNotDisturbOnOutlined
fontSize="small"
color={data.editDefault ? 'primary' : 'disabled'}
/>
);
},
},
Expand Down

0 comments on commit d212280

Please sign in to comment.