fix: cast diagram layout response type to fix TS build error
Some checks failed
CI / build (push) Successful in 1m13s
CI / cleanup-branch (push) Has been skipped
CI / docker (push) Successful in 53s
CI / deploy-feature (push) Has been skipped
CI / deploy (push) Failing after 1m16s

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:
hsiegeln
2026-03-23 21:25:36 +01:00
parent 6a5dba4eba
commit 826466aa55

View File

@@ -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,
});
}