Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WV-3288 Dedupe Granules #5393

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions web/js/map/granule/granule-layer-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
/**
* Query CMR to get dates
* @param {object} def - Layer specs
* @param {object} date - current selected date (Note: may not return this date, but this date will be the max returned)
* @param {object} selectedDate - current selected date (Note: may not return this date, but this date will be the max returned)
*/
const getQueriedGranuleDates = async (def, date) => {
const getQueriedGranuleDates = async (def, selectedDate) => {
const {
title,
} = def;
const state = store.getState();
const { proj: { selected: { crs } } } = state;
const getGranulesUrl = getGranulesUrlSelector(state);
const params = getParamsForGranuleRequest(def, date, crs);
const nrtParams = getParamsForGranuleRequest(def, date, crs, true);
const params = getParamsForGranuleRequest(def, selectedDate, crs);
const nrtParams = getParamsForGranuleRequest(def, selectedDate, crs, true);
let data = [];
let nrtData = [];
try {
Expand Down Expand Up @@ -101,7 +101,14 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {

return transformGranuleData(entry, date, crs);
});
return transformedData;
const dedupedData = transformedData.reduce((acc, granule) => {
const { date } = granule;
const dateIndex = acc.findIndex((g) => g.date === date);
if (dateIndex >= 0) return acc;
return [...acc, granule];
}, []);

return dedupedData;
};

/**
Expand Down
Loading