mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 11:04:27 +08:00
chore(web): mock data of snippet
This commit is contained in:
parent
abedf2506f
commit
559d326cbd
@ -9,6 +9,7 @@ import {
|
|||||||
buildSnippetDetailPayload,
|
buildSnippetDetailPayload,
|
||||||
useSnippetApiDetail,
|
useSnippetApiDetail,
|
||||||
} from '@/service/use-snippets'
|
} from '@/service/use-snippets'
|
||||||
|
import { getSnippetDetailMock } from '@/service/use-snippets.mock'
|
||||||
|
|
||||||
const normalizeNodesDefaultConfigs = (nodesDefaultConfigs: unknown) => {
|
const normalizeNodesDefaultConfigs = (nodesDefaultConfigs: unknown) => {
|
||||||
if (!nodesDefaultConfigs || typeof nodesDefaultConfigs !== 'object')
|
if (!nodesDefaultConfigs || typeof nodesDefaultConfigs !== 'object')
|
||||||
@ -57,19 +58,25 @@ export const useSnippetInit = (snippetId: string) => {
|
|||||||
workflowStore.getState().setPublishedAt(publishedWorkflow.created_at)
|
workflowStore.getState().setPublishedAt(publishedWorkflow.created_at)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const mockData = useMemo(() => getSnippetDetailMock(snippetId), [snippetId])
|
||||||
|
const shouldUseMockData = !snippetApiDetail.isLoading && !snippetApiDetail.data && !!mockData
|
||||||
|
|
||||||
const data = useMemo(() => {
|
const data = useMemo(() => {
|
||||||
if (snippetApiDetail.data && !draftWorkflowQuery.isLoading)
|
if (snippetApiDetail.data && !draftWorkflowQuery.isLoading)
|
||||||
return buildSnippetDetailPayload(snippetApiDetail.data, draftWorkflowQuery.data)
|
return buildSnippetDetailPayload(snippetApiDetail.data, draftWorkflowQuery.data)
|
||||||
|
|
||||||
|
if (shouldUseMockData)
|
||||||
|
return mockData
|
||||||
|
|
||||||
if (snippetApiDetail.error && isNotFoundError(snippetApiDetail.error))
|
if (snippetApiDetail.error && isNotFoundError(snippetApiDetail.error))
|
||||||
return null
|
return null
|
||||||
|
|
||||||
return undefined
|
return undefined
|
||||||
}, [draftWorkflowQuery.data, draftWorkflowQuery.isLoading, snippetApiDetail.data, snippetApiDetail.error])
|
}, [draftWorkflowQuery.data, draftWorkflowQuery.isLoading, mockData, shouldUseMockData, snippetApiDetail.data, snippetApiDetail.error])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...snippetApiDetail,
|
...snippetApiDetail,
|
||||||
data,
|
data,
|
||||||
isLoading: snippetApiDetail.isLoading || draftWorkflowQuery.isLoading,
|
isLoading: shouldUseMockData ? false : snippetApiDetail.isLoading || draftWorkflowQuery.isLoading,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,18 @@ export const getSnippetListMock = (): SnippetListItem[] => ([
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const createSnippetMock = (snippetId: string): SnippetListItem => ({
|
||||||
|
id: snippetId,
|
||||||
|
name: 'Tone Rewriter',
|
||||||
|
description: 'Rewrites rough drafts into a concise, professional tone for internal stakeholder updates.',
|
||||||
|
author: 'Evan',
|
||||||
|
updatedAt: 'Updated 2h ago',
|
||||||
|
usage: 'Used 19 times',
|
||||||
|
icon: '🪄',
|
||||||
|
iconBackground: '#E0EAFF',
|
||||||
|
status: 'Draft',
|
||||||
|
})
|
||||||
|
|
||||||
const getSnippetInputFieldsMock = (): SnippetInputField[] => ([
|
const getSnippetInputFieldsMock = (): SnippetInputField[] => ([
|
||||||
{
|
{
|
||||||
type: PipelineInputVarType.textInput,
|
type: PipelineInputVarType.textInput,
|
||||||
@ -175,11 +187,12 @@ const getSnippetGraphMock = (): SnippetDetailPayload['graph'] => ({
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
const getSnippetDetailMock = (snippetId: string): SnippetDetailPayload | null => {
|
export const getSnippetDetailMock = (snippetId: string): SnippetDetailPayload | null => {
|
||||||
const snippet = getSnippetListMock().find(item => item.id === snippetId)
|
if (!snippetId)
|
||||||
if (!snippet)
|
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
const snippet = getSnippetListMock().find(item => item.id === snippetId) ?? createSnippetMock(snippetId)
|
||||||
|
|
||||||
const inputFields = getSnippetInputFieldsMock()
|
const inputFields = getSnippetInputFieldsMock()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user