Skip to content

Commit

Permalink
Implement dataset metadata refetching
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfdsilva committed Sep 6, 2023
1 parent f976b26 commit 8d5c880
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function DatasetTrackError(props: {
<TrackMessage>
<p>{message}</p>
{typeof onRetryClick === 'function' ? (
<Button variation='danger-fill' size='small'>
<Button variation='danger-fill' size='small' onClick={onRetryClick}>
Retry <CollecticonArrowLoop size='small' />
</Button>
) : null}
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,6 +13,7 @@ import {
startOfYear,
areIntervalsOverlapping
} from 'date-fns';
import { useQueryClient } from '@tanstack/react-query';
import { ScaleTime } from 'd3';
import {
CollecticonEye,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -264,8 +277,7 @@ export function DatasetListItem(props: DatasetListItemProps) {
<DatasetTrackError
message='Oh no, something went wrong'
onRetryClick={() => {
/* eslint-disable-next-line no-console */
console.log('Retry metadata loading');
retryDatasetMetadata();
}}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8d5c880

Please sign in to comment.