feat: The Big One UI #47
@@ -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<NodeId, Map<WarningKey, EditorWarning>>;
|
||||
export type SeverityIndex = Map<WarningSeverity, Set<{ nodeId: NodeId, warningKey: WarningKey}>>;
|
||||
|
||||
type ZustandSet = (partial: Partial<FlowState> | ((state: FlowState) => Partial<FlowState>)) => 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<NodeId, Map<WarningKey, EditorWarning>>(),
|
||||
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) => {},
|
||||
};
|
||||
}}
|
||||
|
||||
|
||||
@@ -308,7 +308,7 @@ const useFlowStore = create<FlowState>(UndoRedo((set, get) => ({
|
||||
return { ruleRegistry: registry };
|
||||
})
|
||||
},
|
||||
...editorWarningRegistry,
|
||||
...editorWarningRegistry(get, set),
|
||||
}))
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user