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: variable name changes when element name/label changes #893

Merged
merged 4 commits into from
Oct 3, 2024

Conversation

abdul99ahad
Copy link
Contributor

@abdul99ahad abdul99ahad commented Aug 26, 2024

Closes #863

Proposed Changes

  • When creating or updating the label in Decision box, the variable name automatically updates
  • Setting the element name automatically sets variable name

@bpmn-io-tasks bpmn-io-tasks bot added the needs review Review pending label Aug 26, 2024
@abdul99ahad abdul99ahad force-pushed the 863-update-variable-after-element-rename branch from 46575b0 to 2ca70f5 Compare August 26, 2024 12:08
@barmac
Copy link
Member

barmac commented Aug 26, 2024

I don't see any changes regarding the decision table. Is it already present in that editor? I know that we don't support variable adding or modification in the decision table, but it could be present in the XML brought by user.

@abdul99ahad abdul99ahad force-pushed the 863-update-variable-after-element-rename branch from fd81b34 to 0aced41 Compare August 26, 2024 19:35
@abdul99ahad
Copy link
Contributor Author

I don't see any changes regarding the decision table. Is it already present in that editor? I know that we don't support variable adding or modification in the decision table, but it could be present in the XML brought by user.

Since variables weren't available in the modeling interface, I initially assumed they weren't part of the decision tables. However, I've now fixed the issue for all elements to ensure everything is covered.

Comment on lines 30 to 31
bo.variable.name = newLabel;
this._modeling.updateProperties(element, { variable: bo.variable });
Copy link
Member

@barmac barmac Aug 27, 2024

Choose a reason for hiding this comment

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

bo.variable.name = newLabel;

This is a technique called monkey-patching. If you add tests for commandStack.undo, you will notice that the change cannot be undone. We need to dispatch an updateProperties call which updates the variable name.
@philippfromme perhaps it makes sense you look into this together with @abdul99ahad

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @barmac, for pointing this out. I discussed the monkey patching technique with @philippfromme earlier and I didn't realize that my implementation went against the recommended approach. I apologize for the oversight. I've updated the implementation to align with the correct approach.

Copy link
Member

@barmac barmac left a comment

Choose a reason for hiding this comment

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

Notice the comment I left. Let's add tests for undo, and fix the code. As I am off for the next two weeks, please ask @philippfromme or other team member for support.

@bpmn-io-tasks bpmn-io-tasks bot added in progress Currently worked on and removed needs review Review pending labels Aug 27, 2024
@abdul99ahad abdul99ahad force-pushed the 863-update-variable-after-element-rename branch from 0aced41 to bf51fc5 Compare August 28, 2024 13:41
@abdul99ahad abdul99ahad marked this pull request as draft August 28, 2024 13:45
@abdul99ahad abdul99ahad force-pushed the 863-update-variable-after-element-rename branch from 4c5c344 to e222864 Compare August 30, 2024 11:10
@abdul99ahad abdul99ahad marked this pull request as ready for review August 30, 2024 11:12
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed in progress Currently worked on labels Aug 30, 2024
@abdul99ahad
Copy link
Contributor Author

Notice the comment I left. Let's add tests for undo, and fix the code. As I am off for the next two weeks, please ask @philippfromme or other team member for support.

I have fixed the code and added the test cases that support undo/redo

@abdul99ahad
Copy link
Contributor Author

@barmac @philippfromme We could move the NameChangeBehavior from dmn-boxed-expression to a shared NameChangeBehavior. The key difference is that the shared version only syncs the element name with the variable name, not the other way around, while the boxed-expression version supports both directions. Should we keep this distinction, or do we need to refactor?

@philippfromme
Copy link
Contributor

philippfromme commented Sep 3, 2024

@barmac @philippfromme We could move the NameChangeBehavior from dmn-boxed-expression to a shared NameChangeBehavior. The key difference is that the shared version only syncs the element name with the variable name, not the other way around, while the boxed-expression version supports both directions. Should we keep this distinction, or do we need to refactor?

Is there anything keeping us from handling both cases in a shared component?

@abdul99ahad
Copy link
Contributor Author

@barmac @philippfromme We could move the NameChangeBehavior from dmn-boxed-expression to a shared NameChangeBehavior. The key difference is that the shared version only syncs the element name with the variable name, not the other way around, while the boxed-expression version supports both directions. Should we keep this distinction, or do we need to refactor?

Is there anything keeping us from handling both cases in a shared component?

We can cover that case as well. I previously discussed this with @barmac, who mentioned that only a one-way sync is required as of now.

@barmac
Copy link
Member

barmac commented Sep 13, 2024

I will look into this today again.

@barmac
Copy link
Member

barmac commented Sep 13, 2024

Note that the variable name change is not reflected in the literal expression editor:

Screen.Recording.2024-09-13.at.10.40.49.mov

@barmac
Copy link
Member

barmac commented Sep 13, 2024

Looks that it's an already existing issue. LiteralExpressionPropertiesEditorComponent does not update on external changes.

@barmac
Copy link
Member

barmac commented Sep 13, 2024

@barmac @philippfromme We could move the NameChangeBehavior from dmn-boxed-expression to a shared NameChangeBehavior. The key difference is that the shared version only syncs the element name with the variable name, not the other way around, while the boxed-expression version supports both directions. Should we keep this distinction, or do we need to refactor?

Is there anything keeping us from handling both cases in a shared component?

We can cover that case as well. I previously discussed this with @barmac, who mentioned that only a one-way sync is required as of now.

The thing about this is that in the future, I expect that we replace dmn-js-literal-expression with dmn-js-boxed-expression entirely where you cannot change the variable name by design. Still, I think that, contrary to what I said before, for the external changes it makes sense to sync it two-way.

@abdul99ahad
Copy link
Contributor Author

Note that the variable name change is not reflected in the literal expression editor:

Screen.Recording.2024-09-13.at.10.40.49.mov

Yes, the variable name is changing but the state is not updating. Hence, when you're on the same screen (lieral expression editor), the change doesn't reflect although its value has been updated.

For variable name changing directly, the element name won't change since it's currently not supported.

@barmac
Copy link
Member

barmac commented Sep 13, 2024

Yes, the variable name is changing but the state is not updating. Hence, when you're on the same screen (lieral expression editor), the change doesn't reflect although its value has been updated.

IMO the update should happen as it does in boxed expression. Let the field display the current value.

@abdul99ahad
Copy link
Contributor Author

Yes, the variable name is changing but the state is not updating. Hence, when you're on the same screen (lieral expression editor), the change doesn't reflect although its value has been updated.

IMO the update should happen as it does in boxed expression. Let the field display the current value.

@barmac need your support in updating the state externally as I'm stuck and can only update the state within the component. We might need to use Wrapper with ChangeSupport just like in boxed-expression.

@abdul99ahad abdul99ahad force-pushed the 863-update-variable-after-element-rename branch from 29ff0c0 to 2e6bb56 Compare September 17, 2024 14:08
@@ -32,6 +32,21 @@ export default class LiteralExpressionPropertiesComponent extends Component {
});
}

componentWillMount() {
this._eventBus.on('elements.changed', this.onChange);
console.log('componentDidUpdate',);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
console.log('componentDidUpdate',);

@abdul99ahad abdul99ahad force-pushed the 863-update-variable-after-element-rename branch from 2e6bb56 to 20f1582 Compare September 23, 2024 15:16
@barmac
Copy link
Member

barmac commented Sep 30, 2024

The CI failure seems to be unrelated. I'll give it a second try.


onChange = () => {
const decision = this._viewer.getDecision();
if (decision.variable) {
Copy link
Member

Choose a reason for hiding this comment

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

🚀

@barmac
Copy link
Member

barmac commented Oct 1, 2024

One optional improvement suggestion, but other than that it looks good.

@abdul99ahad abdul99ahad force-pushed the 863-update-variable-after-element-rename branch 2 times, most recently from 6f53c4a to 6d1e6d6 Compare October 3, 2024 14:31
@abdul99ahad abdul99ahad force-pushed the 863-update-variable-after-element-rename branch from 6d1e6d6 to b381471 Compare October 3, 2024 14:36
@abdul99ahad abdul99ahad merged commit a9804d4 into develop Oct 3, 2024
8 checks passed
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Oct 3, 2024
@abdul99ahad abdul99ahad deleted the 863-update-variable-after-element-rename branch October 3, 2024 14:52
}

isElementVariable(element) {
const variable = element.get('variable');
Copy link
Member

Choose a reason for hiding this comment

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

This breaks when using this feature along with the dmn-js-properties-panel.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ouch. I can reproduce it on the Modeler nightly too.

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.

Update variable name after element is renamed in each editor
4 participants