Skip to content

Commit

Permalink
[frontend/backend] clean
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 committed Dec 12, 2024
1 parent 0b182f0 commit 1761075
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Typography from '@mui/material/Typography';
import { Link } from 'react-router-dom';
import Alert from '@mui/material/Alert';
import { Autocomplete } from '@mui/material';
import * as Yup from 'yup';
import EEChip from '../entreprise_edition/EEChip';
import Drawer from '../drawer/Drawer';
import Chart from '../charts/Chart';
Expand Down Expand Up @@ -194,6 +195,7 @@ const StixCoreObjectSimulationResult = ({ id, type }) => {
const [filters, helpers] = useFiltersState(emptyFilterGroup);
const { t_i18n } = useFormatter();
const isGrantedToUpdate = useGranted([KNOWLEDGE_KNUPDATE]);
const [platformError, setPlatformError] = useState('');

const platformOptions = [
{ label: 'Windows', value: 'Windows' },
Expand Down Expand Up @@ -451,6 +453,25 @@ const StixCoreObjectSimulationResult = ({ id, type }) => {
/>
);
};

// Validation for Platforms
const platformValidation = () => Yup.object().shape({
platforms: Yup.array()
.min(1, t_i18n('This field should not be empty.'))
.required(t_i18n('This field is required.')),
});

const validate = () => {
platformValidation(t_i18n)
.validate({ platforms })
.then(() => {
setPlatformError('');
})
.catch((err) => {
setPlatformError(err.message);
});
};

const renderForm = () => {
return (
<>
Expand Down Expand Up @@ -478,7 +499,7 @@ const StixCoreObjectSimulationResult = ({ id, type }) => {
{t_i18n('Technical (payloads) require attack patterns in this entity.')}
</Alert>
)}
<FormControl style={fieldSpacingContainerStyle}>
<FormControl style={fieldSpacingContainerStyle} error={!!platformError}>
<Autocomplete
id="simulationPlatforms"
multiple
Expand All @@ -487,6 +508,7 @@ const StixCoreObjectSimulationResult = ({ id, type }) => {
onChange={(_event, newValue) => {
const newSelectedValues = newValue.map((platform) => platform.value);
setPlatforms(newSelectedValues);
validate();
}}
getOptionLabel={(option) => option.label}
renderInput={(params) => (
Expand All @@ -495,8 +517,8 @@ const StixCoreObjectSimulationResult = ({ id, type }) => {
label={t_i18n('Targeted platforms')}
variant="standard"
required
error={platforms.length === 0}
helperText={platforms.length === 0 ? t_i18n('This field should not be empty.') : ''}
error={!!platformError}
helperText={platformError}
/>
)}
renderOption={(props, option) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum Architecture {
input SimulationConfig {
interval: Int
selection: Selection
simulationType: SimulationType
simulationType: SimulationType!
platforms: [Platform]
architecture: Architecture
}
Expand Down

0 comments on commit 1761075

Please sign in to comment.