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.

fix(web): reset goto anything search after dialog closes (#41976)

yyh0955b8b810bf
diff --git a/web/app/components/goto-anything/__tests__/index.spec.tsx b/web/app/components/goto-anything/__tests__/index.spec.tsx
index 4fb6e3825f4..4cc4b3a0751 100644
--- a/web/app/components/goto-anything/__tests__/index.spec.tsx
+++ b/web/app/components/goto-anything/__tests__/index.spec.tsx
@@ -388,7 +388,7 @@ describe('GotoAnything', () => {
expect(input).toHaveFocus()
})
- it('should reset search query when modal opens', async () => {
+ it('should reopen with an empty search after the modal finishes closing', async () => {
const user = userEvent.setup()
renderGotoAnything(<GotoAnything />)
diff --git a/web/app/components/goto-anything/index.tsx b/web/app/components/goto-anything/index.tsx
index 336f0d8e99f..b0a23c860e2 100644
--- a/web/app/components/goto-anything/index.tsx
+++ b/web/app/components/goto-anything/index.tsx
@@ -226,7 +226,7 @@ function chunkArray<T>(items: readonly T[], size: number): T[][] {
return rows
}
-function GotoAnythingDialog() {
+export function GotoAnything() {
const { t } = useTranslation()
const pathname = usePathname()
const router = useRouter()
@@ -379,8 +379,8 @@ function GotoAnythingDialog() {
const dedupedResults = dedupeSearchResults(searchResults)
const groupedResults = groupSearchResults(dedupedResults)
- function resetSearch() {
- setSearchQuery('')
+ function handleDialogOpenChangeComplete(open: boolean) {
+ if (!open) setSearchQuery('')
}
useHotkey(
@@ -432,13 +432,6 @@ function GotoAnythingDialog() {
}
}
- function handleAutocompleteOpenChange(
- nextOpen: boolean,
- eventDetails: AutocompleteChangeEventDetails,
- ) {
- if (!nextOpen && eventDetails.reason === 'escape-key') gotoAnythingDialogHandle.close()
- }
-
function handleAutocompleteValueChange(
nextValue: string,
eventDetails: AutocompleteChangeEventDetails,
@@ -500,7 +493,10 @@ function GotoAnythingDialog() {
return (
<>
<SlashCommandProvider />
- <Dialog handle={gotoAnythingDialogHandle} onOpenChange={resetSearch}>
+ <Dialog
+ handle={gotoAnythingDialogHandle}
+ onOpenChangeComplete={handleDialogOpenChangeComplete}
+ >
<DialogPortal>
<DialogBackdrop />
<DialogPopup
@@ -522,7 +518,6 @@ function GotoAnythingDialog() {
items={visibleOptions}
value={searchQuery}
onValueChange={handleAutocompleteValueChange}
- onOpenChange={handleAutocompleteOpenChange}
itemToStringValue={optionToInputValue}
filter={null}
grid={isCommandsMode}
@@ -709,7 +704,3 @@ function GotoAnythingDialog() {
</>
)
}
-
-export function GotoAnything() {
- return <GotoAnythingDialog />
-}