-
Notifications
You must be signed in to change notification settings - Fork 27
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
Remove CourseRollover render modifiers #8280
base: master
Are you sure you want to change the base?
Remove CourseRollover render modifiers #8280
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea to sub in out own modifier where it is very much needed here. Some other cleanup needed as well though before this is ready.
packages/test-app/tests/integration/modifiers/get-element-test.js
Outdated
Show resolved
Hide resolved
@@ -46,6 +40,7 @@ | |||
id="year-{{templateId}}" | |||
data-test-year | |||
{{on "change" this.setSelectedYear}} | |||
{{get-element this.loadValidYear}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This usage doesn't track for me though. There isn't anything here that needs access to the DOM. This data should be loaded in a TrackedAsyncData and processed in a getter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for adding that there is that the Course::RolloverDatePicker
is waiting for the Year <select>
element to load before it gets the selectedYear
+ 1 value. If I don't have that there, then the Year <select>
loads, say, 2025
, and the date picker remains on 11/26/2024
instead of rolling over to 11/25/2025
like it currently does on demo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about wrapping everything in an if
so it only tries to render once the data needed is resolved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is not the whole thing already wrapped in an if
?
{{#if this.allCoursesData.isResolved}}
<select
id="year-{{templateId}}"
data-test-year
{{on "change" this.setSelectedYear}}
{{get-element this.loadValidYear}}
>
{{#each this.years as |year|}}
...
{{/each}}
</select>
{{else}}
<LoadingSpinner />
{{/if}}
@value={{this.startDate}} | ||
@onChange={{set this "startDate"}} | ||
/> | ||
{{#if this.allCourses}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this.allCourses
what? It's working off of the null and that's valid, but it's hard to read it here. Would prefer if this.allCoursesData.isResolved
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing it to {{#if this.allCoursesData.isResolved}}
just makes the DatePicker not show up at all. If I change it to {{#if (is-array this.allCourses)}}
, like the usage for the other <select>
that holds this.years
, then it works. It seems they both check to make sure it's not null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After changing the getters, this is now serviced by the {{#if this.allCoursesData.isResolved}}
.
if (typeof callback === 'function') { | ||
callback(element); // Pass the element to the provided callback | ||
} else { | ||
console.warn('get-element modifier expects a callback as the first positional argument.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be harsher here. Grab import { assert } from '@ember/debug';
and use it to ensure the callback is a function. That will throw nicely in development mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this approach, but couldn't get the new real test to pass for when the modifier is given an invalid/missing callback. I get a global error
from qunit
on the render(hbs``)
call, and no mangling of the global window error event listeners seemed to quell it. There's no example in the codebase where we do this, so I'm currently out of ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't done this one either, fun new stuff! Looks like maybe you can use assert.Throws
from qunit.
Possibly like:
assert.throws(await render(hbs`<div id='root-element' {{get-element}}></div>`));
If that doesn't work I'd be ok with skipping the second test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried my hardest, but all I get in the end is a global failure
in qunit
due to the throwing of an Error. I put in a todo
for now.
packages/test-app/tests/integration/modifiers/get-element-test.js
Outdated
Show resolved
Hide resolved
ab6f5e9
to
cb24649
Compare
Refs ilios/ilios#5374
I could not find a way to get a reference to the root DOM element of a component, which is needed for some loading, so I made a new custom modifier,
get-element
, which feels like a side-step from{did-insert}
instead of a true replacement, but is also what Ember recommends creating, so...all good? :D