From 9cca8118c0f46d1aa018df4bd420f6c63ec02b46 Mon Sep 17 00:00:00 2001 From: Artem Golub Date: Wed, 13 Jul 2022 17:03:35 +0300 Subject: [PATCH] feat: add volume node type --- .../frontend/src/components/useJsPlumb.ts | 29 +++++++++---------- services/frontend/src/types/index.ts | 6 ++++ services/frontend/src/utils/data/libraries.ts | 9 ++++++ services/frontend/src/utils/options.ts | 2 +- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/services/frontend/src/components/useJsPlumb.ts b/services/frontend/src/components/useJsPlumb.ts index bf54b33..19a3824 100644 --- a/services/frontend/src/components/useJsPlumb.ts +++ b/services/frontend/src/components/useJsPlumb.ts @@ -1,5 +1,5 @@ import { useState, useEffect, useRef, useCallback } from "react"; -import { AnchorId } from "@jsplumb/common"; +import { AnchorId, AnchorLocations } from "@jsplumb/common"; import { BeforeDropParams, Connection, @@ -28,12 +28,12 @@ import { } from "../utils/options"; import eventBus from "../events/eventBus"; import { getConnections } from "../utils"; -import { IServiceNodeItem } from "../types"; +import { IServiceNodeItem, IVolumeNodeItem } from "../types"; import { Dictionary, isEqual } from "lodash"; import { IAnchor, CallbackFunction } from "../types"; export const useJsPlumb = ( - nodes: Dictionary, + nodes: Dictionary, connections: Array<[string, string]>, onGraphUpdate: CallbackFunction, onNodeUpdate: CallbackFunction, @@ -47,7 +47,7 @@ export const useJsPlumb = ( ] => { const [instance, setInstance] = useState(null as any); const containerRef = useRef(); - const stateRef = useRef>(); + const stateRef = useRef>(); const instanceRef = useRef(); stateRef.current = nodes; instanceRef.current = instance; @@ -65,12 +65,15 @@ export const useJsPlumb = ( targetAnchors: IAnchor[], maxConnections: number ) => { + if (sourceAnchors.length === 0 && targetAnchors.length === 0) { + instance.addEndpoint(el, { + endpoint: "Blank" + }); + } + sourceAnchors.forEach((x) => { const endpoint = sourceEndpoint; endpoint.maxConnections = maxConnections; - - // arrow overlay for connector to specify - // it's dependency on another service instance.addEndpoint(el, endpoint, { anchor: [ [1, 0.6, 1, 0], @@ -83,8 +86,8 @@ export const useJsPlumb = ( { type: "PlainArrow", options: { - width: 16, - length: 16, + width: 12, + length: 12, location: 1, id: "arrow" } @@ -96,14 +99,8 @@ export const useJsPlumb = ( targetAnchors.forEach((x) => { const endpoint = targetEndpoint; endpoint.maxConnections = maxConnections; - instance.addEndpoint(el, endpoint, { - anchor: [ - [0, 0.4, -1, 0], - [0.4, 1, 0, 1], - [1, 0.4, 1, 0], - [0.4, 0, 0, -1] - ], + anchor: AnchorLocations.AutoDefault, uuid: x.id }); }); diff --git a/services/frontend/src/types/index.ts b/services/frontend/src/types/index.ts index 3ff542f..59df95a 100644 --- a/services/frontend/src/types/index.ts +++ b/services/frontend/src/types/index.ts @@ -335,6 +335,12 @@ export interface IServiceNodeItem extends INodeItem { serviceConfig: Partial; } +export interface IVolumeNodeItem extends INodeItem { + outputs: string[]; + canvasConfig: ICanvasConfig; + volumeConfig: Partial; +} + export interface IProjectPayload { name: string; data: { diff --git a/services/frontend/src/utils/data/libraries.ts b/services/frontend/src/utils/data/libraries.ts index e4e9719..588d622 100644 --- a/services/frontend/src/utils/data/libraries.ts +++ b/services/frontend/src/utils/data/libraries.ts @@ -15,6 +15,15 @@ export const nodeLibraries: INodeGroup[] = [ noInputs: 1, noOutputs: 1, isActive: true + }, + { + id: 2, + name: "volume", + type: "VOLUME", + description: "Volume node", + noInputs: 0, + noOutputs: 0, + isActive: true } ] } diff --git a/services/frontend/src/utils/options.ts b/services/frontend/src/utils/options.ts index a31998d..2fbe77f 100644 --- a/services/frontend/src/utils/options.ts +++ b/services/frontend/src/utils/options.ts @@ -28,7 +28,7 @@ export const sourceEndpoint: EndpointOptions = { endpoint: { type: DotEndpoint.type, options: { - radius: 6 + radius: 8 } }, paintStyle: {