From ee2af7ac83dae998ebff821b1cb9bbe18dd0a9bd Mon Sep 17 00:00:00 2001 From: Sjoerd <svink@graphpolaris.com> Date: Tue, 8 Oct 2024 09:44:39 +0000 Subject: [PATCH] fix: fixed schema error and only nodes schema --- .../lib/schema/pills/nodes/entity/SchemaListEntityPill.tsx | 2 +- .../schema/pills/nodes/relation/SchemaListRelationPill.tsx | 2 +- libs/shared/lib/schema/schema-utils/schema-utils.ts | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/shared/lib/schema/pills/nodes/entity/SchemaListEntityPill.tsx b/libs/shared/lib/schema/pills/nodes/entity/SchemaListEntityPill.tsx index 72b78ffb2..026c94e4a 100644 --- a/libs/shared/lib/schema/pills/nodes/entity/SchemaListEntityPill.tsx +++ b/libs/shared/lib/schema/pills/nodes/entity/SchemaListEntityPill.tsx @@ -83,7 +83,7 @@ export const SchemaListEntityPill = React.memo(({ id, selected, data }: NodeProp }, {} as Record<string, string>, )} - numberOfElements={schemaStats.nodes.stats[data.name].count} + numberOfElements={schemaStats?.nodes?.stats[data.name]?.count} /> </VisualizationTooltip> </div> diff --git a/libs/shared/lib/schema/pills/nodes/relation/SchemaListRelationPill.tsx b/libs/shared/lib/schema/pills/nodes/relation/SchemaListRelationPill.tsx index 57ce01511..2755222f7 100644 --- a/libs/shared/lib/schema/pills/nodes/relation/SchemaListRelationPill.tsx +++ b/libs/shared/lib/schema/pills/nodes/relation/SchemaListRelationPill.tsx @@ -95,7 +95,7 @@ export const SchemaListRelationPill = React.memo(({ id, selected, data, ...props : {} } connections={{ from: data.from, to: data.to }} - numberOfElements={schemaStats.edges.stats[data.collection]?.count} + numberOfElements={schemaStats?.edges?.stats[data.collection]?.count} /> </VisualizationTooltip> </div> diff --git a/libs/shared/lib/schema/schema-utils/schema-utils.ts b/libs/shared/lib/schema/schema-utils/schema-utils.ts index 0dc0e48fc..27f2abc84 100644 --- a/libs/shared/lib/schema/schema-utils/schema-utils.ts +++ b/libs/shared/lib/schema/schema-utils/schema-utils.ts @@ -6,8 +6,9 @@ export class SchemaUtils { // Instantiate a directed graph that allows self loops and parallel edges const schemaGraphology = new SchemaGraphology({ allowSelfLoops: true }); + // The graph schema needs a node for each node AND edge. These need then be connected - if (!nodes || !edges) return schemaGraphology; + if (!nodes) return schemaGraphology; nodes.forEach((node) => { const attributes: SchemaGraphologyNode = { @@ -23,6 +24,8 @@ export class SchemaUtils { schemaGraphology.addNode(node.name, attributes); }); + if (!edges) return schemaGraphology; + // The name of the edge will be name + from + to, since edge names are not unique edges.forEach((edge) => { const edgeID = [edge.name, '_', edge.from, edge.to].join(''); //ensure that all interpreted as string -- GitLab