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/__tests__/index.tsx b/src/components/App/SideBar/FilterSearch/__tests__/index.tsx
index d6b0046d4..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,
})
diff --git a/src/components/App/SideBar/FilterSearch/index.tsx b/src/components/App/SideBar/FilterSearch/index.tsx
index 679d96bb0..d0e00521b 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,7 @@ export const FilterSearch = ({ anchorEl, setAnchorEl, onClose }: Props) => {
}
const handleFiltersApply = async () => {
+
setFilters({
node_type: selectedTypes,
limit: maxResults,
@@ -81,6 +82,8 @@ export const FilterSearch = ({ anchorEl, setAnchorEl, onClose }: Props) => {
top_node_count: sourceNodes.toString(),
})
+ resetData()
+
setAnchorEl(null)
onClose()
}
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/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
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)