From 5357268a9c9d9ddc9690657b97f7e8578ca34149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Tue, 17 Dec 2024 16:12:58 +0300 Subject: [PATCH 1/5] feat: fix search --- src/components/App/ActionsToolbar/GraphClear/index.tsx | 4 ++-- src/components/App/SideBar/FilterSearch/index.tsx | 4 +++- src/components/App/index.tsx | 5 ++++- src/components/Universe/Graph/index.tsx | 8 ++++++++ src/stores/useDataStore/index.ts | 10 ++++++++-- src/stores/useGraphStore/index.ts | 3 +++ 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/components/App/ActionsToolbar/GraphClear/index.tsx b/src/components/App/ActionsToolbar/GraphClear/index.tsx index 4f1e4820f..1edd49591 100644 --- a/src/components/App/ActionsToolbar/GraphClear/index.tsx +++ b/src/components/App/ActionsToolbar/GraphClear/index.tsx @@ -5,11 +5,11 @@ import ClearIcon from '~/components/Icons/ClearIcon' import { useDataStore } from '~/stores/useDataStore' export const GraphClear = () => { - const { resetData } = useDataStore((s) => s) + const { resetGraph } = useDataStore((s) => s) return ( - resetData()} size="medium" startIcon={} /> + resetGraph()} size="medium" startIcon={} /> ) } diff --git a/src/components/App/SideBar/FilterSearch/index.tsx b/src/components/App/SideBar/FilterSearch/index.tsx index 679d96bb0..359798153 100644 --- a/src/components/App/SideBar/FilterSearch/index.tsx +++ b/src/components/App/SideBar/FilterSearch/index.tsx @@ -29,7 +29,7 @@ const defaultValues = { export const FilterSearch = ({ anchorEl, setAnchorEl, onClose }: Props) => { const [schemaAll, setSchemaAll] = useSchemaStore((s) => [s.schemas, s.setSchemas]) - const { abortFetchData, resetGraph, setFilters } = useDataStore((s) => s) + const { abortFetchData, resetGraph, setFilters, resetData } = useDataStore((s) => s) const [selectedTypes, setSelectedTypes] = useState(defaultValues.selectedTypes) const [hops, setHops] = useState(defaultValues.hops) const [sourceNodes, setSourceNodes] = useState(defaultValues.sourceNodes) @@ -74,6 +74,8 @@ export const FilterSearch = ({ anchorEl, setAnchorEl, onClose }: Props) => { } const handleFiltersApply = async () => { + resetData() + setFilters({ node_type: selectedTypes, limit: maxResults, diff --git a/src/components/App/index.tsx b/src/components/App/index.tsx index 4e99431c5..52fa1ce7b 100644 --- a/src/components/App/index.tsx +++ b/src/components/App/index.tsx @@ -79,6 +79,7 @@ export const App = () => { runningProjectId, setRunningProjectMessages, isFetching, + resetData, } = useDataStore((s) => s) const { setAiSummaryAnswer, getKeyExist, aiRefId } = useAiSummaryStore((s) => s) @@ -128,8 +129,10 @@ export const App = () => { } } + resetData() + runSearch() - }, [searchTerm, fetchData, setBudget, setAbortRequests, setSidebarOpen, setSelectedNode]) + }, [searchTerm, fetchData, setBudget, setAbortRequests, setSidebarOpen, setSelectedNode, resetData]) const handleNewNode = useCallback(() => { setNodeCount('INCREMENT') diff --git a/src/components/Universe/Graph/index.tsx b/src/components/Universe/Graph/index.tsx index 7a37e9354..2d653449f 100644 --- a/src/components/Universe/Graph/index.tsx +++ b/src/components/Universe/Graph/index.tsx @@ -33,6 +33,8 @@ export const Graph = () => { (s) => s, ) + const removeSimulation = useGraphStore((s) => s.removeSimulation) + useEffect(() => { if (!dataNew) { return @@ -57,6 +59,12 @@ export const Graph = () => { resetDataNew() }, [setData, dataNew, simulation, simulationCreate, resetDataNew, simulationHelpers, dataInitial]) + useEffect(() => { + if (!dataInitial) { + removeSimulation() + } + }, [dataInitial, removeSimulation]) + useEffect(() => { if (!simulation) { return diff --git a/src/stores/useDataStore/index.ts b/src/stores/useDataStore/index.ts index aec5da799..2dfb79131 100644 --- a/src/stores/useDataStore/index.ts +++ b/src/stores/useDataStore/index.ts @@ -313,9 +313,15 @@ export const useDataStore = create()( resetData: () => { set({ - dataNew: { nodes: [], links: [] }, - dataInitial: { nodes: [], links: [] }, + dataInitial: null, + sidebarFilter: 'all', + sidebarFilters: [], + sidebarFilterCounts: [], + dataNew: null, + runningProjectId: '', nodeTypes: [], + nodesNormalized: new Map(), + linksNormalized: new Map(), }) }, diff --git a/src/stores/useGraphStore/index.ts b/src/stores/useGraphStore/index.ts index b95b63083..82b165742 100644 --- a/src/stores/useGraphStore/index.ts +++ b/src/stores/useGraphStore/index.ts @@ -96,6 +96,7 @@ export type GraphStore = { setSelectionData: (data: GraphData) => void simulationCreate: (nodes: Node[], links: Link[]) => void setIsHovering: (isHovering: boolean) => void + removeSimulation: () => void } const defaultData: Omit< @@ -116,6 +117,7 @@ const defaultData: Omit< | 'setHideNodeDetails' | 'simulationCreate' | 'setIsHovering' + | 'removeSimulation' > = { data: null, simulation: null, @@ -318,6 +320,7 @@ export const useGraphStore = create()((set, get) => ({ set({ simulation }) }, + removeSimulation: () => set({ simulation: null }), })) export const useSelectedNode = () => useGraphStore((s) => s.selectedNode) From d122709645aa83b1be7052ef98eb86d1eae6fedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Tue, 17 Dec 2024 16:51:58 +0300 Subject: [PATCH 2/5] feat: unit test fix --- src/components/App/SideBar/FilterSearch/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/App/SideBar/FilterSearch/index.tsx b/src/components/App/SideBar/FilterSearch/index.tsx index 359798153..d0e00521b 100644 --- a/src/components/App/SideBar/FilterSearch/index.tsx +++ b/src/components/App/SideBar/FilterSearch/index.tsx @@ -74,7 +74,6 @@ export const FilterSearch = ({ anchorEl, setAnchorEl, onClose }: Props) => { } const handleFiltersApply = async () => { - resetData() setFilters({ node_type: selectedTypes, @@ -83,6 +82,8 @@ export const FilterSearch = ({ anchorEl, setAnchorEl, onClose }: Props) => { top_node_count: sourceNodes.toString(), }) + resetData() + setAnchorEl(null) onClose() } From 6d37731ee16252e6c49e34730cc43a9ec39d5a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Tue, 17 Dec 2024 17:51:35 +0300 Subject: [PATCH 3/5] feat: fix tests --- src/components/App/SideBar/FilterSearch/__tests__/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/App/SideBar/FilterSearch/__tests__/index.tsx b/src/components/App/SideBar/FilterSearch/__tests__/index.tsx index d6b0046d4..ede7691f4 100644 --- a/src/components/App/SideBar/FilterSearch/__tests__/index.tsx +++ b/src/components/App/SideBar/FilterSearch/__tests__/index.tsx @@ -91,7 +91,7 @@ describe('FilterSearch Component', () => { expect(type1Pill).toHaveStyle(`color: ${colors.black}`) }) - it('should apply filters when "Apply" is clicked', async () => { + it.skip('should apply filters when "Apply" is clicked', async () => { renderComponent() const type1Pill = screen.getByText('Type1') From e779a04974ea689f204c968630c7a9fd6f372b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Wed, 18 Dec 2024 00:24:41 +0300 Subject: [PATCH 4/5] feat: fix test --- src/components/App/SideBar/FilterSearch/__tests__/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/App/SideBar/FilterSearch/__tests__/index.tsx b/src/components/App/SideBar/FilterSearch/__tests__/index.tsx index ede7691f4..485ea0bd2 100644 --- a/src/components/App/SideBar/FilterSearch/__tests__/index.tsx +++ b/src/components/App/SideBar/FilterSearch/__tests__/index.tsx @@ -48,6 +48,7 @@ describe('FilterSearch Component', () => { ;(useDataStore as jest.Mock).mockReturnValue({ setFilters: mockSetFilters, fetchData: mockFetchData, + resetData: jest.fn(), setAbortRequests: mockSetAbortRequests, }) @@ -91,7 +92,7 @@ describe('FilterSearch Component', () => { expect(type1Pill).toHaveStyle(`color: ${colors.black}`) }) - it.skip('should apply filters when "Apply" is clicked', async () => { + it('should apply filters when "Apply" is clicked', async () => { renderComponent() const type1Pill = screen.getByText('Type1') From 072f8365cd628d3cce3fe51d12c8d5c55890659d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Wed, 18 Dec 2024 01:08:35 +0300 Subject: [PATCH 5/5] feat: fix search --- src/components/Auth/__tests__/index.tsx | 46 ++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/components/Auth/__tests__/index.tsx b/src/components/Auth/__tests__/index.tsx index 7ce03854a..0b8b6620c 100644 --- a/src/components/Auth/__tests__/index.tsx +++ b/src/components/Auth/__tests__/index.tsx @@ -56,6 +56,7 @@ describe('Auth Component', () => { setCategoryFilter: jest.fn(), setAbortRequests: jest.fn(), addNewNode: jest.fn(), + resetData: jest.fn(), splashDataLoading: false, }) @@ -208,13 +209,20 @@ describe('Auth Component', () => { }) test.skip('the unauthorized state is correctly set when the user lacks proper credentials', async () => { - const [setBudget, setIsAdmin, setPubKey, setIsAuthenticated] = [jest.fn(), jest.fn(), jest.fn(), jest.fn()] + const [setBudget, setIsAdmin, setPubKey, setIsAuthenticated, resetData] = [ + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + ] useUserStoreMock.mockReturnValue({ setBudget, setIsAdmin, setPubKey, setIsAuthenticated, + resetData, }) // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -239,13 +247,20 @@ describe('Auth Component', () => { }) test('test unsuccessful attempts to enable Sphinx', async () => { - const [setBudget, setIsAdmin, setPubKey, setIsAuthenticated] = [jest.fn(), jest.fn(), jest.fn(), jest.fn()] + const [setBudget, setIsAdmin, setPubKey, setIsAuthenticated, resetData] = [ + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + ] useUserStoreMock.mockReturnValue({ setBudget, setIsAdmin, setPubKey, setIsAuthenticated, + resetData, }) // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -271,13 +286,20 @@ describe('Auth Component', () => { }) test('test the public key is set correctly on successful Sphinx enablement', async () => { - const [setBudget, setIsAdmin, setPubKey, setIsAuthenticated] = [jest.fn(), jest.fn(), jest.fn(), jest.fn()] + const [setBudget, setIsAdmin, setPubKey, setIsAuthenticated, resetData] = [ + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + ] useUserStoreMock.mockReturnValue({ setBudget, setIsAdmin, setPubKey, setIsAuthenticated, + resetData, }) // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -302,13 +324,20 @@ describe('Auth Component', () => { }) test('test the public key state is handled correctly on Sphinx enablement failure', async () => { - const [setBudget, setIsAdmin, setPubKey, setIsAuthenticated] = [jest.fn(), jest.fn(), jest.fn(), jest.fn()] + const [setBudget, setIsAdmin, setPubKey, setIsAuthenticated, resetData] = [ + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + ] useUserStoreMock.mockReturnValue({ setBudget, setIsAdmin, setPubKey, setIsAuthenticated, + resetData, }) // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -333,13 +362,20 @@ describe('Auth Component', () => { }) test('simulate errors during the authentication process and verify that they are handled gracefully.', async () => { - const [setBudget, setIsAdmin, setPubKey, setIsAuthenticated] = [jest.fn(), jest.fn(), jest.fn(), jest.fn()] + const [setBudget, setIsAdmin, setPubKey, setIsAuthenticated, resetData] = [ + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + jest.fn(), + ] useUserStoreMock.mockReturnValue({ setBudget, setIsAdmin, setPubKey, setIsAuthenticated, + resetData, }) // eslint-disable-next-line @typescript-eslint/ban-ts-comment