fix weird loading state in actions (#439)
This commit is contained in:
@@ -70,6 +70,7 @@ function ScrollableActionList({
|
||||
const selected = activeIndex === index;
|
||||
return (
|
||||
<div
|
||||
key={index}
|
||||
ref={(element) => {
|
||||
refs.current[index] = element;
|
||||
}}
|
||||
|
||||
@@ -22,11 +22,12 @@ function getActionInput(action: ActionApiResponse) {
|
||||
return input;
|
||||
}
|
||||
|
||||
function useActions(
|
||||
taskId: string,
|
||||
): ReturnType<typeof useQuery<Array<Action | null>>> {
|
||||
function useActions(taskId: string): {
|
||||
data?: Array<Action>;
|
||||
isFetching: boolean;
|
||||
} {
|
||||
const credentialGetter = useCredentialGetter();
|
||||
const { data: task } = useQuery<TaskApiResponse>({
|
||||
const { data: task, isFetching: taskIsFetching } = useQuery<TaskApiResponse>({
|
||||
queryKey: ["task", taskId],
|
||||
queryFn: async () => {
|
||||
const client = await getClient(credentialGetter);
|
||||
@@ -37,40 +38,43 @@ function useActions(
|
||||
const taskIsRunningOrQueued =
|
||||
task?.status === Status.Running || task?.status === Status.Queued;
|
||||
|
||||
const useQueryReturn = useQuery<Array<Action | null>>({
|
||||
queryKey: ["task", taskId, "actions"],
|
||||
const stepsQuery = useQuery<Array<StepApiResponse>>({
|
||||
queryKey: ["task", taskId, "steps"],
|
||||
queryFn: async () => {
|
||||
const client = await getClient(credentialGetter);
|
||||
const steps = (await client
|
||||
return client
|
||||
.get(`/tasks/${taskId}/steps`)
|
||||
.then((response) => response.data)) as Array<StepApiResponse>;
|
||||
|
||||
const actions = steps.map((step) => {
|
||||
const actionsAndResults = step.output.actions_and_results;
|
||||
|
||||
const actions = actionsAndResults.map((actionAndResult, index) => {
|
||||
const action: Action = {
|
||||
reasoning: actionAndResult[0].reasoning,
|
||||
confidence: actionAndResult[0].confidence_float,
|
||||
input: getActionInput(actionAndResult[0]),
|
||||
type: actionAndResult[0].action_type,
|
||||
success: actionAndResult[1][0].success,
|
||||
stepId: step.step_id,
|
||||
index,
|
||||
};
|
||||
return action;
|
||||
});
|
||||
return actions;
|
||||
});
|
||||
|
||||
return actions.flat();
|
||||
.then((response) => response.data);
|
||||
},
|
||||
enabled: !!task,
|
||||
staleTime: taskIsRunningOrQueued ? 30 : Infinity,
|
||||
refetchOnWindowFocus: taskIsRunningOrQueued,
|
||||
});
|
||||
|
||||
return useQueryReturn;
|
||||
const actions = stepsQuery.data
|
||||
?.map((step) => {
|
||||
const actionsAndResults = step.output.actions_and_results;
|
||||
|
||||
const actions = actionsAndResults.map((actionAndResult, index) => {
|
||||
const action: Action = {
|
||||
reasoning: actionAndResult[0].reasoning,
|
||||
confidence: actionAndResult[0].confidence_float,
|
||||
input: getActionInput(actionAndResult[0]),
|
||||
type: actionAndResult[0].action_type,
|
||||
success: actionAndResult[1][0].success,
|
||||
stepId: step.step_id,
|
||||
index,
|
||||
};
|
||||
return action;
|
||||
});
|
||||
return actions;
|
||||
})
|
||||
.flat();
|
||||
|
||||
return {
|
||||
data: actions,
|
||||
isFetching: stepsQuery.isFetching || taskIsFetching,
|
||||
};
|
||||
}
|
||||
|
||||
export { useActions };
|
||||
|
||||
Reference in New Issue
Block a user