Skip to content

Commit

Permalink
Check only day level equality for selected date (#676)
Browse files Browse the repository at this point in the history
The date gets set back when I try to change the date for Plume datasets:
https://ghg-demo.netlify.app/data-catalog/emit-ch4plume-v1/explore?projection=mercator%7C%7C&basemapid=satellite&datetime=2023-07-29T10%3A06%3A30.000Z

This is because when a user inputs the date, the code checks if the date
is in datetime list of the collection. Since Dashboard only provides
daily level selection, selected datetime gets rounded down to the
midnight of the selected date. Plume data datetimes don't have 00:00
timestamps, the selected date gets invalidated. I changed the code to
check only day-level equality to align with dashboard capacity.
  • Loading branch information
hanbyul-here authored Oct 5, 2023
2 parents 1ab127e + 64a81aa commit dbb3e22
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/scripts/components/datasets/s-explore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, {
import styled from 'styled-components';
import { useNavigate } from 'react-router';
import useQsStateCreator from 'qs-state-hook';
import { isSameDay } from 'date-fns';
import { themeVal } from '@devseed-ui/theme-provider';
import {
CollecticonExpandFromLeft,
Expand Down Expand Up @@ -113,9 +114,10 @@ const isSelectedDateValid = (dateList, selectedDate) => {
// Since the available dates changes, check if the currently selected
// one is valid.
const validDate = !!dateList.find(
(d) => d.getTime() === selectedDate?.getTime()
// Only check if the date of the selected date is in the range.
// Because Dashboard can only provide daily level selection.
(d) => isSameDay(new Date(d), new Date(selectedDate))
);

return !!validDate;
}
return true;
Expand Down Expand Up @@ -175,7 +177,6 @@ const useDatePickerValue = (
}),
[value]
);

return [val, onConfirm] as [typeof val, typeof onConfirm];
};

Expand Down Expand Up @@ -518,6 +519,7 @@ function DatasetsExplore() {
selectedDatetime,
setSelectedDatetime
);

const [datePickerCompareValue, datePickerCompareConfirm] = useDatePickerValue(
selectedCompareDatetime,
setSelectedCompareDatetime
Expand Down

0 comments on commit dbb3e22

Please sign in to comment.