diff --git a/web/app/components/workflow/block-selector/snippets/snippet-detail-card.tsx b/web/app/components/workflow/block-selector/snippets/snippet-detail-card.tsx index 44a44ee4ad..1a3545a96f 100644 --- a/web/app/components/workflow/block-selector/snippets/snippet-detail-card.tsx +++ b/web/app/components/workflow/block-selector/snippets/snippet-detail-card.tsx @@ -1,6 +1,10 @@ import type { FC } from 'react' import type { SnippetListItem } from '@/types/snippet' +import { useMemo } from 'react' import AppIcon from '@/app/components/base/app-icon' +import { useSnippetPublishedWorkflow } from '@/service/use-snippet-workflows' +import BlockIcon from '../../block-icon' +import { BlockEnum } from '../../types' export type PublishedSnippetListItem = SnippetListItem @@ -12,6 +16,39 @@ const SnippetDetailCard: FC = ({ snippet, }) => { const { author, description, icon_info, name } = snippet + const { data: workflow } = useSnippetPublishedWorkflow(snippet.id) + + const blockTypes = useMemo(() => { + const graph = workflow?.graph + if (!graph || typeof graph !== 'object') + return [] + + const graphRecord = graph as Record + if (!Array.isArray(graphRecord.nodes)) + return [] + + const availableBlockTypes = new Set(Object.values(BlockEnum)) + + return graphRecord.nodes.reduce((result, node) => { + if (!node || typeof node !== 'object') + return result + + const nodeRecord = node as Record + if (!nodeRecord.data || typeof nodeRecord.data !== 'object') + return result + + const dataRecord = nodeRecord.data as Record + const blockType = dataRecord.type + if (typeof blockType !== 'string' || !availableBlockTypes.has(blockType as BlockEnum)) + return result + + const normalizedBlockType = blockType as BlockEnum + if (!result.includes(normalizedBlockType)) + result.push(normalizedBlockType) + + return result + }, []) + }, [workflow?.graph]) return (
@@ -31,6 +68,17 @@ const SnippetDetailCard: FC = ({ {description}
)} + {!!blockTypes.length && ( +
+ {blockTypes.map(blockType => ( + + ))} +
+ )} {!!author && (
diff --git a/web/service/use-snippet-workflows.ts b/web/service/use-snippet-workflows.ts index 9659a1fd8e..765a3210ad 100644 --- a/web/service/use-snippet-workflows.ts +++ b/web/service/use-snippet-workflows.ts @@ -1,10 +1,3 @@ -import type { - SnippetDraftNodeRunPayload, - SnippetDraftRunPayload, - SnippetDraftSyncPayload, - SnippetIterationNodeRunPayload, - SnippetLoopNodeRunPayload, -} from '@/types/snippet' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { consoleQuery } from '@/service/client' @@ -175,11 +168,3 @@ export const useStopSnippetWorkflowTaskMutation = (snippetId: string) => { }), }) } - -export type { - SnippetDraftNodeRunPayload, - SnippetDraftRunPayload, - SnippetDraftSyncPayload, - SnippetIterationNodeRunPayload, - SnippetLoopNodeRunPayload, -}