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

Remove CourseRollover render modifiers #8280

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

Conversation

michaelchadwick
Copy link
Contributor

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

Copy link
Member

@jrjohnson jrjohnson left a 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.

@@ -46,6 +40,7 @@
id="year-{{templateId}}"
data-test-year
{{on "change" this.setSelectedYear}}
{{get-element this.loadValidYear}}
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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}}
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

packages/ilios-common/addon/components/course/rollover.js Outdated Show resolved Hide resolved
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.');
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@michaelchadwick michaelchadwick force-pushed the remove-course-rollover-render-modifiers branch from ab6f5e9 to cb24649 Compare December 20, 2024 18:35
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.

2 participants