Skip to content

Date picker: Ensure we use the new props when updating the weeks in the picker#1732

Merged
johannao76 merged 16 commits intomicrosoft:masterfrom
johannao76:minimonthfixes
May 8, 2017
Merged

Date picker: Ensure we use the new props when updating the weeks in the picker#1732
johannao76 merged 16 commits intomicrosoft:masterfrom
johannao76:minimonthfixes

Conversation

@johannao76
Copy link
Copy Markdown
Collaborator

Pull request checklist

  • Addresses an existing issue: Fixes #0000
  • Include a change request file if publishing
  • New feature, bugfix, or enhancement
    • Includes tests
  • Documentation update

There was a bug where when new props were provided for dateRangeType and firstDayOfWeek, the week generation code was using the old values so the prop change wasn't getting reflected. Fixed by passing these as parameters to _getWeeks and using the new prop values when these were updated.

Focus areas to test

(optional)

this.state = {
activeDescendantId: getId('DatePickerDay-active'),
weeks: this._getWeeks(navigatedDate, selectedDate, today)
weeks: this._getWeeks(props.navigatedDate, props.selectedDate, props.dateRangeType, props.firstDayOfWeek, today)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why add the props. reference here, rather than using the destructive assignment above on line 67?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Changed


this.setState({
weeks: this._getWeeks(navigatedDate, selectedDate, today)
weeks: this._getWeeks(nextProps.navigatedDate, nextProps.selectedDate, nextProps.dateRangeType, nextProps.firstDayOfWeek, today)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment as above

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Changed


private _getWeeks(navigatedDate: Date, selectedDate: Date, todayDate: Date): IDayInfo[][] {
let { firstDayOfWeek, dateRangeType } = this.props;
private _getWeeks(navigatedDate: Date, selectedDate: Date, dateRangeType: DateRangeType, firstDayOfWeek: DayOfWeek, todayDate: Date): IDayInfo[][] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just pass in the props object here, rather than 5 different arguments (all of which are sourced directly from a props object)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Passing props

let { navigatedDate, selectedDate, dateRangeType, firstDayOfWeek } = propsToUse;
let date = new Date(navigatedDate.getFullYear(), navigatedDate.getMonth(), 1);
let today = todayDate || new Date();
let today = propsToUse.today || new Date();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just destruct today from propsToUse as well, and rename the local variable.

let { navigatedDate, selectedDate, dateRangeType, firstDayOfWeek, today } = propsToUse;
let date = new Date(navigatedDate.getFullYear(), navigatedDate.getMonth(), 1);
let today = propsToUse.today || new Date();
let todaysDate = today || new Date();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You need to update the reference to today on line 281 as well.

@johannao76 johannao76 merged commit bf17c17 into microsoft:master May 8, 2017
@johannao76 johannao76 deleted the minimonthfixes branch May 8, 2017 22:08
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants