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

Add Element Editor Custom Element #2614

Merged
merged 13 commits into from
Dec 4, 2023

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Nov 16, 2023

What is this pull request for?

Refactors the imperative coffeescript file into a custom element that maintains its own state and
can be simply rendered without initialization from the outside.

This made it possible to remove the re-rendering of the element editor from the server and simply
collapse and expand the element visually instead.

As a bonus this adds a collapse all elements button.

Removes the fold action from admin elements controller and adds two new actions (collapse and expand)

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

@tvdeyen tvdeyen added this to the 7.1 milestone Nov 16, 2023
@tvdeyen tvdeyen force-pushed the element-editor-component branch 2 times, most recently from f35e9ab to bf8738d Compare November 16, 2023 22:55
@tvdeyen tvdeyen marked this pull request as ready for review November 16, 2023 22:58
@tvdeyen tvdeyen requested review from a team and removed request for sascha-karnatz November 16, 2023 22:58
@tvdeyen tvdeyen changed the title Add Element Editor Component Add Element Editor Custom Element Nov 16, 2023
Copy link
Contributor

@sascha-karnatz sascha-karnatz left a comment

Choose a reason for hiding this comment

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

Very big. I guess we have to split element component in the long run.

@tvdeyen tvdeyen force-pushed the element-editor-component branch 4 times, most recently from e86392e to aa7b7ff Compare November 21, 2023 13:16
@tvdeyen tvdeyen self-assigned this Nov 21, 2023
@tvdeyen tvdeyen marked this pull request as draft November 21, 2023 21:09
@tvdeyen tvdeyen force-pushed the element-editor-component branch 12 times, most recently from 6160be7 to 10ca3cc Compare November 28, 2023 18:11
@tvdeyen tvdeyen force-pushed the element-editor-component branch 2 times, most recently from 76bb488 to cb60676 Compare November 29, 2023 21:21
Introduce a custom element for element editors and handle
all render and event logic inside of this instance instead of
delegating from the outside.

That way we can now also get rid of re-rendering the element after
update or collapse/expand.
Splitting toggle fold into two methods (expand and collapse)
with dedicated endpoints that make it easier to separate the
logic and handle the response accordingly.
This button helps to clean up the elements window with one click.
Compact and fixed always elements stay expanded.
By storing the targets only once per base node we spare some
unneccessary dom queries.
sessionStorage gets emptied after the user closes the browser.
Using localStorage the groups state persists even after the user
logs out.
Using the configuration to calculate the space tinymce will
use if it is initialized upfront, so we can reserve the space for
calculating the element editor height correctly so the browser
is able to scroll to it when we click on the element in the preview.
@tvdeyen tvdeyen force-pushed the element-editor-component branch 2 times, most recently from af2d60c to cf71ffb Compare November 30, 2023 10:43
This makes it nicer to read and fixes a bug where the button disable
callback was not working after dragndrop of an element editor.
These native components let us remove all the custom
event handling and state management from the element editor.
This helps to still pass the localStorage test that is failing because
of a jsdom issue.
@tvdeyen tvdeyen marked this pull request as ready for review November 30, 2023 17:19
import { createHtmlElement } from "../utils/dom_helpers"

export class ElementEditor extends HTMLElement {
connectedCallback() {
Copy link

Choose a reason for hiding this comment

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

Function connectedCallback has 54 lines of code (exceeds 25 allowed). Consider refactoring.

@@ -0,0 +1,532 @@
import TagsAutocomplete from "alchemy_admin/tags_autocomplete"
Copy link

Choose a reason for hiding this comment

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

File element_editor.js has 316 lines of code (exceeds 250 allowed). Consider refactoring.

import { post } from "alchemy_admin/utils/ajax"
import { createHtmlElement } from "../utils/dom_helpers"

export class ElementEditor extends HTMLElement {
Copy link

Choose a reason for hiding this comment

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

ElementEditor has 36 functions (exceeds 20 allowed). Consider refactoring.

* Collapses the element editor and persists the state on the server
* @returns {Promise}
*/
collapse() {
Copy link

Choose a reason for hiding this comment

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

Function collapse has 29 lines of code (exceeds 25 allowed). Consider refactoring.

* Collapses the element editor and persists the state on the server
* @* @returns {Promise}
*/
expand() {
Copy link

Choose a reason for hiding this comment

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

Function expand has 37 lines of code (exceeds 25 allowed). Consider refactoring.

@@ -0,0 +1,544 @@
import TagsAutocomplete from "alchemy_admin/tags_autocomplete"
Copy link

Choose a reason for hiding this comment

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

File element_editor.js has 326 lines of code (exceeds 250 allowed). Consider refactoring.

TagsAutocomplete(this)
}

handleEvent(event) {
Copy link

Choose a reason for hiding this comment

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

Function handleEvent has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.

import { post } from "alchemy_admin/utils/ajax"
import { createHtmlElement } from "../utils/dom_helpers"

export class ElementEditor extends HTMLElement {
Copy link

Choose a reason for hiding this comment

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

ElementEditor has 38 functions (exceeds 20 allowed). Consider refactoring.

TagsAutocomplete(this)
}

handleEvent(event) {
Copy link

Choose a reason for hiding this comment

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

Function handleEvent has 35 lines of code (exceeds 25 allowed). Consider refactoring.

This native callback is used by event listeners in classes
and makes code cleaner and less error prone.
Now that we use handleEvent we can use the constructor
to attach event listeners. This runs once on init instead of
every time it renders with the connectedCallback.
@@ -0,0 +1,543 @@
import TagsAutocomplete from "alchemy_admin/tags_autocomplete"
Copy link

Choose a reason for hiding this comment

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

File element_editor.js has 325 lines of code (exceeds 250 allowed). Consider refactoring.

Copy link
Contributor

@sascha-karnatz sascha-karnatz left a comment

Choose a reason for hiding this comment

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

Super Snappy

@sascha-karnatz
Copy link
Contributor

We can split parts of the element editor in the future to reduce the size of the ElementEditor - component. It is now huge step forward.

@tvdeyen tvdeyen merged commit d3590a1 into AlchemyCMS:main Dec 4, 2023
30 of 31 checks passed
@tvdeyen tvdeyen deleted the element-editor-component branch December 4, 2023 21:57
tvdeyen added a commit to tvdeyen/alchemy_cms that referenced this pull request Apr 10, 2024
This has been removed during refactoring the element editor
into a custom web-component in AlchemyCMS#2614

This restores the behavior.
tvdeyen added a commit to tvdeyen/alchemy_cms that referenced this pull request Apr 10, 2024
This has been removed during refactoring the element editor
into a custom web-component in AlchemyCMS#2614

This restores the behavior.
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.

2 participants