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

[Labs] Timezone Picker #1568

Merged
merged 83 commits into from
Sep 22, 2017
Merged

[Labs] Timezone Picker #1568

merged 83 commits into from
Sep 22, 2017

Conversation

brieb
Copy link
Contributor

@brieb brieb commented Sep 14, 2017

Fixes part of #890

Out of scope for this PR: Incorporating with the other datetime components

Checklist

  • Include tests
  • Update documentation

Changes proposed in this pull request:

Timezone select component

@blueprint-bot
Copy link

Docs nits

Preview: documentation | table
Coverage: core | datetime

@brieb brieb changed the title ⚠️ [WIP] Timezone Select [Labs] Timezone Picker Sep 19, 2017
Copy link
Contributor

@llorca llorca left a comment

Choose a reason for hiding this comment

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

So. Good.

@blueprint-bot
Copy link

Fix lints

Preview: documentation | table
Coverage: core | datetime

@blueprint-bot
Copy link

Timezone picker tests

Preview: documentation | table
Coverage: core | datetime

Copy link
Contributor

@giladgray giladgray left a comment

Choose a reason for hiding this comment

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

(check all my comments--not sure they'll all appear on the diff cuz I created them from the "View changes" partial diff view)

private handleShowLocalTimezoneChange = handleBooleanChange((showLocalTimezone) =>
this.setState({ showLocalTimezone }));
private handleDisabledChange = handleBooleanChange(disabled => this.setState({ disabled }));
private handleShowLocalTimezoneChange = handleBooleanChange(showLocalTimezone =>
Copy link
Contributor

Choose a reason for hiding this comment

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

please always wrap params in parens. this should be a lint failure...

Copy link
Contributor

Choose a reason for hiding this comment

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

no, this is the prettier standard

public componentWillReceiveProps(nextProps: ISelectProps<T>) {
const { inputProps: nextInputProps = {} } = nextProps;
if (nextInputProps.value !== undefined && this.state.query !== nextInputProps.value) {
this.setState({ query: nextInputProps.value });
Copy link
Contributor

Choose a reason for hiding this comment

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

nice! this seems like a valuable fix and could use a unit test (since Select has actual coverage).

in fact you could go so far as to pull this change to a separate PR focused solely on supporting controlled input value.

though in truth we probably want an obvious query prop instead of inputProps.value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to start on this in a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -32,7 +32,7 @@ export function formatTimezone(
const { abbreviation, offsetAsString } = getTimezoneMetadata(timezone, date);
switch (displayFormat) {
case TimezoneDisplayFormat.ABBREVIATION:
// Fall back to the offset in regions where there is no abbreviation.
// Fall back to the offset when there is no abbreviation.
return abbreviation ? abbreviation : offsetAsString;
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer to avoid implicit boolean coercion. abbreviation === undefined ? default : actual

key: string;
/** Text for the timezone. */
Copy link
Contributor

Choose a reason for hiding this comment

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

blank line after each property, before the next doc comment.

@@ -23,9 +23,7 @@ export function getTimezoneMetadata(timezone: string, date: Date): ITimezoneMeta
const offsetAsString = zonedDate.format("Z");
const abbreviation = getAbbreviation(timezone, timestamp);
// TODO: amend moment-timezone typings to include the population field
Copy link
Contributor

Choose a reason for hiding this comment

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

issue to track this? in moment's repo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

filteredItems.push(item);
seenItem[key] = true;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

please add code comments explaining what lines 62-75 are doing... I can't follow and I don't trust it.

it("clicking on button target opens popover", () => {
const timezonePicker = mount(<TimezonePicker popoverProps={{ inline: true }} />);
const button = timezonePicker.find(Button);
button.simulate("click");
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 don't need a reference later then no need to make a variable.

timezonePicker.find(Button).simulate("click");

it("placeholder prop changes the filter placeholder text", () => {
const placeholder = "test placeholder";
const timezonePicker = shallow(
<TimezonePicker popoverProps={{ isOpen: true, inline: true }} inputProps={{ placeholder }} />,
Copy link
Contributor

Choose a reason for hiding this comment

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

popoverProps={POPOVER_PROPS} one object to rule them all?

assert.strictEqual(firstItem.timezone, moment.tz.guess());
});

it("does not render local timezone at top of item list if show local timezone is disabled", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

use prop name in test name: if showLocalTimezone=false
this comment applies widely to this file.

@## JavaScript API

[Moment Timezone](http://momentjs.com/timezone/) is used internally
for the list of available timezones and timezone metadata.
Copy link
Contributor

Choose a reason for hiding this comment

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

this line belongs at the end of the section, not the beginning: it's an implementation detail, not relevant to usage.

@cmslewis
Copy link
Contributor

On filter, can we scroll the matched item to the top of the list? This is what's happening now:
2017-09-20 17 06 14

Also, EST doesn't suggest EST, but rather EST5EDT. I'd expect fuzz-aldrin to return the former, no?

@brieb
Copy link
Contributor Author

brieb commented Sep 21, 2017

@cmslewis Ya, it appears that select has the behavior that if an earlier query matched an item (est5edt in your case), that value stays selected even when a longer query has a different first item. I would expect the first item slot to remain active instead of jumping half-way down the list. We should distinguish between whether the user actually activated an item vs us just activating the first item by default.

Made it so est shows up first. 2b37613

@blueprint-bot
Copy link

Fix tests

Preview: documentation | table
Coverage: core | datetime

@blueprint-bot
Copy link

Concatenate item query candidates for better ranking

Preview: documentation | table
Coverage: core | datetime

@adidahiya adidahiya merged commit 69fa528 into master Sep 22, 2017
@adidahiya adidahiya deleted the bb/timezone branch September 22, 2017 16:05
@llorca llorca mentioned this pull request Sep 22, 2017
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.

6 participants