Date Picker using react-dates#12016
Conversation
|
(still looking at good ways to write tests for this build process) |
053b242 to
ccabf0f
Compare
| 'third_party/vega/**/*.js', | ||
| 'third_party/d3/**/*.js', | ||
| 'third_party/webcomponentsjs/ShadowCSS.js', | ||
| 'third_party/rrule/rrule.js', |
There was a problem hiding this comment.
let's file a security review ticket ( b/ -> Security > Consulting Services > Project Review . Assign to Gabor M) for all third-parties here.
There was a problem hiding this comment.
Should I open one ticket per library, or just one ticket?
There was a problem hiding this comment.
All the dependencies passed security review
examples/date-picker.amp.html
Outdated
| <p>Try to pick a date. This is a single-date picker</p> | ||
| <button on="tap:sdp.setDate(date='2017-10-22')">Set date</button> | ||
| <button on="tap:sdp.clear">Clear</button> | ||
| <amp-date |
There was a problem hiding this comment.
amp-date is too generic of a name IMO, could we rename to amp-date-input and amp-date-range-input if not too much work? (will be more consistent with date namespacing we have planned as well e.g. amp-date-display, amp-date-countdown, etc.. )
There was a problem hiding this comment.
how about amp-date-picker and we distinguish range vs single with a type attribute?
| <script async src="https://cdn.ampproject.org/v0.js"></script> | ||
| </head> | ||
| <body> | ||
| <h1><code>amp-date-picker</code> example</h1> |
There was a problem hiding this comment.
please add an experiment flag before merging and add a note here that it is under the flag.
| @@ -0,0 +1,258 @@ | |||
| <!doctype html> | |||
examples/kayak.amp.html
Outdated
| <span class="highlight-square"></span> | ||
| </template> | ||
| </amp-date-range> | ||
| <!-- <div [class]="!wow.show ? 'wow hidden' : 'wow'" class="wow hidden"> |
There was a problem hiding this comment.
this section is commented out.
|
|
||
| /** | ||
| * Create an array of objects mapping dates to templates. | ||
| * @param {?Promise<!JsonObject|!Array<JsonObject>>} srcTemplatePromise |
There was a problem hiding this comment.
seems to be a void method.
There was a problem hiding this comment.
It mutates this.srcTemplates_ and this.srcDefaultTemplates_, but if you'd prefer it as a pure function I would be glad to do that
|
|
||
| /** @return {!Promise<string>} */ | ||
| renderInfoTemplate_() { | ||
| const template = scopedQuerySelector(this.element, '[info-template]'); |
There was a problem hiding this comment.
scopedQuerySelector is an overkill for all cases I have noticed. normal queryselector should do.
| if (!this.infoTemplatePromise_) { | ||
| this.infoTemplatePromise_ = this.renderInfoTemplate_(); | ||
| } | ||
| this.scanForBindings_([this.container_]); |
There was a problem hiding this comment.
how about other template types? would it make sense to move this to renderTemplate_?
| const data = opt_data || /** @type {!JsonObject} */ ({}); | ||
| return this.templates_.renderTemplate(template, data) | ||
| .then(rendered => { | ||
| rendered.setAttribute('i-amphtml-rendered', ''); |
There was a problem hiding this comment.
you probably don't need to set this unless you need to know which once have been rendered to clear them,
| rendered.setAttribute('i-amphtml-rendered', ''); | ||
| const renderedEvent = createCustomEvent( | ||
| this.win_, | ||
| AmpEvents.DOM_UPDATE, |
There was a problem hiding this comment.
interesting, amp-bind is listening to this, now I don't see a need for scanForBindings_ at all. Can you test and see if scanForBindings_ is needed? (if so, why? looks like bind should be re-scanning on dom mutations anyway)
There was a problem hiding this comment.
It looks like scanForBindings is not needed, I was dispatching the event on the wrong element. It was incorrectly dispatched on the template element, which of course doesn't contain any elements with bindings.
b8f02dd to
64e140d
Compare
Date picker with dist build working
adb138e to
dd12a10
Compare
dd12a10 to
dee99e8
Compare
9efd70d to
7c41aa2
Compare
|
@aghassemi This should be ready for further review now! |
| }, | ||
| { | ||
| filesMatching: '**/*.js', | ||
| mustNotDependOn: 'src/module.js', |
There was a problem hiding this comment.
Do you think this is helpful, or unnecessary? I thought it might make sense to explicitly opt-in to this pattern.
There was a problem hiding this comment.
I like it, good thinking.
aghassemi
left a comment
There was a problem hiding this comment.
Amazing PR Carlos.
Few small requests and some suggestions.
For testing (can be after this PR), I suggest unit tests for the utils and util-like functions and then e-2-e integration tests for the rest. The integration tests can be simple to write and can cover a huge portion of the code.
css/amp.css
Outdated
| } | ||
|
|
||
| amp-date, | ||
| amp-date-range { |
There was a problem hiding this comment.
element was renamed, so these need updating.
Overall I really like the idea of forcing container and having these to make sure pre-attach and post-attach are the same. Maybe also add a comment here explaining why these are here.
For default style changes, I hope we can make most of the changes (for the input part) here instead of date-picker.css so we don't end up duplicating them.
build-system/amp.extern.js
Outdated
| error: (RTC_ERROR_ENUM|undefined)}} */ | ||
| var rtcResponseDef; | ||
|
|
||
| /** @type {!function(string):?} */ |
There was a problem hiding this comment.
nit: short summary comment on why we have this
| }, | ||
| { | ||
| filesMatching: '**/*.js', | ||
| mustNotDependOn: 'src/module.js', |
There was a problem hiding this comment.
I like it, good thinking.
| @@ -0,0 +1,135 @@ | |||
| /** | |||
| * Copyright 2017 The AMP HTML Authors. All Rights Reserved. | |||
There was a problem hiding this comment.
/cc @erwinmombay @rsimha-amp for the build setup.
gulpfile.js
Outdated
| 'third_party/react-dates/bundle.js', | ||
| ]); | ||
| } else if (srcFilename === 'amp-viz-vega.js') { | ||
| bundle = concatFilesToString([ |
| .filter(t => t.dates) | ||
| .map(t => ({ | ||
| dates: new DatesList(t.dates), | ||
| template: this.ampdoc_.getRootNode().querySelector( |
There was a problem hiding this comment.
I assume templates can't be outside of <amp-date-picker> (mostly due to validator restrictions)., unless I am mistaken we should be able to use this.element for the query.
There was a problem hiding this comment.
I think template-impl.js supports templates outside the parent element via the template="" attribute, which queries for the id in the whole document, so I think it shouldn't be too problematic for the validator to do it for the date-picker too.
amphtml/src/service/template-impl.js
Lines 226 to 233 in 4ab32dc
|
|
||
| const defaultTemplate = templates | ||
| .filter(t => t.dates == null) | ||
| .map(t => this.ampdoc_.getElementById(t.id))[0]; |
There was a problem hiding this comment.
ditto for getElementById, scoping to this element via querySelector.
(although ids have to be unique, we don't restrict it and I have seen bugs in AMP pages caused by duplicated ids, this sort of scoping can help be more forgiving of such user mistakes)
| return rendered./*REVIEW*/outerHTML; | ||
| }); | ||
| } else { | ||
| return Promise.resolve(opt_fallback || ''); |
There was a problem hiding this comment.
might be worth calling sanitizeFormattingHtml from sanitizer.js on fallback anyway for additional protection.
| } | ||
| } | ||
|
|
||
| AMP.extension(TAG, '0.1', AMP => { |
There was a problem hiding this comment.
nicely organized extension! awesome job.
src/service/template-impl.js
Outdated
| * Find a specified template inside the parent. Fail if the template is | ||
| * not present. | ||
| * @param {!Element} parent | ||
| * @param {string=} opt_queryString |
There was a problem hiding this comment.
nit: Maybe querySelector?, queryString makes me think of Urls
|
@cvializ @aghassemi After this PR was landed, I'm seeing the following warnings when I run |
|
Ah yeah, thanks for looking out! I was aware of these warnings, and I looked for a way to remove just those warnings, but I didn't find a good way. This PR used |
* Initial wip commit for react-dates date picker Date picker with dist build working * Type lint and type checking mostly working * Fix presubmit errors * Update whitelist * First set of fixes for review feedback * Remove scanForBindings_ * Add experiment * Add externalRequire helper. Remove global library references. Types. * Rename. Remove unnecessary node_modules and changes * Remove need for additional globals like require. * Fix presubmit check * Add experiment flag to example * Address review feedback. Phrasing. * whitelist sanitizer
Date picker effort
Closes #11218
Closes #11219
/to @erwinmombay could you please take a look at the build process and closure compiler pieces?
/to @aghassemi
/to @jridgewell
/cc @ericlindley-g @lswang1618