Skip to content

Commit

Permalink
update disabling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodanswer committed Oct 6, 2024
1 parent 603976e commit 3a144d1
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions web/src/components/search/SearchSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ValidQuestionResponse,
Relevance,
SearchDanswerDocument,
SourceMetadata,
} from "@/lib/search/interfaces";
import { searchRequestStreamed } from "@/lib/search/streamingQa";
import { CancellationToken, cancellable } from "@/lib/search/cancellable";
Expand All @@ -40,6 +41,9 @@ import { ApiKeyModal } from "../llm/ApiKeyModal";
import { useSearchContext } from "../context/SearchContext";
import { useUser } from "../user/UserProvider";
import UnconfiguredProviderText from "../chat_search/UnconfiguredProviderText";
import { DateRangePickerValue } from "@tremor/react";
import { Tag } from "@/lib/types";
import { isEqual } from "lodash";

export type searchState =
| "input"
Expand Down Expand Up @@ -370,8 +374,36 @@ export const SearchSection = ({
setSearchAnswerExpanded(false);
};

const [previousSearch, setPreviousSearch] = useState<string>("");
interface SearchDetails {
query: string;
sources: SourceMetadata[];
agentic: boolean;
documentSets: string[];
timeRange: DateRangePickerValue | null;
tags: Tag[];
persona: Persona;
}

const [previousSearch, setPreviousSearch] = useState<null | SearchDetails>(
null
);
const [agenticResults, setAgenticResults] = useState<boolean | null>(null);
const currentSearch = (overrideMessage?: string): SearchDetails => {
return {
query: overrideMessage || query,
sources: filterManager.selectedSources,
agentic: agentic!,
documentSets: filterManager.selectedDocumentSets,
timeRange: filterManager.timeRange,
tags: filterManager.selectedTags,
persona: assistants.find(
(assistant) => assistant.id === selectedPersona
) as Persona,
};
};
const isSearchChanged = () => {
return !isEqual(currentSearch(), previousSearch);
};

let lastSearchCancellationToken = useRef<CancellationToken | null>(null);
const onSearch = async ({
Expand All @@ -394,7 +426,9 @@ export const SearchSection = ({

setIsFetching(true);
setSearchResponse(initialSearchResponse);
setPreviousSearch(overrideMessage || query);

setPreviousSearch(currentSearch(overrideMessage));

const searchFnArgs = {
query: overrideMessage || query,
sources: filterManager.selectedSources,
Expand Down Expand Up @@ -761,7 +795,7 @@ export const SearchSection = ({
/>

<FullSearchBar
disabled={previousSearch === query}
disabled={!isSearchChanged()}
toggleAgentic={
disabledAgentic ? undefined : toggleAgentic
}
Expand Down

0 comments on commit 3a144d1

Please sign in to comment.