Skip to content

Commit

Permalink
Create LeftMenu & migrate global slice into MainWindow feature [WIP/P…
Browse files Browse the repository at this point in the history
…ROPOSAL]
  • Loading branch information
ivangabriele committed Apr 23, 2024
1 parent 32e1483 commit a7574b3
Show file tree
Hide file tree
Showing 119 changed files with 946 additions and 757 deletions.
2 changes: 1 addition & 1 deletion frontend/src/api/APIWorker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useEffect, useRef, useState } from 'react'

import { SideWindowStatus } from '../domain/entities/sideWindow/constants'
import { VesselSidebarTab } from '../domain/entities/vessel/vessel'
import { setIsUpdatingVessels } from '../domain/shared_slices/Global'
import { getOperationalAlerts } from '../domain/use_cases/alert/getOperationalAlerts'
import { getSilencedAlerts } from '../domain/use_cases/alert/getSilencedAlerts'
import getAllBeaconMalfunctions from '../domain/use_cases/beaconMalfunction/getAllBeaconMalfunctions'
Expand All @@ -15,6 +14,7 @@ import { getVesselControls } from '../domain/use_cases/mission/getVesselControls
import getAllSpecies from '../domain/use_cases/species/getAllSpecies'
import { getVesselReportings } from '../domain/use_cases/vessel/getVesselReportings'
import { updateVesselTracks } from '../domain/use_cases/vessel/updateVesselTracks'
import { setIsUpdatingVessels } from '../features/MainWindow/slice'
import getAllRegulatoryLayers from '../features/Regulation/useCases/getAllRegulatoryLayers'
import { getAllCurrentReportings } from '../features/Reporting/useCases/getAllCurrentReportings'
import { useIsSuperUser } from '../hooks/authorization/useIsSuperUser'
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/BackofficeMode.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'react'

import { setIsBackoffice } from '../domain/shared_slices/Global'
import { setIsBackoffice } from '../features/MainWindow/slice'
import { useMainAppDispatch } from '../hooks/useMainAppDispatch'

export type BackofficeModeProps = {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/domain/entities/vessel/vessel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const VESSEL_SELECTOR_STYLE = 200
export class Vessel {
static vesselIsMovingSpeed = 0.1

static getVesselFeatureId(vessel) {
static getVesselFeatureId(vessel: VesselIdentity) {
return `${MonitorFishLayer.VESSELS}:${getVesselCompositeIdentifier(vessel)}`
}

Expand Down Expand Up @@ -143,7 +143,7 @@ export class Vessel {
}

export const getOnlyVesselIdentityProperties = (
vessel: VesselEnhancedObject | SelectedVessel | VesselTypes.Vessel | Reporting
vessel: VesselEnhancedObject | SelectedVessel | VesselTypes.Vessel | Reporting | VesselIdentity
): VesselIdentity => ({
beaconNumber: 'beaconNumber' in vessel && !!vessel.beaconNumber ? vessel.beaconNumber : null,
districtCode: 'districtCode' in vessel && !!vessel.districtCode ? vessel.districtCode : null,
Expand All @@ -157,7 +157,7 @@ export const getOnlyVesselIdentityProperties = (
vesselName: vessel.vesselName ?? null
})

export const getVesselCompositeIdentifier: (vessel) => VesselCompositeIdentifier = vessel =>
export const getVesselCompositeIdentifier: (vessel: VesselIdentity) => VesselCompositeIdentifier = vessel =>
`${vessel.internalReferenceNumber ?? 'UNKNOWN'}/${vessel.ircs ?? 'UNKNOWN'}/${
vessel.externalReferenceNumber ?? 'UNKNOWN'
}`
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/domain/shared_slices/Vessel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,13 @@ const vesselSlice = createSlice({
state.highlightedVesselTrackPosition = action.payload
},

loadingVessel(state, action) {
loadingVessel(
state,
action: PayloadAction<{
calledFromCron: boolean
vesselIdentity: VesselIdentity
}>
) {
state.selectedVesselIdentity = action.payload.vesselIdentity
state.vesselSidebarIsOpen = true
if (!action.payload.calledFromCron) {
Expand Down Expand Up @@ -303,7 +309,8 @@ const vesselSlice = createSlice({
})

if (
state.selectedVessel &&
!!state.selectedVessel &&
!!state.selectedVesselIdentity &&
Vessel.getVesselFeatureId(state.selectedVesselIdentity) === action.payload.vesselFeatureId
) {
const vesselReportingWithoutFirstFoundReportingType = state.selectedVessel.reportings?.reduce(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/alert/addSilencedAlert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { alertApi } from '../../../api/alert'
import { setError } from '../../../features/MainWindow/slice'
import { setSilencedAlerts } from '../../../features/SideWindow/Alert/slice'
import { setError } from '../../shared_slices/Global'

import type { MainAppThunk } from '../../../store'
import type { SilencedAlertData } from '../../entities/alerts/types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getOperationalAlertsFromAPI } from '../../../api/alert'
import { setError } from '../../../features/MainWindow/slice'
import { setPendingAlerts } from '../../../features/SideWindow/Alert/slice'
import { setError } from '../../shared_slices/Global'

import type { MainAppThunk } from '../../../store'

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/alert/getSilencedAlerts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getSilencedAlertsFromAPI } from '../../../api/alert'
import { setError } from '../../../features/MainWindow/slice'
import { setSilencedAlerts } from '../../../features/SideWindow/Alert/slice'
import { setError } from '../../shared_slices/Global'

export const getSilencedAlerts = () => dispatch => {
getSilencedAlertsFromAPI()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { deleteSilencedAlertFromAPI } from '../../../api/alert'
import { setError } from '../../../features/MainWindow/slice'
import { setSilencedAlerts } from '../../../features/SideWindow/Alert/slice'
import { deleteListItems } from '../../../utils/deleteListItems'
import { updateListItemsProp } from '../../../utils/updateListItemsProp'
import { setError } from '../../shared_slices/Global'

import type { MainAppThunk } from '../../../store'
import type { LEGACY_SilencedAlert } from '../../entities/alerts/types'
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/alert/silenceAlert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { silenceAlertFromAPI } from '../../../api/alert'
import { setError } from '../../../features/MainWindow/slice'
import {
addToPendingAlertsBeingSilenced,
removeFromSilencedAlertsQueue,
Expand All @@ -7,7 +8,6 @@ import {
} from '../../../features/SideWindow/Alert/slice'
import { deleteListItems } from '../../../utils/deleteListItems'
import { Vessel } from '../../entities/vessel/vessel'
import { setError } from '../../shared_slices/Global'
import { removeVesselAlertAndUpdateReporting } from '../../shared_slices/Vessel'

import type { MainAppThunk } from '../../../store'
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/alert/validateAlert.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { validateAlertFromAPI } from '../../../api/alert'
import { setError } from '../../../features/MainWindow/slice'
import { setPendingAlerts } from '../../../features/SideWindow/Alert/slice'
import { deleteListItems } from '../../../utils/deleteListItems'
import { updateListItemsProp } from '../../../utils/updateListItemsProp'
import { Vessel } from '../../entities/vessel/vessel'
import { setError } from '../../shared_slices/Global'
import { removeVesselAlertAndUpdateReporting } from '../../shared_slices/Vessel'
import { getVesselReportings } from '../vessel/getVesselReportings'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { archiveBeaconMalfunctionsFromAPI } from '../../../api/beaconMalfunction'
import { setError } from '../../../features/MainWindow/slice'
import {
setBeaconMalfunctions,
setOpenedBeaconMalfunction,
updateLocalBeaconMalfunctions,
updateVesselBeaconMalfunctionsResumeAndHistory
} from '../../shared_slices/BeaconMalfunction'
import { setError } from '../../shared_slices/Global'

/**
* Archive multiple beacon malfunctions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getAllBeaconMalfunctionsFromAPI } from '../../../api/beaconMalfunction'
import { setError } from '../../../features/MainWindow/slice'
import { setBeaconMalfunctions } from '../../shared_slices/BeaconMalfunction'
import { setError } from '../../shared_slices/Global'

const getAllBeaconMalfunctions = () => dispatch => {
getAllBeaconMalfunctionsFromAPI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { DisplayedErrorKey } from '@libs/DisplayedError/constants'

import openBeaconMalfunction from './openBeaconMalfunction'
import { getVesselBeaconsMalfunctionsFromAPI } from '../../../api/beaconMalfunction'
import { removeError } from '../../../features/MainWindow/slice'
import { getOnlyVesselIdentityProperties } from '../../entities/vessel/vessel'
import {
loadVesselBeaconMalfunctions,
resetVesselBeaconMalfunctionsResumeAndHistory,
setVesselBeaconMalfunctionsResumeAndHistory
} from '../../shared_slices/BeaconMalfunction'
import { displayedErrorActions } from '../../shared_slices/DisplayedError'
import { removeError } from '../../shared_slices/Global'
import { displayOrLogError } from '../error/displayOrLogError'

export const getVesselBeaconMalfunctions = (isFromUserAction: boolean) => async (dispatch, getState) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getBeaconMalfunctionFromAPI } from '../../../api/beaconMalfunction'
import { setError } from '../../../features/MainWindow/slice'
import { setOpenedBeaconMalfunction } from '../../shared_slices/BeaconMalfunction'
import { setError } from '../../shared_slices/Global'

/**
* Open a single beacon malfunction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getBeaconMalfunctionFromAPI } from '../../../api/beaconMalfunction'
import { setError } from '../../../features/MainWindow/slice'
import { setOpenedBeaconMalfunctionsInKanban } from '../../shared_slices/BeaconMalfunction'
import { setError } from '../../shared_slices/Global'

/**
* Open a single beacon malfunction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { saveBeaconMalfunctionCommentFromAPI } from '../../../api/beaconMalfunction'
import { setError } from '../../../features/MainWindow/slice'
import {
setOpenedBeaconMalfunction,
setOpenedBeaconMalfunctionsInKanban,
updateVesselBeaconMalfunctionsResumeAndHistory
} from '../../shared_slices/BeaconMalfunction'
import { setError } from '../../shared_slices/Global'

/**
* Save a new comment to a beacon malfunction
Expand All @@ -13,7 +13,7 @@ import { setError } from '../../shared_slices/Global'
* @param {string} comment
*/
const saveBeaconMalfunctionCommentFromKanban = (beaconMalfunctionId, comment) => (dispatch, getState) => {
const { userType } = getState().global
const { userType } = getState().mainWindow
const newCommentInput = {
comment,
userType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sendNotificationFromAPI } from '../../../api/beaconMalfunction'
import { setError } from '../../../features/MainWindow/slice'
import { NOTIFICATION_TYPE } from '../../entities/beaconMalfunction/constants'
import { setError } from '../../shared_slices/Global'

/**
* Send a notification message
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { updateBeaconMalfunctionFromAPI } from '../../../api/beaconMalfunction'
import { setError } from '../../../features/MainWindow/slice'
import {
setBeaconMalfunctions,
updateLocalBeaconMalfunction,
setOpenedBeaconMalfunctionsInKanban,
setOpenedBeaconMalfunction,
updateVesselBeaconMalfunctionsResumeAndHistory
} from '../../shared_slices/BeaconMalfunction'
import { setError } from '../../shared_slices/Global'

/**
* Update a beacon malfunction
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/error/displayOrLogError.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setError } from '../../../features/MainWindow/slice'
import { DisplayedError } from '../../../libs/DisplayedError'
import { INITIAL_STATE, type DisplayedErrorState, displayedErrorActions } from '../../shared_slices/DisplayedError'
import { setError } from '../../shared_slices/Global'

import type { MainAppUseCase } from '@store'

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/faoAreas/getFAOAreas.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getFAOAreasFromAPI } from '../../../api/faoAreas'
import { setError } from '../../shared_slices/Global'
import { setError } from '../../../features/MainWindow/slice'

const getFAOAreas = () => dispatch =>
getFAOAreasFromAPI().catch(error => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/gearCode/getAllGearCodes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { batch } from 'react-redux'

import { getAllGearsFromAPI } from '../../../api/gearCode'
import { setError } from '../../../features/MainWindow/slice'
import { setIsReadyToShowRegulatoryZones } from '../../../features/Regulation/slice'
import { REGULATED_GEARS_KEYS } from '../../entities/backoffice'
import { setCategoriesToGears, setGears, setGroupsToCategories, setGearsByCode } from '../../shared_slices/Gear'
import { setError } from '../../shared_slices/Global'

/** *
* Get gear group name, see SQL init of table fishing_gear_groups:
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/infraction/getInfractions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getInfractionsFromAPI } from '../../../api/infraction'
import { setError } from '../../shared_slices/Global'
import { setError } from '../../../features/MainWindow/slice'
import { setInfractions } from '../../shared_slices/Infraction'

export const getInfractions = () => dispatch => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/map/clickOnMapFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const clickOnMapFeature =
return
}

if (getState().global.previewFilteredVesselsMode) {
if (getState().mainWindow.previewFilteredVesselsMode) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Circle from 'ol/geom/Circle'
import { fromCircle } from 'ol/geom/Polygon'
import { batch } from 'react-redux'

import { setRightMapBoxOpened } from '../../../features/MainWindow/slice'
import { OPENLAYERS_PROJECTION } from '../../entities/map/constants'
import { setRightMapBoxOpened } from '../../shared_slices/Global'
import { addMeasurementDrawed, resetCircleMeasurementInDrawing } from '../../shared_slices/Measurement'

const saveMeasurement = (feature, measurement) => dispatch => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/mission/getVesselControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DisplayedErrorKey } from '@libs/DisplayedError/constants'

import { getVesselControlsFromAPI } from '../../../api/missionAction'
import NoControlsFoundError from '../../../errors/NoControlsFoundError'
import { removeError, setError } from '../../../features/MainWindow/slice'
import {
loadControls,
resetLoadControls,
Expand All @@ -10,7 +11,6 @@ import {
unsetControlSummary
} from '../../shared_slices/Control'
import { displayedErrorActions } from '../../shared_slices/DisplayedError'
import { removeError, setError } from '../../shared_slices/Global'
import { displayOrLogError } from '../error/displayOrLogError'

export const getVesselControls = (isFromUserAction: boolean) => async (dispatch, getState) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/species/getAllSpecies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAllSpeciesFromAPI } from '../../../api/species'
import { setError } from '../../shared_slices/Global'
import { setError } from '../../../features/MainWindow/slice'
import { setSpeciesAndSpeciesGroups } from '../../shared_slices/Species'

const getAllSpecies = () => async (dispatch, getState) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DisplayedErrorKey } from '@libs/DisplayedError/constants'

import { getVesselReportingsFromAPI } from '../../../api/vessel'
import { removeError } from '../../../features/MainWindow/slice'
import {
loadReporting,
resetCurrentAndArchivedReportingsOfSelectedVessel,
setCurrentAndArchivedReportingsOfSelectedVessel
} from '../../../features/Reporting/slice'
import { displayedErrorActions } from '../../shared_slices/DisplayedError'
import { removeError } from '../../shared_slices/Global'
import { displayOrLogError } from '../error/displayOrLogError'

export const getVesselReportings = (isFromUserAction: boolean) => async (dispatch, getState) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/vessel/searchVessels.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { searchVesselsFromAPI } from '../../../api/vessel'
import { setError } from '../../shared_slices/Global'
import { setError } from '../../../features/MainWindow/slice'

export const searchVessels = searched => dispatch =>
searchVesselsFromAPI(searched).catch(error => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/domain/use_cases/vessel/showVessel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { captureMessage } from '@sentry/react'

import { getVesselFromAPI } from '../../../api/vessel'
import { logbookActions } from '../../../features/Logbook/slice'
import { addSearchedVessel, removeError, setError } from '../../../features/MainWindow/slice'
import { Vessel } from '../../entities/vessel/vessel'
import { getCustomOrDefaultTrackRequest, throwCustomErrorFromAPIFeedback } from '../../entities/vesselTrackDepth'
import { displayedComponentActions } from '../../shared_slices/DisplayedComponent'
import { displayedErrorActions } from '../../shared_slices/DisplayedError'
import { addSearchedVessel, removeError, setError } from '../../shared_slices/Global'
import { doNotAnimate } from '../../shared_slices/Map'
import { loadingVessel, resetLoadingVessel, setSelectedVessel } from '../../shared_slices/Vessel'
import { displayOrLogError } from '../error/displayOrLogError'
Expand Down Expand Up @@ -96,7 +96,7 @@ export const showVessel =
}
}

function dispatchLoadingVessel(dispatch, isFromUserAction: boolean, vesselIdentity) {
function dispatchLoadingVessel(dispatch, isFromUserAction: boolean, vesselIdentity: VesselIdentity) {
dispatch(doNotAnimate(!isFromUserAction))
dispatch(removeError())
dispatch(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/vessel/showVesselTrack.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { transform } from 'ol/proj'

import { getVesselPositionsFromAPI } from '../../../api/vessel'
import { removeError, setError } from '../../../features/MainWindow/slice'
import { OPENLAYERS_PROJECTION, WSG84_PROJECTION } from '../../entities/map/constants'
import { getVesselCompositeIdentifier } from '../../entities/vessel/vessel'
import { getCustomOrDefaultTrackRequest, throwCustomErrorFromAPIFeedback } from '../../entities/vesselTrackDepth'
import { removeError, setError } from '../../shared_slices/Global'
import { doNotAnimate } from '../../shared_slices/Map'
import { addVesselTrackShowed, resetLoadingVessel } from '../../shared_slices/Vessel'

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/domain/use_cases/vessel/unselectVessel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logbookActions } from '../../../features/Logbook/slice'
import { expandRightMenu } from '../../../features/MainWindow/slice'
import { resetCurrentAndArchivedReportingsOfSelectedVessel } from '../../../features/Reporting/slice'
import { resetVesselBeaconMalfunctionsResumeAndHistory } from '../../shared_slices/BeaconMalfunction'
import { expandRightMenu } from '../../shared_slices/Global'
import { closeVesselSidebar, resetSelectedVessel } from '../../shared_slices/Vessel'

export const unselectVessel = () => dispatch => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getVesselPositionsFromAPI } from '../../../api/vessel'
import { logbookActions } from '../../../features/Logbook/slice'
import { removeError, setError } from '../../../features/MainWindow/slice'
import { throwCustomErrorFromAPIFeedback } from '../../entities/vesselTrackDepth'
import { removeError, setError } from '../../shared_slices/Global'
import { animateToExtent, doNotAnimate } from '../../shared_slices/Map'
import {
resetLoadingVessel,
Expand Down
Loading

0 comments on commit a7574b3

Please sign in to comment.