From 81ace7d4d8c45d5c922d3c59d6a546f0284f1c8e Mon Sep 17 00:00:00 2001 From: j8seangel Date: Tue, 24 Sep 2024 19:00:29 +0200 Subject: [PATCH] fix vessel activity reports in vgr --- .../app/selectors/app.reports.selector.ts | 18 ++++++++++++-- .../features/download/download.selectors.ts | 2 +- .../report-activity-vessels.selectors.ts | 5 +++- .../reports/areas/area-reports.hooks.ts | 24 ------------------- .../VGRActivitySubsectionSelector.tsx.tsx | 2 +- .../vessel-group-report.config.ts | 2 +- .../vessel-groups/vessel-groups.types.ts | 2 +- 7 files changed, 24 insertions(+), 31 deletions(-) diff --git a/apps/fishing-map/features/app/selectors/app.reports.selector.ts b/apps/fishing-map/features/app/selectors/app.reports.selector.ts index 18412b7483..903a5ca6aa 100644 --- a/apps/fishing-map/features/app/selectors/app.reports.selector.ts +++ b/apps/fishing-map/features/app/selectors/app.reports.selector.ts @@ -20,6 +20,7 @@ import { } from 'features/reports/areas/area-reports.config.selectors' import { ReportCategory, ReportVesselGraph } from 'features/reports/areas/area-reports.types' import { WORLD_REGION_ID } from 'features/reports/activity/reports-activity.slice' +import { selectVGRActivitySubsection } from 'features/reports/vessel-groups/vessel-group.config.selectors' export const selectCurrentReport = createSelector( [selectReportId, (state) => state.reports], @@ -62,8 +63,21 @@ export const selectReportActiveCategories = createSelector( ) export const selectReportCategory = createSelector( - [selectReportCategorySelector, selectReportActiveCategories], - (reportCategory, activeCategories): ReportCategory => { + [ + selectReportCategorySelector, + selectReportActiveCategories, + selectIsVesselGroupReportLocation, + selectVGRActivitySubsection, + ], + ( + reportCategory, + activeCategories, + isVesselGroupReportLocation, + vGRActivitySubsection + ): ReportCategory => { + if (isVesselGroupReportLocation) { + return vGRActivitySubsection as ReportCategory + } return activeCategories.some((category) => category === reportCategory) ? reportCategory : activeCategories[0] diff --git a/apps/fishing-map/features/download/download.selectors.ts b/apps/fishing-map/features/download/download.selectors.ts index db2a6fa21c..99ce12bbda 100644 --- a/apps/fishing-map/features/download/download.selectors.ts +++ b/apps/fishing-map/features/download/download.selectors.ts @@ -7,7 +7,7 @@ import { AsyncReducerStatus } from 'utils/async-slice' export const selectDownloadActivityArea = createSelector( [selectDownloadActivityAreaKey, selectAreas], (areaKey, areas): DatasetAreaDetail => { - return areas[areaKey!?.datasetId]!.detail[areaKey!?.areaId] + return areas[areaKey!?.datasetId]?.detail?.[areaKey!?.areaId] } ) diff --git a/apps/fishing-map/features/reports/activity/vessels/report-activity-vessels.selectors.ts b/apps/fishing-map/features/reports/activity/vessels/report-activity-vessels.selectors.ts index ece0c5e14b..0ff9d77e5a 100644 --- a/apps/fishing-map/features/reports/activity/vessels/report-activity-vessels.selectors.ts +++ b/apps/fishing-map/features/reports/activity/vessels/report-activity-vessels.selectors.ts @@ -36,9 +36,12 @@ export const selectReportVesselsList = createSelector( [selectReportActivityFlatten, selectAllDatasets, selectReportCategory], (vessels, datasets, reportCategory) => { if (!vessels?.length) return null + return Object.values(groupBy(vessels, (v) => v.vesselId)) .flatMap((vesselActivity) => { - if (vesselActivity[0]?.category !== reportCategory) return EMPTY_ARRAY + if (vesselActivity[0]?.category !== reportCategory) { + return EMPTY_ARRAY + } const activityDataset = datasets.find((d) => vesselActivity[0].activityDatasetId === d.id) const infoDatasetId = getRelatedDatasetByType(activityDataset, DatasetTypes.Vessels)?.id const infoDataset = datasets.find((d) => d.id === infoDatasetId) diff --git a/apps/fishing-map/features/reports/areas/area-reports.hooks.ts b/apps/fishing-map/features/reports/areas/area-reports.hooks.ts index b7b2984f05..45215faac9 100644 --- a/apps/fishing-map/features/reports/areas/area-reports.hooks.ts +++ b/apps/fishing-map/features/reports/areas/area-reports.hooks.ts @@ -253,30 +253,6 @@ export function useFetchReportVessel() { updateWorkspaceReportUrls, ]) - // useEffect(() => { - // const isDifferentDateRange = reportDateRangeHash !== getDateRangeHash(timerange) - // if ( - // areaId && - // reportDataviews?.length && - // timerangeSupported && - // isDifferentDateRange && - // workspaceStatus === AsyncReducerStatus.Finished - // ) { - // dispatchFetchReport() - // } - // // Avoid re-fetching when timerange changes - // // eslint-disable-next-line react-hooks/exhaustive-deps - // }, [ - // dispatch, - // areaId, - // datasetId, - // reportBufferHash, - // reportDataviews, - // timerangeSupported, - // reportDateRangeHash, - // workspaceStatus, - // ]) - return useMemo( () => ({ status, data, error, dispatchFetchReport }), [status, data, error, dispatchFetchReport] diff --git a/apps/fishing-map/features/reports/vessel-groups/activity/VGRActivitySubsectionSelector.tsx.tsx b/apps/fishing-map/features/reports/vessel-groups/activity/VGRActivitySubsectionSelector.tsx.tsx index 76fa79aaad..1f76e8bcbe 100644 --- a/apps/fishing-map/features/reports/vessel-groups/activity/VGRActivitySubsectionSelector.tsx.tsx +++ b/apps/fishing-map/features/reports/vessel-groups/activity/VGRActivitySubsectionSelector.tsx.tsx @@ -18,7 +18,7 @@ function VGRActivitySubsectionSelector() { const fitAreaInViewport = useFitAreaInViewport() const options: ChoiceOption[] = [ { - id: 'fishing-effort', + id: 'fishing', label: t('common.apparentFishing', 'Apparent fishing effort'), disabled: loading, }, diff --git a/apps/fishing-map/features/reports/vessel-groups/vessel-group-report.config.ts b/apps/fishing-map/features/reports/vessel-groups/vessel-group-report.config.ts index c416d3b4a4..b9e7ce4b36 100644 --- a/apps/fishing-map/features/reports/vessel-groups/vessel-group-report.config.ts +++ b/apps/fishing-map/features/reports/vessel-groups/vessel-group-report.config.ts @@ -7,7 +7,7 @@ export const DEFAULT_VESSEL_GROUP_REPORT_STATE: VesselGroupReportState = { viewOnlyVesselGroup: true, vGRSection: 'vessels', vGRVesselsSubsection: 'flag', - vGRActivitySubsection: 'fishing-effort', + vGRActivitySubsection: 'fishing', vGREventsSubsection: 'encounter', vGREventsVesselsProperty: 'flag', vGRVesselPage: 0, diff --git a/apps/fishing-map/features/vessel-groups/vessel-groups.types.ts b/apps/fishing-map/features/vessel-groups/vessel-groups.types.ts index 6238b8840e..f0c2daa343 100644 --- a/apps/fishing-map/features/vessel-groups/vessel-groups.types.ts +++ b/apps/fishing-map/features/vessel-groups/vessel-groups.types.ts @@ -1,6 +1,6 @@ export type VGRSection = 'vessels' | 'insights' | 'activity' | 'events' export type VGRVesselsSubsection = 'flag' | 'shiptypes' | 'geartypes' | 'source' -export type VGRActivitySubsection = 'fishing-effort' | 'presence' +export type VGRActivitySubsection = 'fishing' | 'presence' export type VGREventsVesselsProperty = 'flag' | 'geartype' export type VGREventsSubsection = 'encounter' | 'loitering' | 'gaps' | 'port_visits' export type VGRVesselsOrderProperty = 'shipname' | 'flag' | 'shiptype'