Skip to content

Commit

Permalink
[feat] Suppression de la liste des types de points d'intérêt
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeperrault committed May 16, 2024
1 parent fcd6157 commit 663f4d4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 52 deletions.
4 changes: 2 additions & 2 deletions frontend/src/features/InterestPoint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type InterestPoint = {
feature?: Feature<LineString>
name: string
observations: string
type: string
// type: string
uuid: string
}

Expand All @@ -17,7 +17,7 @@ export type NewInterestPoint = {
feature?: Feature<LineString>
name: string | null
observations: string | null
type: string | null
// type: string | null
uuid: string
}

Expand Down
16 changes: 6 additions & 10 deletions frontend/src/features/map/layers/InterestPointLayer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import GeoJSON from 'ol/format/GeoJSON'
import LineString from 'ol/geom/LineString'
import Draw from 'ol/interaction/Draw'
import Draw, { DrawEvent } from 'ol/interaction/Draw'
import VectorLayer from 'ol/layer/Vector'
import VectorSource from 'ol/source/Vector'
import { getLength } from 'ol/sphere'
Expand All @@ -9,11 +9,7 @@ import { v4 as uuidv4 } from 'uuid'

import { getInterestPointStyle, POIStyle } from './styles/interestPoint.style'
import { InterestPointLine } from '../../../domain/entities/interestPointLine'
import {
coordinatesAreModified,
coordinatesOrTypeAreModified,
interestPointType
} from '../../../domain/entities/interestPoints'
import { coordinatesAreModified, coordinatesOrTypeAreModified } from '../../../domain/entities/interestPoints'
import { Layers } from '../../../domain/entities/layers/constants'
import { MapToolType, OPENLAYERS_PROJECTION } from '../../../domain/entities/map/constants'
import { globalActions } from '../../../domain/shared_slices/Global'
Expand Down Expand Up @@ -164,7 +160,7 @@ export function InterestPointLayer({ map }: BaseMapChildrenProps) {
coordinates: null,
name: null,
observations: null,
type: null,
// type: null,
uuid: uuidv4()
})
)
Expand Down Expand Up @@ -205,20 +201,20 @@ export function InterestPointLayer({ map }: BaseMapChildrenProps) {
function handleDrawEvents() {
if (drawObject) {
drawObject.once(DRAW_START_EVENT, event => {
function startDrawing(e, type) {
function startDrawing(e: DrawEvent) {
dispatch(
updateInterestPointBeingDrawed({
coordinates: e.feature.getGeometry().getLastCoordinate(),
name: null,
observations: null,
type,
// type,
// TODO Check that.
uuid: interestPointBeingDrawed!.uuid
})
)
}

startDrawing(event, interestPointBeingDrawed?.type ?? interestPointType.OTHER)
startDrawing(event)
})

drawObject.once(DRAW_ABORT_EVENT, () => {
Expand Down
80 changes: 40 additions & 40 deletions frontend/src/features/map/tools/interestPoint/EditInterestPoint.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Label, MultiRadio, type Option } from '@mtes-mct/monitor-ui'
import { Label } from '@mtes-mct/monitor-ui'
import { boundingExtent } from 'ol/extent'
import { transform, transformExtent } from 'ol/proj'
import { useCallback, useMemo, useState } from 'react'
import styled from 'styled-components'

import { interestPointType } from '../../../../domain/entities/interestPoints'
import { CoordinatesFormat, OPENLAYERS_PROJECTION, WSG84_PROJECTION } from '../../../../domain/entities/map/constants'
import { addInterestPoint, updateInterestPointKeyBeingDrawed } from '../../../../domain/shared_slices/InterestPoint'
import { setFitToExtent } from '../../../../domain/shared_slices/Map'
Expand All @@ -17,20 +16,20 @@ import { MapToolBox } from '../MapToolBox'

import type { Coordinate } from 'ol/coordinate'

const INTEREST_POINT_OPTIONS: Array<Option> = [
{
label: 'Moyen de contrôle',
value: interestPointType.CONTROL_ENTITY
},
{
label: 'Navire de pêche',
value: interestPointType.FISHING_VESSEL
},
{
label: 'Autre point',
value: interestPointType.OTHER
}
]
// const INTEREST_POINT_OPTIONS: Array<Option> = [
// {
// label: 'Moyen de contrôle',
// value: interestPointType.CONTROL_ENTITY
// },
// {
// label: 'Navire de pêche',
// value: interestPointType.FISHING_VESSEL
// },
// {
// label: 'Autre point',
// value: interestPointType.OTHER
// }
// ]

// TODO Refactor this component
// - Move the state logic to the reducer
Expand All @@ -47,12 +46,12 @@ export function EditInterestPoint({ close, healthcheckTextWarning, isOpen }: Edi

const [localCoordinates, setLocalCoordinates] = useState<Coordinate>([0, 0])

const defaultType = interestPointBeingDrawed?.type
? INTEREST_POINT_OPTIONS.find(interestPointOption => interestPointOption.value === interestPointBeingDrawed.type)
?.value
: INTEREST_POINT_OPTIONS[2]?.value
// const defaultType = interestPointBeingDrawed?.type
// ? INTEREST_POINT_OPTIONS.find(interestPointOption => interestPointOption.value === interestPointBeingDrawed.type)
// ?.value
// : INTEREST_POINT_OPTIONS[2]?.value

const [selectedOption, setSelectedOption] = useState()
// const [selectedOption, setSelectedOption] = useState()

/** Coordinates formatted in DD [latitude, longitude] */
const coordinates: number[] = useMemo(() => {
Expand Down Expand Up @@ -101,20 +100,20 @@ export function EditInterestPoint({ close, healthcheckTextWarning, isOpen }: Edi
[dispatch, interestPointBeingDrawed?.observations]
)

const updateType = useCallback(
option => {
setSelectedOption(option)
if (option && interestPointBeingDrawed?.type !== option) {
dispatch(
updateInterestPointKeyBeingDrawed({
key: 'type',
value: option
})
)
}
},
[dispatch, interestPointBeingDrawed?.type]
)
// const updateType = useCallback(
// option => {
// setSelectedOption(option)
// if (option && interestPointBeingDrawed?.type !== option) {
// dispatch(
// updateInterestPointKeyBeingDrawed({
// key: 'type',
// value: option
// })
// )
// }
// },
// [dispatch, interestPointBeingDrawed?.type]
// )

/**
* Compare with previous coordinates and update interest point coordinates
Expand Down Expand Up @@ -157,15 +156,15 @@ export function EditInterestPoint({ close, healthcheckTextWarning, isOpen }: Edi
dispatch(setFitToExtent(extent))
}

// reset state
setSelectedOption(undefined)
// // reset state
// setSelectedOption(undefined)
}
}

const cancel = () => {
close()
// reset state
setSelectedOption(undefined)
// setSelectedOption(undefined)
}

return (
Expand All @@ -179,15 +178,16 @@ export function EditInterestPoint({ close, healthcheckTextWarning, isOpen }: Edi
<SetCoordinates coordinates={coordinates} updateCoordinates={updateCoordinates} />
</div>

<MultiRadio
{/* <MultiRadio
key={interestPointBeingDrawed?.uuid}
data-cy="interest-point-type-radio"
label="Type de point"
name="interestPointTypeRadio"
onChange={updateType}
options={INTEREST_POINT_OPTIONS}
value={selectedOption ?? defaultType}
/>
/> */}

<div>
<Label>Libellé du point</Label>
<Name
Expand Down

0 comments on commit 663f4d4

Please sign in to comment.