Add experiment logs to the monitoring page #48
95
src/pages/VisProgPage/visualProgrammingUI/EditorWarnings.tsx
Normal file
95
src/pages/VisProgPage/visualProgrammingUI/EditorWarnings.tsx
Normal 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) => {},
|
||||||
|
};
|
||||||
|
|
||||||
@@ -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,
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -130,3 +131,6 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user