Skip to content

Commit

Permalink
fix vessel activity reports in vgr
Browse files Browse the repository at this point in the history
  • Loading branch information
j8seangel committed Sep 24, 2024
1 parent 348e935 commit 81ace7d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 31 deletions.
18 changes: 16 additions & 2 deletions apps/fishing-map/features/app/selectors/app.reports.selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion apps/fishing-map/features/download/download.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 0 additions & 24 deletions apps/fishing-map/features/reports/areas/area-reports.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function VGRActivitySubsectionSelector() {
const fitAreaInViewport = useFitAreaInViewport()
const options: ChoiceOption<VGRActivitySubsection>[] = [
{
id: 'fishing-effort',
id: 'fishing',
label: t('common.apparentFishing', 'Apparent fishing effort'),
disabled: loading,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 81ace7d

Please sign in to comment.