Skip to content

Commit

Permalink
[frontend] Popover removal - Locations
Browse files Browse the repository at this point in the history
Co-authored-by: Bonsai8863 <131906254+Bonsai8863@users.noreply.github.com>
Co-authored-by: Marie Flores <73853856+marieflorescontact@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent 0b78e70 commit e44e755
Show file tree
Hide file tree
Showing 24 changed files with 881 additions and 320 deletions.
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/de.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
" (reversed)": "(umgedreht)",
" & ": "&",
"... successfully deleted": "{entity_type} erfolgreich gelöscht",
"+ N override(s)": "+ {count} Überschreibung(en)",
"0 equals no maximum": "0 entspricht keinem Maximum",
"24 hours": "24 Stunden",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
" (reversed)": " (reversed)",
" & ": " & ",
"... successfully deleted": "{entity_type} successfully deleted",
"+ N override(s)": "+ {count} override(s)",
"0 equals no maximum": "0 equals no maximum",
"24 hours": "24 hours",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/es.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
" (reversed)": "(invertido)",
" & ": "&",
"... successfully deleted": "{entity_type} eliminado exitosamente",
"+ N override(s)": "+ {count} anulación(es)",
"0 equals no maximum": "0 es igual a ningún máximo",
"24 hours": "24 horas",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/fr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
" (reversed)": "(inversé)",
" & ": " & ",
"... successfully deleted": "{entity_type} supprimé·e avec succès",
"+ N override(s)": "+ {count} surcharge(s)",
"0 equals no maximum": "0 pour aucun maximum",
"24 hours": "24 heures",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/ja.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
" (reversed)": "(逆)",
" & ": "&;",
"... successfully deleted": "{entity_type} 正常に削除されました",
"+ N override(s)": "+ {count} オーバーライド(複数可)",
"0 equals no maximum": "0 は最大値なし",
"24 hours": "24時間",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/ko.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
" (reversed)": " (역순)",
" & ": " & ",
"... successfully deleted": "{entity_type} 성공적으로 삭제되었습니다",
"+ N override(s)": "+ {count} 재정의",
"0 equals no maximum": "0은 최대치 없음",
"24 hours": "24시간",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/zh.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
" (reversed)": "(反向)",
" & ": "&;",
"... successfully deleted": "{entity_type} 成功删除",
"+ N override(s)": "+ {count} 覆盖",
"0 equals no maximum": "0 等于没有最大值",
"24 hours": "24小时",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React from 'react';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import { graphql } from 'react-relay';
import { useNavigate } from 'react-router-dom';
import { useFormatter } from '../../../../components/i18n';
import Security from '../../../../utils/Security';
import Transition from '../../../../components/Transition';
import { KNOWLEDGE_KNUPDATE_KNDELETE } from '../../../../utils/hooks/useGranted';
import useDeletion from '../../../../utils/hooks/useDeletion';
import useApiMutation from '../../../../utils/hooks/useApiMutation';

const AdministrativeAreaDeletionDeleteMutation = graphql`
mutation AdministrativeAreaDeletionDeleteMutation($id: ID!) {
administrativeAreaDelete(id: $id)
}
`;

const AdministrativeAreaDeletion = ({ id }: { id: string }) => {
const { t_i18n } = useFormatter();
const navigate = useNavigate();
const deleteSuccessMessage = t_i18n('', {
id: '... successfully deleted',
values: { entity_type: t_i18n('entity_Administrative-Area') },
});
const [commit] = useApiMutation(
AdministrativeAreaDeletionDeleteMutation,
undefined,
{ successMessage: deleteSuccessMessage },
);
const handleClose = () => {};
const {
deleting,
handleOpenDelete,
displayDelete,
handleCloseDelete,
setDeleting,
} = useDeletion({ handleClose });
const submitDelete = () => {
setDeleting(true);
commit({
variables: {
id,
},
onCompleted: () => {
setDeleting(false);
handleClose();
navigate('/dashboard/locations/administrative_areas');
},
});
};
return (
<>
<Security needs={[KNOWLEDGE_KNUPDATE_KNDELETE]}>
<Button
color="error"
variant="contained"
onClick={handleOpenDelete}
disabled={deleting}
sx={{ marginTop: 2 }}
>
{t_i18n('Delete')}
</Button>
</Security>
<Dialog
PaperProps={{ elevation: 1 }}
open={displayDelete}
keepMounted={true}
TransitionComponent={Transition}
onClose={handleCloseDelete}
>
<DialogContent>
<DialogContentText>
{t_i18n('Do you want to delete this area?')}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleCloseDelete} disabled={deleting}>
{t_i18n('Cancel')}
</Button>
<Button color="secondary" onClick={submitDelete} disabled={deleting}>
{t_i18n('Delete')}
</Button>
</DialogActions>
</Dialog>
</>
);
};

export default AdministrativeAreaDeletion;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Field, Form, Formik } from 'formik';
import * as Yup from 'yup';
import { FormikConfig } from 'formik/dist/types';
import ConfidenceField from '@components/common/form/ConfidenceField';
import useHelper from 'src/utils/hooks/useHelper';
import TextField from '../../../../components/TextField';
import { SubscriptionFocus } from '../../../../components/Subscription';
import CreatedByField from '../../common/form/CreatedByField';
Expand All @@ -21,6 +22,7 @@ import useFormEditor, { GenericData } from '../../../../utils/hooks/useFormEdito
import { fieldSpacingContainerStyle } from '../../../../utils/field';
import { GenericContext } from '../../common/model/GenericContextModel';
import AlertConfidenceForEntity from '../../../../components/AlertConfidenceForEntity';
import AdministrativeAreaDeletion from './AdministrativeAreaDeletion';

const administrativeAreaMutationFieldPatch = graphql`
mutation AdministrativeAreaEditionOverviewFieldPatchMutation(
Expand Down Expand Up @@ -230,6 +232,8 @@ AdministrativeAreaEditionOverviewProps
x_opencti_workflow_id: convertStatus(t_i18n, administrativeArea) as Option,
references: [],
};
const { isFeatureEnable } = useHelper();
const isFABReplaced = isFeatureEnable('FAB_REPLACEMENT');
return (
<Formik
enableReinitialize={true}
Expand Down Expand Up @@ -353,6 +357,11 @@ AdministrativeAreaEditionOverviewProps
id={administrativeArea.id}
/>
)}
{isFABReplaced && (
<AdministrativeAreaDeletion
id={administrativeArea.id}
/>
)}
</Form>
)}
</Formik>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { KNOWLEDGE_KNUPDATE_KNDELETE } from '../../../../utils/hooks/useGranted'
import { AdministrativeAreaEditionContainerQuery } from './__generated__/AdministrativeAreaEditionContainerQuery.graphql';
import useDeletion from '../../../../utils/hooks/useDeletion';
import useApiMutation from '../../../../utils/hooks/useApiMutation';
import useHelper from '../../../../utils/hooks/useHelper';

const AdministrativeAreaPopoverDeletionMutation = graphql`
mutation AdministrativeAreaPopoverDeletionMutation($id: ID!) {
Expand Down Expand Up @@ -67,53 +68,58 @@ const AdministrativeAreaPopover = ({ id }: { id: string }) => {
},
});
};
return (
<>
<ToggleButton
value="popover"
size="small"
onClick={handleOpen}
>
<MoreVert fontSize="small" color="primary" />
</ToggleButton>
<Menu anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}>
<MenuItem onClick={handleOpenEdit}>{t_i18n('Update')}</MenuItem>
<Security needs={[KNOWLEDGE_KNUPDATE_KNDELETE]}>
<MenuItem onClick={handleOpenDelete}>{t_i18n('Delete')}</MenuItem>
</Security>
</Menu>
<Dialog
PaperProps={{ elevation: 1 }}
open={displayDelete}
keepMounted={true}
TransitionComponent={Transition}
onClose={handleCloseDelete}
>
<DialogContent>
<DialogContentText>
{t_i18n('Do you want to delete this area?')}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleCloseDelete} disabled={deleting}>
{t_i18n('Cancel')}
</Button>
<Button color="secondary" onClick={submitDelete} disabled={deleting}>
{t_i18n('Delete')}
</Button>
</DialogActions>
</Dialog>
{queryRef && (
<React.Suspense fallback={<div />}>
<AdministrativeAreaEditionContainer
queryRef={queryRef}
handleClose={handleClose}
open={displayEdit}
/>
</React.Suspense>
)}
</>
);
const { isFeatureEnable } = useHelper();
const isFABReplaced = isFeatureEnable('FAB_REPLACEMENT');

return isFABReplaced
? (<></>)
: (
<>
<ToggleButton
value="popover"
size="small"
onClick={handleOpen}
>
<MoreVert fontSize="small" color="primary" />
</ToggleButton>
<Menu anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}>
<MenuItem onClick={handleOpenEdit}>{t_i18n('Update')}</MenuItem>
<Security needs={[KNOWLEDGE_KNUPDATE_KNDELETE]}>
<MenuItem onClick={handleOpenDelete}>{t_i18n('Delete')}</MenuItem>
</Security>
</Menu>
<Dialog
PaperProps={{ elevation: 1 }}
open={displayDelete}
keepMounted={true}
TransitionComponent={Transition}
onClose={handleCloseDelete}
>
<DialogContent>
<DialogContentText>
{t_i18n('Do you want to delete this area?')}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleCloseDelete} disabled={deleting}>
{t_i18n('Cancel')}
</Button>
<Button color="secondary" onClick={submitDelete} disabled={deleting}>
{t_i18n('Delete')}
</Button>
</DialogActions>
</Dialog>
{queryRef && (
<React.Suspense fallback={<div />}>
<AdministrativeAreaEditionContainer
queryRef={queryRef}
handleClose={handleClose}
open={displayEdit}
/>
</React.Suspense>
)}
</>
);
};

export default AdministrativeAreaPopover;
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React from 'react';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import { graphql } from 'react-relay';
import { useNavigate } from 'react-router-dom';
import { useFormatter } from '../../../../components/i18n';
import Security from '../../../../utils/Security';
import Transition from '../../../../components/Transition';
import { KNOWLEDGE_KNUPDATE_KNDELETE } from '../../../../utils/hooks/useGranted';
import useDeletion from '../../../../utils/hooks/useDeletion';
import useApiMutation from '../../../../utils/hooks/useApiMutation';

const CityDeletionDeleteMutation = graphql`
mutation CityDeletionDeleteMutation($id: ID!) {
cityEdit(id: $id) {
delete
}
}
`;

const CityDeletion = ({ id }: { id: string }) => {
const { t_i18n } = useFormatter();
const navigate = useNavigate();
const deleteSuccessMessage = t_i18n('', {
id: '... successfully deleted',
values: { entity_type: t_i18n('entity_City') },
});
const [commit] = useApiMutation(
CityDeletionDeleteMutation,
undefined,
{ successMessage: deleteSuccessMessage },
);
const handleClose = () => { };
const {
deleting,
handleOpenDelete,
displayDelete,
handleCloseDelete,
setDeleting,
} = useDeletion({ handleClose });

const submitDelete = () => {
setDeleting(true);
commit({
variables: {
id,
},
onCompleted: () => {
setDeleting(false);
handleClose();
navigate('/dashboard/locations/cities');
},
});
};
return (
<div style={{ margin: 0 }}>
<Security needs={[KNOWLEDGE_KNUPDATE_KNDELETE]}>
<Button
color="error"
variant="contained"
onClick={handleOpenDelete}
disabled={deleting}
sx={{ marginTop: 2 }}
>
{t_i18n('Delete')}
</Button>
</Security>
<Dialog
PaperProps={{ elevation: 1 }}
open={displayDelete}
keepMounted={true}
TransitionComponent={Transition}
onClose={handleCloseDelete}
>
<DialogContent>
<DialogContentText>
{t_i18n('Do you want to delete this city?')}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleCloseDelete} disabled={deleting}>
{t_i18n('Cancel')}
</Button>
<Button color="secondary" onClick={submitDelete} disabled={deleting}>
{t_i18n('Delete')}
</Button>
</DialogActions>
</Dialog>
</div>
);
};

export default CityDeletion;
Loading

0 comments on commit e44e755

Please sign in to comment.