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: block creation in libraries v2 #1574

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

dcoa
Copy link
Contributor

@dcoa dcoa commented Dec 17, 2024

Description

This PR changes the way components are creating in libraries V2 with the purpose to avoid the creation of a blank component as fist step, behavior that have the following problems:

Supporting information

This PR is liked to #1482 (comment) issue.

Testing instructions

  • Create a component in libraries V2 supported by the editor [text, video, problem]
  • Press the cancel button or the close icon, no new component should appear in the platform.
  • Prove the right creating workflow:
    • Update the title and save it, should be used as usage_key block.
    • If the title does not change should create a unique key.
    • The user is enable to update images.
    • Press the save button should create the component and save the content.

Other information

Include anything else that will help reviewers and consumers understand the change.

  • Does this change depend on other changes elsewhere?
  • Any special concerns or limitations? For example: deprecations, migrations, security, or accessibility.

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

openedx-webhooks commented Dec 17, 2024

Thanks for the pull request, @dcoa!

This repository is currently maintained by @openedx/2u-tnl.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are 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.


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.

@dcoa dcoa changed the title refactor: block creation refactor: block creation in libraries v2 Dec 17, 2024
@dcoa dcoa force-pushed the dcoa/editor-create-block branch 4 times, most recently from 94b0493 to 6af6ee7 Compare December 18, 2024 05:25
@dcoa dcoa force-pushed the dcoa/editor-create-block branch from f70d770 to b8ecbe2 Compare December 27, 2024 00:24
@kdmccormick
Copy link
Member

Hey @dcoa , I'm interested in making sure this gets across the line. Is there anything blocking you or anything that you'd like a second set of eyes on?

@bradenmacdonald
Copy link
Contributor

It just occurred to me that if we need a place to store uploaded static assets when they're uploaded before saving, we could potentially use StagedContent to hold the draft version of the new component. Not sure if it's a good idea or if we should just save things locally in the browser, which is another alternative.

@dcoa
Copy link
Contributor Author

dcoa commented Jan 13, 2025

Sorry, I have had some issues with the pc and additional tasks that slow my progress, but I will continue working on it tomorrow, most of the code is already functional but I need to change the reset logic a little bit.

Thanks @bradenmacdonald for your help giving me options for the images issue, I will start testing that.

@dcoa dcoa force-pushed the dcoa/editor-create-block branch from e995900 to 8c23e0d Compare January 14, 2025 06:45
@dcoa dcoa force-pushed the dcoa/editor-create-block branch from 8c23e0d to e677ed0 Compare January 16, 2025 03:42
@dcoa dcoa force-pushed the dcoa/editor-create-block branch 2 times, most recently from 871b242 to 4832895 Compare January 21, 2025 05:20
@dcoa dcoa force-pushed the dcoa/editor-create-block branch from 4832895 to 3dd53d4 Compare January 21, 2025 09:12
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 90.98361% with 11 lines in your changes missing coverage. Please review.

Project coverage is 93.20%. Comparing base (98fbcff) to head (2a96990).
Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
src/editors/data/redux/thunkActions/requests.js 65.38% 8 Missing and 1 partial ⚠️
src/editors/data/redux/thunkActions/app.js 91.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1574      +/-   ##
==========================================
- Coverage   93.23%   93.20%   -0.04%     
==========================================
  Files        1098     1100       +2     
  Lines       21709    21887     +178     
  Branches     4593     4744     +151     
==========================================
+ Hits        20240    20399     +159     
- Misses       1404     1414      +10     
- Partials       65       74       +9     

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

@dcoa dcoa force-pushed the dcoa/editor-create-block branch from 1773448 to a8f286c Compare January 23, 2025 06:52
@dcoa dcoa marked this pull request as ready for review January 24, 2025 04:12
@dcoa dcoa requested a review from a team as a code owner January 24, 2025 04:12
@dcoa dcoa requested review from bradenmacdonald and removed request for a team January 24, 2025 04:12
@dcoa dcoa force-pushed the dcoa/editor-create-block branch from fc1b4cf to 82e5d80 Compare January 24, 2025 05:04
@dcoa
Copy link
Contributor Author

dcoa commented Jan 27, 2025

@kdmccormick @bradenmacdonald hi, I think the PR is good to start the review process (I just need to fix some test coverage - but the functionality is already implemented and working)

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.

Very nice work @dcoa ! This is exciting to see and will be a really big improvement.

.env.test Show resolved Hide resolved
src/editors/data/redux/app/selectors.ts Outdated Show resolved Hide resolved
app: app.reducer,
requests: requests.reducer,
video: video.reducer,
problem: problem.reducer,
game: game.reducer,
});

const rootReducer = (state: any, action: any) => {
if (action.type === 'resetEditor') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm kind of surprised we didn't have this resetEditor before.

src/editors/data/redux/thunkActions/app.js Outdated Show resolved Hide resolved
Comment on lines 143 to 146
const problemTitles = new Set([...Object.values(ProblemTypes).map((problem) => problem.title),
...Object.values(AdvanceProblems).map((problem) => problem.title)]);

definitionId = problemTitles.has(blockTitle) ? `${uuid4()}` : definitionId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a comment to explain what this code is doing? It's not clear to me what it's for, and why it sometimes needs a UUID as the definition ID.

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 problem editor has 2 steps, fist you need to select the type of problem and secondly edit/add the content. When the problem type is selected that becomes the block title, if the user don't change it will create the UUID to avoid create blocks with the default title and eventually avoid the definitionId is already taken problem.

Comment on lines 151 to 155
promise: createLibraryBlock({
libraryId: selectors.app.learningContextId(getState()),
blockType: selectors.app.blockType(getState()),
definitionId,
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we throw an error if the learning context is not a library, but we get to this function? Or is that definitely impossible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the moment only libraries launch the creation action (I didn't modify courses workflow so it could be manage in a different PR and avoid make something too large and hard for reviewing)

const blockTitle = selectors.app.blockTitle(getState());
let definitionId = blockTitle
? blockTitle.toLowerCase().replaceAll(' ', '-')
: `${uuid4()}`;
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 happen in a follow-up PR, but I think we need a better way to handle what happens when this definitionId is already taken. It should automatically generate a unique ID by appending a number to the definitionId, but instead it just throws an error:

Screenshot

This error could be confusing for users since it's based on the title, but titles aren't required to be unique.

Copy link
Contributor Author

@dcoa dcoa Jan 29, 2025

Choose a reason for hiding this comment

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

I used the title based on my understanding of #1384 (comment), a possible fix could be add a shorten hash after the title part.

Copy link
Contributor

Choose a reason for hiding this comment

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

a possible fix could be add a shorten hash after the title part.

That makes sense to me, yep.

src/library-authoring/add-content/AddContentContainer.tsx Outdated Show resolved Hide resolved
@dcoa dcoa force-pushed the dcoa/editor-create-block branch from 3ac5427 to f350757 Compare January 29, 2025 03:02
@dcoa dcoa force-pushed the dcoa/editor-create-block branch from f350757 to 9a547a6 Compare January 29, 2025 03:11
@bradenmacdonald
Copy link
Contributor

Thanks for those changes! I'll test this again tomorrow :) I've also asked if anyone else wants to review it.

@dcoa dcoa force-pushed the dcoa/editor-create-block branch from f4d678b to c67b88d Compare January 30, 2025 09:53
@dcoa dcoa force-pushed the dcoa/editor-create-block branch 3 times, most recently from 5f19a99 to bb57bd4 Compare February 3, 2025 06:13
@dcoa dcoa force-pushed the dcoa/editor-create-block branch from bb57bd4 to 2a96990 Compare February 3, 2025 06:36
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: Waiting on Author
Development

Successfully merging this pull request may close these issues.

4 participants