Skip to content

Commit

Permalink
use dataview vessel group
Browse files Browse the repository at this point in the history
  • Loading branch information
j8seangel committed Aug 30, 2024
1 parent 398029f commit fee4cf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Fragment, useState } from 'react'
import cx from 'classnames'
import { useTranslation } from 'react-i18next'
import { useSelector } from 'react-redux'
import { VesselGroup } from '@globalfishingwatch/api-types'
import { IconButton, ColorBarOption, Tooltip } from '@globalfishingwatch/ui-components'
import { UrlDataviewInstance } from '@globalfishingwatch/dataviews-client'
import { useGetDeckLayer } from '@globalfishingwatch/deck-layer-composer'
Expand All @@ -28,19 +27,18 @@ import VesselGroupNotFound from './VesselGroupNotFound'

export type VesselGroupLayerPanelProps = {
dataview: UrlDataviewInstance
vesselGroup?: VesselGroup
vesselGroupLoading?: boolean
}

function VesselGroupLayerPanel({
dataview,
vesselGroup,
vesselGroupLoading,
}: VesselGroupLayerPanelProps): React.ReactElement {
const { t } = useTranslation()
const dispatch = useAppDispatch()
const isGFWUser = useSelector(selectIsGFWUser)
const readOnly = useSelector(selectReadOnly)
const { vesselGroup } = dataview
const { upsertDataviewInstance } = useDataviewInstancesConnect()

const activityLayer = useGetDeckLayer<FourwingsLayer>(dataview?.id)
Expand Down Expand Up @@ -105,9 +103,15 @@ function VesselGroupLayerPanel({
content={t('vesselGroupReport.clickToSee', 'Click to see the vessel group report')}
>
<span>
{formatInfoField(vesselGroup?.name, 'name')}{' '}
{vesselGroup?.vessels?.length && (
<span className={styles.secondary}> ({vesselGroup?.vessels.length})</span>
{vesselGroupLoading ? (
t('vesselGroup.loadingInfo', 'Loading vessel group info')
) : (
<Fragment>
{formatInfoField(vesselGroup?.name, 'name')}{' '}
{vesselGroup?.vessels?.length && (
<span className={styles.secondary}> ({vesselGroup?.vessels.length})</span>
)}
</Fragment>
)}
</span>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { useSelector } from 'react-redux'
import { SortableContext } from '@dnd-kit/sortable'
import cx from 'classnames'
import { useTranslation } from 'react-i18next'
import { VesselGroup } from '@globalfishingwatch/api-types'
import styles from 'features/workspace/shared/Sections.module.css'
import { TrackCategory, trackEvent } from 'features/app/analytics.hooks'
import { useDataviewInstancesConnect } from 'features/workspace/workspace.hook'
import { selectReadOnly } from 'features/app/selectors/app.selectors'
import VesselGroupListTooltip from 'features/vessel-groups/VesselGroupListTooltip'
import { getVesselGroupDataviewInstance } from 'features/dataviews/dataviews.utils'
import { selectVesselGroupDataviews } from 'features/dataviews/selectors/dataviews.categories.selectors'
import { selectAllVisibleVesselGroups } from 'features/user/selectors/user.permissions.selectors'
import { useAppDispatch } from 'features/app/app.hooks'
import {
selectVesselGroupsStatusId,
Expand All @@ -27,7 +25,6 @@ function VesselGroupSection(): React.ReactElement {
const { t } = useTranslation()
const dispatch = useAppDispatch()
const dataviews = useSelector(selectVesselGroupDataviews)
const allVesselGroups = useSelector(selectAllVisibleVesselGroups)
const workspaceVesselGroupsStatus = useSelector(selectWorkspaceVesselGroupsStatus)
const vesselGroupsStatusId = useSelector(selectVesselGroupsStatusId)
const { upsertDataviewInstance } = useDataviewInstancesConnect()
Expand Down Expand Up @@ -72,24 +69,14 @@ function VesselGroupSection(): React.ReactElement {
<SortableContext items={dataviews}>
{dataviews.length > 0 ? (
dataviews?.map((dataview) => {
const dataviewVesselGroups = dataview.config?.filters?.['vessel-groups']
let vesselGroup = allVesselGroups.find((vesselGroup) =>
dataviewVesselGroups.includes(vesselGroup.id)
)
if (workspaceVesselGroupsStatus === AsyncReducerStatus.Loading && !vesselGroup) {
vesselGroup = {
id: dataviewVesselGroups[0],
name: t('vesselGroup.loadingInfo', 'Loading vessel group info'),
} as VesselGroup
}
return (
<VesselGroupLayerPanel
key={dataview.id}
dataview={dataview}
vesselGroup={vesselGroup}
vesselGroupLoading={
(!vesselGroup && workspaceVesselGroupsStatus === AsyncReducerStatus.Loading) ||
dataviewVesselGroups[0] === vesselGroupsStatusId
(!dataview.vesselGroup &&
workspaceVesselGroupsStatus === AsyncReducerStatus.Loading) ||
dataview.vesselGroup?.id === vesselGroupsStatusId
}
/>
)
Expand Down

0 comments on commit fee4cf7

Please sign in to comment.