refactor(web): remove useSandboxFilesTree and derive hasFiles in components

Migrate ArtifactsSection to queryOptions + useQuery composition and derive\nfile tree/hasFiles locally from flat data. Remove the now-unused\nuseSandboxFilesTree helper and update related tests to mock the new\nqueryOptions-based flow.
This commit is contained in:
yyh
2026-02-27 12:42:40 +08:00
parent 0bdd21bc17
commit f70d89e80b
3 changed files with 49 additions and 54 deletions

View File

@ -2,8 +2,8 @@ import type {
SandboxFileNode,
SandboxFileTreeNode,
} from '@/types/sandbox-file'
import { skipToken, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { useCallback, useMemo } from 'react'
import { skipToken, useMutation, useQueryClient } from '@tanstack/react-query'
import { useCallback } from 'react'
import { consoleClient, consoleQuery } from '@/service/client'
export function sandboxFileDownloadUrlOptions(appId: string | undefined, path: string | undefined) {
@ -93,21 +93,3 @@ export function buildTreeFromFlatList(nodes: SandboxFileNode[]): SandboxFileTree
return roots
}
export function useSandboxFilesTree(appId: string | undefined) {
const { data, isLoading, error } = useQuery(sandboxFilesTreeOptions(appId))
const treeData = useMemo(() => {
if (!data)
return undefined
return buildTreeFromFlatList(data)
}, [data])
return {
data: treeData,
flatData: data,
hasFiles: (data?.length ?? 0) > 0,
isLoading,
error,
}
}