-
Notifications
You must be signed in to change notification settings - Fork 61
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
[4348] Move quick tools declaration on the backend #4349
base: master
Are you sure you want to change the base?
Conversation
57cca5c
to
482ede5
Compare
Bug: #4348 Signed-off-by: Michaël Charfadi <[email protected]>
482ede5
to
a62964f
Compare
@@ -19,6 +19,8 @@ | |||
*/ | |||
public final class DiagramImageConstants { | |||
|
|||
public static final String HIDE_SVG = "/icons/full/obj16/HideTool.svg"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this image coming from? Do not add coupling between unrelated modules. Is that coming from the diagram view DSL? If so, sirius-components-collaborative-diagrams
can be reused with the view DSL so it cannot be referenced this way. Since I don't see any reference to this constant anywhere in sirius-components-collaborative-diagrams
, you can remove it entirely
>(updateCollapsingStateMutation); | ||
|
||
const collapseExpandElement = useCallback( | ||
async (nodeId: string, collapsingState: GQLCollapsingState) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use async not await
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it was already used so I did not change it but if there was no reason to use async I can remove it.
const { data: collapseNodeData } = await collapseExpandMutation({ variables: { input } }); | ||
if (collapseNodeData) { | ||
const { collapseExpandDiagramElement } = collapseNodeData; | ||
if (isErrorPayload(collapseExpandDiagramElement)) { | ||
addMessages(collapseExpandDiagramElement.messages); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just write this kind of code as we always do
const isSuccessPayload = (payload: GQLDeleteFromDiagramPayload): payload is GQLDeleteFromDiagramSuccessPayload => | ||
payload.__typename === 'DeleteFromDiagramSuccessPayload'; | ||
|
||
export const useDiagramDeleteMutation = (): UseDiagramDeleteMutation => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hook should probably be named useDeleteFromDiagram
to stay consistent with our naming conventions
const deleteElements = useCallback( | ||
async (nodeIds: string[], edgesId: string[], deletePocily: GQLDeletionPolicy) => { | ||
const input: GQLDeleteFromDiagramInput = { | ||
id: crypto.randomUUID(), | ||
editingContextId, | ||
representationId: diagramId, | ||
nodeIds: nodeIds, | ||
edgeIds: edgesId, | ||
deletionPolicy: deletePocily, | ||
}; | ||
|
||
const { data } = await deleteElementsMutation({ variables: { input } }); | ||
if (data) { | ||
const { deleteFromDiagram } = data; | ||
if (isErrorPayload(deleteFromDiagram) || isSuccessPayload(deleteFromDiagram)) { | ||
addMessages(deleteFromDiagram.messages); | ||
} | ||
} | ||
}, | ||
[editingContextId, diagramId, deleteElementsMutation] | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use async / await, we have tons of hooks using mutations, just do the same thing
variables, | ||
}; | ||
|
||
const { data } = await invokeSingleClickOnDiagramElementTool({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use async / await
>(invokeSingleClickOnDiagramElementToolMutation); | ||
|
||
const executeTool = useCallback( | ||
async (tool: GQLTool, variables: GQLToolVariable[]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use async / await
const { fadeDiagramElements } = useFadeDiagramElements(); | ||
const { hideDiagramElements } = useHideDiagramElements(); | ||
const { pinDiagramElements } = usePinDiagramElements(); | ||
const { collapseExpandElement } = useCollapseExpandElement(); | ||
const { deleteElements } = useDiagramDeleteMutation(); | ||
const { showDeletionConfirmation } = useDeletionConfirmationDialog(); | ||
const { invokeSingleClickTool } = useSingleClickOnDiagramElementTool({ | ||
x, | ||
y, | ||
diagramElementId, | ||
targetObjectId, | ||
onDirectEditClick, | ||
}); | ||
|
||
const { nodeLookup, edgeLookup } = useStoreApi<Node<NodeData>, Edge<EdgeData>>().getState(); | ||
const { hideDiagramPalette, setLastToolInvoked } = useDiagramPalette(); | ||
const { hideDiagramElementPalette } = useDiagramElementPalette(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that a good idea to create some coupling between all these concepts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that the coupling was already there in usePalette
.
With this PR, we start to have a hook per mutation that only do the mutation, so it can be reused anywhere and even could be exported later on.
I think we could still reduce the coupling between useInvokeTool
and usePalette
.
The palette should probably call usePalette
in order to only execute the query and useInvokeTool
to get only handleToolClick
would that be be better ? That would allow us to reuse useInvokeTool
too.
Theses changes are helpful to reduce the complexity of the code and later on merge all palettes into one so we don't have the palette in the nodes and in order to simplify the states related to the palette.
Bug: #4348
Pull request template
General purpose
What is the main goal of this pull request?
Project management
priority:
andpr:
labels been added to the pull request? (In case of doubt, start with the labelspriority: low
andpr: to review later
)area:
,difficulty:
,type:
)CHANGELOG.adoc
been updated to reference the relevant issues?CHANGELOG.adoc
? (Including changes in the GraphQL API)CHANGELOG.adoc
? For example indoc/screenshots/2022.5.0-my-new-feature.png
Architectural decision records (ADR)
[doc]
?CHANGELOG.adoc
?Dependencies
CHANGELOG.adoc
?CHANGELOG.adoc
?Frontend
This section is not relevant if your contribution does not come with changes to the frontend.
General purpose
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).
useMutation<DATA_TYPE, VARIABLE_TYPE>(…)
useQuery<DATA_TYPE, VARIABLE_TYPE>(…)
useSubscription<DATA_TYPE, VARIABLE_TYPE>(…)
useMachine<CONTEXT_TYPE, EVENTS_TYPE>(…)
useState<STATE_TYPE>(…)
?.
(if the GraphQL API specifies that a field cannot benull
, do not treat it has potentiallynull
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
Architecture
Review
How to test this PR?
Please describe here the various use cases to test this pull request