handreyrc commented on code in PR #3252: URL: https://github.com/apache/incubator-kie-tools/pull/3252#discussion_r2344577158
########## packages/swf-editor/src/store/Store.ts: ########## @@ -0,0 +1,304 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { enableMapSet, immerable } from "immer"; +import * as RF from "reactflow"; +import { create } from "zustand"; +import { immer } from "zustand/middleware/immer"; +import { SwfDiagramNodeData } from "../diagram/nodes/SwfNodes"; +import { ComputedStateCache } from "./ComputedStateCache"; +import { computeDiagramData } from "./computed/computeDiagramData"; +import { computeIndexedSwf } from "./computed/computeIndexes"; +import { computeIsDropTargetNodeValidForSelection } from "./computed/computeIsDropTargetNodeValidForSelection"; +import { DEFAULT_VIEWPORT } from "../diagram/Diagram"; + +import { Specification } from "@severlessworkflow/sdk-typescript"; + +enableMapSet(); // Necessary because `Computed` has a lot of Maps and Sets. + +export interface SwfEditorDiagramNodeStatus { + selected: boolean; + dragging: boolean; +} + +export interface SwfEditorDiagramEdgeStatus { + selected: boolean; + draggingWaypoint: boolean; +} + +export interface SnapGrid { + isEnabled: boolean; + x: number; + y: number; +} + +export type DropTargetNode = undefined | RF.Node<SwfDiagramNodeData>; + +export interface State { + dispatch: (s: State) => Dispatch; + computed: (s: State) => Computed; + layout: (s: State) => Layout; + swf: { model: Specification.Workflow }; + focus: { + consumableId: string | undefined; + }; + diagram: { + autoLayout: { + canAutoGenerate: boolean; + }; + __unsafeSwfIndex: number; + edgeIdBeingUpdated: string | undefined; + dropTargetNode: DropTargetNode; + ongoingConnection: RF.OnConnectStartParams | undefined; + overlaysPanel: { + isOpen: boolean; + }; + overlays: { + enableNodeHierarchyHighlight: boolean; + enableCustomNodeStyles: boolean; + enableEvaluationHighlights: boolean; + }; + snapGrid: SnapGrid; + nodesPosition: NodesPosition; + edgesWaypoints: EdgesWaypoints; + _selectedNodes: Array<string>; + _selectedEdges: Array<string>; + draggingNodes: Array<string>; + draggingWaypoints: Array<string>; + isEditingStyle: boolean; + viewport: { + x: number; + y: number; + zoom: number; + }; + }; +} + +// Read this to understand why we need computed as part of the store. +// https://github.com/pmndrs/zustand/issues/132#issuecomment-1120467721 +export type Computed = { + isDiagramEditingInProgress(): boolean; + + indexedSwf(): ReturnType<typeof computeIndexedSwf>; + + getDiagramData(requiresLayout?: boolean): ReturnType<typeof computeDiagramData>; + + isDropTargetNodeValidForSelection(): boolean; +}; + +//Handle layout data out of the model +export type Layout = { + setNodePosition: (nodeId: string, newPosition: RF.XYPosition | undefined) => void; + setEdgeWaypoints: (edgeId: string, newWaypoints: RF.XYPosition[] | undefined) => void; + updateWaypointPosition: (edgeId: string, index: number, newPosition: RF.XYPosition | undefined) => void; +}; + +export class NodesPosition { + // Handle node position out of the model + [immerable] = false; Review Comment: @tiagobento It's part of the same problem with the SDK. It is something we can do in the next interations. Do you think we can move forward with it and then address it later? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
