-
Notifications
You must be signed in to change notification settings - Fork 80
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
feat: add onComponentSelected callback function and componentPickerMode types [FC-0062] #1417
feat: add onComponentSelected callback function and componentPickerMode types [FC-0062] #1417
Conversation
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 approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo 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:
🔘 Get a green buildIf 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 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
e016139
to
0831ba7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1417 +/- ##
==========================================
+ Coverage 93.13% 93.15% +0.01%
==========================================
Files 1051 1051
Lines 20262 20328 +66
Branches 4328 4346 +18
==========================================
+ Hits 18871 18936 +65
- Misses 1328 1329 +1
Partials 63 63 ☔ View full report in Codecov by Sentry. |
@@ -49,7 +80,7 @@ export interface LibraryContextData { | |||
componentBeingEdited: string | undefined; | |||
openComponentEditor: (usageKey: string) => void; | |||
closeComponentEditor: () => void; | |||
} | |||
} & ComponentPickerType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type
change is not very pretty on this side, but I think it is beneficial, as we add many related states in the context. It makes things safer using the useLibraryContext
hook on the components side.
i.e
const {
componentPickerMode,
onComponentSelected,
addComponentToSelectedComponents,
removeComponentFromSelectedComponents,
} = useLibraryContext();
if (!componentPickerMode) {
// ❌ This throws a type error
addComponentToSelectedComponents({ usageKey: 'blockId', blockType: 'blockType' });
};
if (componentPickerMode === 'single') {
// ❌ This throws a type error
addComponentToSelectedComponents({ usageKey: 'blockId', blockType: 'blockType' });
};
if (componentPickerMode === 'multiple') {
// ✅ This works
addComponentToSelectedComponents({ usageKey: 'blockId', blockType: 'blockType' });
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's nice. But I think we will soon need to split up LibraryContext
because it's getting too big and messy. We can instead have LibraryContext
, SidebarContext
, and ComponentPickerContext
, and it will clean up our tests a lot too. The SidebarContext
, and ComponentPickerContext
can both have defaults so they don't always have to be present in order to read their values. (e.g. isSidebarOpen
can just be false in the default context, even if there's no SidebarContextProvider
available)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I pushed a few lines of code that I need for the legacy UI multi-select. I also made a note that we need to stop putting so much stuff into LibraryContext
. It's become a messy "everything" provider. Instead, we need to split it up into SidebarContext, ComponentSelectorContext, etc. But that can come later, after the Sumac cut and bugfixes. For now we need to get this merged.
Description
This PR refactors the
ComponentPicker
and adds the multiple-select feature to be used in openedx/edx-platform#35679 and #1173.More information
Testing instructions
'single'
to'multiple'
and opening http://apps.local.edly.io:2001/course-authoring/component-pickerPrivate ref: FAL-3901}