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: insert link plugin tinymce #455

Closed

Conversation

johnvente
Copy link
Contributor

@johnvente johnvente commented Jan 18, 2024

Description

This plugin allows you to insert a link into the text editor. Additionally, you can search for sections, subsections, and units within the course and insert the URL for any of them

Demo

demo-jum-to.mov

How to test it (Devstack)

You need to have this Waffle flag activated

new_core_editors.use_new_text_editor

Create waffle flag

Doc here

  1. Go to ~/workspace/frontend-app-course-authoring
 cd ~/workspace/frontend-app-course-authoring 
  1. Create a file called module.config.js with the following config
module.exports = {
  localModules: [
    {
      moduleName: "@edx/frontend-lib-content-components/dist",
      dir: "./frontend-lib-content-components",
      dist: "src",
    },
    {
      moduleName: "@edx/frontend-lib-content-components",
      dir: "./frontend-lib-content-components",
      dist: "src",
    },
  ],
};
  1. Clone frontend-lib-content-components inside frontend-app-course-authoring
git clone -b jv/feat-tiny-mce-plugin-share-link https://github.com/eduNEXT/frontend-lib-content-components.git
cd frontend-lib-content-components && nvm use && npm install

If you have cloned frontend-lib-content-components already you can do this

cd frontend-lib-content-components && git fetch origin pull/455/head:jv/feat-tiny-mce-plugin-share-link
git checkout jv/feat-tiny-mce-plugin-share-link
nvm use && npm install
  1. initialize frontend-app-course-authoring
cd ~/workspace/frontend-app-course-authoring  && npm start

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

openedx-webhooks commented Jan 18, 2024

Thanks for the pull request, @johnvente!

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.

🔘 Update the status of your PR

Your PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate.

🔘 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.

@johnvente johnvente force-pushed the jv/feat-tiny-mce-plugin-share-link branch from d3cded8 to 53ce3a6 Compare January 18, 2024 03:01
Copy link

codecov bot commented Jan 18, 2024

Codecov Report

Attention: Patch coverage is 85.88710% with 35 lines in your changes missing coverage. Please review.

Project coverage is 89.07%. Comparing base (90d5ac4) to head (989b538).
Report is 53 commits behind head on main.

Files with missing lines Patch % Lines
...editors/sharedComponents/InsertLinkModal/index.jsx 69.11% 20 Missing and 1 partial ⚠️
...rc/editors/sharedComponents/TinyMceWidget/hooks.js 63.63% 7 Missing and 1 partial ⚠️
...redComponents/InsertLinkModal/BlocksList/index.jsx 88.88% 4 Missing ⚠️
...dComponents/InsertLinkModal/SearchBlocks/index.jsx 93.54% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #455      +/-   ##
==========================================
- Coverage   90.70%   89.07%   -1.64%     
==========================================
  Files         229      263      +34     
  Lines        4206     4721     +515     
  Branches      855      974     +119     
==========================================
+ Hits         3815     4205     +390     
- Misses        371      487     +116     
- Partials       20       29       +9     

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

@johnvente johnvente force-pushed the jv/feat-tiny-mce-plugin-share-link branch from 6125a8d to 15f00a8 Compare January 18, 2024 21:26
@johnvente johnvente force-pushed the jv/feat-tiny-mce-plugin-share-link branch from 25f0815 to 173e9f3 Compare January 19, 2024 19:49
@johnvente johnvente marked this pull request as ready for review January 19, 2024 19:54
@johnvente johnvente force-pushed the jv/feat-tiny-mce-plugin-share-link branch from 896a584 to 9cd8d8b Compare January 22, 2024 14:05
Copy link
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

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

All my comments were already addressed, thank you!

@santiagosuarezedunext
Copy link

To Whom It May Concern: This functionality was approved by product in this post

Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

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

Overall this looks really great! It's super exciting to see this functionality built out.

I left a couple comments about possibly moving some things out of utils.js, as well as a comment with some questions about URL validation.

Thank you so much for this PR!

Comment on lines +73 to +75
{isInsertLinkOpen && (
<InsertLinkModal
isOpen={isInsertLinkOpen}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the rest of the modals handle isOpen entirely internally. Does this still work without the isInsertLinkOpen &&?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it does work without isInsertLinkOpen && the main problem is that the status of the modal keeps the same even if I open or close it which means for instance I selected an url that is inside the tree (an unit for example) and I open it again and it shows the link selected without that does not re-render the modal component

src/editors/sharedComponents/TinyMceWidget/hooks.js Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

In general I'm not a huge fan of having things live in a utils file (https://youtu.be/-J3wNP6u5YU?t=328 explains my reasoning behind that quite well). I'm not opposed to keeping this file if need be, but I'll go through it and see if I have any suggestions for what may be better homes for the things it contains.

src/editors/sharedComponents/InsertLinkModal/utils.js Outdated Show resolved Hide resolved
src/editors/sharedComponents/InsertLinkModal/utils.js Outdated Show resolved Hide resolved
src/editors/sharedComponents/InsertLinkModal/utils.js Outdated Show resolved Hide resolved
src/editors/sharedComponents/InsertLinkModal/utils.js Outdated Show resolved Hide resolved
src/editors/sharedComponents/InsertLinkModal/utils.js Outdated Show resolved Hide resolved
src/editors/sharedComponents/InsertLinkModal/utils.js Outdated Show resolved Hide resolved
@johnvente
Copy link
Contributor Author

Overall this looks really great! It's super exciting to see this functionality built out.

I left a couple comments about possibly moving some things out of utils.js, as well as a comment with some questions about URL validation.

Thank you so much for this PR!

Hi @brian-smith-tcril! Thanks for taking a look here. I disagree with moving utils.js, principally the functions, because it's better to have functions that are reusable outside of a component. That way, you could use them in other parts of the code, and for testing purposes, it's easier to test those functions if they are outside a component. It would be tricky to test if they were inside a component, as discussed in this article. I understand that if for now they are only used inside one component, you might want to keep them there. I could move the functions to their respective component folders instead of having only one utils file, so each component will have its own utils

@brian-smith-tcril
Copy link
Contributor

brian-smith-tcril commented Feb 15, 2024

I could move the functions to their respective component folders instead of having only one utils file, so each component will have its own utils

This sounds like a reasonable solution to me. For example, the getChildrenFromList method could move from src/editors/sharedComponents/insertLinkModal/utils.js to src/editors/sharedComponents/insertLinkModal/BlocksList/utils/getChildrenFromList.js, and formatBlockPath could move to src/editors/sharedComponents/insertLinkModal/utils/formatBlockPath.js

That would effectively communicate the current usage scope of each function, and it would make it easy for someone who wants to use one more generally to refactor (by simply moving the file and changing an import path)

@johnvente johnvente force-pushed the jv/feat-tiny-mce-plugin-share-link branch from 2429b3e to c963cfa Compare February 15, 2024 16:21
@brian-smith-tcril
Copy link
Contributor

@johnvente it looks like the CI failures should be resolved if you rebase on latest main (it's @edx vs @openedx stuff that changed in #457)

@brian-smith-tcril
Copy link
Contributor

Yep, but why to check the insertion bar?

Because that's how the native link button behaves. It doesn't make sense to have different UX for the internal link button and the native link button.

@johnvente
Copy link
Contributor Author

Yep, but why to check the insertion bar?

Because that's how the native link button behaves. It doesn't make sense to have different UX for the internal link button and the native link button.

Okay, I will check that would it be enough with that?

@brian-smith-tcril
Copy link
Contributor

I found another issue.

  • Select a link
    image
  • Open the "jump to" editor
    image
  • Click the "remove link" button
    image
  • Click save
    image
  • The link is still there
    image

@johnvente johnvente force-pushed the jv/feat-tiny-mce-plugin-share-link branch from edbbd18 to b11bf08 Compare April 2, 2024 21:29
@johnvente
Copy link
Contributor Author

I found another issue.

@brian-smith-tcril I added a fix for that use case but for the insertion bar not yet since the native plugin is active even when there is not text selected or when the editor is empty completely so is active all the time we should limit our plugin only for text selected instead of trying to have the behavior of the native plugin I'm not sure how long can take and I won't be able to check it after this friday please let me know what do you recommend here

@brian-smith-tcril
Copy link
Contributor

since the native plugin is active even when there is not text selected

The grey indicates it will edit the link instead of create a new one

image

image

vs

image

image

I won't be able to check it after this friday

I'm more than happy to take this over and get it across the finish line.

@johnvente
Copy link
Contributor Author

I'm more than happy to take this over and get it across the finish line.

That is more like new feature that a bug fixing since our code was made for text selected not when the user has insertion bar to edit a link. I will try as much as I can to check it but the time is very short

@johnvente johnvente force-pushed the jv/feat-tiny-mce-plugin-share-link branch from 16b54a3 to 989b538 Compare April 5, 2024 15:33
@johnvente
Copy link
Contributor Author

Hi @brian-smith-tcril I added the support to edit a new link as you mentioned here could you take a look please? I will be checking it

@brian-smith-tcril
Copy link
Contributor

Found a couple more issues

  • Use "jump to" button to create a link
  • Insertion bar and selection is now completely gone from the editor
  • Button state is now both disabled and has the grey box
    image

compared to

  • Use native link button to create link
  • Selection stays, insertion bar stays, native link button state updated correctly

A similar thing with the button state happens when deleting a link using the jump to button

Also

  • Create link using native link editor (to an external site)
  • Select the link (or place insertion bar in it)
  • See "jump to" button in edit state
    image
  • Click on "jump to" button
  • No page is navigated to (since it's an external link)

And another one that's a bit more complicated

  • Create a link using the native link editor (to page url copied by opening a "jump to" link in the native editor)
  • Select the link (or place insertion bar in it)
  • Clock on the "jump to" button
  • See no page selected in the jump to menu

I realize this last one is because the url isn't being parsed to determine if the link is internal or not, but instead an id is being associated with it - but it leads to confusing UX.

@johnvente
Copy link
Contributor Author

Sorry for the delay here, I won't be able to make changes here but any request please let know to @felipemontoya @mariajgrimaldi

Good luck

@brian-smith-tcril
Copy link
Contributor

@johnvente thank you for all of your work on this! I plan on taking this over at the beginning of next week. I know it's turned out to be more complicated than expected, and you've done an amazing job getting it to this point. I'm really happy to be able to use this as a base to get it across the finish line.

Thanks again and all the best!

Comment on lines +171 to +177
editor.on('SelectionChange', () => {
const node = editor.selection.getNode();
const isLink = node.nodeName === 'A';
const hasTextSelected = editor.selection.getContent().length > 0;
api.setActive(isLink);
api.setDisabled(!isLink && !hasTextSelected);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
editor.on('SelectionChange', () => {
const node = editor.selection.getNode();
const isLink = node.nodeName === 'A';
const hasTextSelected = editor.selection.getContent().length > 0;
api.setActive(isLink);
api.setDisabled(!isLink && !hasTextSelected);
});
editor.on('SelectionChange', () => {
const node = editor.selection.getNode();
const isLink = node.nodeName === 'A';
let isInternalLink = false;
if (isLink) {
const selectedHTML = editor.selection.getContent({ format: 'html' }) || node.outerHTML;
const regexDataBlockId = new RegExp(/data-block-id="([^"]+)"/);
isInternalLink = regexDataBlockId.test(selectedHTML);
}
const hasTextSelected = editor.selection.getContent().length > 0;
api.setActive(isInternalLink);
api.setDisabled(!isInternalLink && !hasTextSelected);
});

By doing this I was able to get it so the "jump to" button is only enabled when trying to edit internal links, but I was able to break it decently quickly (and uncovered another bug in the process).

The native link editor doesn't remove data-block-id, so by

  • Creating an internal link using the "jump to" dialog
  • Editing that internal link and changing it to be an external link using the native link dialog

We end up with a link on the page with an associated block id even though the url doesn't match anymore.

This gets cleaned up when opening the "jump to" menu during the block id/url validation, but I'd like to clean it up before getting in there.

I'm looking into ways to do that without duplicating too much code.

@santiagosuarezedunext
Copy link

Hi @brian-smith-tcril, I hope you're doing well. I wanted to ask how the development of this feature is going. What is still needed to finish closing it? Do you need help with anything?

Best regards

@brian-smith-tcril
Copy link
Contributor

@santiagosuarezedunext I have been focused on the edx-platform node 18 upgrade. I'll get back to this once I've worked through the issues with that.

@santiagosuarezedunext
Copy link

Hello @brian-smith-tcril, I hope you are well.
I wrote to you to follow up on the functionality. Is there any update on this? What is needed to finish it? Please tell me if anything is needed from our side.

@brian-smith-tcril
Copy link
Contributor

@santiagosuarezedunext I have been busy with Redwood and haven't had time to dive into this, but I have deployed the current code from this PR on a sandbox here: https://studio.pr-1070-e8373e.sandboxes.opencraft.hosting/

The current implementation differs significantly from what was originally proposed and approved here: https://openedx.atlassian.net/wiki/spaces/OEPM/pages/3887071233/Problem+Authors+don+t+have+enough+options+to+create+the+content+they+would+like?focusedCommentId=3932585997

To move forward with this, the implementation deployed to the sandbox should go through Product and UX/UI testing. That testing should result in updated requirements for getting this PR into a mergeable state.

If I were to perform the Product/UX/UI testing, I would not pass the current implementation because:

  • There should not be 2 "add link" buttons, adding external and internal "jump to" links should be possible using the same button

If, however, someone decides that having 2 link buttons is acceptable, I would still not pass the current implementation because:

  • There should always be a way to add a link without selecting text
    • This is currently only possible with external links
  • The internal "jump to" link button should not allow opening the modal to try to edit external links
    • The internal "jump to" link button currently opens to "search course pages" when an external link is opened with it.
  • Adding a link to an internal page by pasting a URL into the external link editor, then opening that link in the internal "jump to" editor, should result in the correct internal page being selected
    • The internal "jump to" link button currently opens to "search course pages" when an internal link added via URL using the external link editor is opened with it.
  • The internal "jump to" link button is currently using an icon associated with "open in new tab"

@ali-hugo tagging you for visibility. I'm going to put this PR in draft mode until Product and UI has determined the best path forward.

@brian-smith-tcril brian-smith-tcril marked this pull request as draft June 7, 2024 17:59
@ali-hugo
Copy link

@brian-smith-tcril Thanks for putting this on my radar.

I wanted to check out the sandbox so created an account, but I don't seem to be receiving a verification mail. Is it possible for you to verify my email address on your side?

@santiagosuarezedunext
Copy link

@brian-smith-tcril i have the same error that @ali-hugo have.

@brian-smith-tcril
Copy link
Contributor

@santiagosuarezedunext I have marked your user as "Active" and "Staff." Could you try again and let me know if you're still having problems logging in?

Thank you for your patience!

@santiagosuarezedunext
Copy link

It already works for me, thanks @brian-smith-tcril

@KristinAoki
Copy link
Member

Hi! Thank you for your contribution to this repo. This repo is being deprecated and all the code is being moved to frontend-app-course-authoring. If you would like your work to be included in the transition please resolve outstanding requests for this PR. This PR will automatically close once frontend-app-course-authoring PR #1208 is merged.

@bradenmacdonald
Copy link
Contributor

Closing as we've now moved this code, per the notice above. Please re-open this PR against https://github.com/openedx/frontend-app-course-authoring/ if you'd like to continue it. Feel free to reach out to me if you aren't sure how to do that using git and I can help (basically: add your local content-components repo as a remote in course-authoring, then pull the branch and rebase it).

@openedx-webhooks
Copy link

@johnvente Even though your pull request wasn’t merged, please take a moment to answer a two question survey so we can improve your experience in the future.

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.