Skip to content

Commit

Permalink
feat: add try catch, additional check for incorrect links
Browse files Browse the repository at this point in the history
  • Loading branch information
Rassl committed Sep 25, 2024
1 parent 9fc43d7 commit 213d2bc
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/stores/useGraphStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,31 @@ export const useGraphStore = create<GraphStore>()((set, get) => ({
nodes.push(...structuredNodes)
links.push(...structuredLinks)

simulation.nodes(nodes).force('link').links(links)
try {
simulation.nodes(nodes)

const filteredLinks = links.filter((link: Link<NodeExtended | string>) => {
const { target, source } = link
const simulationNodes = simulation.nodes()

// Log the target and source ref_id for debugging
const targetRefId = (target as NodeExtended)?.ref_id || target
const sourceRefId = (source as NodeExtended)?.ref_id || source

return (
simulationNodes.some((n: NodeExtended) => n.ref_id === targetRefId) &&
simulationNodes.some((n: NodeExtended) => n.ref_id === sourceRefId)
)
})

simulation.force('link').links([]).links(filteredLinks)

simulationHelpers.simulationRestart()
} catch (error) {
console.log(error)

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

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

Check warning on line 206 in src/stores/useGraphStore/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 206 in src/stores/useGraphStore/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 206 in src/stores/useGraphStore/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 206 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

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

Unexpected console statement

Check warning on line 206 in src/stores/useGraphStore/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 206 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

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

Unexpected console statement

Check warning on line 206 in src/stores/useGraphStore/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 206 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

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

Unexpected console statement

Check warning on line 206 in src/stores/useGraphStore/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 206 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

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

Unexpected console statement

Check warning on line 206 in src/stores/useGraphStore/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 206 in src/stores/useGraphStore/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 206 in src/stores/useGraphStore/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 206 in src/stores/useGraphStore/index.ts

View workflow job for this annotation

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

Unexpected console statement

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

View workflow job for this annotation

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

Unexpected console statement
// eslint-disable-next-line no-debugger
}

simulationHelpers.simulationRestart()
// Add simulation node to reference (so that we can access reference on tick to update position)
},

Expand Down Expand Up @@ -280,6 +302,8 @@ export const useGraphStore = create<GraphStore>()((set, get) => ({
},
},
simulationCreate: (nodes, links) => {
console.log('created')

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

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

const structuredNodes = structuredClone(nodes)
const structuredLinks = structuredClone(links)

Expand Down

0 comments on commit 213d2bc

Please sign in to comment.