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

[3763] Implements the Selection Dialog TreeView #3870

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

florianbarbin
Copy link
Contributor

@florianbarbin florianbarbin commented Aug 19, 2024

Bug: #3763

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 both :
    testSelectionDialogModel.zip
    TestSelectionDialogStudio.zip

  • Open the diagram in testSelectionDialogModel

  • Use the selection tool

  • Select an existing element (only entity1 are selectable)

  • 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.9.0 milestone Aug 19, 2024
@florianbarbin florianbarbin force-pushed the fba/enh/implementTreeViewSelectionDialog branch from c2a90ac to 0e467aa Compare August 19, 2024 14:20
@florianbarbin florianbarbin force-pushed the fba/enh/treeViewForSelectionDialog branch from af8ac8a to c59f3a4 Compare August 19, 2024 14:25
@florianbarbin florianbarbin force-pushed the fba/enh/implementTreeViewSelectionDialog branch from 0e467aa to 91e4ae5 Compare August 19, 2024 14:26
@florianbarbin florianbarbin force-pushed the fba/enh/implementTreeViewSelectionDialog branch from 91e4ae5 to 45307c2 Compare August 19, 2024 15:37
@florianbarbin florianbarbin force-pushed the fba/enh/treeViewForSelectionDialog branch from c59f3a4 to dd123a8 Compare August 20, 2024 08:02
@florianbarbin florianbarbin force-pushed the fba/enh/implementTreeViewSelectionDialog branch from 45307c2 to f27aab5 Compare August 20, 2024 08:03
Copy link
Contributor

@AxelRICHARD AxelRICHARD left a comment

Choose a reason for hiding this comment

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

The coverage code fails. You should add some tests.
With this PR, it is not possible anymore to create a SelectionDialog with a list. Only trees are available. I didn't remember we talked about removing the support of the list to let only trees.
Furthermore, In the case we have decided that we only support trees in SelectionDialog, what about existing SelectionDialog with list? It seems they are not migrated.

@florianbarbin
Copy link
Contributor Author

The coverage code fails. You should add some tests. With this PR, it is not possible anymore to create a SelectionDialog with a list. Only trees are available. I didn't remember we talked about removing the support of the list to let only trees. Furthermore, In the case we have decided that we only support trees in SelectionDialog, what about existing SelectionDialog with list? It seems they are not migrated.

Yes I know about the code coverage. I see what I can do but for the selection.graphql module it will be complicated to retrieve 100%

About the Tree, we discussed it with Stephane (the ADR will be updated). And we decided to keep only the Tree since if we want a flat list, we can just provide all elements as roots.
Normally, the migration from the previous commit should do the job to keep the existing SelectionDialog running.

@AxelRICHARD
Copy link
Contributor

The coverage code fails. You should add some tests. With this PR, it is not possible anymore to create a SelectionDialog with a list. Only trees are available. I didn't remember we talked about removing the support of the list to let only trees. Furthermore, In the case we have decided that we only support trees in SelectionDialog, what about existing SelectionDialog with list? It seems they are not migrated.

Yes I know about the code coverage. I see what I can do but for the selection.graphql module it will be complicated to retrieve 100%

About the Tree, we discussed it with Stephane (the ADR will be updated). And we decided to keep only the Tree since if we want a flat list, we can just provide all elements as roots. Normally, the migration from the previous commit should do the job to keep the existing SelectionDialog running.

Ok to let only the tree in this case, but it seems the migration does not work.

@florianbarbin
Copy link
Contributor Author

Ok to let only the tree in this case, but it seems the migration does not work.

Ok I will have a look.

@florianbarbin florianbarbin force-pushed the fba/enh/implementTreeViewSelectionDialog branch 3 times, most recently from a37c36e to 539f83d Compare August 21, 2024 14:47
@florianbarbin florianbarbin force-pushed the fba/enh/treeViewForSelectionDialog branch from dd123a8 to 251994c Compare August 21, 2024 14:48
@florianbarbin florianbarbin force-pushed the fba/enh/implementTreeViewSelectionDialog branch 4 times, most recently from c4cb422 to 92bc756 Compare August 23, 2024 06:11
@sbegaudeau sbegaudeau force-pushed the fba/enh/treeViewForSelectionDialog branch from 251994c to eb4c34b Compare August 26, 2024 09:27
Base automatically changed from fba/enh/treeViewForSelectionDialog to master August 26, 2024 09:50
@sbegaudeau sbegaudeau force-pushed the fba/enh/implementTreeViewSelectionDialog branch from 92bc756 to b6e8baf Compare August 26, 2024 10:25
@sbegaudeau
Copy link
Member

I've rebased the PR to prepare its review, I'll try to review it this afternoon

@florianbarbin florianbarbin force-pushed the fba/enh/implementTreeViewSelectionDialog branch 6 times, most recently from 6e5bf9e to 56eeef2 Compare September 5, 2024 15:27
@florianbarbin florianbarbin force-pushed the fba/enh/implementTreeViewSelectionDialog branch 2 times, most recently from 665d5ad to 94f530d Compare September 11, 2024 13:23
@sbegaudeau sbegaudeau modified the milestones: 2024.9.0, 2024.11.0 Sep 11, 2024
@florianbarbin florianbarbin force-pushed the fba/enh/implementTreeViewSelectionDialog branch 3 times, most recently from 7a07b30 to 36df83b Compare September 12, 2024 21:12
@sbegaudeau sbegaudeau force-pushed the fba/enh/implementTreeViewSelectionDialog branch from 36df83b to bdb118c Compare September 16, 2024 19:48
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 perform the minor changes necessary and update the PR to merge it

*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
Copy link
Member

Choose a reason for hiding this comment

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

Wrong location for this class, this is not an API and this is related to diagrams

Copy link
Member

Choose a reason for hiding this comment

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

Done

Comment on lines 206 to 218
private Boolean hasChildren(AQLInterpreter interpreter, SelectionDialogTreeDescription selectionDialogTreeDescription, VariableManager variableManager, Function<VariableManager, Boolean> isSelectableProvider) {
boolean hasChildren = false;
Object self = variableManager.getVariables().get(VariableManager.SELF);
hasChildren = !this.computeChildrenFromExpression(variableManager, interpreter, selectionDialogTreeDescription).isEmpty();
return hasChildren && this.hasCompatibleDescendants(interpreter, selectionDialogTreeDescription, variableManager, self, false, isSelectableProvider);
}

private boolean hasCompatibleDescendants(AQLInterpreter interpreter, SelectionDialogTreeDescription selectionDialogTreeDescription, VariableManager variableManager, Object object, boolean isDescendant, Function<VariableManager, Boolean> isSelectableProvider) {
VariableManager childVariableManager = variableManager.createChild();
childVariableManager.put(VariableManager.SELF, object);
return isDescendant && isSelectableProvider.apply(childVariableManager)
|| this.computeChildrenFromExpression(childVariableManager, interpreter, selectionDialogTreeDescription).stream().anyMatch(eContent -> this.hasCompatibleDescendants(interpreter, selectionDialogTreeDescription, childVariableManager, eContent, true, isSelectableProvider));
}
Copy link
Member

Choose a reason for hiding this comment

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

This is MASSIVELY expensive for something which shouldn't be. You can't start recursively navigating the whole editing context like that and certainly not simply to answer the question "hasChildren". If the specifier choses to display useless data in the dialog that's their choice not ours.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So for you it is the specifier responsibility to define this rules?
It can be complicated to implement in the studio

Copy link
Member

@sbegaudeau sbegaudeau Sep 17, 2024

Choose a reason for hiding this comment

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

Let's consider the following tree:

- A
  - B
    - C
      - D
        - E
          - F (with 1 million elements under F)

For every semantic change in the workbench, for each tree item displayed (here A, B, C, D, E, F) we will execute hasChildren (so 6 times per refresh) which will each perform an eAllContents on the whole tree just because we want to be smarter than the specifier who has told us to display something by trying to not display potentially useless stuff. That's a massive performance penalty for everybody on the whole project just because ONE person has opened the selection dialog.

If the specifier tells us to display something, we display it. I can understand the intention behind this feature but we can't accept such a performance it for something like that. On top of it, I disagree with the need for such feature. One may need to see the children of an element in order to decide which one should be selected. I don't see why we should decide to hide something that the specifier has explicitly told us to display thanks to the childrenExpression. If the specifiers wants to perform eAllContents everywhere that's their choice not ours.

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 understand the arguments. For information, I used the same logic we already have in org.eclipse.sirius.components.collaborative.widget.reference.browser.ModelBrowsersDescriptionProvider.

Copy link
Member

Choose a reason for hiding this comment

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

(●__● )

In that case, I may have missed something there. I'll look into it...

( `▽´)Ψ

Copy link
Member

Choose a reason for hiding this comment

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

FWIW this behavior in ModelBrowsersDescriptionProvider was added explicitly via #2171 (commit a76a04b). I wrote the issue (and PR), but form what I remember this was originally from user feedback on the first version.

Comment on lines 80 to 82
<artifactId>
sirius-components-collaborative-trees
</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

Should be on one line

Copy link
Member

Choose a reason for hiding this comment

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

Done

if (input instanceof SelectionDescriptionMessageInput selectionDescriptionMessageInput) {
String targetObjectId = selectionDescriptionMessageInput.targetObjectId();
Optional<Object> optionalTargetObject = this.objectService.getObject(editingContext, targetObjectId);
if (optionalTargetObject.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

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

You still need to emit a payload in all cases, including if we do not enter the "if"

Comment on lines 53 to 58
if (!loading && selectionDescription) {
setState((prevState) => ({
...prevState,
message: selectionDescription.message,
treeDescriptionId: selectionDescription.treeDescription.id,
}));
Copy link
Member

Choose a reason for hiding this comment

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

I'll look a bit more into the code but you don't seems to need a state and useEffect just for that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, it just a query so the component will be rerender a soon as we receive the data ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

@@ -80,59 +31,48 @@ export const SelectionDialog = ({
onClose,
onFinish,
}: DiagramDialogComponentProps) => {
const { classes } = useSelectionObjectModalStyles();
const initialState: DiagramDialogState = {
Copy link
Member

Choose a reason for hiding this comment

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

SelectionDialogState

Copy link
Member

Choose a reason for hiding this comment

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

Done

targetObjectId: string;
}

export interface SelectionDescription {
Copy link
Member

Choose a reason for hiding this comment

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

GQLSelectionDescription to keep indicating that this type comes from the backend

Copy link
Member

Choose a reason for hiding this comment

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

Done

treeDescription: TreeDescription;
}

export interface TreeDescription {
Copy link
Member

Choose a reason for hiding this comment

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

GQLTreeDescription

Copy link
Member

Choose a reason for hiding this comment

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

Done

Comment on lines 23 to 24
treeDescriptionId: string;
message: string;
Copy link
Member

Choose a reason for hiding this comment

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

string or null to properly identify that you don't have the relevant data. Your code only works because if(aVariableContainingAnEmptyString) evaluates to false and it does not enter the if. That's a very narrow assumption that empty string equals false.

Copy link
Member

Choose a reason for hiding this comment

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

And you probably don't need this in the state too

Copy link
Member

Choose a reason for hiding this comment

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

The state and the useEffect were indeed not needed

const useTreeStyle = makeStyles()((theme) => ({
borderStyle: {
border: '1px solid',
borderColor: theme.palette.grey[500],
Copy link
Member

Choose a reason for hiding this comment

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

theme.palette.divider to stay with the same style as the rest of the application

Copy link
Member

Choose a reason for hiding this comment

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

Done

Comment on lines 277 to 285
result.removeIf(object -> {
if (object instanceof EObject eObject) {
VariableManager childVariableManager = variableManager.createChild();
childVariableManager.put(VariableManager.SELF, eObject);
return !isSelectableProvider.apply(childVariableManager) && !this.hasChildren(interpreter, selectionDialogTreeDescription, childVariableManager, isSelectableProvider);
} else {
return false;
}
});
Copy link
Member

Choose a reason for hiding this comment

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

You can't decide that, let the specifiers display what they want. And you can't decide that without the MASSIVE performance impact from before.

Copy link
Member

Choose a reason for hiding this comment

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

Done

@sbegaudeau
Copy link
Member

I'll wait for the build, squash the commits and merge the PR

@sbegaudeau sbegaudeau force-pushed the fba/enh/implementTreeViewSelectionDialog branch from 3729fad to 1d4158d Compare September 17, 2024 08:51
@sbegaudeau
Copy link
Member

I'll wait for the build and merge it 👍

@sbegaudeau sbegaudeau merged commit c03981c into master Sep 17, 2024
4 checks passed
@sbegaudeau sbegaudeau deleted the fba/enh/implementTreeViewSelectionDialog branch September 17, 2024 09:06
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.

Make it possible to display the content of the Selection Dialog using a tree viewer
4 participants