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

fix(pat relateditems): Import Select2 module before calling it when not yet initialized #1342

Merged
merged 2 commits into from
Sep 18, 2023

Conversation

frapell
Copy link
Member

@frapell frapell commented Sep 13, 2023

This PR fixes gh-1341

@frapell
Copy link
Member Author

frapell commented Sep 13, 2023

@thet Mind taking a look at this if you have some time? My understanding is that the new operator doesn't return a promise, so it cannot be awaited... My first approach at fixing this issue was to add an await in

this.relatedItems = new RelatedItems(this.getEl(), options);
but that doesn't work and
this.relatedItems.selectItem(val);
gets called with the select2 module not yet available.

I don't like my solution very much, but I believe a proper solution would require extensive refactoring, and could potentially break in unexpected places...

Thoughts?

@thet
Copy link
Member

thet commented Sep 13, 2023

Hi, I think using the await_pattern_init from Patternslib should work.
Import:

import events from "@patternslib/patternslib/src/core/events";

then:

createRelatedItems: async function () {
    [...]
    this.relatedItems = new RelatedItems(this.getEl(), options);
    await events.await_pattern_init(this.relatedItems)
}

There should be many examples in Patternslib.

Hope that helps!

I'm happy to review this later.

@frapell
Copy link
Member Author

frapell commented Sep 14, 2023

@thet Thank you for that! had no idea about the await_pattern_init and I think it is a better solution. I force pushed the commit replacing the previous one to avoid excessive commits

frapell added a commit to enfold/plone.staticresources that referenced this pull request Sep 14, 2023
@frapell
Copy link
Member Author

frapell commented Sep 15, 2023

@thet I included my latest commit into this PR, which is totally unrelated to this fix, but I think it is a nice to have. Right now, it is not possible to add the "Insert Link" or "Insert Image" to the menu, they can only be added as buttons to the toolbar.
I added calls to addMenuItem for them (https://www.tiny.cloud/docs/tinymce/6/apis/tinymce.editor.ui.registry/#addMenuItem) and now you can add those actions to the menu:
image

Let me know if you want me to revert it and submit a separate PR for that

Copy link
Member

@thet thet left a comment

Choose a reason for hiding this comment

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

LGTM.

regarding the add image/add link in the insert menu - totally fine for me.
But you have this commit message: "Include ability to add the insert image and insert link in the insert menu". Shouldn't it be: "Include the insert image and insert link in the insert menu"? Because you aren't adding a ability but the menu items itself, right?

@frapell
Copy link
Member Author

frapell commented Sep 18, 2023

@thet No, you still need to add ploneimage and plonelink to the JSON config for the menu in /@@tinymce-controlpanel. What happens today without this code change is that if you cannot have the buttons showing up in the menu, even adding those entries to the config.
By config I mean something like this:

    "insert": {
        "title": "Insert",
        "items": "ploneimage plonelink media inserttable | charmap | anchor | insertdatetime"
    },

@frapell frapell merged commit a580112 into master Sep 18, 2023
2 checks passed
@frapell frapell deleted the frapell-fix-1341 branch September 18, 2023 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pat-relateditems: Issue with existing value when Select2 is not imported
2 participants