Skip to content

Commit

Permalink
[frontend] Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RomuDeuxfois committed Jun 14, 2024
1 parent 345b244 commit 9ca5189
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 49 deletions.
74 changes: 37 additions & 37 deletions openbas-front/src/admin/components/common/injects/Injects.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const Injects = (props) => {
const classes = useStyles();
const { t, tPick } = useFormatter();
const [selectedInjectId, setSelectedInjectId] = useState(null);
const [showTimeline, setShowTimeline] = useState(true);
const [showTimeline, _setShowTimeline] = useState(true);
const { permissions } = useContext(PermissionsContext);
const injectContext = useContext(InjectContext);

Expand All @@ -202,9 +202,9 @@ const Injects = (props) => {
};
const sortedInjects = filtering.filterAndSort(injects);

const handleCheckboxChange = (event) => {
setShowTimeline(event.target.checked);
};
// const handleCheckboxChange = (event) => {
// setShowTimeline(event.target.checked);
// };

// Rendering
if (injects) {
Expand All @@ -226,15 +226,15 @@ const Injects = (props) => {
/>
</div>
<div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
<div style={{ marginRight: 10 }}>
<Checkbox
checked={showTimeline}
onChange={handleCheckboxChange}
name="showTimeline"
color="primary"
/>
<span>{t('Show Timeline')}</span>
</div>
{/* <div style={{ marginRight: 10 }}> */}
{/* <Checkbox */}
{/* checked={showTimeline} */}
{/* onChange={handleCheckboxChange} */}
{/* name="showTimeline" */}
{/* color="primary" */}
{/* /> */}
{/* <span>{t('Show Timeline')}</span> */}
{/* </div> */}
{setViewMode ? (
<ToggleButtonGroup
size="small"
Expand Down Expand Up @@ -289,7 +289,7 @@ const Injects = (props) => {
selected
aria-label="List view mode"
>
<ReorderOutlined fontSize="small" color='inherit'/>
<ReorderOutlined fontSize="small" color='inherit' />
</ToggleButton>
</Tooltip>
<Tooltip title={t('Distribution view')}>
Expand All @@ -298,7 +298,7 @@ const Injects = (props) => {
onClick={() => setViewMode('distribution')}
aria-label="Distribution view mode"
>
<BarChartOutlined fontSize="small" color='primary'/>
<BarChartOutlined fontSize="small" color='primary' />
</ToggleButton>
</Tooltip>
</ToggleButtonGroup>
Expand All @@ -325,27 +325,27 @@ const Injects = (props) => {
>
<Tooltip title={t('Export this list')}>
<IconButton size="medium">
<FileDownloadOutlined color="primary"/>
<FileDownloadOutlined color="primary" />
</IconButton>
</Tooltip>
</CSVLink>
) : (
<IconButton size="medium" disabled>
<FileDownloadOutlined/>
<FileDownloadOutlined />
</IconButton>
)}
</div>
)}
</div>
<div className="clearfix"/>
<div className="clearfix" />
</div>
{showTimeline && (<div style={{ marginBottom: 50 }}>
<Timeline exerciseOrScenarioId={exerciseOrScenarioId}
injects={sortedInjects}
teams={teams}
></Timeline>
<div className="clearfix"/>
</div>
<div className="clearfix" />
</div>
)}
<List>
<ListItem
Expand All @@ -359,9 +359,9 @@ const Injects = (props) => {
checked={selectAll}
disableRipple
onChange={
typeof handleToggleSelectAll === 'function'
&& handleToggleSelectAll.bind(this)
}
typeof handleToggleSelectAll === 'function'
&& handleToggleSelectAll.bind(this)
}
disabled={typeof handleToggleSelectAll !== 'function'}
/>
</ListItemIcon>
Expand Down Expand Up @@ -416,7 +416,7 @@ const Injects = (props) => {
headerStyles,
)}
</>
}
}
/>
<ListItemSecondaryAction> &nbsp; </ListItemSecondaryAction>
</ListItem>
Expand All @@ -440,9 +440,9 @@ const Injects = (props) => {
divider
button
disabled={
!injectContract || isDisabled
|| !inject.inject_enabled
}
!injectContract || isDisabled
|| !inject.inject_enabled
}
onClick={() => setSelectedInjectId(inject.inject_id)}
>
<ListItemIcon
Expand All @@ -451,15 +451,15 @@ const Injects = (props) => {
onClick={(event) => (event.shiftKey
? onToggleShiftEntity(index, inject, event)
: onToggleEntity(inject, event))
}
}
>
<Checkbox
edge="start"
checked={
(selectAll && !(inject.inject_id
in (deSelectedElements || {})))
|| inject.inject_id in (selectedElements || {})
}
(selectAll && !(inject.inject_id
in (deSelectedElements || {})))
|| inject.inject_id in (selectedElements || {})
}
disableRipple
/>
</ListItemIcon>
Expand All @@ -468,9 +468,9 @@ const Injects = (props) => {
tooltip={t(inject.inject_type)}
type={inject.inject_type}
disabled={
!injectContract || isDisabled
|| !inject.inject_enabled
}
!injectContract || isDisabled
|| !inject.inject_enabled
}
/>
</ListItemIcon>
<ListItemText
Expand Down Expand Up @@ -537,7 +537,7 @@ const Injects = (props) => {
/>
</div>
</>
}
}
/>
<ListItemSecondaryAction>
<InjectPopover
Expand Down Expand Up @@ -586,7 +586,7 @@ const Injects = (props) => {
}
return (
<div className={classes.container}>
<Loader/>
<Loader />
</div>
);
};
Expand Down
10 changes: 5 additions & 5 deletions openbas-front/src/admin/components/scenarios/scenario/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const useStyles = makeStyles(() => ({
const IndexScenarioComponent: FunctionComponent<{ scenario: ScenarioStore }> = ({
scenario,
}) => {
const { t, nsd, ft, locale, fld } = useFormatter();
const { t, ft, locale, fld } = useFormatter();
const location = useLocation();
const theme = useTheme<Theme>();
const classes = useStyles();
Expand Down Expand Up @@ -72,18 +72,18 @@ const IndexScenarioComponent: FunctionComponent<{ scenario: ScenarioStore }> = (
}
let sentence = '';
if (noRepeat) {
sentence = `${fld(scenario.scenario_recurrence_start)} ${t('recurrence_at')} ${ft(new Date().setUTCHours(parsedCronExpression.h, parsedCronExpression.m))}`;
sentence = `${fld(scenario.scenario_recurrence_start)} ${t('recurrence_at')} ${ft(new Date().setUTCHours(parsedCronExpression.h, parsedCronExpression.m, 0))}`;
} else {
sentence = cronstrue.toString(cronExpression, {
verbose: true,
tzOffset: -new Date().getTimezoneOffset() / 60,
locale,
});
if (scenario.scenario_recurrence_end) {
sentence += ` ${t('recurrence_from')} ${nsd(scenario.scenario_recurrence_start)}`;
sentence += ` ${t('recurrence_to')} ${nsd(scenario.scenario_recurrence_end)}`;
sentence += ` ${t('recurrence_from')} ${fld(scenario.scenario_recurrence_start)}`;
sentence += ` ${t('recurrence_to')} ${fld(scenario.scenario_recurrence_end)}`;
} else {
sentence += ` ${t('recurrence_starting_from')} ${nsd(scenario.scenario_recurrence_start)}`;
sentence += ` ${t('recurrence_starting_from')} ${fld(scenario.scenario_recurrence_start)}`;
}
}
return sentence;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ const ImportUploaderExercise: React.FC<Props> = () => {
const navigate = useNavigate();

const handleUpload = async (formData: FormData) => {
await dispatch(importingExercise(formData));
navigate('/admin/exercises');
await dispatch(importingExercise(formData)).then((result: { [x: string]: string; }) => {
if (!Object.prototype.hasOwnProperty.call(result, 'FINAL_FORM/form-error')) {
navigate(0);
}
});
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Button, FormControlLabel, Switch, Stack } from '@mui/material';
import { Button, FormControlLabel, Stack, Switch } from '@mui/material';
import { DatePicker, TimePicker } from '@mui/x-date-pickers';
import { Controller, SubmitHandler, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
Expand Down Expand Up @@ -71,7 +71,7 @@ const ExerciseDateForm: React.FC<Props> = ({
time: z.string().min(1, t('Required')),
}).refine(
(data) => {
if (data.date) {
if (!checked && data.date) {
return new Date(data.date).getTime() >= new Date(new Date().setUTCHours(0, 0, 0, 0)).getTime();
}
return true;
Expand All @@ -83,7 +83,7 @@ const ExerciseDateForm: React.FC<Props> = ({
)
.refine(
(data) => {
if (data.time) {
if (!checked && data.time) {
return (new Date().getTime() + _MS_DELAY_TOO_CLOSE) < new Date(data.time).getTime();
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const Buttons = ({ exerciseId, exerciseStatus, exerciseName }: {
color="primary"
onClick={() => setOpenChangeStatus('RUNNING')}
>
{t('Start')}
{t('Start now')}
</Button>
);
}
Expand Down
6 changes: 5 additions & 1 deletion openbas-front/src/components/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ export const useFormatter = () => {
});
};
const time = (date) => {
return intl.formatTime(date);
return intl.formatTime(date, {
second: 'numeric',
minute: 'numeric',
hour: 'numeric',
});
};
const standardDate = (date) => {
if (isNone(date)) {
Expand Down
1 change: 1 addition & 0 deletions openbas-front/src/utils/Localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ const i18n = {
'Export to CSV': 'Exporter en CSV',
Copy: 'Copier',
Start: 'Démarrer',
'Start now': 'Démarrer maintenant',
Status: 'Statut',
Information: 'Information',
Control: 'Contrôle',
Expand Down

0 comments on commit 9ca5189

Please sign in to comment.