Skip to content

fix(label): improve editing position and 'label changed" event#567

Merged
tbouffard merged 1 commit intomaxGraph:mainfrom
HalilFocic:fix/cant-edit-story-issue-544
Nov 21, 2024
Merged

fix(label): improve editing position and 'label changed" event#567
tbouffard merged 1 commit intomaxGraph:mainfrom
HalilFocic:fix/cant-edit-story-issue-544

Conversation

@HalilFocic
Copy link

@HalilFocic HalilFocic commented Nov 9, 2024

Updated the Editing story and CellMixing to make Editing storywork. Vertex is now editable and value is saved after stopEditing has been called.

PR Checklist

  • Addresses an existing open issue: Fixes [BUG]Editing story: can't edit value. #544.
  • You have discussed this issue with the maintainers of maxGraph, and you are assigned to the issue.
  • The scope of the PR is sufficiently narrow to be examined in a single session. A PR covering several issues must be split into separate PRs. Do not create a large PR, otherwise it cannot be reviewed and you will be asked to split it later or the PR will be closed.
  • I have added tests to prove my fix is effective or my feature works. This can be done in the form of automatic tests in packages/core/_tests_ or a new or altered Storybook story in packages/html/stories (an existing story may also demonstrate the change).
  • I have provided screenshot/videos to demonstrate the change. If no releavant, explain why.
  • I have added or edited necessary documentation, or no docs changes are needed.
  • The PR title follows the "Conventional Commits" guidelines.

Overview

Editing story functionality after this change:

Screen.Recording.2024-11-09.at.17.23.27.mov
  • "editable" property for vertex in story is now true when inserting
  • mxPlainTextEditor has position absolute instead of relative that prevents snappy behaviour.
  • Setting trigger to null was moved after the applyValue function since applyValue had to use the original fieldName from event to update the value.

Notes

fixes #544

@HalilFocic HalilFocic changed the title fix: allow the edit inside the editing story example (#544) fix: allow the edit inside the editing story example Nov 9, 2024
position: [100, 60],
size: [120, 80],
style: { overflow: 'fill' },
style: { overflow: 'fill', editable: true },
Copy link
Member

Choose a reason for hiding this comment

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

note: Once #570 has been merged, this should no longer be necessary.

Copy link
Member

Choose a reason for hiding this comment

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

#570 has been merged, so merging main into the branch of this PR should allow to remove the "editable" configuration

Copy link
Author

@HalilFocic HalilFocic Nov 13, 2024

Choose a reason for hiding this comment

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

Updated this branch to be up to date with main, works properly without having to add editable:true when inserting vertex. I've removed the property from story example

Copy link
Member

@tbouffard tbouffard left a comment

Choose a reason for hiding this comment

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

Thanks @HalilFocic for this PR
I've only had time to do a static review and it looks promising. ✨
I'll do more testing later.

}

this.textarea.style.position = 'relative';
this.textarea.style.position = 'absolute';
Copy link
Member

@tbouffard tbouffard Nov 12, 2024

Choose a reason for hiding this comment

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

question: Have you checked this change outside the StoryBook stories to see if there's any change in behavior? In the js-example or ts-example applications provided in this repository, for example?
In mxGraph, the position was calculated dynamically: https://github.com/jgraph/mxgraph/blob/v4.2.2/javascript/src/js/view/mxCellEditor.js#L281
It seems to have been removed during migration and I don't know why. Probably because of the name of the function and its comments, even though it seems to have had an impact on modern browsers (and not only in IE 8).

Here, we could at least introduce a way to set the value with a new property and let people decide what they want to use as a position.
I haven't thought this through any further, so feel free to suggest alternatives or contradict the proposal. 😸

Copy link
Author

@HalilFocic HalilFocic Nov 12, 2024

Choose a reason for hiding this comment

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

I checked right now, and on main I have this issue where if i just add cellsEditable and try to dobuleclick, the tooltip goes to bottom like this:

image

This image maybe doesn't show much detail, but I double click on the topleft blue rectangle and it scrolled the graph down and focused on textarea which is misplaced.

Switching to my branch and clicking on it seemed to work as intented.

I am pretty sure reason for this behaviour is that textarea is being added like this:
this.graph.container.appendChild(textarea);

If we put relative it will go to the bottom of the graph, then move but its still taking same space.

Copy link
Member

@tbouffard tbouffard Nov 19, 2024

Choose a reason for hiding this comment

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

Yes you are right, I also tested with ts-example and other standalone applications.
I reproduce the problem for both the vertices and the edges.

image

In the mxGraph code, a check was done on the SVG node in the container. Generally, no style is applied to it so isLegacyEditor returned true and the absolute position was then used for the "text edition div". See https://github.com/jgraph/mxgraph/blob/v4.2.2/javascript/src/js/view/mxCellEditor.js#L750
The relative position was applied to the "text edition div" when the SVG node had a position explicitly set to absolute.

I tested the main branch (064c349) by applying an absolute position to the SVG. Using the relative position correctly position the "text edition div" in this case. But using the absolute position works as well, so I guess we can always set the absolute position.

});
}

this.trigger = null;
Copy link
Member

Choose a reason for hiding this comment

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

question: do you know why this statement must be moved?
In mxGraph, it was at the former place and it worked: https://github.com/jgraph/mxgraph/blob/v4.2.2/javascript/src/js/view/mxCellEditor.js#L968

Copy link
Author

Choose a reason for hiding this comment

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

Okay, so this trigger is inside stopEditing function. We change the label inside the if statement if innerHTML is not equal to initial which is okay and we call the applyValue function which takes state and the value, which also seemed fine.
Problem arised because the applyValue function used this.trigger when calling labelChanged function and labelChanged always received null. This is because no matter what, we set the trigger to null even before checking if values has changed. I can look up logic inside the mxGraph for this aswell, but I since the editing of value doesn't work in the example, I would assume they had the bug too.

Copy link
Member

@tbouffard tbouffard Nov 20, 2024

Choose a reason for hiding this comment

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

OK thanks for the information I got what you mean 😄

I didn't understand why this change was needed at a first glance, because most stories and examples work without this change.
The Editing story relies on the triggered event in the overridden Graph.labelChanged method. It needs the event to be correctly set to correctly assign the label (using the custom Cell.value which is an object and not a string, which stores the 2 label values). See https://github.com/maxGraph/maxGraph/blob/v0.13.1/packages/html/stories/Editing.stories.js#L116
Here is video showing the problem (i.e. the labels are not updated) without the change 👇🏿

PR_567_Editing_story_required_change_in_trigger_management.webm

The regular Graph.labelChanged method doesn't directly used the event (except to send another event which is not used in stories). That is why, most of the time, the existing code was working. 😸

ℹ️ Notice that such a fix has been proposed in the past in 4a63940#diff-470b5171fde7755241a36fb45a75aec1a323913b5088e08646d182cfda9dc86c

ℹ️ For the record, the mxGraph "Editing" example doesn't work: https://jgraph.github.io/mxgraph/javascript/examples/editing.html. It doesn't set the label correctly after edition, for all reasons explained in this thread.

@tbouffard tbouffard added the bug Something isn't working label Nov 13, 2024
Properly editable is not being set by default for cells, hence the editing was never allowed to start.
Major issue that was also present inside the mxGraph old example was that the value doesn't actually get updated. This commit fixes that as well.

Furthermore, the container for the textarea editing had position relative instead of absolute which caused snappy behaviour while editing.
@HalilFocic HalilFocic force-pushed the fix/cant-edit-story-issue-544 branch from c96a2fa to f629053 Compare November 13, 2024 12:16
Copy link
Member

@tbouffard tbouffard left a comment

Choose a reason for hiding this comment

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

LGTM, good job @HalilFocic and thanks for the additional explanations which helped during the review 👍🏿 .

✔️ The position of the label editing area is now is for both vertices and edges
✔️ The edition of the 2 custom labels in the Editing story is now working (see #567 (comment) for more explanations)

Tested with various stories, ts-example, js-example and personal applications with both Firefox and Chrome on Ubuntu 22.04.

@tbouffard tbouffard changed the title fix: allow the edit inside the editing story example fix(label): improve editing position and 'label changed" event Nov 21, 2024
@tbouffard tbouffard merged commit bf1f874 into maxGraph:main Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]Editing story: can't edit value.

2 participants