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

refactor training pages to allow rendering on client-side instead of … #5523

Conversation

sharon-odhiambo
Copy link
Contributor

What this PR does

Whenever a user is logged in wiki-education mode, they are able to access the get help button. The button is however not available when the user launches the training modules from the course page. This PR solves that problem:
Refactoring the training libraries page from the server side rendering by refactoring the index.html.erb to a React component
Refactoring a single library page from the server side to the client side

This PR addresses issue #5486

Screenshots

After:
This video shows the affected pages functionalities and visual appearance.
Screencast from 10-24-2023 02:09:35 AM.webm

@sharon-odhiambo
Copy link
Contributor Author

Hi @ragesoss . This PR is ready for review.

@ragesoss
Copy link
Member

Thanks! This is a deeper React conversion than what I was suggesting — it converts the entire Training and Module views, rather than just implementing the nav in React and leaving the rest as server-rendered.

This is potentially good, and it looks like you've basically got it working!

One thing I notice as I try it out is that the 'No Libraries' message flashes briefly whenever you load the training index. The first render of any of these pages should avoid flashing any temporary messages like that.

Comment on lines +15 to +20
if (!response.ok) {
const data = await response.text();
response.responseText = data;
throw response;
}
const data = await response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be extracted to a function — its used in a few places even before this PR

Copy link
Contributor Author

@sharon-odhiambo sharon-odhiambo Oct 27, 2023

Choose a reason for hiding this comment

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

Hi @TheTrio , sure lemme do that.

<ul className="training-libraries no-bullets no-margin action-card-text">
{slides.map((slide, index) => (
<li key={index}>
<a href={`https://dashboard.wikiedu.org/training/${slide.path}`} target="_blank">
Copy link
Contributor

Choose a reason for hiding this comment

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

don't think this is correct? The root url will not always be https://dashboard.wikiedu.org/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, while I didn't make any changes on this and not very sure, I think it will always be that url because the slides controller that has the data is using the TrainingSlide model.

@sharon-odhiambo
Copy link
Contributor Author

Thanks! This is a deeper React conversion than what I was suggesting — it converts the entire Training and Module views, rather than just implementing the nav in React and leaving the rest as server-rendered.

This is potentially good, and it looks like you've basically got it working!

One thing I notice as I try it out is that the 'No Libraries' message flashes briefly whenever you load the training index. The first render of any of these pages should avoid flashing any temporary messages like that.

Hi @ragesoss . Sure, lemme check this out. And thank you for the feedback.

<div className="training-module-source">
<a href={`https://meta.wikimedia.org/wiki/${this.props.training.module.wiki_page}`} target="_blank">{I18n.t('training.view_module_source')}</a>
<br />
<a href={`/reload_trainings?module=${this.props.training.module.slug}`}>{I18n.t('training.reload_from_source')}</a>
Copy link
Member

Choose a reason for hiding this comment

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

I think these messages are still relevant, they just shouldn't be shown until after the data has been loaded. If any empty response has already been received from the server, at that point we should show relevant 'missing' messages.

@sharon-odhiambo
Copy link
Contributor Author

Hi @ragesoss, so I was working on getting the module progress and I think this is ready now. However, I have 3 specs failing, in relation to the flashing messages. Initially the messages were only showing when @libraries.empty? is truthy. Currently though, that also seems to be truthy while the data is loading. Can you kindly assist on how I can counter that? I've moved the messages rendering to the controller as before but the specs are still failing.

@ragesoss
Copy link
Member

ragesoss commented Nov 2, 2023

Hmm... I'm not sure. On the server, @libraries ought to be set by the time it renders, as Rails will wait until the data is loaded in that controller code before moving on. However, I think it would be ideal to move the message to React, and just not show it until after the data has been fetched and received... then only show it at that point if an empty array was received for Libraries.

@sharon-odhiambo
Copy link
Contributor Author

Hi @ragesoss . So after updating this as advised, there are 2 specs that are failing from the training _tool_spec. However when I try to clear the libraries list using my rails console I get the no libraries message so I'm not entirely sure why it's still failing.
I've worked on all the features for rendering the training pages on the client-side and this PR is ready.
I would appreciate any help on anything else I need to do.

@ragesoss
Copy link
Member

ragesoss commented Nov 7, 2023

Hmm... I'm not sure what is going wrong. I suggest running the failing test locally with headless mode turned off (by removing the headless arg in rails_helper.rb).

@sharon-odhiambo sharon-odhiambo force-pushed the refactor-training-pages branch from b9838c0 to 512b3d7 Compare November 9, 2023 15:23
@ragesoss
Copy link
Member

ragesoss commented Dec 4, 2023

@sharon-odhiambo what's the status of this? it looks like some of the training-specific tests are still failing; were they passing for you locally? anything you are stuck with that i can try to get you unstuck with?

@ragesoss ragesoss marked this pull request as draft December 4, 2023 20:12
@sharon-odhiambo
Copy link
Contributor Author

Hi @ragesoss , the tests weren't passing locally when I run them but when I check the page when my database is empty the messages appear for both wiki edu and non-wiki edu mode. I'm not sure how to go about it from here.
I'll appreciate any help.

@ragesoss ragesoss closed this Jun 20, 2024
@ragesoss ragesoss reopened this Jun 20, 2024
@ragesoss
Copy link
Member

Sorry, I didn't get a chance to dive into this to provide advice to get you unstuck. I'm going to close this now, as it overlaps with some work we're doing with the trainings currently, so it will be best to start fresh if/when someone returns to it.

@ragesoss ragesoss closed this Jun 20, 2024
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.

3 participants