-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f979d7
commit 04f023d
Showing
13 changed files
with
187 additions
and
26 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/base/DeleteBase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package fr.gouv.cacem.monitorenv.domain.use_cases.base | ||
|
||
import fr.gouv.cacem.monitorenv.config.UseCase | ||
import fr.gouv.cacem.monitorenv.domain.repositories.IBaseRepository | ||
|
||
@UseCase | ||
class DeleteBase(private val baseRepository: IBaseRepository) { | ||
fun execute(baseId: Int) { | ||
baseRepository.deleteById(baseId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { CustomSearch, IconButton, type Filter, Size, Icon } from '@mtes-mct/monitor-ui' | ||
|
||
import { BASE_TABLE_COLUMNS } from './constants' | ||
import { backOfficeActions } from '../../../BackOffice/slice' | ||
import { BackOfficeConfirmationModalActionType } from '../../../BackOffice/types' | ||
|
||
import type { FiltersState } from './types' | ||
import type { Base } from '../../../../domain/entities/base' | ||
import type { AppDispatch } from '../../../../store' | ||
import type { CellContext, ColumnDef } from '@tanstack/react-table' | ||
|
||
function deleteBase(info: CellContext<Base.Base, unknown>, dispatch: AppDispatch) { | ||
const base = info.getValue<Base.Base>() | ||
|
||
dispatch( | ||
backOfficeActions.openConfirmationModal({ | ||
actionType: BackOfficeConfirmationModalActionType.DELETE_BASE, | ||
entityId: base.id, | ||
modalProps: { | ||
confirmationButtonLabel: 'Supprimer', | ||
message: `Êtes-vous sûr de vouloir supprimer la base "${base.name}" ?`, | ||
title: `Suppression de la base` | ||
} | ||
}) | ||
) | ||
} | ||
|
||
export function getBaseTableColumns(dispatch: AppDispatch): Array<ColumnDef<Base.Base>> { | ||
const deleteColumn: ColumnDef<Base.Base> = { | ||
accessorFn: row => row, | ||
cell: info => ( | ||
<IconButton | ||
Icon={Icon.Delete} | ||
onClick={() => deleteBase(info, dispatch)} | ||
size={Size.SMALL} | ||
title="Supprimer cette base" | ||
/> | ||
), | ||
enableSorting: false, | ||
header: () => '', | ||
id: 'delete', | ||
size: 44 | ||
} | ||
|
||
return [...BASE_TABLE_COLUMNS, deleteColumn] | ||
} | ||
|
||
export function getFilters(data: Base.Base[], filtersState: FiltersState): Filter<Base.Base>[] { | ||
const customSearch = new CustomSearch(data, ['name'], { | ||
cacheKey: 'BACK_OFFICE_BASE_LIST', | ||
isStrict: true | ||
}) | ||
const filters: Array<Filter<Base.Base>> = [] | ||
|
||
if (filtersState.query && filtersState.query.trim().length > 0) { | ||
const filter: Filter<Base.Base> = () => customSearch.find(filtersState.query as string) | ||
|
||
filters.push(filter) | ||
} | ||
|
||
return filters | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { THEME, logSoftError } from '@mtes-mct/monitor-ui' | ||
|
||
import { basesAPI } from '../../../api/basesAPI' | ||
import { FrontendError } from '../../../libs/FrontendError' | ||
import { isUserError } from '../../../libs/UserError' | ||
import { backOfficeActions } from '../../BackOffice/slice' | ||
|
||
import type { AppThunk } from '../../../store' | ||
|
||
export const deleteBase = (): AppThunk<Promise<void>> => async (dispatch, getState) => { | ||
const { confirmationModal } = getState().backOffice | ||
if (!confirmationModal) { | ||
throw new FrontendError('`confirmationModal` is undefined.') | ||
} | ||
|
||
try { | ||
const { error } = await dispatch(basesAPI.endpoints.deleteBase.initiate(confirmationModal.entityId) as any) | ||
if (error) { | ||
throw error | ||
} | ||
} catch (err) { | ||
if (isUserError(err)) { | ||
dispatch( | ||
backOfficeActions.openDialog({ | ||
dialogProps: { | ||
color: THEME.color.maximumRed, | ||
message: err.userMessage, | ||
title: `Suppression impossible`, | ||
titleBackgroundColor: THEME.color.maximumRed | ||
} | ||
}) | ||
) | ||
|
||
return | ||
} | ||
|
||
logSoftError({ | ||
message: `An error happened while deleting an base (ID=${confirmationModal.entityId}").`, | ||
originalError: err, | ||
userMessage: "Une erreur est survenue pendant la suppression de l'base." | ||
}) | ||
} | ||
} |