feat: error connections
This commit is contained in:
48
frontend/src/lib/connectionStatus.ts
Normal file
48
frontend/src/lib/connectionStatus.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Connection status: visual state of an edge (color/class).
|
||||
* Priority when multiple apply: error > paused > updating > default.
|
||||
* Nodes report state via FlowContext (e.g. addConnectionPathError); edges derive status here.
|
||||
*/
|
||||
|
||||
export type ConnectionStatus = 'default' | 'updating' | 'paused' | 'error'
|
||||
|
||||
export type ConnectionStatusInputs = {
|
||||
source: string
|
||||
target: string
|
||||
pathNodeIds: Set<string>
|
||||
pausedSegmentNodeIds: Set<string>
|
||||
activeSegmentNodeIds: Set<string>
|
||||
errorTargetNodeIds: Set<string>
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the single connection status for an edge (priority: error > paused > updating > default).
|
||||
* Use in edge components; add new statuses by extending the type and adding a branch here.
|
||||
*/
|
||||
export function getConnectionStatus(inputs: ConnectionStatusInputs): ConnectionStatus {
|
||||
const { target, pathNodeIds, pausedSegmentNodeIds, activeSegmentNodeIds, errorTargetNodeIds, source } = inputs
|
||||
if (errorTargetNodeIds.has(target)) return 'error'
|
||||
if (
|
||||
pathNodeIds.has(source) &&
|
||||
pathNodeIds.has(target) &&
|
||||
pausedSegmentNodeIds.has(source) &&
|
||||
pausedSegmentNodeIds.has(target)
|
||||
)
|
||||
return 'paused'
|
||||
if (
|
||||
pathNodeIds.has(source) &&
|
||||
pathNodeIds.has(target) &&
|
||||
activeSegmentNodeIds.has(source) &&
|
||||
activeSegmentNodeIds.has(target)
|
||||
)
|
||||
return 'updating'
|
||||
return 'default'
|
||||
}
|
||||
|
||||
/** CSS class suffix for each status (animated-edge-path--{status}). */
|
||||
export const CONNECTION_STATUS_CLASS: Record<ConnectionStatus, string> = {
|
||||
default: '',
|
||||
updating: 'animated-edge-path--updating',
|
||||
paused: 'animated-edge-path--paused',
|
||||
error: 'animated-edge-path--error',
|
||||
}
|
||||
@@ -46,6 +46,12 @@ export type FlowContextValue = {
|
||||
addConnectionPathPausedNode: (nodeId: string) => void
|
||||
/** Remove this node from paused. */
|
||||
removeConnectionPathPausedNode: (nodeId: string) => void
|
||||
/** Node ids that have an error (e.g. Render node). Incoming edges show error status (red). */
|
||||
connectionPathErrorNodeIds: string[]
|
||||
/** Call when this node has an error; remove when error is cleared. */
|
||||
addConnectionPathError: (nodeId: string) => void
|
||||
/** Call when this node's error is cleared. */
|
||||
removeConnectionPathError: (nodeId: string) => void
|
||||
/** Call when a path update starts for this node. Animation runs at least CONNECTION_PATH_UPDATE_MIN_MS. */
|
||||
startConnectionPathUpdate: (nodeId: string) => void
|
||||
/** Call when a path update ends for this node. If min duration not reached, animation continues until then. */
|
||||
|
||||
Reference in New Issue
Block a user