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

feat: add onComponentSelected callback function and componentPickerMode types [FC-0062] #1417

Conversation

rpenido
Copy link
Contributor

@rpenido rpenido commented Oct 21, 2024

Description

This PR refactors the ComponentPicker and adds the multiple-select feature to be used in openedx/edx-platform#35679 and #1173.

image

More information

Testing instructions


Private ref: FAL-3901}

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 21, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Oct 21, 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-3901-component-picker-refactor branch from e016139 to 0831ba7 Compare October 21, 2024 19:31
Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 98.78049% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.15%. Comparing base (8c8d911) to head (e755b62).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ary-authoring/component-picker/ComponentPicker.tsx 91.66% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@@ -49,7 +80,7 @@ export interface LibraryContextData {
componentBeingEdited: string | undefined;
openComponentEditor: (usageKey: string) => void;
closeComponentEditor: () => void;
}
} & ComponentPickerType;
Copy link
Contributor Author

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' });
  };

Copy link
Contributor

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)

<FormattedMessage {...messages.componentPickerSingleSelectTitle} />
</Button>
);
}
Copy link
Contributor

@bradenmacdonald bradenmacdonald Oct 22, 2024

Choose a reason for hiding this comment

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

This code seems to be duplicated with the code in ComponentInfo.tsx ? (Though maybe not, I don't have time to look to closely now - sorry)

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 really close. It's the button in the sidebar to mark the component as selected.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I didn't know we had a button for that in the sidebar.

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 put it there for consistency. We can remove it later if the UX team doesn't feel it is necessary.

@rpenido rpenido changed the title refactor: add onComponentSelected callback function and componentPickerMode types refactor: add onComponentSelected callback function and componentPickerMode types [FC-0062] Oct 22, 2024
@rpenido rpenido marked this pull request as ready for review October 22, 2024 17:53
@rpenido rpenido requested a review from a team as a code owner October 22, 2024 17:53
@rpenido rpenido changed the title refactor: add onComponentSelected callback function and componentPickerMode types [FC-0062] feat: add onComponentSelected callback function and componentPickerMode types [FC-0062] Oct 22, 2024
Copy link
Contributor

@bradenmacdonald bradenmacdonald left a 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.

@bradenmacdonald bradenmacdonald merged commit 11470f2 into openedx:master Oct 22, 2024
8 checks passed
@bradenmacdonald bradenmacdonald deleted the rpenido/fal-3901-component-picker-refactor branch October 22, 2024 23:41
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
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants