Conversation
9604791 to
b8f1359
Compare
b8f1359 to
183a512
Compare
183a512 to
75655ca
Compare
|
This version of XYFlow brings a stronger typage of nodes so we can no longer use |
CHANGELOG.adoc
Outdated
| All usage of `IDiagramContext` within Sirius Web have been replaced by `DiagramContext` for example in `IDiagramEventHandler#handle`. | ||
| The record `DiagramContext` is still implementing `IDiagramContext` for the moment and it still provides methods like `getDiagram()` or `getDiagramEvents()` but consumers of Sirius Web should switch to the new methods like `diagram()` or `diagramEvents()` as soon as possible. | ||
| - https://github.com/eclipse-sirius/sirius-web/issues/5277[#5277] [sirius-web] Update the `ProjectSearchRepositoryDelegate` to include natures along with the returned projects for `#findAll(Before|After)`. | ||
| - [releng] Since the switch to @xyflow/react 12.8.2 everything typed as `Node<NodeData, DiagramNodeType>` is now typed `Node<NodeData>` |
There was a problem hiding this comment.
Why? I don't see any trace of such change on the changelog of ReactFlow. NodeProps seems to be still typed with both NodeData and NodeType.
There was a problem hiding this comment.
This is from 12.7.0 Improve typing for Nodes
We now have this error in some files :
Argument of type 'Node<NodeData>[]' is not assignable to parameter of type 'Node<NodeData, string>[]'.
Type 'Node<NodeData>' is not assignable to type 'Node<NodeData, string>'.
Type 'Node<NodeData>' is not assignable to type '{ type: string; }'.
Types of property 'type' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
This occurs when pushing a node typed as Node<NodeData> into an array typed as Node<NodeData, string>[] for example
I think that the easiest way to fix is to get rid of Node<NodeData, string> for typing nodes
There was a problem hiding this comment.
As a note not related to the bump.
The xyflow doc recommend to type the nodes like this :
export type FreeFormNodeType = Node<
{
imageURL: string | null;
positionDependentRotation: boolean;
} & NodeData,
'freeFormNode'
>;
And to use a union type representing all types available
export type DiagramNodeType =
| FreeFormNodeType
| IconLabelNodeType
| ListNodeType
| EdgeAnchorNodeCreationHandlesType
| EdgeAnchorNodeType;
Then use this union type when possible for example like this
const store = useStoreApi<DiagramNodeType, DiagramEdgeType>();
But this is a considerable change and I was not able to make it work
There was a problem hiding this comment.
This occurs when pushing a node typed as
Node<NodeData>into an array typed asNode<NodeData, string>[]for example
I think that the easiest way to fix is to get rid ofNode<NodeData, string>for typing nodes
Why remove some typing information instead of fixing the code to ensure that we always have Node<NodeData, NodeType>?
There was a problem hiding this comment.
If we set the type of the node, this information should not be lost.
The issue is not there, the issue is that NodeType from xyflow is actually string | undefinied
See here
So with Node<NodeData> we are correctly typing like xyflow and with Node<NodeData, string> we are not
So an alternative fix would be to do :
export type DiagramNodeType = string | undefined;
export type DiagramNodeTypes = {
[key in DiagramNodeType as string]: ComponentType<NodeProps>;
};
And to replace every Node<NodeData, string> with Node<NodeData, string | undefined>
Using Node<NodeData> seems easier
There was a problem hiding this comment.
I understand that reactflow allows us to remove the type by making it optional with string | undefined, what I don't understand would be why we would like to do so since we have so much code with this type already.
In a similar fashion, React is fine with not having some type for useState and Apollo client is also fine with the lack of typing for useQuery and other hooks.
There are tons of example of TypeScript frameworks that are onboarding their consumers nicely without requiring everything to be strictly typed. In Sirius Web, we are constantly moving in a direction with additional safety checks so I don't see why, we should remove some existing typing.
75655ca to
03d9322
Compare
e2fbf77 to
5cc01fd
Compare
2364b4e to
b11c108
Compare
b11c108 to
4eaa72f
Compare
4eaa72f to
8353ec1
Compare
8353ec1 to
fd17371
Compare
8218ec5 to
d82ed46
Compare
Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com> Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
d82ed46 to
529140f
Compare
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: lowandpr: to review later)area:,difficulty:,type:)CHANGELOG.adocbeen 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.pngArchitectural 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 potentiallynullfor 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