From f174623a4c67527c17af074110ee66a1f5dd8493 Mon Sep 17 00:00:00 2001 From: JGerla Date: Wed, 14 Jan 2026 16:46:50 +0100 Subject: [PATCH] feat: implemented basic add and remove functions ref: N25B-450 --- .../visualProgrammingUI/EditorWarnings.tsx | 58 +++++++++++++++---- .../visualProgrammingUI/VisProgStores.tsx | 2 +- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/pages/VisProgPage/visualProgrammingUI/EditorWarnings.tsx b/src/pages/VisProgPage/visualProgrammingUI/EditorWarnings.tsx index 65f8e6c..7ecde38 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/EditorWarnings.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/EditorWarnings.tsx @@ -2,6 +2,8 @@ // --| Type definitions |-- +import type {FlowState} from "./VisProgTypes.tsx"; + export type NodeId = string; export type WarningType = | 'MISSING_INPUT' @@ -29,6 +31,9 @@ export type WarningKey = { type: WarningType, handleId: string | null }; // for export type WarningRegistry = Map>; export type SeverityIndex = Map>; +type ZustandSet = (partial: Partial | ((state: FlowState) => Partial)) => void; +type ZustandGet = () => FlowState; + export type EditorWarningRegistry = { editorWarningRegistry: WarningRegistry; severityIndex: SeverityIndex; @@ -47,18 +52,13 @@ export type EditorWarningRegistry = { * registers a warning to the warningRegistry and the SeverityIndex * @param {EditorWarning} warning */ - registerWarning: ( - warning: EditorWarning - ) => void; + registerWarning: (warning: EditorWarning) => void; /** * unregisters a warning from the warningRegistry and the SeverityIndex * @param {EditorWarning} warning */ - unregisterWarning: ( - nodeId: NodeId, - warningKey: WarningKey, - ) => void + unregisterWarning: (nodeId: NodeId, warningKey: WarningKey) => void /** * unregisters warnings from the warningRegistry and the SeverityIndex @@ -69,7 +69,7 @@ export type EditorWarningRegistry = { // --| implemented logic |-- -export const editorWarningRegistry : EditorWarningRegistry = { +export function editorWarningRegistry(get: ZustandGet, set: ZustandSet) : EditorWarningRegistry {return { editorWarningRegistry: new Map>(), severityIndex: new Map([ ['INFO', new Set<{ nodeId: NodeId, warningKey: WarningKey}>()], @@ -82,10 +82,46 @@ export const editorWarningRegistry : EditorWarningRegistry = { getWarnings: () => { return []}, - registerWarning: () => {}, + registerWarning: (warning) => { + const { nodeId, type, severity, handleId } = warning; + const warningKey = handleId ? { type, handleId } : { type, handleId: null}; + const wRegistry = get().editorWarningRegistry; + const sIndex = get().severityIndex; - unregisterWarning: () => {}, + // add to registry + if (!wRegistry.has(nodeId)) { + wRegistry.set(nodeId, new Map()); + } + wRegistry.get(nodeId)!.set(warningKey, warning); + + // add to severityIndex + sIndex.get(severity)!.add({nodeId,warningKey}); + + set({ + editorWarningRegistry: wRegistry, + severityIndex: sIndex + }) + }, + + unregisterWarning: (nodeId, warningKey) => { + + const wRegistry = get().editorWarningRegistry; + const sIndex = get().severityIndex; + + const warning = wRegistry.get(nodeId)!.get(warningKey); + // remove from registry + wRegistry.get(nodeId)!.delete(warningKey); + + + // remove from severityIndex + sIndex.get(warning!.severity)!.delete({nodeId,warningKey}); + + set({ + editorWarningRegistry: wRegistry, + severityIndex: sIndex + }) + }, unregisterWarningsForNode: (_nodeId) => {}, -}; +}} diff --git a/src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx b/src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx index faa3f3c..570d0df 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx @@ -308,7 +308,7 @@ const useFlowStore = create(UndoRedo((set, get) => ({ return { ruleRegistry: registry }; }) }, - ...editorWarningRegistry, + ...editorWarningRegistry(get, set), })) );