feat: added full definition of editor warning infrastructure

Everything is now defined architecturally, and can be implemented properly.

ref: N25B-450
This commit is contained in:
JGerla
2026-01-14 16:04:44 +01:00
parent 3f7e196bb7
commit 67558a7ac7
3 changed files with 104 additions and 3 deletions

View File

@@ -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<NodeId, Map<WarningKey, EditorWarning>>;
export type SeverityIndex = Map<WarningSeverity, Set<string>>;
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<NodeId, Map<WarningKey, EditorWarning>>(),
severityIndex: new Map([
['INFO', new Set<string>()],
['WARNING', new Set<string>()]
]),
getWarningsBySeverity: (_warningSeverity) => { return []},
isProgramValid: () => { return true},
getWarnings: () => { return []},
registerWarning: () => {},
unregisterWarning: () => {},
unregisterWarningsForNode: (_nodeId) => {},
};

View File

@@ -9,6 +9,7 @@ import {
type XYPosition, type XYPosition,
} from '@xyflow/react'; } from '@xyflow/react';
import '@xyflow/react/dist/style.css'; import '@xyflow/react/dist/style.css';
import { editorWarningRegistry } from "./EditorWarnings.tsx";
import type { FlowState } from './VisProgTypes'; import type { FlowState } from './VisProgTypes';
import { import {
NodeDefaults, NodeDefaults,
@@ -306,7 +307,8 @@ const useFlowStore = create<FlowState>(UndoRedo((set, get) => ({
}) })
return { ruleRegistry: registry }; return { ruleRegistry: registry };
}) })
} },
...editorWarningRegistry,
})) }))
); );

View File

@@ -9,6 +9,7 @@ import type {
OnEdgesDelete, OnEdgesDelete,
OnNodesDelete OnNodesDelete
} from '@xyflow/react'; } from '@xyflow/react';
import type {EditorWarningRegistry} from "./EditorWarnings.tsx";
import type {HandleRule} from "./HandleRuleLogic.ts"; import type {HandleRule} from "./HandleRuleLogic.ts";
import type { NodeTypes } from './NodeRegistry'; import type { NodeTypes } from './NodeRegistry';
import type {FlowSnapshot} from "./EditorUndoRedo.ts"; import type {FlowSnapshot} from "./EditorUndoRedo.ts";
@@ -94,7 +95,7 @@ export type FlowState = {
* @param node - the Node object to add * @param node - the Node object to add
*/ */
addNode: (node: Node) => void; addNode: (node: Node) => void;
} & UndoRedoState & HandleRuleRegistry; } & UndoRedoState & HandleRuleRegistry & EditorWarningRegistry;
export type UndoRedoState = { export type UndoRedoState = {
// UndoRedo Types // UndoRedo Types
@@ -129,4 +130,7 @@ export type HandleRuleRegistry = {
// cleans up all registered rules of all handles of the provided node // cleans up all registered rules of all handles of the provided node
unregisterNodeRules: (nodeId: string) => void unregisterNodeRules: (nodeId: string) => void
} }