Skip to content

Commit

Permalink
[Surveillance] Résolution du bug à la suppression d'une thématique de…
Browse files Browse the repository at this point in the history
… surveillance (#484)

- Resolve #423 : 
       - Résolution du souci lors de la suppression d'une thématique
- Résolution du bug qui "vidait" les champs sous-thématiques et espèces
protégées des thèmes restants à la suppression d'une thématique
  • Loading branch information
claire2212 authored May 10, 2023
2 parents 7fef5bb + b3edebf commit 6cac951
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions frontend/cypress/e2e/side_window_mission.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ context('Missions', () => {
cy.get('form').submit()

// Then
cy.wait('@updateMission').then(({ request, response }) => {
cy.wait('@updateMission').then(({ response }) => {
expect(response && response.statusCode).equal(200)

const { themes } = request.body.envActions.find(a => a.id === 'b8007c8a-5135-4bc3-816f-c69c7b75d807')
const { themes } = response && response.body.envActions.find(a => a.id === 'b8007c8a-5135-4bc3-816f-c69c7b75d807')
expect(themes.length).equal(2)
expect(themes[0].theme).equal('Police des espèces protégées et de leurs habitats (faune et flore)')
expect(themes[0].subThemes.length).equal(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styled from 'styled-components'
import { ActionTheme } from './ActionTheme'

export function MultipleThemeElement({ currentActionIndex, form, push, remove }) {
const handleRemoveTheme = index => () => {
const handleRemoveTheme = (index: number) => {
remove(index)
}
const handleAddTheme = () => {
Expand All @@ -19,18 +19,18 @@ export function MultipleThemeElement({ currentActionIndex, form, push, remove })

return (
<ThemesWrapper>
{currentThemes.map((_, i) => (
{currentThemes.map((_, index) => (
// eslint-disable-next-line react/no-array-index-key
<ThemeBloc key={i}>
<ThemeBloc key={index}>
<ActionTheme
labelSubTheme="Sous-thématiques de surveillance"
labelTheme="Thématique de surveillance"
themePath={`envActions.${currentActionIndex}.themes.${i}`}
themePath={`envActions.${currentActionIndex}.themes.${index}`}
/>

{i > 0 && (
{index > 0 && (
<RemoveButtonWrapper>
<IconButton accent={Accent.SECONDARY} Icon={Icon.Delete} onClick={handleRemoveTheme(i)} />
<IconButton accent={Accent.SECONDARY} Icon={Icon.Delete} onClick={() => handleRemoveTheme(index)} />
</RemoveButtonWrapper>
)}
</ThemeBloc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export function useCleanSubThemesOnThemeChange(path) {
const { setFieldValue, values } = useFormikContext()
const previousPath = usePrevious(path)
const previousTheme = usePrevious(_.get(values, `${path}.theme`))

useEffect(() => {
const currentTheme = _.get(values, `${path}.theme`)
if (path === previousPath && currentTheme !== previousTheme) {

if (path === previousPath && currentTheme !== previousTheme && !currentTheme) {
setFieldValue(`${path}.subThemes`, [])
setFieldValue(`${path}.protectedSpecies`, [])
}
Expand Down

0 comments on commit 6cac951

Please sign in to comment.