confirm publish

This commit is contained in:
zxhlyh 2025-06-06 14:21:23 +08:00
parent 5193fa2118
commit 3db864561e
7 changed files with 113 additions and 33 deletions

View File

@ -9,7 +9,10 @@ import {
RiPlayCircleLine,
RiTerminalBoxLine,
} from '@remixicon/react'
import { useKeyPress } from 'ahooks'
import {
useBoolean,
useKeyPress,
} from 'ahooks'
import { useTranslation } from 'react-i18next'
import {
useStore,
@ -29,6 +32,7 @@ import { useParams, useRouter } from 'next/navigation'
import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail'
import { useInvalid } from '@/service/use-base'
import { publishedPipelineInfoQueryKeyPrefix } from '@/service/use-pipeline'
import Confirm from '@/app/components/base/confirm'
const PUBLISH_SHORTCUT = ['⌘', '⇧', 'P']
@ -46,29 +50,52 @@ const Popup = () => {
const { mutateAsync: publishWorkflow } = usePublishWorkflow()
const { notify } = useToastContext()
const workflowStore = useWorkflowStore()
const [confirmVisible, {
setFalse: hideConfirm,
setTrue: showConfirm,
}] = useBoolean(false)
const [publishing, {
setFalse: hidePublishing,
setTrue: showPublishing,
}] = useBoolean(false)
const invalidPublishedPipelineInfo = useInvalid([...publishedPipelineInfoQueryKeyPrefix, pipelineId])
const handlePublish = useCallback(async (params?: PublishWorkflowParams) => {
if (await handleCheckBeforePublish()) {
const res = await publishWorkflow({
url: `/rag/pipelines/${pipelineId}/workflows/publish`,
title: params?.title || '',
releaseNotes: params?.releaseNotes || '',
})
setPublished(true)
if (publishing)
return
try {
const checked = await handleCheckBeforePublish()
if (res) {
notify({ type: 'success', message: t('common.api.actionSuccess') })
workflowStore.getState().setPublishedAt(res.created_at)
mutateDatasetRes?.()
invalidPublishedPipelineInfo()
if (checked) {
if (!publishedAt && !confirmVisible) {
showConfirm()
return
}
showPublishing()
const res = await publishWorkflow({
url: `/rag/pipelines/${pipelineId}/workflows/publish`,
title: params?.title || '',
releaseNotes: params?.releaseNotes || '',
})
setPublished(true)
if (res) {
notify({ type: 'success', message: t('common.api.actionSuccess') })
workflowStore.getState().setPublishedAt(res.created_at)
mutateDatasetRes?.()
invalidPublishedPipelineInfo()
}
}
}
else {
throw new Error('Checklist failed')
catch {
}
}, [handleCheckBeforePublish, publishWorkflow, pipelineId, notify, t, workflowStore, mutateDatasetRes, invalidPublishedPipelineInfo])
finally {
if (publishing)
hidePublishing()
if (confirmVisible)
hideConfirm()
}
}, [handleCheckBeforePublish, publishWorkflow, pipelineId, notify, t, workflowStore, mutateDatasetRes, invalidPublishedPipelineInfo, showConfirm, publishedAt, confirmVisible, hidePublishing, showPublishing, hideConfirm, publishing])
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.shift.p`, (e) => {
e.preventDefault()
@ -108,7 +135,7 @@ const Popup = () => {
variant='primary'
className='mt-3 w-full'
onClick={() => handlePublish()}
disabled={published}
disabled={published || publishing}
>
{
published
@ -163,6 +190,18 @@ const Popup = () => {
</div>
</Button>
</div>
{
confirmVisible && (
<Confirm
isShow={confirmVisible}
title={t('pipeline.common.confirmPublish')}
content={t('pipeline.common.confirmPublishContent')}
onCancel={hideConfirm}
onConfirm={handlePublish}
isDisabled={publishing}
/>
)
}
</div>
)
}

View File

@ -30,7 +30,7 @@ export const COMMON_OUTPUT = [
},
]
export const FILE_OUTPUT = [
export const LOCAL_FILE_OUTPUT = [
{
name: 'file',
type: VarType.file,
@ -80,7 +80,7 @@ export const FILE_OUTPUT = [
},
]
export const WEBSITE_OUTPUT = [
export const WEBSITE_CRAWL_OUTPUT = [
{
name: 'source_url',
type: VarType.string,
@ -102,3 +102,21 @@ export const WEBSITE_OUTPUT = [
description: 'The description of the crawled website',
},
]
export const ONLINE_DOCUMENT_OUTPUT = [
{
name: 'workspace_id',
type: VarType.string,
description: 'The ID of the workspace where the document is stored',
},
{
name: 'page_id',
type: VarType.string,
description: 'The ID of the page in the document',
},
{
name: 'content',
type: VarType.string,
description: 'The content of the online document',
},
]

View File

@ -5,8 +5,9 @@ import { genNodeMetaData } from '@/app/components/workflow/utils'
import { BlockEnum } from '@/app/components/workflow/types'
import {
COMMON_OUTPUT,
FILE_OUTPUT,
WEBSITE_OUTPUT,
LOCAL_FILE_OUTPUT,
ONLINE_DOCUMENT_OUTPUT,
WEBSITE_CRAWL_OUTPUT,
} from './constants'
import { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types'
@ -58,18 +59,24 @@ const nodeDefault: NodeDefault<DataSourceNodeType> = {
const {
provider_type,
} = payload
const isLocalFile = provider_type === DataSourceClassification.file
const isWebsiteCrawl = provider_type === DataSourceClassification.website
const isLocalFile = provider_type === DataSourceClassification.localFile
const isWebsiteCrawl = provider_type === DataSourceClassification.websiteCrawl
const isOnlineDocument = provider_type === DataSourceClassification.onlineDocument
return [
...COMMON_OUTPUT.map(item => ({ variable: item.name, type: item.type })),
...(
isLocalFile
? FILE_OUTPUT.map(item => ({ variable: item.name, type: item.type }))
? LOCAL_FILE_OUTPUT.map(item => ({ variable: item.name, type: item.type }))
: []
),
...(
isWebsiteCrawl
? WEBSITE_OUTPUT.map(item => ({ variable: item.name, type: item.type }))
? WEBSITE_CRAWL_OUTPUT.map(item => ({ variable: item.name, type: item.type }))
: []
),
...(
isOnlineDocument
? ONLINE_DOCUMENT_OUTPUT.map(item => ({ variable: item.name, type: item.type }))
: []
),
...ragVars,

View File

@ -20,8 +20,9 @@ import { useNodesReadOnly } from '@/app/components/workflow/hooks'
import { useConfig } from './hooks/use-config'
import {
COMMON_OUTPUT,
FILE_OUTPUT,
WEBSITE_OUTPUT,
LOCAL_FILE_OUTPUT,
ONLINE_DOCUMENT_OUTPUT,
WEBSITE_CRAWL_OUTPUT,
} from './constants'
import { useStore } from '@/app/components/workflow/store'
import Button from '@/app/components/base/button'
@ -48,8 +49,9 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
handleFileExtensionsChange,
handleParametersChange,
} = useConfig(id)
const isLocalFile = provider_type === DataSourceClassification.file
const isWebsiteCrawl = provider_type === DataSourceClassification.website
const isLocalFile = provider_type === DataSourceClassification.localFile
const isWebsiteCrawl = provider_type === DataSourceClassification.websiteCrawl
const isOnlineDocument = provider_type === DataSourceClassification.onlineDocument
const currentDataSource = dataSourceList?.find(ds => ds.plugin_id === plugin_id)
const isAuthorized = !!currentDataSource?.is_authorized
const [showAuthModal, {
@ -166,7 +168,7 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
))
}
{
isLocalFile && FILE_OUTPUT.map(item => (
isLocalFile && LOCAL_FILE_OUTPUT.map(item => (
<VarItem
name={item.name}
type={item.type}
@ -180,7 +182,16 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
))
}
{
isWebsiteCrawl && WEBSITE_OUTPUT.map(item => (
isWebsiteCrawl && WEBSITE_CRAWL_OUTPUT.map(item => (
<VarItem
name={item.name}
type={item.type}
description={item.description}
/>
))
}
{
isOnlineDocument && ONLINE_DOCUMENT_OUTPUT.map(item => (
<VarItem
name={item.name}
type={item.type}

View File

@ -7,8 +7,9 @@ export enum VarType {
}
export enum DataSourceClassification {
file = 'local_file',
website = 'website_crawl',
localFile = 'local_file',
websiteCrawl = 'website_crawl',
onlineDocument = 'online_document',
}
export type ToolVarInputs = Record<string, {

View File

@ -2,6 +2,8 @@ const translation = {
common: {
goToAddDocuments: 'Go to add documents',
publishAs: 'Publish as a Knowledge Pipeline',
confirmPublish: 'Confirm Publish',
confirmPublishContent: 'After successfully publishing the knowledge pipeline, the chunk structure of this knowledge base cannot be modified. Are you sure you want to publish it?',
},
}

View File

@ -2,6 +2,8 @@ const translation = {
common: {
goToAddDocuments: '去添加文档',
publishAs: '发布为知识管道',
confirmPublish: '确认发布',
confirmPublishContent: '成功发布知识管道后,此知识库的分段结构将无法修改。您确定要发布吗?',
},
}