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

feat: Month granularity for date-range-picker #3077

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

dpitcock
Copy link
Member

@dpitcock dpitcock commented Nov 29, 2024

Month granularity for date-range-picker

The Date Picker component has a granularity prop that can be set to "month" which disallows the selection of day and allows the selection of month. This functionality is now being extended onto Date Range Picker component, so it will also support month range selection

issues: [AWSUI-18630, AWSUI-20124, AWSUI-8139]

Previous PRs for this project

How has this been tested?

test coverage expanded to include both unit tests and integration tests for the DateRangePicker component utilizing the 'month' granularity setting. These tests now encompass rendered iterations of the components, ensuring comprehensive validation of this specific functionality.

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

codecov bot commented Nov 29, 2024

Codecov Report

Attention: Patch coverage is 97.40933% with 10 lines in your changes missing coverage. Please review.

Project coverage is 96.45%. Comparing base (76a85a0) to head (ac9e99a).

Files with missing lines Patch % Lines
src/date-range-picker/calendar/grids/index.tsx 90.62% 3 Missing ⚠️
src/date-range-picker/calendar/grids/grid.tsx 98.37% 2 Missing ⚠️
src/date-range-picker/calendar/header/index.tsx 91.66% 1 Missing ⚠️
src/date-range-picker/calendar/index.tsx 97.43% 1 Missing ⚠️
src/date-range-picker/calendar/range-inputs.tsx 95.65% 1 Missing ⚠️
src/date-range-picker/dropdown.tsx 83.33% 1 Missing ⚠️
src/date-range-picker/relative-range/index.tsx 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3077      +/-   ##
==========================================
+ Coverage   96.44%   96.45%   +0.01%     
==========================================
  Files         790      791       +1     
  Lines       22246    22461     +215     
  Branches     7229     7345     +116     
==========================================
+ Hits        21455    21665     +210     
- Misses        784      789       +5     
  Partials        7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dpitcock dpitcock force-pushed the denpitco-monthly-range-picker2 branch from 7491fa5 to 7f28657 Compare December 3, 2024 09:26
@dpitcock dpitcock force-pushed the denpitco-monthly-range-picker2 branch 3 times, most recently from e8bd8f5 to f61d398 Compare December 11, 2024 00:52
@dpitcock dpitcock force-pushed the denpitco-monthly-range-picker2 branch from f61d398 to 74458ef Compare December 11, 2024 08:51
@dpitcock dpitcock force-pushed the denpitco-monthly-range-picker2 branch from 74458ef to 73641df Compare December 11, 2024 10:19
@dpitcock dpitcock force-pushed the denpitco-monthly-range-picker2 branch from d63e7be to 24aba24 Compare December 11, 2024 13:58
@dpitcock dpitcock force-pushed the denpitco-monthly-range-picker2 branch from 24aba24 to 0773794 Compare December 11, 2024 14:22
@dpitcock dpitcock marked this pull request as ready for review December 11, 2024 14:41
@dpitcock dpitcock requested a review from a team as a code owner December 11, 2024 14:41
@dpitcock dpitcock requested review from just-boris and removed request for a team December 11, 2024 14:41
src/i18n/messages-types.ts Outdated Show resolved Hide resolved
Copy link
Member

@just-boris just-boris left a comment

Choose a reason for hiding this comment

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

Approved to merge, but still looking forward for a refactoring around that day/month strategy switch

);
}

const isInFirstGrouping = (granularity: DateRangePickerProps['granularity'], date: Date) => {
Copy link
Member

Choose a reason for hiding this comment

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

okay, got it

this.isMonthPicker = isMonthPicker;
}

getStrategy(): DatePickerStrategyUtils {
Copy link
Member

Choose a reason for hiding this comment

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

This is not how pattern should work. There is still the same number of isMonthPicker checks, just in a different place.

It could be something like this

interface GridUtils {
   getItemKey(rowIndex: number, columnIndex: number): string;
   isSameItem: (date1: Date, date2: Date): boolean;
   isSamePage: (date1: Date, date2: Date): boolean;

   ... etc
}

const monthUtils: GridUtils = {
   // note, argument types are not needed, they are coming with `GridUtils` type declaration
   getItemKey: (rowIndex, columnIndex) => `Month ${rowIndex * 3 + rowItemIndex + 1}`,
   isSameItem: isSameMonth,
   isSamePage: isSameYear,
   ... etc
}

const dayUtils: GridUtils = {
   getItemKey: (rowIndex, columnIndex) => `${rowIndex}:${rowItemIndex}`,
   isSameItem: isSameDay,
   isSamePage: isSameMonth,
   ... etc
}

// pull the right strategy depending on the mode
const gridUtils = isMonthPicker ? monthUtils : dayUtils

"strategy" == "utils" in this code. The name does not really matter, the concept does. Because it makes code shorter and easier to follow

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.

2 participants