From 8d5c880bc0628b3ef3e4bf4d5b99e4cbe361a133 Mon Sep 17 00:00:00 2001 From: Daniel da Silva Date: Wed, 6 Sep 2023 12:33:32 +0100 Subject: [PATCH] Implement dataset metadata refetching --- .../datasets/dataset-list-item-status.tsx | 2 +- .../components/datasets/dataset-list-item.tsx | 18 +++++++++++++++--- .../hooks/use-stac-metadata-datasets.ts | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/scripts/components/exploration/components/datasets/dataset-list-item-status.tsx b/app/scripts/components/exploration/components/datasets/dataset-list-item-status.tsx index 5e304e0d3..572dcbb0f 100644 --- a/app/scripts/components/exploration/components/datasets/dataset-list-item-status.tsx +++ b/app/scripts/components/exploration/components/datasets/dataset-list-item-status.tsx @@ -99,7 +99,7 @@ export function DatasetTrackError(props: {

{message}

{typeof onRetryClick === 'function' ? ( - ) : null} diff --git a/app/scripts/components/exploration/components/datasets/dataset-list-item.tsx b/app/scripts/components/exploration/components/datasets/dataset-list-item.tsx index d7bf5721b..a5805e264 100644 --- a/app/scripts/components/exploration/components/datasets/dataset-list-item.tsx +++ b/app/scripts/components/exploration/components/datasets/dataset-list-item.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react'; +import React, { useCallback, useMemo } from 'react'; import { useAtomValue } from 'jotai'; import { Reorder, useDragControls } from 'framer-motion'; import styled, { useTheme } from 'styled-components'; @@ -13,6 +13,7 @@ import { startOfYear, areIntervalsOverlapping } from 'date-fns'; +import { useQueryClient } from '@tanstack/react-query'; import { ScaleTime } from 'd3'; import { CollecticonEye, @@ -157,6 +158,18 @@ export function DatasetListItem(props: DatasetListItemProps) { const [isVisible, setVisible] = useTimelineDatasetVisibility(datasetAtom); + const queryClient = useQueryClient(); + + const retryDatasetMetadata = useCallback(() => { + queryClient.invalidateQueries( + { + queryKey: ['dataset', datasetId], + exact: true + }, + { throwOnError: false } + ); + }, [queryClient, datasetId]); + const controls = useDragControls(); // Hook to handle the hover state of the dataset. Check the source file as to @@ -264,8 +277,7 @@ export function DatasetListItem(props: DatasetListItemProps) { { - /* eslint-disable-next-line no-console */ - console.log('Retry metadata loading'); + retryDatasetMetadata(); }} /> )} diff --git a/app/scripts/components/exploration/hooks/use-stac-metadata-datasets.ts b/app/scripts/components/exploration/hooks/use-stac-metadata-datasets.ts index f709a48b6..8e038e0ca 100644 --- a/app/scripts/components/exploration/hooks/use-stac-metadata-datasets.ts +++ b/app/scripts/components/exploration/hooks/use-stac-metadata-datasets.ts @@ -17,8 +17,8 @@ import { resolveLayerTemporalExtent } from '../data-utils'; import { useEffectPrevious } from '$utils/use-effect-previous'; function didDataChange(curr: UseQueryResult, prev?: UseQueryResult) { - const currKey = `${curr.errorUpdatedAt}-${curr.dataUpdatedAt}`; - const prevKey = `${prev?.errorUpdatedAt}-${prev?.dataUpdatedAt}`; + const currKey = `${curr.errorUpdatedAt}-${curr.dataUpdatedAt}-${curr.failureCount}`; + const prevKey = `${prev?.errorUpdatedAt}-${prev?.dataUpdatedAt}-${prev?.failureCount}`; return prevKey !== currKey; }