Skip to content

Commit

Permalink
[DrawModal] improve draw modal interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed May 13, 2024
1 parent b17ff19 commit d51425e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ export enum MapInteractionListenerEnum {
export const updateMapInteractionListeners = (listener: MapInteractionListenerEnum) => dispatch => {
switch (listener) {
case MapInteractionListenerEnum.DRAW_ZONE_OR_POINT:
openDrawLayerModal(dispatch)
openDrawLayerModal(dispatch, true)
dispatch(attachMissionToReportingSliceActions.setIsMissionAttachmentInProgress(false))
dispatch(attachReportingToMissionSliceActions.setIsReportingAttachmentInProgress(false))
break

case MapInteractionListenerEnum.ATTACH_MISSION:
openDrawLayerModal(dispatch)
openDrawLayerModal(dispatch, false)
dispatch(attachMissionToReportingSliceActions.setIsMissionAttachmentInProgress(true))
dispatch(attachReportingToMissionSliceActions.setIsReportingAttachmentInProgress(false))
dispatch(resetInteraction())
break

case MapInteractionListenerEnum.ATTACH_REPORTING:
openDrawLayerModal(dispatch)
openDrawLayerModal(dispatch, false)
dispatch(attachReportingToMissionSliceActions.setIsReportingAttachmentInProgress(true))
dispatch(attachMissionToReportingSliceActions.setIsMissionAttachmentInProgress(false))
dispatch(resetInteraction())
Expand All @@ -42,12 +42,12 @@ export const updateMapInteractionListeners = (listener: MapInteractionListenerEn
}
}

const openDrawLayerModal = dispatch => {
const openDrawLayerModal = (dispatch, displayLayersSidebar = true) => {
dispatch(
setDisplayedItems({
displayDrawModal: true,
displayInterestPoint: false,
displayLayersSidebar: false,
displayLayersSidebar,
displayLocateOnMap: true,
displayMeasurement: false,
displayMissionMenuButton: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function Position() {
<StyledPositionContainer>
<Button
accent={meta.error ? Accent.ERROR : Accent.SECONDARY}
disabled={field.value?.coordinates}
disabled={field.value?.coordinates.length > 0}
Icon={Icon.Plus}
isFullWidth
onClick={handleAddZone}
Expand All @@ -37,7 +37,7 @@ export function Position() {
</Button>
<Button
accent={meta.error ? Accent.ERROR : Accent.SECONDARY}
disabled={field.value?.coordinates}
disabled={field.value?.coordinates.length > 0}
Icon={Icon.Plus}
isFullWidth
onClick={handleAddPoint}
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/features/commonComponents/Modals/MapInteraction.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Accent, Button } from '@mtes-mct/monitor-ui'
import { Accent, Button, Icon, IconButton } from '@mtes-mct/monitor-ui'
import styled from 'styled-components'

type MapIntercationProps = {
children?: React.ReactNode
customTools?: React.ReactNode
isValidatedButtonDisabled?: boolean
onCancel?: () => void
onReset: () => void
onValidate: () => void
resetButtonText?: string
Expand All @@ -15,6 +16,7 @@ export function MapInteraction({
children = undefined,
customTools = undefined,
isValidatedButtonDisabled = false,
onCancel,
onReset,
onValidate,
resetButtonText = undefined,
Expand All @@ -26,6 +28,7 @@ export function MapInteraction({
<Panel>
<Header>
<Title>{title}</Title>
<IconButton Icon={Icon.Close} onClick={onCancel} />
</Header>

<Body>
Expand Down Expand Up @@ -59,11 +62,12 @@ const Panel = styled.div`
box-shadow: 0px 3px 6px #00000029;
`
const Header = styled.div`
display: flex;
align-items: center;
background: ${p => p.theme.color.charcoal};
display: flex;
justify-content: space-between;
padding: 12px 24px;
width: 580px;
justify-content: space-around;
padding: 12px;
`

const Title = styled.h1`
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/features/map/draw/DrawModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export function DrawModal() {
const handleSelectInteraction = nextInteraction => () => {
dispatch(setInteractionType(nextInteraction))
}
const handleCancel = () => {
handleReset()

dispatch(updateMapInteractionListeners(MapInteractionListenerEnum.NONE))
}

const handleReset = () => {
if (!initialGeometry) {
return dispatch(eraseDrawedGeometries(initialFeatureNumberRef.current))
Expand Down Expand Up @@ -190,6 +196,7 @@ export function DrawModal() {
)
}
isValidatedButtonDisabled={!isGeometryValid}
onCancel={handleCancel}
onReset={handleReset}
onValidate={handleValidate}
title={`Vous êtes en train d'ajouter ${listener && titlePlaceholder[listener]}`}
Expand Down

0 comments on commit d51425e

Please sign in to comment.