Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(web): scope empty dataset creation to its dialog session (#44652)
Winoren6278a128b7ed
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.jsonindex 09eccebd9a1..272e853ab21 100644--- a/oxlint-suppressions.json+++ b/oxlint-suppressions.json@@ -2175,11 +2175,6 @@"count": 1}},- "web/app/components/datasets/create/step-one/index.tsx": {- "better-tailwindcss/enforce-logical-properties": {- "count": 2- }- },"web/app/components/datasets/create/step-one/upgrade-card.tsx": {"better-tailwindcss/enforce-logical-properties": {"count": 3diff --git a/web/app/components/datasets/create/empty-dataset-creation-modal/__tests__/index.spec.tsx b/web/app/components/datasets/create/empty-dataset-creation-modal/__tests__/index.spec.tsxindex 21a78aa2d5b..ea971197117 100644--- a/web/app/components/datasets/create/empty-dataset-creation-modal/__tests__/index.spec.tsx+++ b/web/app/components/datasets/create/empty-dataset-creation-modal/__tests__/index.spec.tsx@@ -1,3 +1,4 @@+import { Dialog, DialogContent } from '@langgenius/dify-ui/dialog'import { act, screen, waitFor } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { consoleQuery } from '@/service/console'@@ -5,7 +6,7 @@ import { createEmptyDataset } from '@/service/datasets'import { createConsoleQueryClient, renderWithConsoleQuery } from '@/test/console/query-data'import { createDeferred } from '@/test/deferred'import { createDatasetFixture } from '@/test/fixtures/dataset'-import EmptyDatasetCreationModal from '../index'+import EmptyDatasetCreationContent from '../index'const { mockNotify, mockToast } = vi.hoisted(() => {const mockNotify = vi.fn()@@ -50,7 +51,19 @@ function setup() {queryClient.setQueryData(listKey, { data: [], page: 1, limit: 20, total: 0, has_more: false })return {onHide,- ...renderWithConsoleQuery(<EmptyDatasetCreationModal show onHide={onHide} />, { queryClient }),+ ...renderWithConsoleQuery(+ <Dialog+ defaultOpen+ onOpenChange={(open) => {+ if (!open) onHide()+ }}+ >+ <DialogContent>+ <EmptyDatasetCreationContent onCreated={onHide} onPendingChange={vi.fn()} />+ </DialogContent>+ </Dialog>,+ { queryClient },+ ),}}beforeEach(() => mockCreate.mockReset().mockResolvedValue(dataset))@@ -128,15 +141,3 @@ it.each(['datasetCreation.stepOne.modal.cancelButton', 'common.operation.close']expect(mockCreate).not.toHaveBeenCalled()},)--it('preserves the unsaved name after the modal is hidden and reopened', async () => {- const user = userEvent.setup()- const { onHide, rerender } = setup()- await user.type(field(), 'Draft')- rerender(<EmptyDatasetCreationModal show={false} onHide={onHide} />)- await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())- rerender(<EmptyDatasetCreationModal show onHide={onHide} />)- expect(- await screen.findByRole('textbox', { name: 'datasetCreation.stepOne.modal.input' }),- ).toHaveValue('Draft')-})diff --git a/web/app/components/datasets/create/empty-dataset-creation-modal/index.tsx b/web/app/components/datasets/create/empty-dataset-creation-modal/index.tsxindex 748eaf1aadc..a1c1c36c69f 100644--- a/web/app/components/datasets/create/empty-dataset-creation-modal/index.tsx+++ b/web/app/components/datasets/create/empty-dataset-creation-modal/index.tsx@@ -1,9 +1,8 @@'use client'import { Button } from '@langgenius/dify-ui/button'import {- Dialog,DialogBody,- DialogContent,+ DialogClose,DialogDescription,DialogFooter,DialogHeader,@@ -24,11 +23,14 @@ import { consoleQuery } from '@/service/console'import { createEmptyDataset } from '@/service/datasets'import s from './index.module.css'-type IProps = {- show: boolean- onHide: () => void+type EmptyDatasetCreationContentProps = {+ onCreated: () => void+ onPendingChange: (pending: boolean) => void}-const EmptyDatasetCreationModal = ({ show = false, onHide }: IProps) => {+const EmptyDatasetCreationContent = ({+ onCreated,+ onPendingChange,+}: EmptyDatasetCreationContentProps) => {const [inputValue, setInputValue] = useState('')const [isSubmitting, setIsSubmitting] = useState(false)const { t } = useTranslation(['common', 'datasetCreation'])@@ -48,6 +50,7 @@ const EmptyDatasetCreationModal = ({ show = false, onHide }: IProps) => {toast.error(t(($) => $['stepOne.modal.nameLengthInvalid'], { ns: 'datasetCreation' }))return}+ onPendingChange(true)setIsSubmitting(true)try {const dataset = await createEmptyDataset({ name: inputValue })@@ -56,55 +59,49 @@ const EmptyDatasetCreationModal = ({ show = false, onHide }: IProps) => {name: inputValue,dataset_id: dataset.id,})- onHide()+ onCreated()router.push(`/datasets/${dataset.id}/documents`)} catch {toast.error(t(($) => $['stepOne.modal.failed'], { ns: 'datasetCreation' }))} finally {+ onPendingChange(false)setIsSubmitting(false)}}return (- <Dialog- open={show}- onOpenChange={(open) => {- if (!open) onHide()- }}- >- <DialogContent className="w-130">- <DialogHeader>- <DialogTitle>{t(($) => $['stepOne.modal.title'], { ns: 'datasetCreation' })}</DialogTitle>- <DialogDescription>- {t(($) => $['stepOne.modal.tip'], { ns: 'datasetCreation' })}- </DialogDescription>- <DialogHeaderCloseButton aria-label={t(($) => $['operation.close'], { ns: 'common' })} />- </DialogHeader>- <Form className="contents" onFormSubmit={() => void submit()}>- <DialogBody>- <Field name="datasetName">- <FieldLabel className={s.label}>- {t(($) => $['stepOne.modal.input'], { ns: 'datasetCreation' })}- </FieldLabel>- <Input- value={inputValue}- placeholder={- t(($) => $['stepOne.modal.placeholder'], { ns: 'datasetCreation' }) || ''- }- onValueChange={setInputValue}- />- </Field>- </DialogBody>- <DialogFooter>- <Button type="button" className="w-24" onClick={onHide}>- {t(($) => $['stepOne.modal.cancelButton'], { ns: 'datasetCreation' })}- </Button>- <Button type="submit" className="w-24" variant="primary" loading={isSubmitting}>- {t(($) => $['stepOne.modal.confirmButton'], { ns: 'datasetCreation' })}- </Button>- </DialogFooter>- </Form>- </DialogContent>- </Dialog>+ <>+ <DialogHeader>+ <DialogTitle>{t(($) => $['stepOne.modal.title'], { ns: 'datasetCreation' })}</DialogTitle>+ <DialogDescription>+ {t(($) => $['stepOne.modal.tip'], { ns: 'datasetCreation' })}+ </DialogDescription>+ <DialogHeaderCloseButton aria-label={t(($) => $['operation.close'], { ns: 'common' })} />+ </DialogHeader>+ <Form className="contents" onFormSubmit={() => void submit()}>+ <DialogBody>+ <Field name="datasetName">+ <FieldLabel className={s.label}>+ {t(($) => $['stepOne.modal.input'], { ns: 'datasetCreation' })}+ </FieldLabel>+ <Input+ value={inputValue}+ placeholder={+ t(($) => $['stepOne.modal.placeholder'], { ns: 'datasetCreation' }) || ''+ }+ onValueChange={setInputValue}+ />+ </Field>+ </DialogBody>+ <DialogFooter>+ <DialogClose render={<Button type="button" className="w-24" />}>+ {t(($) => $['stepOne.modal.cancelButton'], { ns: 'datasetCreation' })}+ </DialogClose>+ <Button type="submit" className="w-24" variant="primary" loading={isSubmitting}>+ {t(($) => $['stepOne.modal.confirmButton'], { ns: 'datasetCreation' })}+ </Button>+ </DialogFooter>+ </Form>+ </>)}-export default EmptyDatasetCreationModal+export default EmptyDatasetCreationContentdiff --git a/web/app/components/datasets/create/step-one/__tests__/index.spec.tsx b/web/app/components/datasets/create/step-one/__tests__/index.spec.tsxindex 737752ca2e7..d8f0fce3f65 100644--- a/web/app/components/datasets/create/step-one/__tests__/index.spec.tsx+++ b/web/app/components/datasets/create/step-one/__tests__/index.spec.tsx@@ -6,11 +6,18 @@ import userEvent from '@testing-library/user-event'import { useState } from 'react'import { DataSourceType } from '@/models/datasets'import { consoleQuery } from '@/service/console'+import { createEmptyDataset } from '@/service/datasets'import { createConsoleQueryClient, renderWithConsoleQuery } from '@/test/console/query-data'import { createDeferred } from '@/test/deferred'+import { createDatasetFixture } from '@/test/fixtures/dataset'import { createNuqsTestRenderer } from '@/test/nuqs-testing'import StepOne from '../index'+vi.mock('@/service/datasets', async (importOriginal) => ({+ ...(await importOriginal<typeof import('@/service/datasets')>()),+ createEmptyDataset: vi.fn(),+}))+const vectorSpace = vi.hoisted(() =>vi.fn<typeof import('@/service/console').consoleClient.features.vectorSpace.get>(),)@@ -223,6 +230,59 @@ it('offers empty creation only for a new dataset and closes its real dialog on c).not.toBeInTheDocument()})+it('announces empty creation as a dialog', async () => {+ const { user } = setup()+ const trigger = screen.getByRole('button', {+ name: 'datasetCreation.stepOne.emptyDatasetCreation',+ })+ expect(trigger).toHaveAttribute('aria-haspopup', 'dialog')+ await user.click(trigger)+ expect(trigger).toHaveAttribute('aria-expanded', 'true')+})++it('starts a fresh empty-dataset draft after cancellation', async () => {+ const { user } = setup()+ const trigger = screen.getByRole('button', {+ name: 'datasetCreation.stepOne.emptyDatasetCreation',+ })+ await user.click(trigger)+ const dialog = screen.getByRole('dialog', { name: 'datasetCreation.stepOne.modal.title' })+ await user.type(+ within(dialog).getByRole('textbox', { name: 'datasetCreation.stepOne.modal.input' }),+ 'Cancelled draft',+ )+ await user.click(+ within(dialog).getByRole('button', { name: 'datasetCreation.stepOne.modal.cancelButton' }),+ )+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())+ await user.click(trigger)+ expect(+ await screen.findByRole('textbox', { name: 'datasetCreation.stepOne.modal.input' }),+ ).toHaveValue('')+})++it('keeps a pending creation open until it succeeds', async () => {+ const dataset = createDatasetFixture({ id: 'created-dataset', name: 'New Dataset' })+ const pending = createDeferred<typeof dataset>()+ vi.mocked(createEmptyDataset).mockReturnValueOnce(pending.promise)+ const { user } = setup()+ await user.click(+ screen.getByRole('button', { name: 'datasetCreation.stepOne.emptyDatasetCreation' }),+ )+ await user.type(+ screen.getByRole('textbox', { name: 'datasetCreation.stepOne.modal.input' }),+ 'New Dataset{Enter}',+ )+ await user.keyboard('{Escape}')+ expect(screen.getByRole('dialog')).toBeInTheDocument()+ await user.click(+ screen.getByRole('button', { name: 'datasetCreation.stepOne.modal.cancelButton' }),+ )+ expect(screen.getByRole('dialog')).toBeInTheDocument()+ await act(async () => pending.resolve(dataset))+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())+})+it('requires an upgrade before advancing multiple uploaded files on the sandbox plan', async () => {const { user, onStepChange } = setup({ files: [uploadedFile('first'), uploadedFile('second')] },diff --git a/web/app/components/datasets/create/step-one/index.tsx b/web/app/components/datasets/create/step-one/index.tsxindex dd560409127..c47b290386e 100644--- a/web/app/components/datasets/create/step-one/index.tsx+++ b/web/app/components/datasets/create/step-one/index.tsx@@ -1,14 +1,16 @@'use client'import type { DatasourceProviderAuthResponse } from '@dify/contracts/api/console/auth/types.gen'+import type { DialogActions } from '@langgenius/dify-ui/dialog'import type { DataSourceProvider, NotionPage } from '@/models/common'import type { CrawlOptions, CrawlResultItem, FileItem } from '@/models/datasets'import { cn } from '@langgenius/dify-ui/cn'+import { Dialog, DialogContent, DialogTrigger } from '@langgenius/dify-ui/dialog'import { RiFolder6Line } from '@remixicon/react'import { useQuery } from '@tanstack/react-query'import { useBoolean } from 'ahooks'import { useAtomValue } from 'jotai'-import { useCallback, useId, useMemo } from 'react'+import { useCallback, useId, useMemo, useRef } from 'react'import { useTranslation } from 'react-i18next'import NotionConnector from '@/app/components/base/notion-connector'import { NotionPageSelector } from '@/app/components/base/notion-page-selector'@@ -19,7 +21,7 @@ import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail'import { deploymentEditionAtom } from '@/features/system-features/state'import { DataSourceType } from '@/models/datasets'import { consoleQuery } from '@/service/console'-import EmptyDatasetCreationModal from '../empty-dataset-creation-modal'+import EmptyDatasetCreationContent from '../empty-dataset-creation-modal'import FileUploader from '../file-uploader'import Website from '../website'import { DataSourceTypeSelector, NextStepButton, PreviewPanel } from './components'@@ -124,8 +126,8 @@ const StepOne = ({hideWebsitePreview,} = usePreviewState()- // Empty dataset modal state- const [showModal, { setTrue: openModal, setFalse: closeModal }] = useBoolean(false)+ const emptyDatasetDialogActionsRef = useRef<DialogActions>(null)+ const isCreatingEmptyDatasetRef = useRef(false)// Plan upgrade modal stateconst [@@ -366,18 +368,36 @@ const StepOne = ({{!datasetId && (<><div className="my-8 h-px max-w-160 bg-divider-regular" />- <button- type="button"- className="inline-flex cursor-pointer items-center rounded-sm text-left text-[13px] leading-4 text-text-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-components-input-border-active"- onClick={openModal}+ <Dialog+ actionsRef={emptyDatasetDialogActionsRef}+ onOpenChange={(open, details) => {+ if (+ !open &&+ isCreatingEmptyDatasetRef.current &&+ details.reason !== 'imperative-action'+ )+ details.cancel()+ }}>- <RiFolder6Line aria-hidden="true" className="mr-1 size-4 shrink-0" />- {t(($) => $['stepOne.emptyDatasetCreation'], { ns: 'datasetCreation' })}- </button>+ <DialogTrigger+ type="button"+ className="inline-flex cursor-pointer items-center rounded-sm text-start text-[13px] leading-4 text-text-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-components-input-border-active"+ >+ <RiFolder6Line aria-hidden="true" className="me-1 size-4 shrink-0" />+ {t(($) => $['stepOne.emptyDatasetCreation'], { ns: 'datasetCreation' })}+ </DialogTrigger>+ <DialogContent className="w-130">+ <EmptyDatasetCreationContent+ onCreated={() => emptyDatasetDialogActionsRef.current?.close()}+ onPendingChange={(pending) => {+ isCreatingEmptyDatasetRef.current = pending+ }}+ />+ </DialogContent>+ </Dialog></>)}</div>- <EmptyDatasetCreationModal show={showModal} onHide={closeModal} /></div></div>diff --git a/web/features/skills/__tests__/detail-page-publishing.spec.tsx b/web/features/skills/__tests__/detail-page-publishing.spec.tsxindex 7bd065b24be..df80387a4fb 100644--- a/web/features/skills/__tests__/detail-page-publishing.spec.tsx+++ b/web/features/skills/__tests__/detail-page-publishing.spec.tsx@@ -315,14 +315,27 @@ describe('SkillDetailPage publishing', () => {})it('uses the references query count when the cached sidebar reference count is stale', async () => {+ const queryClient = new QueryClient({+ defaultOptions: {+ queries: { retry: false, staleTime: Infinity },+ mutations: { retry: false },+ },+ })+ const references = [+ createAgentReference({ display_name: 'Sidebar Agent', name: 'sidebar-agent' }),+ ]mocks.skillDetail = createSkillDetail({ reference_count: 0 })mocks.skillReferencesQueryOptions.mockImplementation(() => ({- queryFn: async () => ({- data: [createAgentReference({ display_name: 'Sidebar Agent', name: 'sidebar-agent' })],- }),+ queryFn: async () => ({ data: references }),}))+ queryClient.setQueryData(+ consoleQueryKey('workspaces.current.skills.bySkillId.references.get', {+ params: { skill_id: 'skill-1' },+ }),+ { data: references },+ )- renderSkillDetailPage()+ renderSkillDetailPage({ queryClient })expect(await screen.findByRole('button', {