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

Implement the levelbuilder version of extra links for Lab2 #58410

Merged
merged 12 commits into from
May 7, 2024

Conversation

molly-moen
Copy link
Contributor

@molly-moen molly-moen commented May 3, 2024

The gray extra links box used by levelbuilders and project validators does not work correctly on lab2 levels because it is populated via haml. Therefore, if the level changes and we don't reload the page (which is the case for switching between lab2 levels within a lesson), the box won't get updated. This creates a react version of the extra links box. To keep things scoped I just implemented the levelbuilder version of this (and skipped a few things for now), and left the project validator version in haml. See follow-up work for details on that.

Instead of a box that can hide/show, there is now a button the pops a modal up.

To get this to work, I made a new level api /extra_links, which returns the links for a level. There was a strong desire from curriculum to get a minimal version working asap, so I skipped a few things, specifically on the level side listing contained levels and a lot of blockly links that aren't currently used in any lab2 levels. Long-term this api can be improved/slimmed down to not be so prescriptive as to what we show on the frontend, but it was easiest for now to get parity with haml to put this on the rails side.

In order to get delete to work, I needed to update the delete api to check the accept header and return a json response if we ask for it. Otherwise it was trying to do a redirect the client could not process.

The project validator version of this box will need data generate from elsewhere (or may be mostly be able to be generated from the frontend), as it is not level-specific but project specific. Since projects are always loaded from the server it made sense to split this work out into a separate task and continue using the old haml version for now.

Before

Screenshot 2024-05-03 at 3 33 19 PM

After

Screenshot 2024-05-03 at 3 32 36 PM

New Modal

Python Lab
Screenshot 2024-05-03 at 3 30 52 PM

Clone button clicked
Screenshot 2024-05-03 at 3 32 07 PM

Delete button clicked
Screenshot 2024-05-03 at 3 32 16 PM

Note I left start and exemplar in the modal as start mode is actively being worked on, and exemplars are a near-term task.

Music Lab
Screenshot 2024-05-03 at 3 34 32 PM

AI Chat
Screenshot 2024-05-03 at 3 34 57 PM

Links

Testing story

Tested on Music Lab, Python Lab, and AI Chat levels. This button only shows up for levelbuilders, otherwise we show no button (most of the time), or show the haml box (for project validators).

Follow-up work

There is work to do to achieve parity with the old extra links box. This is tracked in CT-550

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

const ExtraLinks: React.FunctionComponent<ExtraLinksProps> = ({
levelId,
}: ExtraLinksProps) => {
const {loading, data} = useFetch('/api/v1/users/current/permissions');
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 had us get all permissions here because we eventually want to extend this to more than just levelbuilders, and it would be useful to know what permissions a user has here.

# Get the extra links for the level, for use by levelbuilders.
# This is used by lab2 levels that cannot use the haml "extra links" box
# as that box will not refresh when changing levels.
def extra_links
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 don't know if this is where this logic should all live long term. It might make more sense to return a slimmed down version that the frontend can parse. In order to get something working for levelbuilders I think it's a decent start (I was able to copy a lot of this from the haml file), but I am tracking improving it here

@molly-moen molly-moen marked this pull request as ready for review May 3, 2024 23:45
@molly-moen molly-moen requested review from sanchitmalhotra126, a team and breville May 3, 2024 23:45
Copy link
Contributor

@sanchitmalhotra126 sanchitmalhotra126 left a comment

Choose a reason for hiding this comment

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

Awesome, nice work getting this up so quickly! A few minor things but LGTM overall

apps/src/lab2/views/ExtraLinks.tsx Outdated Show resolved Hide resolved
apps/src/lab2/views/ExtraLinksModal.tsx Outdated Show resolved Hide resolved
apps/src/lab2/views/ExtraLinksModal.tsx Outdated Show resolved Hide resolved
apps/src/lab2/views/ExtraLinksModal.tsx Outdated Show resolved Hide resolved
@@ -78,7 +78,8 @@
-# special tracking image to make sure a cookie is set when hoc starts (/hoc/1)
= image_tag(tracking_pixel_url(@script))

= render partial: 'levels/admin'
- if current_user && (!@level.uses_lab2? || (@level.uses_lab2? && !current_user.levelbuilder?))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to confirm - since previously there are no checks here for current_user or current_user.levelbuilder, are we okay to add them here in addition to the lab2 check? Logically seems fine to me, but just want to double check if there are any other assumptions changing here (e.g. if there's another permission type that's able to view the extra links box)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it should be fine. The first line of the haml file is

if current_user && (current_user.levelbuilder? || current_user.project_validator? || Experiment.get_editor_experiment(current_user))

So we were already gating on current_user. Then we either show the box if this isn't a lab2 level (same as before), or if it is lab2 and the user is not a levelbuilder (so we can show the links for project validators).

},
}
);
if (response.ok) {
Copy link
Contributor

@ebeastlake ebeastlake May 7, 2024

Choose a reason for hiding this comment

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

nit: I've typically used both response.ok and try/catch together, and now I'm wondering why. I think it's to catch errors related to network issues or CORS (not included in response.ok?) and any errors that don't happen until the JSON parsing step. Thoughts? Maybe it's not necessary when I do it.

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'm still getting used to fetch vs ajax, adding a try/catch makes sense!

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, HttpClient functions should throw even when a response is not ok, so just wrapping those in a try/catch should be sufficient!

@molly-moen molly-moen merged commit 210712d into staging May 7, 2024
2 checks passed
@molly-moen molly-moen deleted the molly/lab2-extra-links branch May 7, 2024 19:48
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.

None yet

3 participants