Skip to content

Commit

Permalink
feat: fix search
Browse files Browse the repository at this point in the history
  • Loading branch information
Rassl committed Dec 17, 2024
1 parent 9c64b0c commit 5357268
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/App/ActionsToolbar/GraphClear/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Tooltip content="Clear Graph" fontSize="13px" position="left">
<ClearButton href="" onClick={() => resetData()} size="medium" startIcon={<ClearIcon />} />
<ClearButton href="" onClick={() => resetGraph()} size="medium" startIcon={<ClearIcon />} />
</Tooltip>
)
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/App/SideBar/FilterSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>(defaultValues.selectedTypes)
const [hops, setHops] = useState(defaultValues.hops)
const [sourceNodes, setSourceNodes] = useState<number>(defaultValues.sourceNodes)
Expand Down Expand Up @@ -74,6 +74,8 @@ export const FilterSearch = ({ anchorEl, setAnchorEl, onClose }: Props) => {
}

const handleFiltersApply = async () => {
resetData()

setFilters({
node_type: selectedTypes,
limit: maxResults,
Expand Down
5 changes: 4 additions & 1 deletion src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const App = () => {
runningProjectId,
setRunningProjectMessages,
isFetching,
resetData,
} = useDataStore((s) => s)

const { setAiSummaryAnswer, getKeyExist, aiRefId } = useAiSummaryStore((s) => s)
Expand Down Expand Up @@ -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')
Expand Down
8 changes: 8 additions & 0 deletions src/components/Universe/Graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const Graph = () => {
(s) => s,
)

const removeSimulation = useGraphStore((s) => s.removeSimulation)

useEffect(() => {
if (!dataNew) {
return
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/stores/useDataStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,15 @@ export const useDataStore = create<DataStore>()(

resetData: () => {
set({
dataNew: { nodes: [], links: [] },
dataInitial: { nodes: [], links: [] },
dataInitial: null,
sidebarFilter: 'all',
sidebarFilters: [],
sidebarFilterCounts: [],
dataNew: null,
runningProjectId: '',
nodeTypes: [],
nodesNormalized: new Map<string, Node>(),
linksNormalized: new Map<string, Link>(),
})
},

Expand Down
3 changes: 3 additions & 0 deletions src/stores/useGraphStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand All @@ -116,6 +117,7 @@ const defaultData: Omit<
| 'setHideNodeDetails'
| 'simulationCreate'
| 'setIsHovering'
| 'removeSimulation'
> = {
data: null,
simulation: null,
Expand Down Expand Up @@ -318,6 +320,7 @@ export const useGraphStore = create<GraphStore>()((set, get) => ({

set({ simulation })
},
removeSimulation: () => set({ simulation: null }),
}))

export const useSelectedNode = () => useGraphStore((s) => s.selectedNode)
Expand Down

0 comments on commit 5357268

Please sign in to comment.