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: split up library context #1539

Merged

Conversation

rpenido
Copy link
Contributor

@rpenido rpenido commented Nov 29, 2024

Description

This PR split the library context into smaller contexts:

  • LibraryContext
  • ComponentPickerContext
  • SidebarContext

Addition Information

Testing Instructions

  • Tested library's normal functionality, like adding components, using the sidebar, editing components, adding collections, etc..)

Private ref: FAL-3983

@rpenido rpenido requested a review from a team as a code owner November 29, 2024 17:54
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 29, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Nov 29, 2024

Thanks for the pull request, @rpenido!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/2u-tnl. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@rpenido rpenido force-pushed the rpenido/fal-3983-split-up-library-context branch from 00e4b2e to 3662b82 Compare November 29, 2024 19:53
Copy link

codecov bot commented Nov 29, 2024

Codecov Report

Attention: Patch coverage is 99.09502% with 2 lines in your changes missing coverage. Please review.

Project coverage is 92.96%. Comparing base (c7e2bf9) to head (9b28bb1).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...uthoring/common/context/ComponentPickerContext.tsx 94.11% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1539      +/-   ##
==========================================
+ Coverage   92.94%   92.96%   +0.01%     
==========================================
  Files        1073     1075       +2     
  Lines       21098    21171      +73     
  Branches     4550     4554       +4     
==========================================
+ Hits        19610    19682      +72     
- Misses       1422     1423       +1     
  Partials       66       66              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rpenido rpenido marked this pull request as draft November 30, 2024 15:02
@rpenido rpenido force-pushed the rpenido/fal-3983-split-up-library-context branch from 7eb7e15 to 1819bc5 Compare December 4, 2024 18:27
</Routes>
<CreateCollectionModal />
<ComponentEditorModal />
<LibraryTeamModal />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once the LibraryTeamModal was used only inside the LibraryInfo, I moved the Modal there and removed the methods from the LibraryContext.

Copy link
Contributor

@navinkarkera navinkarkera left a comment

Choose a reason for hiding this comment

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

@rpenido Thanks! Looks good. Left a comment about default values for sidebar context.

  • I tested this: (Tested libraries normal functionality, like adding component, using sidebar, editing component, adding collection etc.)
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation

Comment on lines 159 to 162
if (ctx === undefined) {
/* istanbul ignore next */
throw new Error('useSidebarContext() was used in a component without a <SidebarProvider> ancestor.');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to set a default context instead of raising an error as per this issue: #1510

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this, @navinkarkera!
I changed the LibaryContext and the SidebarContext to return default values here: 829cb5a

It went fine for the SidebarContext. For the LibraryContext, we will need to handle the case where libraryId = undefined at the component level if we don't throw (check the CD/CI errors), and I think it would be better to throw the error at the context level.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

@rpenido Yes, I think that LibraryContext doesn't need a default, because of that reason - it's annoying to account for libraryId being undefined everywhere, and it doesn't make sense - libraryId is never undefined on any library page. Since our tests already include that context, I think it's better to make it have no default and throw an error in as it was before.

Copy link
Contributor Author

@rpenido rpenido Dec 10, 2024

Choose a reason for hiding this comment

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

Thanks @bradenmacdonald!
Done here: c805858

Copy link
Contributor

Choose a reason for hiding this comment

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

@rpenido Thanks!

@rpenido rpenido force-pushed the rpenido/fal-3983-split-up-library-context branch from 526b915 to 829cb5a Compare December 10, 2024 18:38
@rpenido rpenido marked this pull request as ready for review December 10, 2024 21:30
@rpenido rpenido force-pushed the rpenido/fal-3983-split-up-library-context branch from 0de1c07 to c805858 Compare December 10, 2024 21:31
Comment on lines 61 to 63
<SidebarProvider>
{children}
</SidebarProvider>
Copy link
Contributor

Choose a reason for hiding this comment

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

@rpenido Now that we have default values for sidebar context, the providers can be removed from tests that don't actually use it. For example, this one works without SidebarProvider. Similarly we can simplify other tests, which was the reason for adding default values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @navinkarkera! Fixed!

Comment on lines 159 to 162
if (ctx === undefined) {
/* istanbul ignore next */
throw new Error('useSidebarContext() was used in a component without a <SidebarProvider> ancestor.');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@rpenido Thanks!

Copy link
Contributor

@ChrisChV ChrisChV left a comment

Choose a reason for hiding this comment

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

@rpenido Looks good! Great work!

@ChrisChV ChrisChV merged commit 69bbeda into openedx:master Dec 12, 2024
7 checks passed
@ChrisChV ChrisChV deleted the rpenido/fal-3983-split-up-library-context branch December 12, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants