feat: The Big One UI #47
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
// --| Type definitions |--
|
// --| Type definitions |--
|
||||||
|
|
||||||
|
import type {FlowState} from "./VisProgTypes.tsx";
|
||||||
|
|
||||||
export type NodeId = string;
|
export type NodeId = string;
|
||||||
export type WarningType =
|
export type WarningType =
|
||||||
| 'MISSING_INPUT'
|
| '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 WarningRegistry = Map<NodeId, Map<WarningKey, EditorWarning>>;
|
||||||
export type SeverityIndex = Map<WarningSeverity, Set<{ nodeId: NodeId, warningKey: WarningKey}>>;
|
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 = {
|
export type EditorWarningRegistry = {
|
||||||
editorWarningRegistry: WarningRegistry;
|
editorWarningRegistry: WarningRegistry;
|
||||||
severityIndex: SeverityIndex;
|
severityIndex: SeverityIndex;
|
||||||
@@ -47,18 +52,13 @@ export type EditorWarningRegistry = {
|
|||||||
* registers a warning to the warningRegistry and the SeverityIndex
|
* registers a warning to the warningRegistry and the SeverityIndex
|
||||||
* @param {EditorWarning} warning
|
* @param {EditorWarning} warning
|
||||||
*/
|
*/
|
||||||
registerWarning: (
|
registerWarning: (warning: EditorWarning) => void;
|
||||||
warning: EditorWarning
|
|
||||||
) => void;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unregisters a warning from the warningRegistry and the SeverityIndex
|
* unregisters a warning from the warningRegistry and the SeverityIndex
|
||||||
* @param {EditorWarning} warning
|
* @param {EditorWarning} warning
|
||||||
*/
|
*/
|
||||||
unregisterWarning: (
|
unregisterWarning: (nodeId: NodeId, warningKey: WarningKey) => void
|
||||||
nodeId: NodeId,
|
|
||||||
warningKey: WarningKey,
|
|
||||||
) => void
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unregisters warnings from the warningRegistry and the SeverityIndex
|
* unregisters warnings from the warningRegistry and the SeverityIndex
|
||||||
@@ -69,7 +69,7 @@ export type EditorWarningRegistry = {
|
|||||||
|
|
||||||
// --| implemented logic |--
|
// --| implemented logic |--
|
||||||
|
|
||||||
export const editorWarningRegistry : EditorWarningRegistry = {
|
export function editorWarningRegistry(get: ZustandGet, set: ZustandSet) : EditorWarningRegistry {return {
|
||||||
editorWarningRegistry: new Map<NodeId, Map<WarningKey, EditorWarning>>(),
|
editorWarningRegistry: new Map<NodeId, Map<WarningKey, EditorWarning>>(),
|
||||||
severityIndex: new Map([
|
severityIndex: new Map([
|
||||||
['INFO', new Set<{ nodeId: NodeId, warningKey: WarningKey}>()],
|
['INFO', new Set<{ nodeId: NodeId, warningKey: WarningKey}>()],
|
||||||
@@ -82,10 +82,46 @@ export const editorWarningRegistry : EditorWarningRegistry = {
|
|||||||
|
|
||||||
getWarnings: () => { return []},
|
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) => {},
|
unregisterWarningsForNode: (_nodeId) => {},
|
||||||
};
|
}}
|
||||||
|
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ const useFlowStore = create<FlowState>(UndoRedo((set, get) => ({
|
|||||||
return { ruleRegistry: registry };
|
return { ruleRegistry: registry };
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
...editorWarningRegistry,
|
...editorWarningRegistry(get, set),
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user