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
refactor(web): migrate document rename input (#41029)
yyhaba3f9c1d63b
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.jsonindex efc16374ff0..8443bef451e 100644--- a/oxlint-suppressions.json+++ b/oxlint-suppressions.json@@ -2085,11 +2085,6 @@"count": 1}},- "web/app/components/datasets/documents/components/rename-modal.tsx": {- "no-restricted-imports": {- "count": 1- }- },"web/app/components/datasets/documents/create-from-pipeline/data-source-options/option-card.tsx": {"jsx-a11y/click-events-have-key-events": {"count": 1diff --git a/web/app/components/datasets/documents/components/__tests__/rename-modal.spec.tsx b/web/app/components/datasets/documents/components/__tests__/rename-modal.spec.tsxindex 46db2aa5ed8..f6fe6688041 100644--- a/web/app/components/datasets/documents/components/__tests__/rename-modal.spec.tsx+++ b/web/app/components/datasets/documents/components/__tests__/rename-modal.spec.tsx@@ -1,4 +1,5 @@import { fireEvent, render, screen, waitFor } from '@testing-library/react'+import userEvent from '@testing-library/user-event'import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'// Import after mockimport { renameDocumentName } from '@/service/datasets'@@ -44,7 +45,7 @@ describe('RenameModal', () => {it('should render name label', () => {render(<RenameModal {...defaultProps} />)- expect(screen.getByText(/list\.table\.name/i)).toBeInTheDocument()+ expect(screen.getByRole('textbox', { name: /list\.table\.name/i })).toBeInTheDocument()})it('should render input with initial name', () => {@@ -130,7 +131,7 @@ describe('RenameModal', () => {})describe('Loading State', () => {- it('should show loading state while saving', async () => {+ it('should not submit again while saving', async () => {// Create a promise that we can resolve manuallylet resolvePromise: (value: { result: 'success' | 'fail' }) => voidconst pendingPromise = new Promise<{ result: 'success' | 'fail' }>((resolve) => {@@ -139,18 +140,21 @@ describe('RenameModal', () => {mockRenameDocumentName.mockReturnValueOnce(pendingPromise)render(<RenameModal {...defaultProps} />)- const saveButton = screen.getByText(/operation\.save/i)- fireEvent.click(saveButton)+ const user = userEvent.setup()+ const input = screen.getByRole('textbox', { name: /list\.table\.name/i })+ await user.click(input)+ await user.keyboard('{Enter}')- // The button should be in loading stateawait waitFor(() => {- const buttons = screen.getAllByRole('button')- const saveBtn = buttons.find((btn) => btn.textContent?.includes('operation.save'))- expect(saveBtn).toBeInTheDocument()+ expect(mockRenameDocumentName).toHaveBeenCalledTimes(1)})+ await user.keyboard('{Enter}')+ expect(mockRenameDocumentName).toHaveBeenCalledTimes(1)- // Resolve the promise to clean upresolvePromise!({ result: 'success' })+ await waitFor(() => {+ expect(defaultProps.onClose).toHaveBeenCalledTimes(1)+ })})})@@ -180,6 +184,7 @@ describe('RenameModal', () => {render(<RenameModal {...defaultProps} name="" />)const input = screen.getByRole('textbox')expect(input).toHaveValue('')+ expect(input).toHaveAttribute('placeholder', 'common.placeholder.input')})it('should handle name with special characters', () => {diff --git a/web/app/components/datasets/documents/components/rename-modal.tsx b/web/app/components/datasets/documents/components/rename-modal.tsxindex 6a4e9ba6f19..1875e23f385 100644--- a/web/app/components/datasets/documents/components/rename-modal.tsx+++ b/web/app/components/datasets/documents/components/rename-modal.tsx@@ -2,12 +2,14 @@import type { FC } from 'react'import { Button } from '@langgenius/dify-ui/button'import { Dialog, DialogContent, DialogTitle } from '@langgenius/dify-ui/dialog'+import { Field, FieldLabel } from '@langgenius/dify-ui/field'+import { Form } from '@langgenius/dify-ui/form'+import { Input } from '@langgenius/dify-ui/input'import { toast } from '@langgenius/dify-ui/toast'import { useBoolean } from 'ahooks'import * as React from 'react'import { useState } from 'react'import { useTranslation } from 'react-i18next'-import Input from '@/app/components/base/input'import { renameDocumentName } from '@/service/datasets'type Props = Readonly<{@@ -26,6 +28,8 @@ const RenameModal: FC<Props> = ({ documentId, datasetId, name, onClose, onSaveduseBoolean(false)const handleSave = async () => {+ if (saveLoading) return+setSaveLoadingTrue()try {await renameDocumentName({@@ -54,20 +58,28 @@ const RenameModal: FC<Props> = ({ documentId, datasetId, name, onClose, onSaved<DialogTitle className="title-2xl-semi-bold text-text-primary">{t(($) => $['list.table.rename'], { ns: 'datasetDocuments' })}</DialogTitle>+ <Form onFormSubmit={() => void handleSave()}>+ <Field name="documentName" className="mt-6 gap-0">+ <FieldLabel className="py-0 text-sm leading-5.25 font-medium text-text-primary">+ {t(($) => $['list.table.name'], { ns: 'datasetDocuments' })}+ </FieldLabel>+ <Input+ className="mt-2 h-10"+ value={newName}+ placeholder={t(($) => $['placeholder.input'], { ns: 'common' }) || ''}+ onValueChange={setNewName}+ />+ </Field>- <div className="mt-6 text-sm leading-5.25 font-medium text-text-primary">- {t(($) => $['list.table.name'], { ns: 'datasetDocuments' })}- </div>- <Input className="mt-2 h-10" value={newName} onChange={(e) => setNewName(e.target.value)} />-- <div className="mt-10 flex justify-end">- <Button className="mr-2 shrink-0" onClick={onClose}>- {t(($) => $['operation.cancel'], { ns: 'common' })}- </Button>- <Button variant="primary" className="shrink-0" onClick={handleSave} loading={saveLoading}>- {t(($) => $['operation.save'], { ns: 'common' })}- </Button>- </div>+ <div className="mt-10 flex justify-end">+ <Button type="button" className="mr-2 shrink-0" onClick={onClose}>+ {t(($) => $['operation.cancel'], { ns: 'common' })}+ </Button>+ <Button type="submit" variant="primary" className="shrink-0" loading={saveLoading}>+ {t(($) => $['operation.save'], { ns: 'common' })}+ </Button>+ </div>+ </Form></DialogContent></Dialog>)