Skip to content

Conversation

@oskarhurst
Copy link
Contributor

Update the Date Range Slider to fix bugs and allow the user to set a min and max range.

@oskarhurst oskarhurst requested a review from Copilot September 5, 2025 21:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the Date Range Slider component to fix bugs and allow users to set minimum and maximum date ranges. The changes replace the previous date formatting with interactive DatePicker components and add state management for better user control.

Key changes:

  • Replaced static date labels with interactive DatePicker components in both the main products page and date range slider
  • Added state synchronization between parent and child components for date range management
  • Implemented ResizeObserver for better responsive behavior and layout calculations

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/app-pages/products/products.js Added DatePicker components to main interface with state management for start/end dates
src/app-pages/products/date-range-slider.js Refactored slider to use DatePicker components and improved layout calculations with ResizeObserver
src/app-pages/products/DatePickerOverrides.css Added custom CSS styling for DatePicker components
src/app-bundles/product-bundle.js Added fallback logic for date range boundaries
package.json Updated react-datepicker dependency and added react-date-picker and react-calendar

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

calendarIcon={<CalendarIcon className="w-5 h-5 ml-[-10px]"/>}
calendarProps={{
prevLabel: <ChevronLeftIcon/>,
nextLabel: <ChevronRightIcon/>,
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace after the comma on these lines should be removed.

Suggested change
nextLabel: <ChevronRightIcon/>,
nextLabel: <ChevronRightIcon/>,

Copilot uses AI. Check for mistakes.
calendarIcon={<CalendarIcon className="w-5 h-5 ml-[-10px]"/>}
calendarProps={{
prevLabel: <ChevronLeftIcon/>,
nextLabel: <ChevronRightIcon/>,
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace after the comma on these lines should be removed.

Copilot uses AI. Check for mistakes.
calendarIcon={<CalendarIcon className="w-5 h-5 ml-[-10px]"/>}
calendarProps={{
prevLabel: <ChevronLeftIcon/>,
nextLabel: <ChevronRightIcon/>,
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace after the comma on these lines should be removed.

Suggested change
nextLabel: <ChevronRightIcon/>,
nextLabel: <ChevronRightIcon/>,

Copilot uses AI. Check for mistakes.
calendarIcon={<CalendarIcon className="w-5 h-5"/>}
calendarProps={{
prevLabel: <ChevronLeftIcon/>,
nextLabel: <ChevronRightIcon/>,
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace after the comma on these lines should be removed.

Copilot uses AI. Check for mistakes.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: define a shared invalid_date (or whatever jan 1, 3000 means)

invalid_date = new Date('01-Jan-3000')

and use everywhere instead of magic date.

}
});
if (out.getTime() === new Date('01-Jan-3000').getTime()) {
out = new Date('01-Jan-1980');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider defining

cumulus_begin = new Date('01-Jan-1980')
and use that wherever used.

if (barRef.current) {
barWidth = barRef.current.offsetWidth;
}
const [offsetFrom, setOffsetFrom] = useState(((from - min) / (max - min)) * (barWidth - labelWidthFrom));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [offsetFrom, setOffsetFrom] = useState(((from - min) / (max - min)) * (barWidth - labelWidthFrom));
const posPx = ( value, min, max, containerPx, subtractPx = 0, addPx = 0) =>
((value - min) / (max - min)) * (containerPx - subtractPx) + addPx;
const [offsetFrom, setOffsetFrom] = useState(posPx(from,min,max,barWidth,labelWidthFrom));
const [offsetTo, setOffsetTo] = useState(posPx(to, min, max, barWidth, labelWidthTo));
const [rangeBarFrom, setRangeBarFrom] = useState(posPx(from, min, max, barWidth, 14, 7) );
const [rangeBarTo, setRangeBarTo] = useState( posPx(to, min, max, barWidth, 14, 7));

Comment on lines 91 to 96
useEffect(() => {
setOffsetFrom(((from - min) / (max - min)) * (barWidth - labelWidthFrom));
setOffsetTo(((to - min) / (max - min)) * (barWidth - labelWidthTo));
setRangeBarFrom(((from - min) / (max - min)) * (barWidth - 14) + 7);
setRangeBarTo(((to - min) / (max - min)) * (barWidth - 14) + 7);
}, [barWidth, labelWidthFrom, labelWidthTo, min, max, from, to]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
useEffect(() => {
setOffsetFrom(((from - min) / (max - min)) * (barWidth - labelWidthFrom));
setOffsetTo(((to - min) / (max - min)) * (barWidth - labelWidthTo));
setRangeBarFrom(((from - min) / (max - min)) * (barWidth - 14) + 7);
setRangeBarTo(((to - min) / (max - min)) * (barWidth - 14) + 7);
}, [barWidth, labelWidthFrom, labelWidthTo, min, max, from, to]);
useEffect(() => {
setOffsetFrom (posPx(from, min, max, barWidth, labelWidthFrom));
setOffsetTo (posPx(to, min, max, barWidth, labelWidthTo));
setRangeBarFrom(posPx(from, min, max, barWidth, 14, 7));
setRangeBarTo (posPx(to, min, max, barWidth, 14, 7));
}, [barWidth, labelWidthFrom, labelWidthTo, min, max, from, to]);

Copy link

@ktarbet ktarbet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please consider making:

const MAX_DATE = new Date('3000-01-01'); (or better name if you have one)

for clarity, instead of magic number.

@oskarhurst oskarhurst merged commit 0c0701c into cwbi-dev Sep 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants