From 67558a7ac748e6c5aa56b2450cdb29218e76cfc0 Mon Sep 17 00:00:00 2001 From: JGerla Date: Wed, 14 Jan 2026 16:04:44 +0100 Subject: [PATCH] feat: added full definition of editor warning infrastructure Everything is now defined architecturally, and can be implemented properly. ref: N25B-450 --- .../visualProgrammingUI/EditorWarnings.tsx | 95 +++++++++++++++++++ .../visualProgrammingUI/VisProgStores.tsx | 4 +- .../visualProgrammingUI/VisProgTypes.tsx | 8 +- 3 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 src/pages/VisProgPage/visualProgrammingUI/EditorWarnings.tsx diff --git a/src/pages/VisProgPage/visualProgrammingUI/EditorWarnings.tsx b/src/pages/VisProgPage/visualProgrammingUI/EditorWarnings.tsx new file mode 100644 index 0000000..54c5c11 --- /dev/null +++ b/src/pages/VisProgPage/visualProgrammingUI/EditorWarnings.tsx @@ -0,0 +1,95 @@ + + +// --| Type definitions |-- + +export type NodeId = string; +export type WarningType = + | 'MISSING_INPUT' + | 'MISSING_OUTPUT' + | string +export type WarningSeverity = + | 'INFO' // Acceptable, but probably not desirable + | 'WARNING' // Prevents running program, should be fixed before running program is allowed + + +export type EditorWarning = { + nodeId: NodeId; + type: WarningType; + severity: WarningSeverity; + description: string; + handleId?: string; +}; + +/** + * either a single warningType, or a scoped warningKey. + * + * supported-scopes: + * - `handle` + */ +export type WarningKey = + | WarningType // for warnings that can only occur once per node + | { type: WarningType, handleId: string }; // for warnings that can occur on a per-handle basis + +export type WarningRegistry = Map>; +export type SeverityIndex = Map>; + +export type EditorWarningRegistry = { + editorWarningRegistry: WarningRegistry; + severityIndex: SeverityIndex; + + getWarnings: () => EditorWarning[]; + + getWarningsBySeverity: (warningSeverity: WarningSeverity) => EditorWarning[]; + + /** + * checks if there are no warnings of breaking severity + * @returns {boolean} + */ + isProgramValid: () => boolean; + + /** + * registers a warning to the warningRegistry and the SeverityIndex + * @param {EditorWarning} warning + */ + registerWarning: ( + warning: EditorWarning + ) => void; + + /** + * unregisters a warning from the warningRegistry and the SeverityIndex + * @param {EditorWarning} warning + */ + unregisterWarning: ( + nodeId: NodeId, + warningKey: WarningKey, + ) => void + + /** + * unregisters warnings from the warningRegistry and the SeverityIndex + * @param {EditorWarning} warning + */ + unregisterWarningsForNode: (nodeId: string) => void; +} + +// --| implemented logic |-- + +export const editorWarningRegistry : EditorWarningRegistry = { + editorWarningRegistry: new Map>(), + severityIndex: new Map([ + ['INFO', new Set()], + ['WARNING', new Set()] + ]), + + getWarningsBySeverity: (_warningSeverity) => { return []}, + + isProgramValid: () => { return true}, + + getWarnings: () => { return []}, + + registerWarning: () => {}, + + unregisterWarning: () => {}, + + unregisterWarningsForNode: (_nodeId) => {}, +}; + diff --git a/src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx b/src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx index defa934..faa3f3c 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx @@ -9,6 +9,7 @@ import { type XYPosition, } from '@xyflow/react'; import '@xyflow/react/dist/style.css'; +import { editorWarningRegistry } from "./EditorWarnings.tsx"; import type { FlowState } from './VisProgTypes'; import { NodeDefaults, @@ -306,7 +307,8 @@ const useFlowStore = create(UndoRedo((set, get) => ({ }) return { ruleRegistry: registry }; }) - } + }, + ...editorWarningRegistry, })) ); diff --git a/src/pages/VisProgPage/visualProgrammingUI/VisProgTypes.tsx b/src/pages/VisProgPage/visualProgrammingUI/VisProgTypes.tsx index 8ae3cad..bf1bffd 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/VisProgTypes.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/VisProgTypes.tsx @@ -9,6 +9,7 @@ import type { OnEdgesDelete, OnNodesDelete } from '@xyflow/react'; +import type {EditorWarningRegistry} from "./EditorWarnings.tsx"; import type {HandleRule} from "./HandleRuleLogic.ts"; import type { NodeTypes } from './NodeRegistry'; import type {FlowSnapshot} from "./EditorUndoRedo.ts"; @@ -94,7 +95,7 @@ export type FlowState = { * @param node - the Node object to add */ addNode: (node: Node) => void; -} & UndoRedoState & HandleRuleRegistry; +} & UndoRedoState & HandleRuleRegistry & EditorWarningRegistry; export type UndoRedoState = { // UndoRedo Types @@ -129,4 +130,7 @@ export type HandleRuleRegistry = { // cleans up all registered rules of all handles of the provided node unregisterNodeRules: (nodeId: string) => void -} \ No newline at end of file +} + + +