From 8a9b3d05ef4d27026d6aadb226a941bbbc5823cc Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Wed, 3 Jan 2024 13:32:36 -0500 Subject: [PATCH 01/13] Handle analysis/define datasets w/o collection summaries --- .../analysis/define/use-stac-collection-search.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index add2f924b..8faa519cc 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -156,6 +156,12 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { const collection = collectionData.find( (c) => c.id === l.stacCol && stacApiEndpointUsed === c.stacApiEndpoint ); + + if(!collection.summaries) { + // TODO: We should also add it to "unselectableDatasetLayers" + return null; + } + return { ...l, isPeriodic: collection['dashboard:is_periodic'], @@ -164,6 +170,7 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { timeseries: collection.summaries.datetime }; }); - - return filteredDatasetsWithCollections; + + const filteredDatasetsWithCollectionsAndSummaries = filteredDatasetsWithCollections.filter(d => d); + return filteredDatasetsWithCollectionsAndSummaries; } From 961d551782d011037c8889d8371720e832f3f519 Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Wed, 3 Jan 2024 15:45:14 -0500 Subject: [PATCH 02/13] Add datasets w/o summaries to unselectableDatasetLayers --- .../define/use-stac-collection-search.ts | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index 8faa519cc..b4019bb7f 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -20,6 +20,13 @@ interface UseStacSearchProps { aoi?: FeatureCollection | null; } +interface DatasetWithCollections extends DatasetLayer { + isPeriodic: boolean, + timeDensity: string, + domain: string[], + timeseries?: string[]; +} + export type DatasetWithTimeseriesData = TimeseriesDataResult & DatasetLayer & { numberOfItems: number }; @@ -64,14 +71,15 @@ export function useStacCollectionSearch({ enabled: readyToLoadDatasets }); - const datasetLayersInRange = useMemo(() => { + const [datasetLayersInRange, invalidDatasets] = useMemo(() => { try { - return getInTemporalAndSpatialExtent(result.data, aoi, { + const [datasetWithSummaries, datasetWithoutSummaries] = getInTemporalAndSpatialExtent(result.data, aoi, { start, end }); + return [datasetWithSummaries, datasetWithoutSummaries]; } catch (e) { - return []; + return [[], []]; } }, [result.data, aoi, start, end]); @@ -89,11 +97,13 @@ export function useStacCollectionSearch({ ); }, [datasetLayersInRangeWithNumberOfItems]); - const unselectableDatasetLayers = useMemo(() => { + let unselectableDatasetLayers: DatasetWithTimeseriesData[] | DatasetWithCollections[] = useMemo(() => { return datasetLayersInRangeWithNumberOfItems.filter( (l) => l.numberOfItems > MAX_QUERY_NUM ); }, [datasetLayersInRangeWithNumberOfItems]); + + if (invalidDatasets) unselectableDatasetLayers = unselectableDatasetLayers.concat(invalidDatasets); return { selectableDatasetLayers, @@ -157,20 +167,27 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { (c) => c.id === l.stacCol && stacApiEndpointUsed === c.stacApiEndpoint ); - if(!collection.summaries) { - // TODO: We should also add it to "unselectableDatasetLayers" - return null; - } - - return { + const datapoint: DatasetWithCollections = { ...l, isPeriodic: collection['dashboard:is_periodic'], timeDensity: collection['dashboard:time_density'], domain: collection.extent.temporal.interval[0], + }; + + if(!collection.summaries) { + // NOTE: Invalid data because collection does not include summaries + return datapoint; + } + + return { + ...datapoint, timeseries: collection.summaries.datetime }; }); - const filteredDatasetsWithCollectionsAndSummaries = filteredDatasetsWithCollections.filter(d => d); - return filteredDatasetsWithCollectionsAndSummaries; + const [collectionsWithSummaries, collectionsWithoutSummaries] = filteredDatasetsWithCollections.reduce((result, d) => { + d.timeseries ? result[0].push(d) : result[1].push(d); + return result; + },[[], []]); + return [collectionsWithSummaries, collectionsWithoutSummaries] } From 470eb9cd38002c998cbddbba884ec49a177c2afa Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Wed, 3 Jan 2024 16:18:51 -0500 Subject: [PATCH 03/13] Guard when summaries is an empty arrow --- .../components/analysis/define/use-stac-collection-search.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index b4019bb7f..16952a9ab 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -174,7 +174,7 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { domain: collection.extent.temporal.interval[0], }; - if(!collection.summaries) { + if(!collection.summaries || !!collection.summaries.length) { // NOTE: Invalid data because collection does not include summaries return datapoint; } From c71c440e6f2025f0262377657e49980df1981eb7 Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Wed, 3 Jan 2024 16:41:58 -0500 Subject: [PATCH 04/13] Fix some lint warnings --- .../components/analysis/define/use-stac-collection-search.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index 16952a9ab..74456cada 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -103,7 +103,7 @@ export function useStacCollectionSearch({ ); }, [datasetLayersInRangeWithNumberOfItems]); - if (invalidDatasets) unselectableDatasetLayers = unselectableDatasetLayers.concat(invalidDatasets); + if (invalidDatasets.length) unselectableDatasetLayers = unselectableDatasetLayers.concat(invalidDatasets); return { selectableDatasetLayers, @@ -189,5 +189,5 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { d.timeseries ? result[0].push(d) : result[1].push(d); return result; },[[], []]); - return [collectionsWithSummaries, collectionsWithoutSummaries] + return [collectionsWithSummaries, collectionsWithoutSummaries]; } From 02dcacadf9dfffa056d45d2a613c1ecd53381d4d Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Thu, 4 Jan 2024 12:36:20 -0500 Subject: [PATCH 05/13] Fix ts errors and update flag comment for when summaries unavailable --- app/scripts/components/analysis/define/index.tsx | 2 +- .../analysis/define/use-stac-collection-search.ts | 12 +++--------- .../components/analysis/results/timeseries-data.ts | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/scripts/components/analysis/define/index.tsx b/app/scripts/components/analysis/define/index.tsx index 4eeb35af9..d49717dd6 100644 --- a/app/scripts/components/analysis/define/index.tsx +++ b/app/scripts/components/analysis/define/index.tsx @@ -517,7 +517,7 @@ export default function Analysis() { {datasetLayer.name} ~ - {datasetLayer.numberOfItems} data points + {datasetLayer.numberOfItems ? `${datasetLayer.numberOfItems} data points`: "Data temporarily unavailable"} ))} diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index 74456cada..0475f228f 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -20,15 +20,9 @@ interface UseStacSearchProps { aoi?: FeatureCollection | null; } -interface DatasetWithCollections extends DatasetLayer { - isPeriodic: boolean, - timeDensity: string, - domain: string[], - timeseries?: string[]; -} +export type DatasetWithCollections = TimeseriesDataResult & DatasetLayer; -export type DatasetWithTimeseriesData = TimeseriesDataResult & - DatasetLayer & { numberOfItems: number }; +export type DatasetWithTimeseriesData = DatasetWithCollections & { numberOfItems: number }; const collectionEndpointSuffix = '/collections'; @@ -185,7 +179,7 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { }; }); - const [collectionsWithSummaries, collectionsWithoutSummaries] = filteredDatasetsWithCollections.reduce((result, d) => { + const [collectionsWithSummaries, collectionsWithoutSummaries]: [DatasetWithCollections[], DatasetWithCollections[]] = filteredDatasetsWithCollections.reduce((result: [DatasetWithCollections[], DatasetWithCollections[]], d) => { d.timeseries ? result[0].push(d) : result[1].push(d); return result; },[[], []]); diff --git a/app/scripts/components/analysis/results/timeseries-data.ts b/app/scripts/components/analysis/results/timeseries-data.ts index 969ad0287..7d6e818b3 100644 --- a/app/scripts/components/analysis/results/timeseries-data.ts +++ b/app/scripts/components/analysis/results/timeseries-data.ts @@ -35,7 +35,7 @@ export interface TimeseriesDataResult { isPeriodic: boolean; timeDensity: TimeDensity; domain: string[]; - timeseries: TimeseriesDataUnit[]; + timeseries?: TimeseriesDataUnit[]; // NOTE: Summaries on collections will not always be available } // Different options based on status. From 4a69b11811787f5b0ed331ff85b0b1545faade0e Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Thu, 4 Jan 2024 12:46:32 -0500 Subject: [PATCH 06/13] Fix another ts error and disable mutating lint rule --- .../components/analysis/define/use-stac-collection-search.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index 0475f228f..2c69abcac 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -91,13 +91,13 @@ export function useStacCollectionSearch({ ); }, [datasetLayersInRangeWithNumberOfItems]); - let unselectableDatasetLayers: DatasetWithTimeseriesData[] | DatasetWithCollections[] = useMemo(() => { + let unselectableDatasetLayers: DatasetWithTimeseriesData[] = useMemo(() => { return datasetLayersInRangeWithNumberOfItems.filter( (l) => l.numberOfItems > MAX_QUERY_NUM ); }, [datasetLayersInRangeWithNumberOfItems]); - if (invalidDatasets.length) unselectableDatasetLayers = unselectableDatasetLayers.concat(invalidDatasets); + if (invalidDatasets.length) unselectableDatasetLayers = unselectableDatasetLayers.concat((invalidDatasets as unknown) as DatasetWithTimeseriesData[]); return { selectableDatasetLayers, @@ -180,6 +180,7 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { }); const [collectionsWithSummaries, collectionsWithoutSummaries]: [DatasetWithCollections[], DatasetWithCollections[]] = filteredDatasetsWithCollections.reduce((result: [DatasetWithCollections[], DatasetWithCollections[]], d) => { + /* eslint-disable-next-line fp/no-mutating-methods */ d.timeseries ? result[0].push(d) : result[1].push(d); return result; },[[], []]); From 94c564bee03756b85976402c06899742072ef1d2 Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Thu, 4 Jan 2024 13:02:34 -0500 Subject: [PATCH 07/13] Optionally chain for type safety in results --- app/scripts/components/analysis/results/chart-card.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/scripts/components/analysis/results/chart-card.tsx b/app/scripts/components/analysis/results/chart-card.tsx index 9b580b289..d0fa0e88f 100644 --- a/app/scripts/components/analysis/results/chart-card.tsx +++ b/app/scripts/components/analysis/results/chart-card.tsx @@ -101,7 +101,7 @@ const getNoDownloadReason = ({ status, data }: TimeseriesData) => { if (status === 'loading') { return 'Download will be available once the data finishes loading.'; } - if (!data.timeseries.length) { + if (!data.timeseries?.length) { return 'There is no data to download.'; } return ''; @@ -145,7 +145,7 @@ export default function ChartCard(props: ChartCardProps) { const onExportClick = useCallback( (e: MouseEvent, type: 'image' | 'text') => { e.preventDefault(); - if (!chartData.data?.timeseries.length) { + if (!chartData.data?.timeseries?.length) { return; } @@ -182,7 +182,7 @@ export default function ChartCard(props: ChartCardProps) { const chartDates = useMemo( () => - data?.timeseries.map((e) => + data?.timeseries?.map((e) => dateFormatter(new Date(e.date), timeDensityFormat) ) ?? [], [data?.timeseries, timeDensityFormat] @@ -273,13 +273,13 @@ export default function ChartCard(props: ChartCardProps) { ) : null} {status === 'succeeded' ? ( - data.timeseries.length ? ( + data.timeseries?.length ? ( !activeMetrics.length ? ( ) : ( Date: Thu, 4 Jan 2024 13:05:52 -0500 Subject: [PATCH 08/13] Fix another ts error... --- app/scripts/components/analysis/results/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/components/analysis/results/index.tsx b/app/scripts/components/analysis/results/index.tsx index 82c8fa757..493e9b7ef 100644 --- a/app/scripts/components/analysis/results/index.tsx +++ b/app/scripts/components/analysis/results/index.tsx @@ -130,7 +130,7 @@ export default function AnalysisResults() { const availableDomain: [Date, Date] | null = useMemo(() => { if (!start || !end) return null; const onlySingleValues = requestStatus.every( - (rs) => rs.data?.timeseries.length === 1 + (rs) => rs.data?.timeseries?.length === 1 ); const { minDate, maxDate } = requestStatus.reduce( From 3e61fdfe1d414deadd64cd0d60e157a0aa4d7c8b Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Thu, 4 Jan 2024 16:03:49 -0500 Subject: [PATCH 09/13] Fix to pr comments --- .../define/use-stac-collection-search.ts | 22 ++++++++----------- .../analysis/results/chart-card.tsx | 8 +++---- .../components/analysis/results/index.tsx | 2 +- .../analysis/results/timeseries-data.ts | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index 2c69abcac..232ca3f74 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -97,7 +97,7 @@ export function useStacCollectionSearch({ ); }, [datasetLayersInRangeWithNumberOfItems]); - if (invalidDatasets.length) unselectableDatasetLayers = unselectableDatasetLayers.concat((invalidDatasets as unknown) as DatasetWithTimeseriesData[]); + unselectableDatasetLayers = [...unselectableDatasetLayers, ...(invalidDatasets as unknown) as DatasetWithTimeseriesData[]] return { selectableDatasetLayers, @@ -107,7 +107,7 @@ export function useStacCollectionSearch({ }; } -function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { +function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange): [DatasetWithCollections[], DatasetLayer[]] { const matchingCollectionIds = collectionData.reduce((acc, col) => { const { id, stacApiEndpoint } = col; @@ -161,25 +161,21 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { (c) => c.id === l.stacCol && stacApiEndpointUsed === c.stacApiEndpoint ); - const datapoint: DatasetWithCollections = { - ...l, - isPeriodic: collection['dashboard:is_periodic'], - timeDensity: collection['dashboard:time_density'], - domain: collection.extent.temporal.interval[0], - }; - if(!collection.summaries || !!collection.summaries.length) { // NOTE: Invalid data because collection does not include summaries - return datapoint; + return l; } return { - ...datapoint, - timeseries: collection.summaries.datetime + ...l, + isPeriodic: collection['dashboard:is_periodic'], + timeDensity: collection['dashboard:time_density'], + domain: collection.extent.temporal.interval[0], + timeseries: collection.summaries.datetime, }; }); - const [collectionsWithSummaries, collectionsWithoutSummaries]: [DatasetWithCollections[], DatasetWithCollections[]] = filteredDatasetsWithCollections.reduce((result: [DatasetWithCollections[], DatasetWithCollections[]], d) => { + const [collectionsWithSummaries, collectionsWithoutSummaries]: [DatasetWithCollections[], DatasetLayer[]] = filteredDatasetsWithCollections.reduce((result: [DatasetWithCollections[], DatasetLayer[]], d: DatasetWithCollections) => { /* eslint-disable-next-line fp/no-mutating-methods */ d.timeseries ? result[0].push(d) : result[1].push(d); return result; diff --git a/app/scripts/components/analysis/results/chart-card.tsx b/app/scripts/components/analysis/results/chart-card.tsx index d0fa0e88f..a42650fdb 100644 --- a/app/scripts/components/analysis/results/chart-card.tsx +++ b/app/scripts/components/analysis/results/chart-card.tsx @@ -101,7 +101,7 @@ const getNoDownloadReason = ({ status, data }: TimeseriesData) => { if (status === 'loading') { return 'Download will be available once the data finishes loading.'; } - if (!data.timeseries?.length) { + if (!data.timeseries.length) { return 'There is no data to download.'; } return ''; @@ -145,7 +145,7 @@ export default function ChartCard(props: ChartCardProps) { const onExportClick = useCallback( (e: MouseEvent, type: 'image' | 'text') => { e.preventDefault(); - if (!chartData.data?.timeseries?.length) { + if (!chartData.data?.timeseries.length) { return; } @@ -182,7 +182,7 @@ export default function ChartCard(props: ChartCardProps) { const chartDates = useMemo( () => - data?.timeseries?.map((e) => + data?.timeseries.map((e) => dateFormatter(new Date(e.date), timeDensityFormat) ) ?? [], [data?.timeseries, timeDensityFormat] @@ -273,7 +273,7 @@ export default function ChartCard(props: ChartCardProps) { ) : null} {status === 'succeeded' ? ( - data.timeseries?.length ? ( + data.timeseries.length ? ( !activeMetrics.length ? ( ) : ( diff --git a/app/scripts/components/analysis/results/index.tsx b/app/scripts/components/analysis/results/index.tsx index 493e9b7ef..82c8fa757 100644 --- a/app/scripts/components/analysis/results/index.tsx +++ b/app/scripts/components/analysis/results/index.tsx @@ -130,7 +130,7 @@ export default function AnalysisResults() { const availableDomain: [Date, Date] | null = useMemo(() => { if (!start || !end) return null; const onlySingleValues = requestStatus.every( - (rs) => rs.data?.timeseries?.length === 1 + (rs) => rs.data?.timeseries.length === 1 ); const { minDate, maxDate } = requestStatus.reduce( diff --git a/app/scripts/components/analysis/results/timeseries-data.ts b/app/scripts/components/analysis/results/timeseries-data.ts index 7d6e818b3..9a38712da 100644 --- a/app/scripts/components/analysis/results/timeseries-data.ts +++ b/app/scripts/components/analysis/results/timeseries-data.ts @@ -35,7 +35,7 @@ export interface TimeseriesDataResult { isPeriodic: boolean; timeDensity: TimeDensity; domain: string[]; - timeseries?: TimeseriesDataUnit[]; // NOTE: Summaries on collections will not always be available + timeseries: TimeseriesDataUnit[]; // NOTE: Summaries on collections will not always be available } // Different options based on status. From b931042b96491080421807a4819ebb4aefd3f006 Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Thu, 4 Jan 2024 16:06:51 -0500 Subject: [PATCH 10/13] Fix lint errors --- .../components/analysis/define/use-stac-collection-search.ts | 2 +- app/scripts/components/analysis/results/chart-card.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index 232ca3f74..e424a506e 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -97,7 +97,7 @@ export function useStacCollectionSearch({ ); }, [datasetLayersInRangeWithNumberOfItems]); - unselectableDatasetLayers = [...unselectableDatasetLayers, ...(invalidDatasets as unknown) as DatasetWithTimeseriesData[]] + unselectableDatasetLayers = [...unselectableDatasetLayers, ...(invalidDatasets as unknown) as DatasetWithTimeseriesData[]]; return { selectableDatasetLayers, diff --git a/app/scripts/components/analysis/results/chart-card.tsx b/app/scripts/components/analysis/results/chart-card.tsx index a42650fdb..9b580b289 100644 --- a/app/scripts/components/analysis/results/chart-card.tsx +++ b/app/scripts/components/analysis/results/chart-card.tsx @@ -279,7 +279,7 @@ export default function ChartCard(props: ChartCardProps) { ) : ( Date: Tue, 9 Jan 2024 14:57:42 -0500 Subject: [PATCH 11/13] PR comments --- .../define/use-stac-collection-search.ts | 37 ++++++++----------- .../analysis/results/timeseries-data.ts | 2 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index e424a506e..f835c8064 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -65,25 +65,30 @@ export function useStacCollectionSearch({ enabled: readyToLoadDatasets }); - const [datasetLayersInRange, invalidDatasets] = useMemo(() => { + const datasetLayersInRange = useMemo(() => { try { - const [datasetWithSummaries, datasetWithoutSummaries] = getInTemporalAndSpatialExtent(result.data, aoi, { + return getInTemporalAndSpatialExtent(result.data, aoi, { start, end }); - return [datasetWithSummaries, datasetWithoutSummaries]; } catch (e) { - return [[], []]; + return []; } }, [result.data, aoi, start, end]); + const [datasetsWithSummaries, invalidDatasets]: [DatasetWithCollections[], DatasetLayer[]] = datasetLayersInRange.reduce((result: [DatasetWithCollections[], DatasetLayer[]], d: DatasetWithCollections) => { + /* eslint-disable-next-line fp/no-mutating-methods */ + d.timeseries ? result[0].push(d) : result[1].push(d); + return result; + },[[], []]); + const datasetLayersInRangeWithNumberOfItems: DatasetWithTimeseriesData[] = useMemo(() => { - return datasetLayersInRange.map((l) => { + return datasetsWithSummaries.map((l) => { const numberOfItems = getNumberOfItemsWithinTimeRange(start, end, l); return { ...l, numberOfItems }; }); - }, [datasetLayersInRange, start, end]); + }, [datasetsWithSummaries, start, end]); const selectableDatasetLayers = useMemo(() => { return datasetLayersInRangeWithNumberOfItems.filter( @@ -94,7 +99,7 @@ export function useStacCollectionSearch({ let unselectableDatasetLayers: DatasetWithTimeseriesData[] = useMemo(() => { return datasetLayersInRangeWithNumberOfItems.filter( (l) => l.numberOfItems > MAX_QUERY_NUM - ); + ) }, [datasetLayersInRangeWithNumberOfItems]); unselectableDatasetLayers = [...unselectableDatasetLayers, ...(invalidDatasets as unknown) as DatasetWithTimeseriesData[]]; @@ -107,7 +112,7 @@ export function useStacCollectionSearch({ }; } -function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange): [DatasetWithCollections[], DatasetLayer[]] { +function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { const matchingCollectionIds = collectionData.reduce((acc, col) => { const { id, stacApiEndpoint } = col; @@ -161,24 +166,14 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange): [Dataset (c) => c.id === l.stacCol && stacApiEndpointUsed === c.stacApiEndpoint ); - if(!collection.summaries || !!collection.summaries.length) { - // NOTE: Invalid data because collection does not include summaries - return l; - } - return { ...l, isPeriodic: collection['dashboard:is_periodic'], timeDensity: collection['dashboard:time_density'], domain: collection.extent.temporal.interval[0], - timeseries: collection.summaries.datetime, + timeseries: collection.summaries?.datetime, }; }); - const [collectionsWithSummaries, collectionsWithoutSummaries]: [DatasetWithCollections[], DatasetLayer[]] = filteredDatasetsWithCollections.reduce((result: [DatasetWithCollections[], DatasetLayer[]], d: DatasetWithCollections) => { - /* eslint-disable-next-line fp/no-mutating-methods */ - d.timeseries ? result[0].push(d) : result[1].push(d); - return result; - },[[], []]); - return [collectionsWithSummaries, collectionsWithoutSummaries]; -} + return filteredDatasetsWithCollections; +}; diff --git a/app/scripts/components/analysis/results/timeseries-data.ts b/app/scripts/components/analysis/results/timeseries-data.ts index 9a38712da..969ad0287 100644 --- a/app/scripts/components/analysis/results/timeseries-data.ts +++ b/app/scripts/components/analysis/results/timeseries-data.ts @@ -35,7 +35,7 @@ export interface TimeseriesDataResult { isPeriodic: boolean; timeDensity: TimeDensity; domain: string[]; - timeseries: TimeseriesDataUnit[]; // NOTE: Summaries on collections will not always be available + timeseries: TimeseriesDataUnit[]; } // Different options based on status. From f58d42aca96122639b10c07f37d6fe4192d46cf3 Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Tue, 9 Jan 2024 15:00:23 -0500 Subject: [PATCH 12/13] Fix linter errors --- .../components/analysis/define/use-stac-collection-search.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index f835c8064..33b6adcca 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -99,7 +99,7 @@ export function useStacCollectionSearch({ let unselectableDatasetLayers: DatasetWithTimeseriesData[] = useMemo(() => { return datasetLayersInRangeWithNumberOfItems.filter( (l) => l.numberOfItems > MAX_QUERY_NUM - ) + ); }, [datasetLayersInRangeWithNumberOfItems]); unselectableDatasetLayers = [...unselectableDatasetLayers, ...(invalidDatasets as unknown) as DatasetWithTimeseriesData[]]; @@ -176,4 +176,4 @@ function getInTemporalAndSpatialExtent(collectionData, aoi, timeRange) { }); return filteredDatasetsWithCollections; -}; +} From 156c0a5e7e5602a25ea4d1c1eac907220b1eeac6 Mon Sep 17 00:00:00 2001 From: Hanbyul Jo Date: Wed, 10 Jan 2024 11:08:11 -0500 Subject: [PATCH 13/13] Fix ts warning by setting up TimeseriesWithMissingSummaries explicitly --- app/scripts/components/analysis/define/index.tsx | 4 ++-- .../analysis/define/use-stac-collection-search.ts | 13 +++++++------ .../components/analysis/results/timeseries-data.ts | 7 +++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/scripts/components/analysis/define/index.tsx b/app/scripts/components/analysis/define/index.tsx index d49717dd6..6cc845f54 100644 --- a/app/scripts/components/analysis/define/index.tsx +++ b/app/scripts/components/analysis/define/index.tsx @@ -516,8 +516,8 @@ export default function Analysis() { {datasetLayer.name} - ~ - {datasetLayer.numberOfItems ? `${datasetLayer.numberOfItems} data points`: "Data temporarily unavailable"} + + {'numberOfItems' in datasetLayer ? `${datasetLayer.numberOfItems} data points`: 'Data temporarily unavailable'} ))} diff --git a/app/scripts/components/analysis/define/use-stac-collection-search.ts b/app/scripts/components/analysis/define/use-stac-collection-search.ts index 33b6adcca..f19c7453b 100644 --- a/app/scripts/components/analysis/define/use-stac-collection-search.ts +++ b/app/scripts/components/analysis/define/use-stac-collection-search.ts @@ -8,7 +8,7 @@ import { areIntervalsOverlapping } from 'date-fns'; import { DatasetLayer } from 'veda'; import { MAX_QUERY_NUM } from '../constants'; -import { TimeseriesDataResult } from '../results/timeseries-data'; +import { TimeseriesMissingSummaries, TimeseriesDataResult } from '../results/timeseries-data'; import { getNumberOfItemsWithinTimeRange } from './utils'; import { allAvailableDatasetsLayers } from '.'; @@ -21,8 +21,9 @@ interface UseStacSearchProps { } export type DatasetWithCollections = TimeseriesDataResult & DatasetLayer; - +type DatasetMissingSummaries = TimeseriesMissingSummaries & DatasetLayer; export type DatasetWithTimeseriesData = DatasetWithCollections & { numberOfItems: number }; +export type InvalidDatasets = DatasetMissingSummaries | DatasetWithTimeseriesData; const collectionEndpointSuffix = '/collections'; @@ -76,9 +77,9 @@ export function useStacCollectionSearch({ } }, [result.data, aoi, start, end]); - const [datasetsWithSummaries, invalidDatasets]: [DatasetWithCollections[], DatasetLayer[]] = datasetLayersInRange.reduce((result: [DatasetWithCollections[], DatasetLayer[]], d: DatasetWithCollections) => { + const [datasetsWithSummaries, invalidDatasets]: [DatasetWithCollections[], DatasetMissingSummaries[]] = datasetLayersInRange.reduce((result: [DatasetWithCollections[], DatasetMissingSummaries[]], d) => { /* eslint-disable-next-line fp/no-mutating-methods */ - d.timeseries ? result[0].push(d) : result[1].push(d); + d.timeseries ? result[0].push(d as DatasetWithCollections) : result[1].push(d as DatasetMissingSummaries); return result; },[[], []]); @@ -96,13 +97,13 @@ export function useStacCollectionSearch({ ); }, [datasetLayersInRangeWithNumberOfItems]); - let unselectableDatasetLayers: DatasetWithTimeseriesData[] = useMemo(() => { + const datasetsWithTooManyRequests: DatasetWithTimeseriesData[] = useMemo(() => { return datasetLayersInRangeWithNumberOfItems.filter( (l) => l.numberOfItems > MAX_QUERY_NUM ); }, [datasetLayersInRangeWithNumberOfItems]); - unselectableDatasetLayers = [...unselectableDatasetLayers, ...(invalidDatasets as unknown) as DatasetWithTimeseriesData[]]; + const unselectableDatasetLayers:InvalidDatasets[] = [...datasetsWithTooManyRequests, ...invalidDatasets]; return { selectableDatasetLayers, diff --git a/app/scripts/components/analysis/results/timeseries-data.ts b/app/scripts/components/analysis/results/timeseries-data.ts index 969ad0287..2a5ea4396 100644 --- a/app/scripts/components/analysis/results/timeseries-data.ts +++ b/app/scripts/components/analysis/results/timeseries-data.ts @@ -38,6 +38,13 @@ export interface TimeseriesDataResult { timeseries: TimeseriesDataUnit[]; } +export interface TimeseriesMissingSummaries { + isPeriodic: boolean; + timeDensity: TimeDensity; + domain: string[]; + timeseries?: unknown; +} + // Different options based on status. export type TimeseriesData = | {