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

DatePicker - adding better year selection - #580

Open
Zombiefruit wants to merge 17 commits into
masterfrom
kieran/datepicker-better-year-selection
Open

DatePicker - adding better year selection#580
Zombiefruit wants to merge 17 commits into
masterfrom
kieran/datepicker-better-year-selection

Conversation

@Zombiefruit

Copy link
Copy Markdown
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.

Comment thread src/components/date-picker/calendar.tsx Outdated
private getCalendarView = () => {
if (this.state.showYearView) {
return (
<div className="year-view" data-automation-id="YEAR_VIEW">

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.

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

Comment thread src/components/date-picker/calendar.tsx Outdated
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
Copy Markdown
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.

Comment thread src/components/date-picker/calendar.tsx Outdated
private toggleMonthView = () => {
this.setState({showMonthView: !this.state.showMonthView});
private toggleDateSelectView = () => {
if (this.state.showYearView && this.state.showMonthView) {

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.

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

Comment thread src/components/date-picker/calendar.tsx Outdated
}

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

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 though?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

@JoMarton JoMarton left a comment

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.

Component looks good!

Comment thread src/components/date-picker/calendar.tsx Outdated
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
Copy Markdown
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

data-automation-id="CALENDAR_HEADER"
className="headerDate"
onMouseDown={this.headerClicked}
onMouseDown={this.onHeaderClick}

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.

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

Copy link
Copy Markdown
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

Comment thread test/components/date-picker.spec.tsx Outdated
});
});

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

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.

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
Copy Markdown
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

Comment thread src/components/date-picker/calendar.tsx Outdated
this.setState({showMonthView: !this.state.showMonthView});
private toggleDateSelectView = () => {
if (this.state.showYearView && this.state.showMonthView) {
this.state.showYearView = false;

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.

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
Copy Markdown
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

Comment thread src/components/date-picker/calendar.tsx Outdated
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
Copy Markdown
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?

Comment thread src/components/date-picker/calendar.tsx Outdated
: getMonthFromOffset(new Date(this.props.value.getFullYear(), this.props.value.getMonth(), 1), 1);

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

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.

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

-st-extends: calendar;
}

.year-view {

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 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