mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 09:28:04 +08:00
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:
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user