From d696fd0f75192915868cddba0a2c1823f055b048 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 10 Sep 2024 08:44:50 -0700 Subject: [PATCH] Prevent spam search (#2367) --- web/src/components/search/SearchBar.tsx | 18 +++++++++++++----- .../components/search/SearchResultsDisplay.tsx | 5 ++++- web/src/components/search/SearchSection.tsx | 8 ++++++-- web/src/lib/connectors/connectors.ts | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/web/src/components/search/SearchBar.tsx b/web/src/components/search/SearchBar.tsx index 7d62b099206..e15319931a6 100644 --- a/web/src/components/search/SearchBar.tsx +++ b/web/src/components/search/SearchBar.tsx @@ -2,7 +2,9 @@ import React, { KeyboardEvent, ChangeEvent, useContext } from "react"; import { MagnifyingGlass } from "@phosphor-icons/react"; interface FullSearchBarProps { + disabled: boolean; query: string; + setPopup: (popupSpec: PopupSpec | null) => void; setQuery: (query: string) => void; onSearch: (fast?: boolean) => void; agentic?: boolean; @@ -14,6 +16,7 @@ interface FullSearchBarProps { finalAvailableSources: string[]; tags: Tag[]; showingSidebar: boolean; + previousSearch: string; } import { useState, useEffect, useRef } from "react"; @@ -25,6 +28,7 @@ import { SettingsContext } from "../settings/SettingsProvider"; import { HorizontalSourceSelector, SourceSelector } from "./filtering/Filters"; import { CCPairBasicInfo, DocumentSet, Tag } from "@/lib/types"; import { SourceMetadata } from "@/lib/search/interfaces"; +import { PopupSpec } from "../admin/connectors/Popup"; export const AnimatedToggle = ({ isOn, @@ -123,6 +127,7 @@ export const AnimatedToggle = ({ export default AnimatedToggle; export const FullSearchBar = ({ + disabled, showingSidebar, query, setQuery, @@ -133,8 +138,10 @@ export const FullSearchBar = ({ documentSets, filterManager, finalAvailableDocumentSets, + setPopup, finalAvailableSources, tags, + previousSearch, }: FullSearchBarProps) => { const handleChange = (event: ChangeEvent) => { const target = event.target; @@ -152,8 +159,10 @@ export const FullSearchBar = ({ !event.shiftKey && !(event.nativeEvent as any).isComposing ) { - onSearch(agentic); event.preventDefault(); + if (!disabled) { + onSearch(agentic); + } } }; @@ -200,13 +209,12 @@ export const FullSearchBar = ({ style={{ scrollbarWidth: "thin" }} role="textarea" aria-multiline - placeholder="Search for something..." + placeholder="Search for anything..." value={query} onChange={handleChange} onKeyDown={(event) => {}} suppressContentEditableWarning={true} /> -
@@ -226,9 +234,9 @@ export const FullSearchBar = ({ {toggleAgentic && ( )} -
} + >