Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix search #2552

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('FilterSearch Component', () => {
;(useDataStore as jest.Mock).mockReturnValue({
setFilters: mockSetFilters,
fetchData: mockFetchData,
resetData: jest.fn(),
setAbortRequests: mockSetAbortRequests,
})

Expand Down
5 changes: 4 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,13 +74,16 @@ export const FilterSearch = ({ anchorEl, setAnchorEl, onClose }: Props) => {
}

const handleFiltersApply = async () => {

setFilters({
node_type: selectedTypes,
limit: maxResults,
depth: hops.toString(),
top_node_count: sourceNodes.toString(),
})

resetData()

setAnchorEl(null)
onClose()
}
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 @@
runningProjectId,
setRunningProjectMessages,
isFetching,
resetData,
} = useDataStore((s) => s)

const { setAiSummaryAnswer, getKeyExist, aiRefId } = useAiSummaryStore((s) => s)
Expand Down Expand Up @@ -128,8 +129,10 @@
}
}

resetData()

runSearch()
}, [searchTerm, fetchData, setBudget, setAbortRequests, setSidebarOpen, setSelectedNode])
}, [searchTerm, fetchData, setBudget, setAbortRequests, setSidebarOpen, setSelectedNode, resetData])

const handleNewNode = useCallback(() => {
setNodeCount('INCREMENT')
Expand Down Expand Up @@ -276,7 +279,7 @@
])

useEffect(() => {
if (!runningProjectId || true) {

Check warning on line 282 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected constant condition

Check warning on line 282 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected constant condition

Check warning on line 282 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected constant condition

Check warning on line 282 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected constant condition

Check warning on line 282 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected constant condition

Check warning on line 282 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected constant condition

Check warning on line 282 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected constant condition

Check warning on line 282 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected constant condition

Check warning on line 282 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected constant condition

Check warning on line 282 in src/components/App/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected constant condition
return
}

Expand Down
46 changes: 41 additions & 5 deletions src/components/Auth/__tests__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('Auth Component', () => {
setCategoryFilter: jest.fn(),
setAbortRequests: jest.fn(),
addNewNode: jest.fn(),
resetData: jest.fn(),
splashDataLoading: false,
})

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
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 @@
(s) => s,
)

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

useEffect(() => {
if (!dataNew) {
return
Expand All @@ -57,6 +59,12 @@
resetDataNew()
}, [setData, dataNew, simulation, simulationCreate, resetDataNew, simulationHelpers, dataInitial])

useEffect(() => {
if (!dataInitial) {
removeSimulation()
}
}, [dataInitial, removeSimulation])

useEffect(() => {
if (!simulation) {
return
Expand All @@ -82,7 +90,7 @@

const sphereRadius = Math.min(5000, boundingSphere.radius)

if (false) {

Check warning on line 93 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected constant condition

Check warning on line 93 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected constant condition

Check warning on line 93 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected constant condition

Check warning on line 93 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected constant condition

Check warning on line 93 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected constant condition

Check warning on line 93 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected constant condition

Check warning on line 93 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected constant condition

Check warning on line 93 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected constant condition
setGraphRadius(sphereRadius)
cameraSettled.current = true
}
Expand Down Expand Up @@ -174,7 +182,7 @@

const boundingBox = new Box3().setFromPoints(nodesVector)

console.log(boundingBox)

Check warning on line 185 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected console statement

Check warning on line 185 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected console statement

Check warning on line 185 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected console statement

Check warning on line 185 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected console statement

Check warning on line 185 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected console statement

Check warning on line 185 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected console statement

Check warning on line 185 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected console statement

Check warning on line 185 in src/components/Universe/Graph/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected console statement
})
}, [dataInitial, simulation, setGraphRadius, normalizedSchemasByType])

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 @@

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 Expand Up @@ -346,11 +352,11 @@
setHideNodeDetails: (hideNodeDetails) => set({ hideNodeDetails }),
setSeedQuestions: (questions) => set({ seedQuestions: questions }),
updateNode: (updatedNode) => {
console.info(updatedNode)

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addSource.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/createGeneratedEdges/createGeneratedEdges.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/topics.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/sourcesTable/sourcesTable.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/curationTable/curation.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected console statement

Check warning on line 355 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected console statement
},

removeNode: (id) => {
console.log(id)

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addSource.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/createGeneratedEdges/createGeneratedEdges.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/topics.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/sourcesTable/sourcesTable.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/curationTable/curation.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected console statement

Check warning on line 359 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected console statement
},

setRunningProjectId: (runningProjectId) => set({ runningProjectId, runningProjectMessages: [] }),
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 @@
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 @@
| 'setHideNodeDetails'
| 'simulationCreate'
| 'setIsHovering'
| 'removeSimulation'
> = {
data: null,
simulation: null,
Expand Down Expand Up @@ -294,7 +296,7 @@
simulationRestart: () => {
const { simulation } = get()

if (false) {

Check warning on line 299 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected constant condition

Check warning on line 299 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected constant condition

Check warning on line 299 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected constant condition

Check warning on line 299 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected constant condition

Check warning on line 299 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected constant condition

Check warning on line 299 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected constant condition

Check warning on line 299 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected constant condition

Check warning on line 299 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected constant condition

Check warning on line 299 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected constant condition
runSimulationPhase(simulation)
}

Expand All @@ -318,6 +320,7 @@

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

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