fix: cast diagram layout response type to fix TS build error
The render endpoint returns a union type (SVG string | JSON object). Cast to DiagramLayout interface so .nodes is accessible. Also rename useDiagramByRoute parameter from group to application. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../client';
|
||||
|
||||
interface DiagramLayout {
|
||||
width?: number;
|
||||
height?: number;
|
||||
nodes?: Array<{ id?: string; label?: string; type?: string; x?: number; y?: number; width?: number; height?: number }>;
|
||||
edges?: Array<{ from?: string; to?: string }>;
|
||||
}
|
||||
|
||||
export function useDiagramLayout(contentHash: string | null) {
|
||||
return useQuery({
|
||||
queryKey: ['diagrams', 'layout', contentHash],
|
||||
@@ -10,22 +17,22 @@ export function useDiagramLayout(contentHash: string | null) {
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
if (error) throw new Error('Failed to load diagram layout');
|
||||
return data!;
|
||||
return data as DiagramLayout;
|
||||
},
|
||||
enabled: !!contentHash,
|
||||
});
|
||||
}
|
||||
|
||||
export function useDiagramByRoute(group: string | undefined, routeId: string | undefined) {
|
||||
export function useDiagramByRoute(application: string | undefined, routeId: string | undefined) {
|
||||
return useQuery({
|
||||
queryKey: ['diagrams', 'byRoute', group, routeId],
|
||||
queryKey: ['diagrams', 'byRoute', application, routeId],
|
||||
queryFn: async () => {
|
||||
const { data, error } = await api.GET('/diagrams', {
|
||||
params: { query: { group: group!, routeId: routeId! } },
|
||||
params: { query: { group: application!, routeId: routeId! } },
|
||||
});
|
||||
if (error) throw new Error('Failed to load diagram for route');
|
||||
return data!;
|
||||
},
|
||||
enabled: !!group && !!routeId,
|
||||
enabled: !!application && !!routeId,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user