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): let menus close themselves and open settings drawers from triggers (#43902)

yyh75dd75702209
diff --git a/web/app/components/app-sidebar/dataset-info/dropdown.tsx b/web/app/components/app-sidebar/dataset-info/dropdown.tsx
index 6483cfa5e09..8d32ee552f7 100644
--- a/web/app/components/app-sidebar/dataset-info/dropdown.tsx
+++ b/web/app/components/app-sidebar/dataset-info/dropdown.tsx
@@ -64,7 +64,6 @@ const getErrorMessage = async (error: unknown) => {
const DropDown = ({ expand, triggerClassName }: DropDownProps) => {
const { t } = useTranslation(['app', 'common', 'dataset', 'datasetPipeline', 'navigation'])
const { push, replace } = useRouter()
- const [open, setOpen] = useState(false)
const [showRenameModal, setShowRenameModal] = useState(false)
const [confirmMessage, setConfirmMessage] = useState<string>('')
const [showConfirmDelete, setShowConfirmDelete] = useState(false)
@@ -108,7 +107,6 @@ const DropDown = ({ expand, triggerClassName }: DropDownProps) => {
}, [invalidDatasetDetail, invalidDatasetList])
const openRenameModal = useCallback(() => {
- setOpen(false)
queueMicrotask(() => {
setShowRenameModal(true)
})
@@ -120,7 +118,6 @@ const DropDown = ({ expand, triggerClassName }: DropDownProps) => {
async (include = false) => {
const { pipeline_id, name } = dataset
if (!pipeline_id) return
- setOpen(false)
try {
const { data } = await exportPipelineConfig({
pipelineId: pipeline_id,
@@ -136,7 +133,6 @@ const DropDown = ({ expand, triggerClassName }: DropDownProps) => {
)
const detectIsUsedByApp = useCallback(async () => {
- setOpen(false)
try {
const { is_using: isUsedByApp } = await checkIsUsedInApp(dataset.id)
setConfirmMessage(
@@ -151,7 +147,6 @@ const DropDown = ({ expand, triggerClassName }: DropDownProps) => {
}, [dataset.id, t])
const openAccessConfig = useCallback(() => {
- setOpen(false)
push(`/datasets/${dataset.id}/access-config`)
}, [dataset.id, push])
@@ -172,7 +167,7 @@ const DropDown = ({ expand, triggerClassName }: DropDownProps) => {
if (!canShowOperations) return null
return (
- <DropdownMenu open={open} onOpenChange={setOpen}>
+ <DropdownMenu>
<DropdownMenuTrigger
render={
<IconButton
diff --git a/web/app/components/app-sidebar/snippet-info/dropdown.tsx b/web/app/components/app-sidebar/snippet-info/dropdown.tsx
index 801a02ff9ac..0e7f00a32e9 100644
--- a/web/app/components/app-sidebar/snippet-info/dropdown.tsx
+++ b/web/app/components/app-sidebar/snippet-info/dropdown.tsx
@@ -44,7 +44,6 @@ const SnippetInfoDropdown = ({ snippet }: SnippetInfoDropdownProps) => {
const { t } = useTranslation(['snippet', 'common'])
const { replace } = useRouter()
const workspacePermissionKeys = useAtomValue(workspacePermissionKeysAtom)
- const [open, setOpen] = React.useState(false)
const [isEditDialogOpen, setIsEditDialogOpen] = React.useState(false)
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = React.useState(false)
const updateSnippetMutation = useUpdateSnippetMutation()
@@ -63,14 +62,12 @@ const SnippetInfoDropdown = ({ snippet }: SnippetInfoDropdownProps) => {
)
const handleOpenEditDialog = React.useCallback(() => {
- setOpen(false)
setIsEditDialogOpen(true)
}, [])
const handleExportSnippet = React.useCallback(async () => {
if (!canCreateAndModifySnippet) return
- setOpen(false)
try {
const data = await exportSnippetMutation.mutateAsync({ snippetId: snippet.id })
const file = new Blob([data], { type: 'application/yaml' })
@@ -125,7 +122,7 @@ const SnippetInfoDropdown = ({ snippet }: SnippetInfoDropdownProps) => {
return (
<>
- <DropdownMenu open={open} onOpenChange={setOpen}>
+ <DropdownMenu>
<DropdownMenuTrigger
render={
<IconButton
@@ -160,10 +157,7 @@ const SnippetInfoDropdown = ({ snippet }: SnippetInfoDropdownProps) => {
<DropdownMenuItem
className="mx-0 gap-2"
variant="destructive"
- onClick={() => {
- setOpen(false)
- setIsDeleteDialogOpen(true)
- }}
+ onClick={() => setIsDeleteDialogOpen(true)}
>
<span aria-hidden className="i-ri-delete-bin-line size-4 shrink-0" />
<span className="grow">{t(($) => $['menu.deleteSnippet'])}</span>
diff --git a/web/app/components/app/annotation/header-opts/index.tsx b/web/app/components/app/annotation/header-opts/index.tsx
index ce031d78623..882c03b91b0 100644
--- a/web/app/components/app/annotation/header-opts/index.tsx
+++ b/web/app/components/app/annotation/header-opts/index.tsx
@@ -38,7 +38,6 @@ type Props = Readonly<{
type OperationsMenuProps = {
list: AnnotationItemBasic[]
- onClose: () => void
onBulkImport: () => void
onClearAll: () => void
onExportJsonl: () => void
@@ -66,7 +65,6 @@ const downloadAnnotationCsv = (list: AnnotationItemBasic[], locale: string) => {
const OperationsMenu: FC<OperationsMenuProps> = ({
list,
- onClose,
onBulkImport,
onClearAll,
onExportJsonl,
@@ -80,7 +78,6 @@ const OperationsMenu: FC<OperationsMenuProps> = ({
<DropdownMenuItem
className="gap-2"
onClick={() => {
- onClose()
onBulkImport()
}}
>
@@ -102,7 +99,6 @@ const OperationsMenu: FC<OperationsMenuProps> = ({
<DropdownMenuItem
disabled={annotationUnavailable}
onClick={() => {
- onClose()
downloadAnnotationCsv(list, locale)
}}
>
@@ -111,7 +107,6 @@ const OperationsMenu: FC<OperationsMenuProps> = ({
<DropdownMenuItem
disabled={annotationUnavailable}
onClick={() => {
- onClose()
onExportJsonl()
}}
>
@@ -123,7 +118,6 @@ const OperationsMenu: FC<OperationsMenuProps> = ({
variant="destructive"
className="gap-2"
onClick={() => {
- onClose()
onClearAll()
}}
>
@@ -161,7 +155,6 @@ const HeaderOptions: FC<Props> = ({ appId, onAdd, onAdded, controlUpdateList })
},
}),
)
- const [isOperationsMenuOpen, setIsOperationsMenuOpen] = useState(false)
const handleShowBulkImportModal = React.useCallback(() => {
setShowBulkImportModal(true)
}, [])
@@ -179,11 +172,7 @@ const HeaderOptions: FC<Props> = ({ appId, onAdd, onAdded, controlUpdateList })
<span aria-hidden className="i-ri-add-line size-4" />
<div>{t(($) => $['table.header.addAnnotation'], { ns: 'appAnnotation' })}</div>
</Button>
- <DropdownMenu
- modal={false}
- open={isOperationsMenuOpen}
- onOpenChange={setIsOperationsMenuOpen}
- >
+ <DropdownMenu modal={false}>
<DropdownMenuTrigger
aria-label={t(($) => $['operation.more'], { ns: 'common' })}
className="mr-0 box-border inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border-[0.5px] border-components-button-secondary-border bg-components-button-secondary-bg p-0 text-components-button-secondary-text shadow-xs backdrop-blur-[5px] hover:border-components-button-secondary-border-hover hover:bg-components-button-secondary-bg-hover data-popup-open:border-components-button-secondary-border-hover data-popup-open:bg-components-button-secondary-bg-hover"
@@ -193,7 +182,6 @@ const HeaderOptions: FC<Props> = ({ appId, onAdd, onAdded, controlUpdateList })
<DropdownMenuContent placement="bottom-end" sideOffset={4} className="w-38.75">
<OperationsMenu
list={list}
- onClose={() => setIsOperationsMenuOpen(false)}
onBulkImport={handleShowBulkImportModal}
onClearAll={handleClearAll}
onExportJsonl={handleExportJsonl}
diff --git a/web/app/components/app/configuration/dataset-config/card-item/index.tsx b/web/app/components/app/configuration/dataset-config/card-item/index.tsx
index 08778adc17e..0e491e6de23 100644
--- a/web/app/components/app/configuration/dataset-config/card-item/index.tsx
+++ b/web/app/components/app/configuration/dataset-config/card-item/index.tsx
@@ -1,4 +1,5 @@
'use client'
+import type { DrawerActions } from '@langgenius/dify-ui/drawer'
import type { FC } from 'react'
import type { DataSet } from '@/models/datasets'
import { cn } from '@langgenius/dify-ui/cn'
@@ -8,11 +9,12 @@ import {
DrawerContent,
DrawerPopup,
DrawerPortal,
+ DrawerTrigger,
DrawerViewport,
} from '@langgenius/dify-ui/drawer'
import { IconButton } from '@langgenius/dify-ui/icon-button'
import * as React from 'react'
-import { useState } from 'react'
+import { useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import AppIcon from '@/app/components/base/app-icon'
import Badge from '@/app/components/base/badge'
@@ -32,13 +34,13 @@ type ItemProps = {
const Item: FC<ItemProps> = ({ config, onSave, onRemove, readonly = false, editable = true }) => {
const media = useBreakpoints()
const isMobile = media === MediaType.mobile
- const [showSettingsModal, setShowSettingsModal] = useState(false)
+ const settingsDrawerActionsRef = useRef<DrawerActions>(null)
const { formatIndexingTechniqueAndMethod } = useKnowledge()
const { t } = useTranslation(['common', 'dataset'])
const handleSave = (newDataset: DataSet) => {
onSave(newDataset)
- setShowSettingsModal(false)
+ settingsDrawerActionsRef.current?.close()
}
const [isDeleting, setIsDeleting] = useState(false)
@@ -72,18 +74,35 @@ const Item: FC<ItemProps> = ({ config, onSave, onRemove, readonly = false, edita
</div>
<div className="ml-2 hidden shrink-0 items-center space-x-1 group-hover:flex">
{editable && !readonly && (
- <IconButton
- aria-label={t(($) => $['operation.edit'], { ns: 'common' })}
- onClick={(e) => {
- e.stopPropagation()
- setShowSettingsModal(true)
- }}
- >
- <span
- aria-hidden="true"
- className="i-ri-edit-line size-4 shrink-0 text-text-tertiary"
+ <Drawer actionsRef={settingsDrawerActionsRef} modal swipeDirection="right">
+ <DrawerTrigger
+ render={
+ <IconButton
+ aria-label={t(($) => $['operation.edit'], { ns: 'common' })}
+ onClick={(e) => e.stopPropagation()}
+ >
+ <span
+ aria-hidden="true"
+ className="i-ri-edit-line size-4 shrink-0 text-text-tertiary"
+ />
+ </IconButton>
+ }
/>
- </IconButton>
+ <DrawerPortal>
+ <DrawerBackdrop className={cn(!isMobile && 'bg-transparent')} />
+ <DrawerViewport>
+ <DrawerPopup className="p-0! data-[swipe-direction=right]:top-16 data-[swipe-direction=right]:right-2 data-[swipe-direction=right]:bottom-3 data-[swipe-direction=right]:h-auto data-[swipe-direction=right]:w-full data-[swipe-direction=right]:max-w-160 data-[swipe-direction=right]:rounded-xl">
+ <DrawerContent className="flex min-h-0 flex-1 flex-col p-0 pb-0">
+ <SettingsModal
+ currentDataset={config}
+ onCancel={() => settingsDrawerActionsRef.current?.close()}
+ onSave={handleSave}
+ />
+ </DrawerContent>
+ </DrawerPopup>
+ </DrawerViewport>
+ </DrawerPortal>
+ </Drawer>
)}
{!readonly && (
<IconButton
@@ -112,31 +131,6 @@ const Item: FC<ItemProps> = ({ config, onSave, onRemove, readonly = false, edita
text={t(($) => $.externalTag, { ns: 'dataset' }) as string}
/>
)}
- <Drawer
- open={showSettingsModal}
- modal
- swipeDirection="right"
- onOpenChange={(open) => {
- if (!open) setShowSettingsModal(false)
- }}
- >
- <DrawerPortal>
- <DrawerBackdrop className={cn(!isMobile && 'bg-transparent')} />
- <DrawerViewport>
- <DrawerPopup className="p-0! data-[swipe-direction=right]:top-16 data-[swipe-direction=right]:right-2 data-[swipe-direction=right]:bottom-3 data-[swipe-direction=right]:h-auto data-[swipe-direction=right]:w-full data-[swipe-direction=right]:max-w-160 data-[swipe-direction=right]:rounded-xl">
- <DrawerContent className="flex min-h-0 flex-1 flex-col p-0 pb-0">
- {showSettingsModal && (
- <SettingsModal
- currentDataset={config}
- onCancel={() => setShowSettingsModal(false)}
- onSave={handleSave}
- />
- )}
- </DrawerContent>
- </DrawerPopup>
- </DrawerViewport>
- </DrawerPortal>
- </Drawer>
</div>
)
}
diff --git a/web/app/components/datasets/documents/components/operations.tsx b/web/app/components/datasets/documents/components/operations.tsx
index 6d6e4025b51..177985f7813 100644
--- a/web/app/components/datasets/documents/components/operations.tsx
+++ b/web/app/components/datasets/documents/components/operations.tsx
@@ -99,7 +99,6 @@ const Operations = ({
display_status,
} = detail || {}
const [showModal, setShowModal] = useState(false)
- const [isOperationsMenuOpen, setIsOperationsMenuOpen] = useState(false)
const [deleting, setDeleting] = useState(false)
const { t } = useTranslation(['common', 'datasetDocuments'])
const router = useRouter()
@@ -246,9 +245,6 @@ const Operations = ({
const handleRenamed = useCallback(() => {
onUpdate()
}, [onUpdate])
- const closeOperationsMenu = useCallback(() => {
- setIsOperationsMenuOpen(false)
- }, [])
const stopPropagation = useCallback((e: React.SyntheticEvent) => {
e.stopPropagation()
}, [])
@@ -268,25 +264,22 @@ const Operations = ({
downloadUrl({ url: res.url, fileName: name })
}, [canDownload, datasetId, downloadDocument, id, isDownloading, name, t])
const handleShowRename = useCallback(() => {
- closeOperationsMenu()
handleShowRenameModal({
id: detail.id,
name: detail.name,
})
- }, [closeOperationsMenu, detail.id, detail.name, handleShowRenameModal])
+ }, [detail.id, detail.name, handleShowRenameModal])
const handleMenuOperation = useCallback(
(operationName: OperationName) => {
- closeOperationsMenu()
void onOperate(operationName)
},
- [closeOperationsMenu, onOperate],
+ [onOperate],
)
const handleDeleteClick = useCallback(() => {
if (!canDelete) return
- closeOperationsMenu()
setShowModal(true)
- }, [canDelete, closeOperationsMenu])
+ }, [canDelete])
const handleDownloadClick = useCallback(
(evt: React.MouseEvent<HTMLElement>) => {
evt.preventDefault()
@@ -294,10 +287,9 @@ const Operations = ({
evt.nativeEvent.stopImmediatePropagation?.()
if (!canDownload) return
- closeOperationsMenu()
void handleDownload()
},
- [canDownload, closeOperationsMenu, handleDownload],
+ [canDownload, handleDownload],
)
const menuActionClassName = 'h-9 w-[calc(100%-8px)] gap-2 px-3 py-2 text-left'
const menuDeleteActionClassName = cn(menuActionClassName, 'group')
@@ -308,10 +300,9 @@ const Operations = ({
evt.nativeEvent.stopImmediatePropagation?.()
if (!canViewSettings) return
- closeOperationsMenu()
router.push(`/datasets/${datasetId}/documents/${detail.id}/settings`)
},
- [canViewSettings, closeOperationsMenu, datasetId, detail.id, router],
+ [canViewSettings, datasetId, detail.id, router],
)
const settingsMenuItem = (
<DropdownMenuItem className={menuActionClassName} onClick={handleSettingsClick}>
@@ -391,7 +382,7 @@ const Operations = ({
)}
{hasOperationsMenu && (
<>
- <DropdownMenu open={isOperationsMenuOpen} onOpenChange={setIsOperationsMenuOpen}>
+ <DropdownMenu>
<DropdownMenuTrigger
aria-label={t(($) => $['operation.more'], { ns: 'common' })}
className={cn(
diff --git a/web/app/components/header/account-setting/access-rules-page/access-rule-row-menu.tsx b/web/app/components/header/account-setting/access-rules-page/access-rule-row-menu.tsx
index 611a04e4a1c..8127fa9067f 100644
--- a/web/app/components/header/account-setting/access-rules-page/access-rule-row-menu.tsx
+++ b/web/app/components/header/account-setting/access-rules-page/access-rule-row-menu.tsx
@@ -32,7 +32,6 @@ type AccessRuleRowMenuProps = {
const AccessRuleRowMenu = ({ rule, onView, onEdit }: AccessRuleRowMenuProps) => {
const { t } = useTranslation(['common', 'permission'])
- const [open, setOpen] = useState(false)
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
const { mutate: copyAccessRule } = useMutation(
@@ -52,7 +51,6 @@ const AccessRuleRowMenu = ({ rule, onView, onEdit }: AccessRuleRowMenuProps) =>
{
onSuccess: () => {
toast.success(t(($) => $['accessRule.copied'], { ns: 'permission' }))
- setOpen(false)
},
},
)
@@ -60,7 +58,6 @@ const AccessRuleRowMenu = ({ rule, onView, onEdit }: AccessRuleRowMenuProps) =>
const openDeleteConfirm = useCallback(() => {
setShowDeleteConfirm(true)
- setOpen(false)
}, [])
const handleDelete = useCallback(() => {
@@ -78,7 +75,7 @@ const AccessRuleRowMenu = ({ rule, onView, onEdit }: AccessRuleRowMenuProps) =>
return (
<>
- <DropdownMenu open={open} onOpenChange={setOpen}>
+ <DropdownMenu>
<DropdownMenuTrigger
render={
<IconButton
diff --git a/web/app/components/header/account-setting/members-page/member-menu.tsx b/web/app/components/header/account-setting/members-page/member-menu.tsx
index ace359ee671..635ab40b817 100644
--- a/web/app/components/header/account-setting/members-page/member-menu.tsx
+++ b/web/app/components/header/account-setting/members-page/member-menu.tsx
@@ -44,7 +44,6 @@ const MemberMenu = ({
}: MemberMenuProps) => {
const { t } = useTranslation(['common', 'workspaceMembers'])
const queryClient = useQueryClient()
- const [open, setOpen] = useState(false)
const [assignModalOpen, setAssignModalOpen] = useState(false)
const [removeConfirmOpen, setRemoveConfirmOpen] = useState(false)
const [removing, setRemoving] = useState(false)
@@ -61,7 +60,6 @@ const MemberMenu = ({
: t(($) => $['members.editRole'], { ns: 'workspaceMembers', defaultValue: 'Edit Role' })
const handleOpenAssignRoles = useCallback(() => {
- setOpen(false)
setAssignModalOpen(true)
}, [])
@@ -89,7 +87,6 @@ const MemberMenu = ({
)
const handleOpenRemoveConfirm = useCallback(() => {
- setOpen(false)
setRemoveConfirmOpen(true)
}, [])
@@ -106,7 +103,6 @@ const MemberMenu = ({
}, [member.id, queryClient])
const handleTransferOwnership = useCallback(() => {
- setOpen(false)
onTransferOwnership?.()
}, [onTransferOwnership])
@@ -114,7 +110,7 @@ const MemberMenu = ({
return (
<div>
- <DropdownMenu open={open} onOpenChange={setOpen}>
+ <DropdownMenu>
<DropdownMenuTrigger
render={
<IconButton
diff --git a/web/app/components/header/account-setting/permissions-page/role-list/row-menu.tsx b/web/app/components/header/account-setting/permissions-page/role-list/row-menu.tsx
index 26d353404a1..84eacc27321 100644
--- a/web/app/components/header/account-setting/permissions-page/role-list/row-menu.tsx
+++ b/web/app/components/header/account-setting/permissions-page/role-list/row-menu.tsx
@@ -37,7 +37,6 @@ type RowMenuProps = {
const RowMenu = ({ roleCategory, role, onView, onEdit }: RowMenuProps) => {
const { t } = useTranslation(['common', 'permission'])
- const [open, setOpen] = useState(false)
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
const [showCopyMembersConfirm, setShowCopyMembersConfirm] = useState(false)
@@ -58,7 +57,6 @@ const RowMenu = ({ roleCategory, role, onView, onEdit }: RowMenuProps) => {
if (!canManageRoles) return
setShowCopyMembersConfirm(true)
- setOpen(false)
}, [canManageRoles])
const handleDuplicate = useCallback(
@@ -86,7 +84,6 @@ const RowMenu = ({ roleCategory, role, onView, onEdit }: RowMenuProps) => {
if (!canManageRoles) return
setShowDeleteConfirm(true)
- setOpen(false)
}, [canManageRoles])
const handleDelete = useCallback(() => {
@@ -105,7 +102,7 @@ const RowMenu = ({ roleCategory, role, onView, onEdit }: RowMenuProps) => {
return (
<>
- <DropdownMenu open={open} onOpenChange={setOpen}>
+ <DropdownMenu>
<DropdownMenuTrigger
render={
<IconButton
diff --git a/web/app/components/integrations/index.tsx b/web/app/components/integrations/index.tsx
index 97236a3d090..84d9db49383 100644
--- a/web/app/components/integrations/index.tsx
+++ b/web/app/components/integrations/index.tsx
@@ -1,5 +1,6 @@
'use client'
+import type { DrawerActions } from '@langgenius/dify-ui/drawer'
import type { CSSProperties, ReactNode } from 'react'
import type { IntegrationSection } from './routes'
import type { DocPathWithoutLang } from '@/types/doc-paths'
@@ -25,7 +26,7 @@ import {
ScrollAreaThumb,
ScrollAreaViewport,
} from '@langgenius/dify-ui/scroll-area'
-import { useEffect, useId, useState, useSyncExternalStore } from 'react'
+import { useEffect, useId, useRef, useState, useSyncExternalStore } from 'react'
import { useTranslation } from 'react-i18next'
import { UpdateSettingDialog } from '@/app/components/header/account-setting/update-setting-dialog'
import {
@@ -170,7 +171,7 @@ export default function IntegrationsPage({
showPluginCategorySetting,
} = useIntegrationPermissions(section)
const [providerSearchText, setProviderSearchText] = useState('')
- const [isNavigationOpen, setIsNavigationOpen] = useState(false)
+ const navigationDrawerActionsRef = useRef<DrawerActions>(null)
const showInstallAction = canInstallPlugin
const reserveInstallActionSlot = showInstallAction || isReferenceSettingLoading
const showUtilityActions = canDebugger || showPermissionQuickPanel
@@ -249,7 +250,7 @@ export default function IntegrationsPage({
}
const handleSelectSection = (nextSection: IntegrationSection) => {
if (onSectionChange) {
- setIsNavigationOpen(false)
+ navigationDrawerActionsRef.current?.close()
onSectionChange(nextSection)
return
}
@@ -385,7 +386,7 @@ export default function IntegrationsPage({
)}
{isCompact ? (
<div className="shrink-0 border-b border-divider-burn px-2 pb-2">
- <Drawer swipeDirection="left" open={isNavigationOpen} onOpenChange={setIsNavigationOpen}>
+ <Drawer swipeDirection="left" actionsRef={navigationDrawerActionsRef}>
<DrawerTrigger render={<Button variant="secondary" className="max-w-full" />}>
<span aria-hidden="true" className="i-ri-menu-line size-4 shrink-0" />
<span className="truncate">
diff --git a/web/app/components/main-nav/components/workspace-switcher.tsx b/web/app/components/main-nav/components/workspace-switcher.tsx
index 51cf5fd76c8..b0ad8c99224 100644
--- a/web/app/components/main-nav/components/workspace-switcher.tsx
+++ b/web/app/components/main-nav/components/workspace-switcher.tsx
@@ -44,7 +44,6 @@ function WorkspaceSwitchControls({
onSortChange: (value: WorkspaceSort) => void
}) {
const { t } = useTranslation(['common', 'navigation'])
- const [sortMenuOpen, setSortMenuOpen] = useState(false)
const sortMenuLabel = t(($) => $['mainNav.workspace.sort.openMenu'], {
ns: 'navigation',
})
@@ -74,7 +73,7 @@ function WorkspaceSwitchControls({
{t(($) => $['userProfile.workspace'], { ns: 'common' })}
</span>
</div>
- <DropdownMenu open={sortMenuOpen} onOpenChange={setSortMenuOpen}>
+ <DropdownMenu>
<DropdownMenuTrigger
disabled={disabled}
className="data-popup-open:bg-state-base-hover data-popup-open:text-text-secondary"
@@ -91,13 +90,7 @@ function WorkspaceSwitchControls({
sideOffset={4}
className="w-40 bg-components-panel-bg-blur! p-1! backdrop-blur-[5px]"
>
- <DropdownMenuRadioGroup<WorkspaceSort>
- value={sort}
- onValueChange={(value) => {
- onSortChange(value)
- setSortMenuOpen(false)
- }}
- >
+ <DropdownMenuRadioGroup<WorkspaceSort> value={sort} onValueChange={onSortChange}>
{sortOptions.map((option) => (
<DropdownMenuRadioItem<WorkspaceSort>
key={option.value}
diff --git a/web/app/components/snippet-list/components/snippet-card.tsx b/web/app/components/snippet-list/components/snippet-card.tsx
index 2f98996f66c..800ce8bdb10 100644
--- a/web/app/components/snippet-list/components/snippet-card.tsx
+++ b/web/app/components/snippet-list/components/snippet-card.tsx
@@ -55,7 +55,6 @@ const SnippetCard = ({
const { t: tCommon } = useTranslation(['common'])
const workspacePermissionKeys = useAtomValue(workspacePermissionKeysAtom)
const { data: membersData } = useMembers()
- const [isOperationsMenuOpen, setIsOperationsMenuOpen] = useState(false)
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false)
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false)
const updateSnippetMutation = useUpdateSnippetMutation()
@@ -88,14 +87,12 @@ const SnippetCard = ({
)
const handleOpenEditDialog = () => {
- setIsOperationsMenuOpen(false)
setIsEditDialogOpen(true)
}
const handleExportSnippet = async () => {
if (!canCreateAndModifySnippet) return
- setIsOperationsMenuOpen(false)
try {
const data = await exportSnippetMutation.mutateAsync({ snippetId: snippet.id })
const file = new Blob([data], { type: 'application/yaml' })
@@ -187,11 +184,7 @@ const SnippetCard = ({
{canShowOperations && (
<div className="pointer-events-none absolute top-1/2 right-1.5 flex -translate-y-1/2 items-center opacity-0 transition-opacity group-focus-within:pointer-events-auto group-focus-within:opacity-100 group-hover:pointer-events-auto group-hover:opacity-100 has-data-popup-open:pointer-events-auto has-data-popup-open:opacity-100">
<div className="mx-1 h-3.5 w-px shrink-0 bg-divider-regular" />
- <DropdownMenu
- modal={false}
- open={isOperationsMenuOpen}
- onOpenChange={setIsOperationsMenuOpen}
- >
+ <DropdownMenu modal={false}>
<DropdownMenuTrigger
aria-label={tCommon(($) => $['operation.moreActionsFor'], {
ns: 'common',
@@ -228,10 +221,7 @@ const SnippetCard = ({
<DropdownMenuItem
variant="destructive"
className="gap-2 px-3"
- onClick={() => {
- setIsOperationsMenuOpen(false)
- setIsDeleteDialogOpen(true)
- }}
+ onClick={() => setIsDeleteDialogOpen(true)}
>
<span className="system-sm-regular">
{t(($) => $['menu.deleteSnippet'])}
diff --git a/web/app/components/tools/edit-custom-collection-modal/get-schema.tsx b/web/app/components/tools/edit-custom-collection-modal/get-schema.tsx
index 998d68bca75..78a815b4825 100644
--- a/web/app/components/tools/edit-custom-collection-modal/get-schema.tsx
+++ b/web/app/components/tools/edit-custom-collection-modal/get-schema.tsx
@@ -42,8 +42,6 @@ const GetSchema: FC<Props> = ({ onChange }) => {
}
}
- const [showExamples, setShowExamples] = useState(false)
-
return (
<div className="flex w-56 justify-end gap-1">
<Popover open={showImportFromUrl} onOpenChange={setShowImportFromUrl}>
@@ -90,7 +88,7 @@ const GetSchema: FC<Props> = ({ onChange }) => {
</form>
</PopoverContent>
</Popover>
- <DropdownMenu open={showExamples} onOpenChange={setShowExamples}>
+ <DropdownMenu>
<DropdownMenuTrigger render={<Button size="small" />}>
<span className="system-xs-medium text-text-secondary">
{t(($) => $['createTool.examples'], { ns: 'tools' })}
@@ -103,7 +101,6 @@ const GetSchema: FC<Props> = ({ onChange }) => {
key={item.key}
onClick={() => {
onChange(item.content)
- setShowExamples(false)
}}
className="system-sm-regular whitespace-nowrap text-text-secondary"
>
diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/components/dataset-item.tsx b/web/app/components/workflow/nodes/knowledge-retrieval/components/dataset-item.tsx
index d23b568ac70..c33f7f96fdf 100644
--- a/web/app/components/workflow/nodes/knowledge-retrieval/components/dataset-item.tsx
+++ b/web/app/components/workflow/nodes/knowledge-retrieval/components/dataset-item.tsx
@@ -1,4 +1,5 @@
'use client'
+import type { DrawerActions } from '@langgenius/dify-ui/drawer'
import type { FC } from 'react'
import type { DataSet } from '@/models/datasets'
import { cn } from '@langgenius/dify-ui/cn'
@@ -8,11 +9,12 @@ import {
DrawerContent,
DrawerPopup,
DrawerPortal,
+ DrawerTrigger,
DrawerViewport,
} from '@langgenius/dify-ui/drawer'
import { IconButton } from '@langgenius/dify-ui/icon-button'
import * as React from 'react'
-import { useCallback, useState } from 'react'
+import { useCallback, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import SettingsModal from '@/app/components/app/configuration/dataset-config/settings-modal'
import AppIcon from '@/app/components/base/app-icon'
@@ -51,12 +53,12 @@ const DatasetItem: FC<Props> = ({
const { formatIndexingTechniqueAndMethod } = useKnowledge()
const [isDeleteHovered, setIsDeleteHovered] = useState(false)
- const [isShowSettingsModal, setIsShowSettingsModal] = useState(false)
+ const settingsDrawerActionsRef = useRef<DrawerActions>(null)
const handleSave = useCallback(
(newDataset: DataSet) => {
onChange(newDataset)
- setIsShowSettingsModal(false)
+ settingsDrawerActionsRef.current?.close()
},
[onChange],
)
@@ -97,15 +99,48 @@ const DatasetItem: FC<Props> = ({
{!readonly && (
<div className="ml-2 hidden shrink-0 items-center space-x-1 group-hover/dataset-item:flex">
{editable && (
- <IconButton
- aria-label={t(($) => $['operation.edit'], { ns: 'common' })}
- onClick={(e) => {
- e.stopPropagation()
- setIsShowSettingsModal(true)
- }}
- >
- <span aria-hidden className="i-ri-edit-line size-4 shrink-0 text-text-tertiary" />
- </IconButton>
+ <Drawer actionsRef={settingsDrawerActionsRef} modal swipeDirection="right">
+ <DrawerTrigger
+ render={
+ <IconButton
+ aria-label={t(($) => $['operation.edit'], { ns: 'common' })}
+ onClick={(e) => e.stopPropagation()}
+ >
+ <span
+ aria-hidden
+ className="i-ri-edit-line size-4 shrink-0 text-text-tertiary"
+ />
+ </IconButton>
+ }
+ />
+ <DrawerPortal>
+ <DrawerBackdrop
+ forceRender={settingsDrawerBackdropForceRender}
+ className={cn(
+ !settingsDrawerBackdropClassName && !isMobile && 'bg-transparent',
+ settingsDrawerBackdropClassName,
+ )}
+ />
+ <DrawerViewport>
+ <DrawerPopup
+ className={cn(
+ 'p-0! data-[swipe-direction=right]:right-2 data-[swipe-direction=right]:h-auto data-[swipe-direction=right]:w-full data-[swipe-direction=right]:max-w-160 data-[swipe-direction=right]:rounded-xl',
+ settingsDrawerPopupClassName ??
+ 'data-[swipe-direction=right]:top-16 data-[swipe-direction=right]:bottom-3',
+ )}
+ >
+ <DrawerContent className="flex h-full min-h-0 flex-1 flex-col p-0 pb-0">
+ <SettingsModal
+ currentDataset={payload}
+ height={settingsModalHeight}
+ onCancel={() => settingsDrawerActionsRef.current?.close()}
+ onSave={handleSave}
+ />
+ </DrawerContent>
+ </DrawerPopup>
+ </DrawerViewport>
+ </DrawerPortal>
+ </Drawer>
)}
<IconButton
aria-label={t(($) => $['operation.remove'], { ns: 'common' })}
@@ -138,45 +173,6 @@ const DatasetItem: FC<Props> = ({
text={t(($) => $.externalTag, { ns: 'dataset' })}
/>
)}
-
- {isShowSettingsModal && (
- <Drawer
- open={isShowSettingsModal}
- modal
- swipeDirection="right"
- onOpenChange={(open) => {
- if (!open) setIsShowSettingsModal(false)
- }}
- >
- <DrawerPortal>
- <DrawerBackdrop
- forceRender={settingsDrawerBackdropForceRender}
- className={cn(
- !settingsDrawerBackdropClassName && !isMobile && 'bg-transparent',
- settingsDrawerBackdropClassName,
- )}
- />
- <DrawerViewport>
- <DrawerPopup
- className={cn(
- 'p-0! data-[swipe-direction=right]:right-2 data-[swipe-direction=right]:h-auto data-[swipe-direction=right]:w-full data-[swipe-direction=right]:max-w-160 data-[swipe-direction=right]:rounded-xl',
- settingsDrawerPopupClassName ??
- 'data-[swipe-direction=right]:top-16 data-[swipe-direction=right]:bottom-3',
- )}
- >
- <DrawerContent className="flex h-full min-h-0 flex-1 flex-col p-0 pb-0">
- <SettingsModal
- currentDataset={payload}
- height={settingsModalHeight}
- onCancel={() => setIsShowSettingsModal(false)}
- onSave={handleSave}
- />
- </DrawerContent>
- </DrawerPopup>
- </DrawerViewport>
- </DrawerPortal>
- </Drawer>
- )}
</div>
)
}