mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-23 08:56:42 +08:00
fix(web): prevent search popover from flashing at top-left on checkbox toggle (#17148)
This commit is contained in:
@@ -22,7 +22,7 @@ import {
|
||||
} from '@/hooks/use-knowledge-request';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { CheckIcon, ChevronDown, Files, XIcon } from 'lucide-react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
interface IProps {
|
||||
@@ -52,10 +52,15 @@ const RetrievalDocuments = ({
|
||||
}
|
||||
}, [isTesting, setLoading]);
|
||||
|
||||
const { documents: useDocuments } = {
|
||||
documents:
|
||||
documentsAll?.length > documents?.length ? documentsAll : documents,
|
||||
};
|
||||
const latestDocuments =
|
||||
documentsAll?.length > documents?.length ? documentsAll : documents;
|
||||
// Keep the last non-empty list so the popover anchor is not unmounted
|
||||
// while a new testing request is pending.
|
||||
const documentsRef = useRef(latestDocuments);
|
||||
if (latestDocuments?.length) {
|
||||
documentsRef.current = latestDocuments;
|
||||
}
|
||||
const useDocuments = documentsRef.current;
|
||||
const [selectedValues, setSelectedValues] =
|
||||
useState<string[]>(selectedDocumentIds);
|
||||
|
||||
@@ -115,7 +120,7 @@ const RetrievalDocuments = ({
|
||||
return (
|
||||
<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
{useDocuments?.length && (
|
||||
{useDocuments?.length > 0 && (
|
||||
<Button
|
||||
onClick={handleTogglePopover}
|
||||
className={cn(
|
||||
|
||||
Reference in New Issue
Block a user