mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-15 06:09:35 +02:00
* fix(api): use instance_id in deleteCloudRuntimeNode body Fleet API requires instance_id, not id. Fixes 'instance_id is required' error. MUL-2510 Co-authored-by: multica-agent <github@multica.ai> * fix(ui): pass node.instance_id instead of node.id to deleteNode mutation Fleet expects the actual AWS instance_id (e.g. i-0123456789abcdef0), not the internal DB id. Updated the mutate call in cloud-runtime-dialog to pass node.instance_id so the correct value reaches Fleet's DELETE /api/v1/nodes endpoint. Co-authored-by: multica-agent <github@multica.ai> * fix: pass node.instance_id and rename param to instanceId - cloud-runtime-dialog.tsx: deleteNode.mutate(node.instance_id) - client.ts: rename nodeId param to instanceId - cloud-runtime.ts: rename nodeId param to instanceId - client.test.ts: use i-0123456789abcdef0 test value Co-authored-by: multica-agent <github@multica.ai> * fix: update test description from 'node id' to 'instance id' Co-authored-by: multica-agent <github@multica.ai> --------- Co-authored-by: multica-agent <github@multica.ai>
92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
import { queryOptions, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import { api } from "../api";
|
|
|
|
export interface CloudRuntimeNode {
|
|
id: string;
|
|
owner_id: string;
|
|
instance_id: string;
|
|
region: string;
|
|
instance_type: string;
|
|
image_id: string;
|
|
subnet_id: string;
|
|
name: string;
|
|
status: string;
|
|
tags: Record<string, string>;
|
|
metadata: Record<string, unknown>;
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
export interface ListCloudRuntimeNodesParams {
|
|
limit?: number;
|
|
offset?: number;
|
|
}
|
|
|
|
export interface CreateCloudRuntimeNodeRequest {
|
|
instance_type: string;
|
|
name?: string;
|
|
region?: string;
|
|
image_id?: string;
|
|
subnet_id?: string;
|
|
key_name?: string;
|
|
iam_instance_profile?: string;
|
|
disk_size_gb?: number;
|
|
tags?: Record<string, string>;
|
|
}
|
|
|
|
export const cloudRuntimeKeys = {
|
|
all: (wsId: string) => ["cloud-runtime", wsId] as const,
|
|
nodes: (wsId: string) => [...cloudRuntimeKeys.all(wsId), "nodes"] as const,
|
|
};
|
|
|
|
const PENDING_NODE_STATUSES = new Set([
|
|
"launching",
|
|
"pending",
|
|
"starting",
|
|
"stopping",
|
|
"rebooting",
|
|
"terminating",
|
|
]);
|
|
|
|
export function isCloudRuntimeNodePending(status: string): boolean {
|
|
return PENDING_NODE_STATUSES.has(status.toLowerCase());
|
|
}
|
|
|
|
export function cloudRuntimeNodeListOptions(
|
|
wsId: string,
|
|
params?: ListCloudRuntimeNodesParams,
|
|
) {
|
|
const limit = params?.limit ?? 20;
|
|
const offset = params?.offset ?? 0;
|
|
return queryOptions({
|
|
queryKey: [...cloudRuntimeKeys.nodes(wsId), { limit, offset }] as const,
|
|
queryFn: () => api.listCloudRuntimeNodes({ limit, offset }),
|
|
refetchInterval: (query) =>
|
|
query.state.data?.some((node) => isCloudRuntimeNodePending(node.status))
|
|
? 5000
|
|
: false,
|
|
staleTime: 15 * 1000,
|
|
});
|
|
}
|
|
|
|
export function useCreateCloudRuntimeNode(wsId: string) {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (data: CreateCloudRuntimeNodeRequest) =>
|
|
api.createCloudRuntimeNode(data),
|
|
onSettled: () => {
|
|
qc.invalidateQueries({ queryKey: cloudRuntimeKeys.all(wsId) });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteCloudRuntimeNode(wsId: string) {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (instanceId: string) => api.deleteCloudRuntimeNode(instanceId),
|
|
onSettled: () => {
|
|
qc.invalidateQueries({ queryKey: cloudRuntimeKeys.all(wsId) });
|
|
},
|
|
});
|
|
}
|