Skip to content

armgit / dify

Public Imported from GitHub
0

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.

refactor(web): migrate subscription confirmation input (#41051)

yyh7b1339a1565e
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json
index 87542c6a9db..feac884e55c 100644
--- a/oxlint-suppressions.json
+++ b/oxlint-suppressions.json
@@ -2870,11 +2870,6 @@
"count": 1
}
},
- "web/app/components/plugins/plugin-detail-panel/subscription-list/delete-confirm.tsx": {
- "no-restricted-imports": {
- "count": 1
- }
- },
"web/app/components/plugins/plugin-detail-panel/subscription-list/index.tsx": {
"no-barrel-files/no-barrel-files": {
"count": 2
diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/__tests__/delete-confirm.spec.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/__tests__/delete-confirm.spec.tsx
index e3905e98e33..8838cffef8f 100644
--- a/web/app/components/plugins/plugin-detail-panel/subscription-list/__tests__/delete-confirm.spec.tsx
+++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/__tests__/delete-confirm.spec.tsx
@@ -1,9 +1,11 @@
import { fireEvent, render, screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'
import { DeleteConfirm } from '../delete-confirm'
const mockRefetch = vi.fn()
const mockDelete = vi.fn()
+const mockDeleteState = { isPending: false }
const mockToastSuccess = vi.hoisted(() => vi.fn())
const mockToastError = vi.hoisted(() => vi.fn())
@@ -12,7 +14,10 @@ vi.mock('../use-subscription-list', () => ({
}))
vi.mock('@/service/use-triggers', () => ({
- useDeleteTriggerSubscription: () => ({ mutate: mockDelete, isPending: false }),
+ useDeleteTriggerSubscription: () => ({
+ mutate: mockDelete,
+ isPending: mockDeleteState.isPending,
+ }),
}))
vi.mock('@langgenius/dify-ui/toast', async (importOriginal) => {
@@ -29,6 +34,7 @@ vi.mock('@langgenius/dify-ui/toast', async (importOriginal) => {
beforeEach(() => {
vi.clearAllMocks()
+ mockDeleteState.isPending = false
mockDelete.mockImplementation((_id: string, options?: { onSuccess?: () => void }) => {
options?.onSuccess?.()
})
@@ -58,8 +64,9 @@ describe('DeleteConfirm', () => {
)
})
- it('should allow deletion after matching input name', () => {
+ it('should allow deletion by submitting a matching input name', async () => {
const onClose = vi.fn()
+ const user = userEvent.setup()
render(
<DeleteConfirm
@@ -71,17 +78,11 @@ describe('DeleteConfirm', () => {
/>,
)
- fireEvent.change(
- screen.getByPlaceholderText(
- /pluginTrigger\.subscription\.list\.item\.actions\.deleteConfirm\.confirmInputPlaceholder/,
- ),
- { target: { value: 'Subscription One' } },
- )
-
- fireEvent.click(
- screen.getByRole('button', {
- name: /pluginTrigger\.subscription\.list\.item\.actions\.deleteConfirm\.confirm/,
+ await user.type(
+ screen.getByRole('textbox', {
+ name: /pluginTrigger\.subscription\.list\.item\.actions\.deleteConfirm\.confirmInputTip/,
}),
+ 'Subscription One{Enter}',
)
expect(mockDelete).toHaveBeenCalledWith('sub-1', expect.any(Object))
@@ -112,4 +113,28 @@ describe('DeleteConfirm', () => {
expect(mockToastError).toHaveBeenCalledWith('network error')
})
+
+ it('should ignore form submission while deletion is pending', async () => {
+ mockDeleteState.isPending = true
+ const user = userEvent.setup()
+
+ render(
+ <DeleteConfirm
+ isShow
+ currentId="sub-1"
+ currentName="Subscription One"
+ workflowsInUse={1}
+ onClose={vi.fn()}
+ />,
+ )
+
+ await user.type(
+ screen.getByRole('textbox', {
+ name: /pluginTrigger\.subscription\.list\.item\.actions\.deleteConfirm\.confirmInputTip/,
+ }),
+ 'Subscription One{Enter}',
+ )
+
+ expect(mockDelete).not.toHaveBeenCalled()
+ })
})
diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/delete-confirm.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/delete-confirm.tsx
index 0ebc09f3e06..8f1e281ca17 100644
--- a/web/app/components/plugins/plugin-detail-panel/subscription-list/delete-confirm.tsx
+++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/delete-confirm.tsx
@@ -7,10 +7,11 @@ import {
AlertDialogDescription,
AlertDialogTitle,
} from '@langgenius/dify-ui/alert-dialog'
+import { Field, FieldLabel } from '@langgenius/dify-ui/field'
+import { Input } from '@langgenius/dify-ui/input'
import { toast } from '@langgenius/dify-ui/toast'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
-import Input from '@/app/components/base/input'
import { useDeleteTriggerSubscription } from '@/service/use-triggers'
import { useSubscriptionList } from './use-subscription-list'
@@ -38,6 +39,8 @@ export const DeleteConfirm = (props: Props) => {
}
const onConfirm = () => {
+ if (isDeleting) return
+
if (workflowsInUse > 0 && inputName !== currentName) {
toast.error(t(($) => $[`${tPrefix}.confirmInputWarning`], { ns: 'pluginTrigger' }))
return
@@ -61,45 +64,52 @@ export const DeleteConfirm = (props: Props) => {
return (
<AlertDialog open={isShow} onOpenChange={handleOpenChange}>
<AlertDialogContent backdropProps={{ forceRender: true }}>
- <div className="flex flex-col gap-2 px-6 pt-6 pb-4">
- <AlertDialogTitle className="w-full truncate title-2xl-semi-bold text-text-primary">
- {t(($) => $[`${tPrefix}.title`], { ns: 'pluginTrigger', name: currentName })}
- </AlertDialogTitle>
- <AlertDialogDescription className="w-full system-md-regular wrap-break-word whitespace-pre-wrap text-text-tertiary">
- {workflowsInUse > 0
- ? t(($) => $[`${tPrefix}.contentWithApps`], {
- ns: 'pluginTrigger',
- count: workflowsInUse,
- })
- : t(($) => $[`${tPrefix}.content`], { ns: 'pluginTrigger' })}
- </AlertDialogDescription>
- {workflowsInUse > 0 && (
- <div className="mt-6">
- <div className="mb-2 system-sm-medium text-text-secondary">
- {t(($) => $[`${tPrefix}.confirmInputTip`], {
- ns: 'pluginTrigger',
- name: currentName,
- })}
- </div>
- <Input
- value={inputName}
- onChange={(e) => setInputName(e.target.value)}
- placeholder={t(($) => $[`${tPrefix}.confirmInputPlaceholder`], {
- ns: 'pluginTrigger',
- name: currentName,
- })}
- />
- </div>
- )}
- </div>
- <AlertDialogActions>
- <AlertDialogCancelButton disabled={isDeleting}>
- {t(($) => $['operation.cancel'], { ns: 'common' })}
- </AlertDialogCancelButton>
- <AlertDialogConfirmButton loading={isDeleting} disabled={isDeleting} onClick={onConfirm}>
- {t(($) => $[`${tPrefix}.confirm`], { ns: 'pluginTrigger' })}
- </AlertDialogConfirmButton>
- </AlertDialogActions>
+ <form
+ onSubmit={(event) => {
+ event.preventDefault()
+ onConfirm()
+ }}
+ >
+ <div className="flex flex-col gap-2 px-6 pt-6 pb-4">
+ <AlertDialogTitle className="w-full truncate title-2xl-semi-bold text-text-primary">
+ {t(($) => $[`${tPrefix}.title`], { ns: 'pluginTrigger', name: currentName })}
+ </AlertDialogTitle>
+ <AlertDialogDescription className="w-full system-md-regular wrap-break-word whitespace-pre-wrap text-text-tertiary">
+ {workflowsInUse > 0
+ ? t(($) => $[`${tPrefix}.contentWithApps`], {
+ ns: 'pluginTrigger',
+ count: workflowsInUse,
+ })
+ : t(($) => $[`${tPrefix}.content`], { ns: 'pluginTrigger' })}
+ </AlertDialogDescription>
+ {workflowsInUse > 0 && (
+ <Field className="mt-6 gap-2" name="confirmation">
+ <FieldLabel className="py-0">
+ {t(($) => $[`${tPrefix}.confirmInputTip`], {
+ ns: 'pluginTrigger',
+ name: currentName,
+ })}
+ </FieldLabel>
+ <Input
+ value={inputName}
+ onChange={(e) => setInputName(e.target.value)}
+ placeholder={t(($) => $[`${tPrefix}.confirmInputPlaceholder`], {
+ ns: 'pluginTrigger',
+ name: currentName,
+ })}
+ />
+ </Field>
+ )}
+ </div>
+ <AlertDialogActions>
+ <AlertDialogCancelButton disabled={isDeleting}>
+ {t(($) => $['operation.cancel'], { ns: 'common' })}
+ </AlertDialogCancelButton>
+ <AlertDialogConfirmButton type="submit" loading={isDeleting}>
+ {t(($) => $[`${tPrefix}.confirm`], { ns: 'pluginTrigger' })}
+ </AlertDialogConfirmButton>
+ </AlertDialogActions>
+ </form>
</AlertDialogContent>
</AlertDialog>
)