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

[2759] Reactivate the SelectionDialog #3658

Merged
merged 1 commit into from
Jul 19, 2024
Merged

Conversation

florianbarbin
Copy link
Contributor

@florianbarbin florianbarbin commented Jun 20, 2024

Pull request template

General purpose

What is the main goal of this pull request?

  • Bug fixes
  • New features
  • Documentation
  • Cleanup
  • Tests
  • Build / releng

Project management

  • Has the pull request been added to the relevant project and milestone? (Only if you know that your work is part of a specific iteration such as the current one)
  • Have the priority: and pr: labels been added to the pull request? (In case of doubt, start with the labels priority: low and pr: to review later)
  • Have the relevant issues been added to the pull request?
  • Have the relevant labels been added to the issues? (area:, difficulty:, type:)
  • Have the relevant issues been added to the same project and milestone as the pull request?
  • Has the CHANGELOG.adoc been updated to reference the relevant issues?
  • Have the relevant API breaks been described in the CHANGELOG.adoc? (Including changes in the GraphQL API)
  • In case of a change with a visual impact, are there any screenshots in the CHANGELOG.adoc? For example in doc/screenshots/2022.5.0-my-new-feature.png

Architectural decision records (ADR)

  • Does the title of the commit contributing the ADR start with [doc]?
  • Are the ADRs mentioned in the relevant section of the CHANGELOG.adoc?

Dependencies

  • Are the new / upgraded dependencies mentioned in the relevant section of the CHANGELOG.adoc?
  • Are the new dependencies justified in the CHANGELOG.adoc?

Frontend

This section is not relevant if your contribution does not come with changes to the frontend.

General purpose

  • Is the code properly tested? (Plain old JavaScript tests for business code and tests based on React Testing Library for the components)

Typing

We need to improve the typing of our code, as such, we require every contribution to come with proper TypeScript typing for both changes contributing new files and those modifying existing files.
Please ensure that the following statements are true for each file created or modified (this may require you to improve code outside of your contribution).

  • Variables have a proper type
  • Functions’ arguments have a proper type
  • Functions’ return type are specified
  • Hooks are properly typed:
    • useMutation<DATA_TYPE, VARIABLE_TYPE>(…)
    • useQuery<DATA_TYPE, VARIABLE_TYPE>(…)
    • useSubscription<DATA_TYPE, VARIABLE_TYPE>(…)
    • useMachine<CONTEXT_TYPE, EVENTS_TYPE>(…)
    • useState<STATE_TYPE>(…)
  • All components have a proper typing for their props
  • No useless optional chaining with ?. (if the GraphQL API specifies that a field cannot be null, do not treat it has potentially null for example)
  • Nullable values have a proper type (for example let diagram: Diagram | null = null;)

Backend

This section is not relevant if your contribution does not come with changes to the backend.

General purpose

  • Are all the event handlers tested?
  • Are the event processor tested?
  • Is the business code (services) tested?
  • Are diagram layout changes tested?

Architecture

  • Are data structure classes properly separated from behavioral classes?
  • Are all the relevant fields final?
  • Is any data structure mutable? If so, please write a comment indicating why
  • Are behavioral classes either stateless or side effect free?

Review

How to test this PR?

  • Import the Studio

  • Studio.zip

  • This studio is based on default one but with two additional tools:

    • One in the diagram palette which renamed the selected element
    • One on the Entity1 node that also open a selection dialog to rename the selected element
  • Create a new project

  • Create a new model based on the studio MM

  • Create a new diagram

  • Create some element by using the node creation tools

  • Use the selectionTool in the diagram contextual palette:

    • The selection dialog should be opened with all the model elements selectable
    • Select an element and perform finished
    • The element should be renamed
  • Use the selection tool on an Entity1

  • The selection dialog should only contain the selected element

  • Select it and perform finish

  • The element should be renamed

  • Has the Kiwi TCMS test suite been updated with tests for this contribution?

@florianbarbin florianbarbin added this to the 2024.7.0 milestone Jun 20, 2024
@florianbarbin florianbarbin linked an issue Jun 20, 2024 that may be closed by this pull request
1 task
@florianbarbin florianbarbin force-pushed the fba/enh/SelectionDialog branch 4 times, most recently from 4c139c8 to 578411d Compare June 25, 2024 07:13
@florianbarbin florianbarbin force-pushed the fba/enh/SelectionDialog branch from 0ddba48 to f048137 Compare June 25, 2024 14:56
@florianbarbin florianbarbin changed the title WIP [2759] Reactivate the SelectionDialog [2759] Reactivate the SelectionDialog Jun 25, 2024
@florianbarbin florianbarbin force-pushed the fba/enh/SelectionDialog branch 3 times, most recently from b75142f to a20983f Compare June 26, 2024 15:27
CHANGELOG.adoc Outdated Show resolved Hide resolved
@@ -174,7 +176,7 @@ export const SelectionDialog = ({
color="primary"
onClick={() => {
if (selectedObjectId) {
onFinish(selectedObjectId);
onFinish([{ name: 'selectedObject', value: selectedObjectId, type: GQLToolVariableType.objectId }]);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems you create a new GQLToolVariable with the selectedObjectId as value, but you name it selectedObject. Why you don't name it selectedObjectId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "specifier" will manipulate the object (the variable value will be the object and not its id)

Copy link
Contributor

Choose a reason for hiding this comment

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

So the "operation" that will transform an objectId to an object is done on the backend right?
So why you have to create a variable here, in the frontend?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that the backend part does not make any assumptions on the variables provided by the frontend component. For now, we have identified 3 kinds of values which can be provided by a Dialog: An Object: in that case we use the Id. An array of objects or a simple string.

Copy link
Contributor

Choose a reason for hiding this comment

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

I get that, but it still seems strange.
Here you set the variable type to GQLToolVariableType.objectId which indicates that the variable will contain an objectId, but you set the variable name to selectedObject which indicates that the variable will contain an Object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The type represents a technical information to describe which kind of value is set.
We can change the variable type by object instead of objectId, in that case, it will represent the value type once converted by the backend side.

Copy link
Member

Choose a reason for hiding this comment

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

Here you set the variable type to GQLToolVariableType.objectId which indicates that the variable will contain an objectId, but you set the variable name to selectedObject which indicates that the variable will contain an Object

No that's not how we should think about this. As the contributor of a dialog, I want my dialog to be used to create a variable named selectedObject. To populate this variable, I'll give the backend some string as the value and it should be interpreted as the identifier of an object to resolve.

@florianbarbin florianbarbin force-pushed the fba/enh/SelectionDialog branch from cf524ec to f830573 Compare June 27, 2024 13:55
@florianbarbin florianbarbin force-pushed the fba/enh/SelectionDialog branch 2 times, most recently from 29bc1b4 to 93b4a08 Compare June 28, 2024 14:06
CHANGELOG.adoc Outdated
}
```

* The `SingleClickOnDiagramElementTool#dialogDescriptionId` has been replaced by a `dialog: Dialog` field to provide the information about the dialog that the frontend needs to retrieve in the extension point.
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't that a XXXDescription? Could you please use something like ToolDialogDescription or DiagramToolDialogDescription in order not to use such a common name which may be used elsewhere in the future.

Why the need for a whole concept instead of of the identifier?

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 idea was to own both the id and the information about the dialog type. We need to change the id to own the information about the dialog type if we want to keep only a dialogDescriptionId field?

Copy link
Member

Choose a reason for hiding this comment

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

I still don't know why we would need both this two pieces of information. Why isn't an identifier enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am modifying the way we generate this identifier to have something similar to the other representation: siriusComponents://dialogDescription?kind=selectionDialogDescription etc"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 367 to 368
invokeSingleClickOnDiagramElementTool(
input: InvokeSingleClickOnDiagramElementToolInput!
Copy link
Member

Choose a reason for hiding this comment

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

No need to change the formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

invokeSingleClickOnDiagramElementTool(
input: InvokeSingleClickOnDiagramElementToolInput!
): InvokeSingleClickOnDiagramElementToolPayload!
invokeSingleClickOnTwoDiagramElementsTool(
Copy link
Member

Choose a reason for hiding this comment

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

No need to change the formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 292 to 293
dialogDescriptionId: String!
dialogDescriptionType: String!
Copy link
Member

Choose a reason for hiding this comment

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

  • This should be a XxxDescription or be removed entirely since I'm not sure why it needs to be a dedicated type?
  • You could use id and type
  • I'm not sure why this concept isn't an interface and why you need more than id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The id currently contains only an UUID that does not allow to identify the dialog type.
If we want to keep only an id, we need to modify the way we generate this id to own the dialog type information?

Copy link
Member

Choose a reason for hiding this comment

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

Ok so that's the limitation that I was missing. We should indeed change the way this identifier is computed. I don't even know how a simple UUID can be enough to open a dialog. For other description elements, the identifier has way more information. For example, the identifier of a node description is siriusComponents://nodeDescription?sourceKind=view&sourceId=c5857f07-7382-3215-8c53-b690ca983655&sourceElementId=fe82e80e-7308-35a9-986d-f010401063ee.

So, for a selection dialog, having an identifier like this would be necessary:

siriusComponents://selectionDialogDescription?sourceKind=view&sourceId=XXX&sourceElementId=XXXX

I don't know how we could retrieve the proper Dialog object otherwise since we don't know the id of its view model.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

*
* @author fbarbin
*/
public record Dialog(String dialogDescriptionId, String dialogDescriptionType) {
Copy link
Member

Choose a reason for hiding this comment

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

This will have to be renamed not to use such a common concept name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment on lines 20 to 23
export interface DialogComponentProps {
editingContextId: string;
dialogDescriptionId: string;
targetObjectId: string;
onClose: () => void;
onFinish: (variables: GQLToolVariable[]) => void;
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure that the editingContextId is not needed and the targetObjectId too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, replaced by the useDialog hook to retrieve the editingContext from the DialogContext


import { GQLToolVariable } from '../renderer/palette/Palette.types';
export interface DiagramDialogContribution {
canHandle: (dialogTypeId: string) => boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Why not use the descriptionId? Why have two pieces of information?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The descriptionId is just an UUID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed and replaced by the descriptionId that now contains the type information.

targetObjectId,
onClose,
onFinish,
}: SelectionDialogProps) => {
}: DialogComponentProps) => {
Copy link
Member

Choose a reason for hiding this comment

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

DialogComponentProps is too generic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

type: GQLToolVariableType;
}

export enum GQLToolVariableType {
Copy link
Member

Choose a reason for hiding this comment

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

Do not use enum in TypeScript, it creates a weird result, use an union instead:

`export type GQLToolVariableType = 'STRING' | 'OBJECT_ID' | 'OBJECT_ID_ARRAY';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@@ -174,7 +176,7 @@ export const SelectionDialog = ({
color="primary"
onClick={() => {
if (selectedObjectId) {
onFinish(selectedObjectId);
onFinish([{ name: 'selectedObject', value: selectedObjectId, type: GQLToolVariableType.objectId }]);
Copy link
Member

Choose a reason for hiding this comment

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

Here you set the variable type to GQLToolVariableType.objectId which indicates that the variable will contain an objectId, but you set the variable name to selectedObject which indicates that the variable will contain an Object

No that's not how we should think about this. As the contributor of a dialog, I want my dialog to be used to create a variable named selectedObject. To populate this variable, I'll give the backend some string as the value and it should be interpreted as the identifier of an object to resolve.

@florianbarbin florianbarbin force-pushed the fba/enh/SelectionDialog branch 4 times, most recently from 3f6485e to f9ec7fb Compare July 8, 2024 13:12
@florianbarbin florianbarbin force-pushed the fba/doc/adr_152 branch 2 times, most recently from 98497f7 to de754a8 Compare July 10, 2024 10:03
@florianbarbin florianbarbin force-pushed the fba/enh/SelectionDialog branch from f9ec7fb to c022bec Compare July 10, 2024 10:10
@florianbarbin florianbarbin changed the base branch from fba/doc/adr_152 to master July 10, 2024 10:13
@AxelRICHARD
Copy link
Contributor

Please squash the commits before the merge

@florianbarbin florianbarbin force-pushed the fba/enh/SelectionDialog branch 6 times, most recently from 46095ef to e444ba2 Compare July 12, 2024 16:25
Copy link
Member

@sbegaudeau sbegaudeau left a comment

Choose a reason for hiding this comment

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

I'll have to review some details while running the code and I'll fix the last small issue remaining to merge it

@@ -32,6 +32,7 @@
"peerDependencies": {
"@apollo/client": "3.10.4",
"@eclipse-sirius/sirius-components-core": "*",
"@eclipse-sirius/sirius-components-diagrams": "*",
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why selection needs to depend on diagrams now...

import { GQLToolVariable } from '../renderer/palette/Palette.types';

export interface DialogContextValue {
currentEditingContextId: string | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Why this currentEditingContextId and why can it be undefined? even null would be very odd

@@ -61,6 +62,8 @@ public class ModelOperationDiagramDescriptionProvider implements IEditingContext

private NodeTool createNodeTool;

private NodeTool renameNodeTool;
Copy link
Member

Choose a reason for hiding this comment

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

A dedicated example should be created instead of just taking one to change the scope of its behavior

@@ -130,4 +129,48 @@ public void givenDiagramWhenToolWithComplexModelOperationsIsExecutedThenItWorksA
.thenCancel()
.verify(Duration.ofSeconds(10));
}

@Test
Copy link
Member

Choose a reason for hiding this comment

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

Can be moved to a dedicated test suite

@sbegaudeau sbegaudeau force-pushed the fba/enh/SelectionDialog branch 4 times, most recently from 4670a4b to 051527c Compare July 19, 2024 19:29
@sbegaudeau
Copy link
Member

So now things are working as expected but I still have two elements to review and possibly modify (the dependency to sirius-components-diagrams and the tests)

@sbegaudeau
Copy link
Member

I've reduced the dependency to sirius-components-diagrams as much as possible but it will still remain for now since the impact is minimal, we will just have to ensure that it does not grow over time.

/cc @florianbarbin When we will work on the support for dialogs in the explorer, we will have to move DialogDescription in view.ecore (from diagram.ecore now), rename DiagramDialogComponentProps to DialogComponentProps and move it to sirius-components-core.

Let's not add more dependencies to sirius-components-diagrams in sirius-components-selection.

@sbegaudeau sbegaudeau force-pushed the fba/enh/SelectionDialog branch from 051527c to 06bd199 Compare July 19, 2024 20:32
In addition, this commit introduces the generic concept of Dialog
to make it possible to define any kind of dialog for diagram node tools.

Bug: #2759
Signed-off-by: Florian Barbin <[email protected]>
@sbegaudeau sbegaudeau force-pushed the fba/enh/SelectionDialog branch from 06bd199 to 89cdf78 Compare July 19, 2024 20:35
@sbegaudeau
Copy link
Member

Some tests will have to be moved later

@sbegaudeau sbegaudeau merged commit 1aca131 into master Jul 19, 2024
4 checks passed
@sbegaudeau sbegaudeau deleted the fba/enh/SelectionDialog branch July 19, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A tool cannot open a selection dialog in react flow
3 participants