From 672ef51f943598d6292eb85a8f886fb3f596ddee Mon Sep 17 00:00:00 2001 From: saithsab877 Date: Thu, 15 Aug 2024 02:28:15 +0500 Subject: [PATCH] fix(search): clear search filter --- .../App/SideBar/FilterSearch/index.tsx | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/components/App/SideBar/FilterSearch/index.tsx b/src/components/App/SideBar/FilterSearch/index.tsx index d08e9a343..945420f63 100644 --- a/src/components/App/SideBar/FilterSearch/index.tsx +++ b/src/components/App/SideBar/FilterSearch/index.tsx @@ -18,6 +18,13 @@ type Props = { anchorEl: HTMLElement | null } +const defaultValues = { + selectedTypes: [] as string[], + hops: 1, + sourceNodes: 10, + maxResults: 30, +} + export const FilterSearch = ({ showAllSchemas, setShowAllSchemas, schemaAll, anchorEl }: Props) => { const handleSchemaTypeClick = (type: string) => { setSelectedTypes((prevSelectedTypes) => @@ -26,16 +33,20 @@ export const FilterSearch = ({ showAllSchemas, setShowAllSchemas, schemaAll, anc } const { setFilters } = useDataStore((s) => s) - const [selectedTypes, setSelectedTypes] = useState([]) - const [hops, setHops] = useState(1) - const [sourceNodes, setSourceNodes] = useState(10) - const [maxResults, setMaxResults] = useState(30) + const [selectedTypes, setSelectedTypes] = useState(defaultValues.selectedTypes) + const [hops, setHops] = useState(defaultValues.hops) + const [sourceNodes, setSourceNodes] = useState(defaultValues.sourceNodes) + const [maxResults, setMaxResults] = useState(defaultValues.maxResults) + + const resetToDefaultValues = () => { + setSelectedTypes(defaultValues.selectedTypes) + setHops(defaultValues.hops) + setSourceNodes(defaultValues.sourceNodes) + setMaxResults(defaultValues.maxResults) + } const handleClear = async () => { - setSelectedTypes([]) - setHops(1) - setSourceNodes(10) - setMaxResults(30) + resetToDefaultValues() } const handleViewMoreClick = () => {