confirm publish

pull/21398/head
zxhlyh 12 months ago
parent 5193fa2118
commit 3db864561e

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

@ -30,7 +30,7 @@ export const COMMON_OUTPUT = [
}, },
] ]
export const FILE_OUTPUT = [ export const LOCAL_FILE_OUTPUT = [
{ {
name: 'file', name: 'file',
type: VarType.file, type: VarType.file,
@ -80,7 +80,7 @@ export const FILE_OUTPUT = [
}, },
] ]
export const WEBSITE_OUTPUT = [ export const WEBSITE_CRAWL_OUTPUT = [
{ {
name: 'source_url', name: 'source_url',
type: VarType.string, type: VarType.string,
@ -102,3 +102,21 @@ export const WEBSITE_OUTPUT = [
description: 'The description of the crawled website', 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',
},
]

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

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

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

@ -2,6 +2,8 @@ const translation = {
common: { common: {
goToAddDocuments: 'Go to add documents', goToAddDocuments: 'Go to add documents',
publishAs: 'Publish as a Knowledge Pipeline', 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?',
}, },
} }

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

Loading…
Cancel
Save