Skip to content

Commit

Permalink
Resolve PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
johanah29 committed Sep 6, 2024
1 parent 2ce3117 commit b202791
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 71 deletions.
80 changes: 10 additions & 70 deletions openbas-front/src/admin/components/common/injects/InjectPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import React, { FunctionComponent, useContext, useEffect, useState } from 'react';
import {
Alert,
Button,
Dialog,
DialogActions,
DialogContent,
DialogContentText,
IconButton,
Link,
Menu,
MenuItem,
SnackbarCloseReason,
Table,
TableBody,
TableCell,
TableRow,
} from '@mui/material';
import React, { FunctionComponent, useContext, useState } from 'react';
import { Link } from 'react-router-dom';
import { Alert, Button, Dialog, DialogActions, DialogContent, DialogContentText, IconButton, Menu, MenuItem, Table, TableBody, TableCell, TableRow } from '@mui/material';
import { MoreVert } from '@mui/icons-material';
import { useFormatter } from '../../../../components/i18n';
import Transition from '../../../../components/common/Transition';
Expand All @@ -28,6 +13,7 @@ import DialogDuplicate from '../../../../components/common/DialogDuplicate';
import { useHelper } from '../../../../store';
import type { ExercisesHelper } from '../../../../actions/exercises/exercise-helper';
import DialogTest from '../../../../components/common/DialogTest';
import { MESSAGING$ } from '../../../../utils/Environment';

type InjectPopoverType = {
inject_id: string,
Expand Down Expand Up @@ -77,7 +63,6 @@ const InjectPopover: FunctionComponent<Props> = ({
const [openResult, setOpenResult] = useState(false);
const [openTrigger, setOpenTrigger] = useState(false);
const [injectResult, setInjectResult] = useState<InjectStatus | null>(null);
const [_injectTestResult, setInjectTestResult] = useState<InjectTestStatus | null>(null);
const [anchorEl, setAnchorEl] = useState<Element | null>(null);

const isExercise = useHelper((helper: ExercisesHelper) => helper.getExercisesMap()[exerciseOrScenarioId!] !== undefined);
Expand Down Expand Up @@ -145,38 +130,18 @@ const InjectPopover: FunctionComponent<Props> = ({

const handleCloseTest = () => {
setOpenTest(false);
setInjectTestResult(null);
};

const [openDialog, setOpenDialog] = React.useState<boolean>(false);
const handleCloseDialog = (
event?: React.SyntheticEvent | Event,
reason?: SnackbarCloseReason,
) => {
if (reason === 'clickaway') {
return;
}
setOpenDialog(false);
};
const [detailsLink, setDetailsLink] = React.useState<string>('');

useEffect(() => {
if (openDialog) {
setTimeout(() => {
handleCloseDialog();
setDetailsLink('');
}, 6000);
}
}, [openDialog]);

const submitTest = () => {
testInject(inject.inject_id).then((result: { data: InjectTestStatus }) => {
setInjectTestResult(result.data);
setOpenDialog(true);
if (isExercise) {
setDetailsLink(`/admin/exercises/${exerciseOrScenarioId}/tests/${result.data.status_id}`);
MESSAGING$.notifySuccess(t('Inject test has been sent, you can view test logs details on {itsDedicatedPage}.', {
itsDedicatedPage: <Link to={`/admin/exercises/${exerciseOrScenarioId}/tests/${result.data.status_id}`}>{t('its dedicated page')}</Link>,
}));
} else {
setDetailsLink(`/admin/scenarios/${exerciseOrScenarioId}/tests/${result.data.status_id}`);
MESSAGING$.notifySuccess(t('Inject test has been sent, you can view test logs details on {itsDedicatedPage}.', {
itsDedicatedPage: <Link to={`/admin/scenarios/${exerciseOrScenarioId}/tests/${result.data.status_id}`}>{t('its dedicated page')}</Link>,
}));
}
});
handleCloseTest();
Expand Down Expand Up @@ -241,31 +206,6 @@ const InjectPopover: FunctionComponent<Props> = ({

return (
<>
<Dialog open={openDialog}
slotProps={{
backdrop: {
sx: {
backgroundColor: 'transparent',
},
},
}}
PaperProps={{
sx: {
position: 'fixed',
top: '20px',
left: '660px',
margin: 0,
},
}}
>
<Alert
onClose={handleCloseDialog}
severity="success"
sx={{ width: '100%' }}
>
{t('Inject test has been sent, you can view test logs details on ')} <Link href={detailsLink} underline="hover">{t('its dedicated page.')}</Link>
</Alert>
</Dialog>
<IconButton
onClick={handlePopoverOpen}
aria-haspopup="true"
Expand Down
2 changes: 1 addition & 1 deletion openbas-front/src/utils/Localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ const i18n = {
'Trigger time': 'Heure de lancement',
'Attribute mapping configuration': 'Configuration d\'attribut de mapper',
'The imported file contains absolute dates (ex.: 9h30). A starting date must be provided for the Scenario to be build': 'Le fichier importé contient des dates absolues (ex.: 9h30). Une date de début doit être fournie pour que le scénario puisse être créé',
Test: 'Test',
Test: 'Tester',
'Replay test': 'Rejouer le test',
'Delete test': 'Supprimer le test',
'Do you want to test this inject?':
Expand Down

0 comments on commit b202791

Please sign in to comment.