Skip to content

Commit

Permalink
[Reporting] fix bug to attach multiple reportings to a mission
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Jan 4, 2024
1 parent 9af76b6 commit d373ee3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@ import omit from 'lodash/omit'

import { reportingsAPI } from '../../../api/reportingsAPI'
import { attachMissionToReportingSliceActions } from '../../../features/Reportings/slice'
import { isNewReporting } from '../../../features/Reportings/utils'
import { setToast, ReportingContext } from '../../shared_slices/Global'
import { reportingActions } from '../../shared_slices/reporting'
import { MapInteractionListenerEnum, updateMapInteractionListeners } from '../map/updateMapInteractionListeners'

import type { Reporting } from '../../entities/reporting'

export const unattachMissionFromReporting =
(values: Reporting | Partial<Reporting>, reportingContext: ReportingContext) => async dispatch => {
(values: Reporting | Partial<Reporting>, reportingContext: ReportingContext) => async (dispatch, getState) => {
const newOrNextReportingData = omit(values, ['attachedMission'])
const endpoint = reportingsAPI.endpoints.updateReporting

const { initialAttachedMission } = getState().attachMissionToReporting

const reportingIsNew = isNewReporting(values.id)

if (reportingIsNew) {
await dispatch(updateMapInteractionListeners(MapInteractionListenerEnum.NONE))
await dispatch(attachMissionToReportingSliceActions.setAttachedMission(initialAttachedMission))

return
}

try {
const response = await dispatch(endpoint.initiate(newOrNextReportingData))
if ('data' in response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function AttachMission({ onAttachMission }) {
// the form listens to the redux store to update the attached mission
// because of the map interaction to attach mission
useEffect(() => {
if (missionId && missionId !== values.missionId) {
if ((missionId && missionId !== values.missionId) || (!missionId && values.missionId)) {
setFieldValue('missionId', missionId)
setFieldValue('attachedMission', attachedMission)
setFieldValue('attachedToMissionAtUtc', new Date().toISOString())
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/map/layers/Reportings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function ReportingsLayer({ map, mapClickEvent }: BaseMapChildrenProps) {
const isLayerVisible = useMemo(
() =>
(displayReportingsLayer && !hasMapListener) ||
!!(attachedReportingsToActiveMission && attachedReportingsToActiveMission?.length > 0),
!!(attachedReportingsToActiveMission && attachedReportingsToActiveMission?.length > 0 && !hasMapListener),
[displayReportingsLayer, hasMapListener, attachedReportingsToActiveMission]
)

Expand Down

0 comments on commit d373ee3

Please sign in to comment.