Skip to content

Conversation

@jkachel
Copy link
Contributor

@jkachel jkachel commented Jun 25, 2024

What are the relevant tickets?

Closes mitodl/hq#4528

Description (What does it do?)

Adds a new tab button component for the featured courses that can load the data that will be displayed in the tab, and then will disable itself if there's no content for the tab.

This also fixes a small issue with the regex validator for channels - they get created with names that have - in them, but the validator didn't include that so you can't edit channels that were created via pipeline.

How can this be tested?

Automated tests should pass.

Populate your featured lists with 0 items: ./manage.py populate_featured_lists 0
You should see no tabs in Featured Courses.

Then, do the same thing but add some stuff: ./manage.py populate_featured_lists 10
You should see the tabs appear now.

Additional Context

The tabs buttons do the loading now - so they appear as the data is retrieved. Locally, this means they pop in sorta slowly as for whatever reason these API hits take a while. Not sure if it would be better to have them load the tab, then remove themselves if they load 0 resources (it seems kinda disruptive either way).

This may highlight efficiency issues with the featured resources API - as noted, it's pretty slow for me but I'm not sure if that's the API being slow or if it's just Docker networking on macOS (which is pretty poky anyway).

jkachel added 4 commits June 27, 2024 07:45
…f on tabs

- Channel model: update the regex to allow for dash (it didn't but ETLs create them with dash and so you can't edit them)
- Added a new tab button wrapper that loads data so it can tell if it needs to be displayed or not. This is WIP
We now need to load and wait for the component to show up before checking for carousel tabs for the featured carousel.
@jkachel jkachel force-pushed the jkachel/4528-resource-carousel-empty-tabs-fix branch from 6ebe8dd to be0f09c Compare June 27, 2024 12:46
The one here will only ever take a FeaturedDataSource
@jkachel jkachel marked this pull request as ready for review June 27, 2024 15:32
@jkachel jkachel added Needs Review An open Pull Request that is ready for review product:mit-open Issues related to the MIT Open product and removed Work in Progress labels Jun 27, 2024
@abeglova abeglova self-assigned this Jun 28, 2024
Copy link
Contributor

@abeglova abeglova left a comment

Choose a reason for hiding this comment

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

LGTM. One small question

label: React.ReactNode
cardProps?: CardProps
data: D
eager?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

is this used?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like not currently used.

On production right now, the carousels only load the data once the tab is clicked into. With this PR, they will load all the tab data immediately (eagerly). So we'll get a bunch more API requests—for example, the homepage has 7 carousel tabs, so it will make 7 API requests on load. Similarly, the dashboard page has lots of carousels. James and I discussed the idea of making the eager behavior opt-in.

@jkachel You probably have a better sense than I do whether all those parallel API requests would be problematic (for the server). I'm happy to do always-eager and make opt-in later if seems appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is set up so only the 4 in the Featured tab eager load - the rest lazy load. So, you should only get 4 from the featured carousel plus single ones for the other carousel(s), and the featured ones shouldn't have to reload if you select tabs (since React Query should cache that response if it's successful).

FWIW, and the code sorta gets halfway there now, we can use a similar pattern to the DataPanel to eager load the tab buttons; if we do that, we can add the eager toggle there. (It seemed more like Featured was special in this regard so didn't go all the way with it here.)

(I was working on making this flaggable with that prop but I went a different route instead. That's a bit I missed from that so did in edef882 .)

@abeglova abeglova added Waiting on author and removed Needs Review An open Pull Request that is ready for review labels Jun 28, 2024
Comment on lines +129 to +134
/**
* Tab button that loads the resource, so we can determine if it needs to be
* displayed or not. This shouldn't cause double-loading since React Query
* should only run the thing once - when you switch into the tab, the data
* should already be in the cache.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought this was going to take more refactoring. Good idea 😁

@jkachel jkachel force-pushed the jkachel/4528-resource-carousel-empty-tabs-fix branch from ae0c08b to edef882 Compare June 28, 2024 19:00
@jkachel
Copy link
Contributor Author

jkachel commented Jun 28, 2024

pre-commit.ci run

@jkachel
Copy link
Contributor Author

jkachel commented Jun 28, 2024

pre-commit.ci run

@jkachel jkachel merged commit ebe1dfe into main Jun 28, 2024
@jkachel jkachel deleted the jkachel/4528-resource-carousel-empty-tabs-fix branch June 28, 2024 20:06
This was referenced Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:mit-open Issues related to the MIT Open product Waiting on author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants