Skip to content
This repository has been archived by the owner on Nov 1, 2019. It is now read-only.

DatePicker - adding better year selection #580

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

Zombiefruit
Copy link
Contributor

Added the ability to click on the header twice, in order to see a selection of years to pick from. The user is able to then change the decade using the arrow keys.

private getCalendarView = () => {
if (this.state.showYearView) {
return (
<div className="year-view" data-automation-id="YEAR_VIEW">
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a mix of camelCase and kebab-case class names in the stylesheet, I think our convention is to use camelCase.

const yearArray: JSX.Element[] = [];

for (let year = this.state.viewDate.getFullYear() - 5; year <= this.state.viewDate.getFullYear() + 5; year ++) {
if (year === this.props.value.getFullYear()) { continue; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a suggestion: maybe show the currently selected year and make it highlighted?

  1. It would solve the problem with variable number of years in the popup.
  2. Right now you need to perform two different actions depending on which year you want to select. You either need to click on the header or on the item in the list.

private toggleMonthView = () => {
this.setState({showMonthView: !this.state.showMonthView});
private toggleDateSelectView = () => {
if (this.state.showYearView && this.state.showMonthView) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about having only this.state.view that can be equal to year|month|default?

}

private onSelectYear: React.EventHandler<React.SyntheticEvent<Element>> = event => {
event.preventDefault();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Copy link
Contributor

@JoMarton JoMarton left a comment

Choose a reason for hiding this comment

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

Component looks good!

export class Calendar extends React.Component<CalendarProps, CalendarState> {
public state: CalendarState = {showMonthView: false};
export class Calendar extends React.Component<CalendarProps> {
@observable public state: CalendarState = {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to use mobx instead of react state - please rename state to something less confusing

@@ -55,7 +61,7 @@ export class Calendar extends React.Component<CalendarProps, CalendarState> {
<span
data-automation-id="CALENDAR_HEADER"
className="headerDate"
onMouseDown={this.headerClicked}
onMouseDown={this.onHeaderClick}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this span necessary to wrap the DOM you get back from getHeader()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, but the alternative is duplicating those attributes on all three of the possible return values for getHeader

});
});

it('when in the year-view, it should not show the current year', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

what should it show? why not test for positive outcome?

});
});

it('when in the month-view, clicking on the arrows should not change the actual date', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

is the outcome of pressing the arrows in month view being tested anywhere? if not this is a good place for it, and during making sure the data value stays the same

this.setState({showMonthView: !this.state.showMonthView});
private toggleDateSelectView = () => {
if (this.state.showYearView && this.state.showMonthView) {
this.state.showYearView = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

This boolean flag game could be a bit much. consider if using an enum like this.state.view = ClendarViews.Year would make this shorter and more readable

});
});

it('when in the month-view, clicking on the arrows should not change the actual date', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

is the outcome of pressing the arrows in month view being tested anywhere? if not this is a good place for it, and during making sure the data value stays the same

export class Calendar extends React.Component<CalendarProps, CalendarState> {
public state: CalendarState = {showMonthView: false};
export class Calendar extends React.Component<CalendarProps> {
@observable public calendarState: CalendarState = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need to be public?


this.props.updateDropdownDate(nextDate);
if (this.calendarState.view !== 'default') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to flip the condition if (view === default) { do stuff } else { do other stuff }

@@ -165,6 +165,10 @@
-st-extends: calendar;
}

.year-view {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just one last detail, this should be in camel case.

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.

4 participants