feat(FN-3955): align mesh state hook contract with topology consumers
- Change useMeshState to expose NodeMeshState[] and unwrap API snapshot nodes in refresh and polling flows - Update NodesView mesh topology rendering to consume the flattened hook result directly - Revise mesh-state and NodesView tests to validate array-based contract and topology behavior - Document the Nodes UI mesh topology contract in architecture docs Fusion-Task-Id: FN-3955
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import type { MeshClusterSnapshot } from "@fusion/core";
|
||||
import type { NodeMeshState } from "@fusion/core";
|
||||
import { fetchMeshState } from "../api";
|
||||
|
||||
const POLL_INTERVAL_MS = 10000;
|
||||
const VISIBILITY_REFRESH_DEBOUNCE_MS = 1000;
|
||||
|
||||
export interface UseMeshStateResult {
|
||||
meshState: MeshClusterSnapshot | null;
|
||||
meshState: NodeMeshState[];
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
refresh: () => Promise<void>;
|
||||
}
|
||||
|
||||
export function useMeshState(): UseMeshStateResult {
|
||||
const [meshState, setMeshState] = useState<MeshClusterSnapshot | null>(null);
|
||||
const [meshState, setMeshState] = useState<NodeMeshState[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const intervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
@@ -23,7 +23,7 @@ export function useMeshState(): UseMeshStateResult {
|
||||
try {
|
||||
setError(null);
|
||||
const data = await fetchMeshState();
|
||||
setMeshState(data);
|
||||
setMeshState(data.nodes);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : "Failed to fetch mesh state");
|
||||
}
|
||||
@@ -37,7 +37,7 @@ export function useMeshState(): UseMeshStateResult {
|
||||
try {
|
||||
const data = await fetchMeshState();
|
||||
if (!cancelled) {
|
||||
setMeshState(data);
|
||||
setMeshState(data.nodes);
|
||||
setError(null);
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user