@reltio/graph 1.4.1585 → 1.4.1586-mui5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +1 -0
- package/package.json +26 -9
- package/public/bundle.js +205 -0
- package/public/bundle.js.LICENSE.txt +88 -0
- package/public/package.json +29 -0
- package/scripts/build/index.js +20 -0
- package/src/__tests__/GraphView.test.tsx +25 -0
- package/src/components/CircleLayout/CircleLayout.tsx +76 -0
- package/src/components/CircleLayout/__tests__/CircleLayout.test.tsx +194 -0
- package/src/components/GotoButton/GotoButton.tsx +23 -0
- package/src/components/GotoButton/__tests__/GotoButton.test.tsx +33 -0
- package/src/components/GotoButton/styles.ts +15 -0
- package/src/components/GraphArea/GraphArea.tsx +113 -0
- package/src/components/GraphArea/__tests__/GraphArea.test.tsx +202 -0
- package/src/components/GraphArea/styles.ts +30 -0
- package/src/components/GraphLayoutSelector/GraphLayoutSelector.tsx +43 -0
- package/src/components/GraphLayoutSelector/__tests__/GraphLayoutSelector.spec.tsx +44 -0
- package/src/components/GraphLayoutSelector/styles.ts +15 -0
- package/src/components/GraphPerspectiveView/GraphPerspectiveView.tsx +58 -0
- package/src/components/GraphPerspectiveView/__tests__/GraphPerspectiveView.test.tsx +115 -0
- package/src/components/GraphPerspectiveView/__tests__/useGraphLoader.test.tsx +1519 -0
- package/src/components/GraphPerspectiveView/__tests__/useRelationshipTable.test.tsx +1003 -0
- package/src/components/GraphPerspectiveView/__tests__/useSelectedEntity.test.tsx +373 -0
- package/src/components/GraphPerspectiveView/styles.ts +34 -0
- package/src/components/GraphRightSidePanel/GraphRightSidePanel.tsx +27 -0
- package/src/components/GraphRightSidePanel/__tests__/GraphRightSidePanel.test.tsx +18 -0
- package/src/components/GraphRightSidePanel/icons/relationship-icon.svg +3 -0
- package/src/components/GraphRightSidePanel/styles.ts +8 -0
- package/src/components/GraphTypeSelector/GraphTypeSelector.tsx +56 -0
- package/src/components/GraphTypeSelector/__tests__/GraphTypeSelector.test.tsx +109 -0
- package/src/components/GraphTypeSelector/styles.ts +17 -0
- package/src/components/HierarchyLayout/HierarchyLayout.ts +102 -0
- package/src/components/HierarchyLayout/__tests__/HierarchyLayout.spec.tsx +241 -0
- package/src/components/HierarchyLayout/__tests__/buildHierarchy.spec.ts +130 -0
- package/src/components/HierarchyLayout/__tests__/calculations.spec.ts +230 -0
- package/src/components/HierarchyLayout/buildHierarchy.ts +109 -0
- package/src/components/HierarchyLayout/calculations.ts +86 -0
- package/src/components/RightPanelEntityDetails/RightPanelEntityDetails.tsx +33 -0
- package/src/components/RightPanelEntityDetails/__tests__/RightPanelEntityDetails.test.tsx +39 -0
- package/src/components/RightPanelEntityDetails/styles.ts +12 -0
- package/src/components/RightPanelProfileBand/RightPanelProfileBand.tsx +33 -0
- package/src/components/RightPanelProfileBand/__tests__/RightPanelProfileBand.test.tsx +67 -0
- package/src/components/RightPanelProfileBand/styles.ts +8 -0
- package/src/components/RightPanelRelationship/RightPanelRelationship.tsx +25 -0
- package/src/components/RightPanelRelationship/__tests__/RightPanelRelationship.test.tsx +18 -0
- package/src/components/RightPanelRelationship/components/CollapsibleTable/CollapsibleTable.tsx +100 -0
- package/src/components/RightPanelRelationship/components/CollapsibleTable/TableHead.tsx +38 -0
- package/src/components/RightPanelRelationship/components/CollapsibleTable/__tests__/CollapsibleTable.test.tsx +169 -0
- package/src/components/RightPanelRelationship/components/CollapsibleTable/__tests__/TableHead.test.tsx +107 -0
- package/src/components/RightPanelRelationship/components/CollapsibleTable/styles.ts +38 -0
- package/src/components/RightPanelRelationship/components/CollapsibleTable/types.ts +20 -0
- package/src/components/RightPanelRelationship/components/DeleteRelationDialog/DeleteRelationDialog.tsx +34 -0
- package/src/components/RightPanelRelationship/components/DeleteRelationDialog/__tests__/DeleteRelationDialog.test.tsx +46 -0
- package/src/components/RightPanelRelationship/components/GraphAddRelationDialog/GraphAddRelationButton.tsx +43 -0
- package/src/components/RightPanelRelationship/components/GraphAddRelationDialog/GraphAddRelationDialog.tsx +121 -0
- package/src/components/RightPanelRelationship/components/GraphAddRelationDialog/__tests__/GraphAddRelationButton.test.tsx +80 -0
- package/src/components/RightPanelRelationship/components/GraphAddRelationDialog/__tests__/GraphAddRelationDialog.test.tsx +262 -0
- package/src/components/RightPanelRelationship/components/GraphAddRelationDialog/__tests__/mockdata.ts +75 -0
- package/src/components/RightPanelRelationship/components/GraphAddRelationDialog/styles.ts +25 -0
- package/src/components/RightPanelRelationship/components/GraphAddRelationDialog/useCreatableInOutRelationTypes.ts +13 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/RelationshipTable.tsx +126 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/__tests__/RelationshipTable.test.tsx +176 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/ControlsCellRenderer.tsx +59 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/DefaultCellRenderer.tsx +29 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/ExpandedRowRenderer.tsx +94 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/HeadCellRenderer.tsx +34 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/ProfileCellRenderer.tsx +41 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/__tests__/ControlsCellRenderer.test.tsx +80 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/__tests__/DefaultCellRenderer.test.tsx +47 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/__tests__/ExpandedRowRenderer.test.tsx +166 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/__tests__/HeadCellRenderer.test.tsx +23 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/__tests__/ProfileCellRenderer.test.tsx +47 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/components/DeleteRelationButton.tsx +32 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/components/__tests__/DeleteRelationButton.test.tsx +28 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/cell-renderers/styles.ts +113 -0
- package/src/components/RightPanelRelationship/components/RelationshipTable/styles.ts +36 -0
- package/src/components/RightPanelRelationship/components/RelationshipsFilters/RelationshipsFilters.tsx +41 -0
- package/src/components/RightPanelRelationship/components/RelationshipsFilters/RelationshipsFiltersDialog/RelationshipsFiltersDialog.tsx +91 -0
- package/src/components/RightPanelRelationship/components/RelationshipsFilters/RelationshipsFiltersDialog/__tests__/RelationshipsFilterDialog.test.tsx +192 -0
- package/src/components/RightPanelRelationship/components/RelationshipsFilters/RelationshipsFiltersDialog/styles.ts +34 -0
- package/src/components/RightPanelRelationship/components/RelationshipsFilters/RelationshipsSearchTextField/RelationshipsSearchTextField.tsx +31 -0
- package/src/components/RightPanelRelationship/components/RelationshipsFilters/RelationshipsSearchTextField/__tests__/RelationshipsSearchTextField.test.tsx +43 -0
- package/src/components/RightPanelRelationship/components/RelationshipsFilters/RelationshipsSearchTextField/styles.ts +17 -0
- package/src/components/RightPanelRelationship/components/RelationshipsFilters/__tests__/RelationshipsFilters.test.tsx +76 -0
- package/src/components/RightPanelRelationship/components/RelationshipsFilters/styles.ts +19 -0
- package/src/components/RightPanelRelationship/styles.ts +20 -0
- package/src/components/SigmaCustomRenderers/SigmaCustomRenderersContainer.tsx +16 -0
- package/src/components/SigmaGraphContainer/SigmaGraphContainer.tsx +55 -0
- package/src/components/SigmaGraphContainer/__tests__/SigmaGraphContainer.test.tsx +25 -0
- package/src/components/SigmaGraphResizer/SigmaGraphResizer.tsx +13 -0
- package/src/components/SigmaGraphResizer/__tests__/SigmaGraphResizer.test.tsx +28 -0
- package/src/components/TreeLayout/TreeLayout.tsx +33 -0
- package/src/components/TreeLayout/__tests__/TreeLayout.test.tsx +42 -0
- package/src/components/TreeLayout/styles.ts +10 -0
- package/src/components/ZoomSlider/ZoomSlider.tsx +90 -0
- package/src/components/ZoomSlider/__tests__/ZoomSlider.test.tsx +84 -0
- package/src/components/ZoomSlider/styles.ts +57 -0
- package/src/constants/index.ts +1 -0
- package/src/contexts/GraphStateContext.tsx +19 -0
- package/src/contexts/SigmaCustomRenderersContext.ts +20 -0
- package/src/helpers/relationsHelpers.ts +9 -0
- package/src/hooks/__tests__/useGraphLayout.test.tsx +825 -0
- package/src/hooks/__tests__/useGraphLayoutSelector.test.tsx +19 -0
- package/src/hooks/__tests__/useSelfRelationLoopsRenderer.test.ts +198 -0
- package/src/hooks/__tests__/useSigmaCustomRenderers.test.ts +273 -0
- package/src/hooks/__tests__/useTooltipRenderer.test.ts +289 -0
- package/src/hooks/useGraphLayout.ts +308 -0
- package/src/hooks/useGraphLayoutSelector.ts +19 -0
- package/src/hooks/useGraphLoader.ts +279 -0
- package/src/hooks/useGraphRightSidePanelElements.tsx +36 -0
- package/src/hooks/useGraphState.ts +40 -0
- package/src/hooks/useGraphType.ts +32 -0
- package/src/hooks/useRelationshipTable.ts +212 -0
- package/src/hooks/useRelationshipTableFilters.ts +43 -0
- package/src/hooks/useSelectedEntity.ts +89 -0
- package/src/hooks/useSelfRelationLoopsRenderer.ts +52 -0
- package/src/hooks/useSigmaCustomRenderers.ts +112 -0
- package/src/hooks/useTooltipRenderer.ts +80 -0
- package/src/index.tsx +37 -0
- package/src/rendering/canvas/__tests__/hover.spec.ts +31 -0
- package/src/rendering/canvas/__tests__/label.spec.ts +64 -0
- package/src/rendering/canvas/__tests__/nodeBackground.spec.ts +99 -0
- package/src/rendering/canvas/__tests__/selfRelationLoop.spec.ts +88 -0
- package/src/rendering/canvas/__tests__/tooltip.spec.ts +33 -0
- package/src/rendering/canvas/hover.ts +13 -0
- package/src/rendering/canvas/label.ts +33 -0
- package/src/rendering/canvas/nodeBackground.ts +61 -0
- package/src/rendering/canvas/selfRelationLoop.ts +108 -0
- package/src/rendering/canvas/tooltip.ts +38 -0
- package/src/rendering/icons/collapseIcon.inline.svg.ts +6 -0
- package/src/rendering/icons/expandIcon.inline.svg.ts +5 -0
- package/src/rendering/icons/no_photo.inline.svg.ts +13 -0
- package/src/rendering/webgl/edge.arrowHead.ts +87 -0
- package/src/rendering/webgl/edge.clamped.ts +246 -0
- package/src/rendering/webgl/edge.reversedArrowHead.ts +14 -0
- package/src/rendering/webgl/helpers/__tests__/imageHelper.spec.ts +36 -0
- package/src/rendering/webgl/helpers/imageHelper.ts +13 -0
- package/src/rendering/webgl/image.ts +115 -0
- package/src/rendering/webgl/node.border.ts +78 -0
- package/src/rendering/webgl/node.buttons.ts +241 -0
- package/src/rendering/webgl/node.image.ts +169 -0
- package/src/rendering/webgl/shaders/edge.clamped.vert.glsl.ts +55 -0
- package/src/rendering/webgl/shaders/node.border.frag.glsl.ts +30 -0
- package/src/rendering/webgl/shaders/node.border.vert.glsl.ts +37 -0
- package/src/rendering/webgl/shaders/node.buttons.frag.glsl.ts +32 -0
- package/src/rendering/webgl/shaders/node.buttons.vert.glsl.ts +49 -0
- package/src/rendering/webgl/shaders/node.image.frag.glsl.ts +46 -0
- package/src/rendering/webgl/shaders/node.image.vert.glsl.ts +42 -0
- package/src/types/graphDataTypes.ts +143 -0
- package/src/types/sigmaCustomRenderersTypes.ts +13 -0
- package/src/utils/__tests__/graph.spec.ts +152 -0
- package/src/utils/__tests__/graphLayout.spec.ts +125 -0
- package/src/utils/__tests__/hopsData.spec.ts +456 -0
- package/src/utils/__tests__/processResponceToGraph.spec.ts +165 -0
- package/src/utils/graph.ts +83 -0
- package/src/utils/graphLayout.ts +70 -0
- package/src/utils/hopsData.ts +198 -0
- package/src/utils/processResponseToGraph.ts +32 -0
- package/tsconfig.json +4 -0
- package/webpack.config.js +10 -0
- package/bundle.js +0 -2
- package/bundle.js.LICENSE.txt +0 -54
- /package/{5271a9e7b6651c852e93.png → public/5271a9e7b6651c852e93.png} +0 -0
- /package/{main.css → public/main.css} +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {RelationTypeDirection} from '@reltio/mdm-sdk';
|
|
2
|
+
import Graph from 'graphology';
|
|
3
|
+
import {bidirectional} from 'graphology-shortest-path';
|
|
4
|
+
import {GraphPathType} from '../types/graphDataTypes';
|
|
5
|
+
|
|
6
|
+
const directionTypes = {
|
|
7
|
+
[RelationTypeDirection.bidirectional]: 'doubleArrow',
|
|
8
|
+
[RelationTypeDirection.directed]: 'arrow',
|
|
9
|
+
[RelationTypeDirection.undirected]: 'line'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const directionTypeToEdgeType = (directionType: RelationTypeDirection) =>
|
|
13
|
+
directionTypes[directionType] || 'line';
|
|
14
|
+
|
|
15
|
+
export const mouseIsOnNode = (mouseX: number, mouseY: number, nodeX: number, nodeY: number, size: number): boolean => {
|
|
16
|
+
return (
|
|
17
|
+
mouseX > nodeX - size &&
|
|
18
|
+
mouseX < nodeX + size &&
|
|
19
|
+
mouseY > nodeY - size &&
|
|
20
|
+
mouseY < nodeY + size &&
|
|
21
|
+
Math.sqrt(Math.pow(mouseX - nodeX, 2) + Math.pow(mouseY - nodeY, 2)) < size
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const getMousePos = (canvas: HTMLCanvasElement, event: MouseEvent) => {
|
|
26
|
+
const rect = canvas.getBoundingClientRect();
|
|
27
|
+
const x = ((event.clientX - rect.left) / (rect.right - rect.left)) * canvas.width;
|
|
28
|
+
const y = ((event.clientY - rect.top) / (rect.bottom - rect.top)) * canvas.height;
|
|
29
|
+
return {x, y};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const edgePathFromNodePath = (graph: Graph, nodes: string[], isDirected = false): string[] => {
|
|
33
|
+
const edges = [];
|
|
34
|
+
const searchFn = isDirected ? 'findOutEdge' : 'findEdge';
|
|
35
|
+
if (nodes) {
|
|
36
|
+
nodes.forEach((startNode, index, array) => {
|
|
37
|
+
const secondNode = array[index + 1];
|
|
38
|
+
|
|
39
|
+
if (secondNode) {
|
|
40
|
+
edges.push(graph[searchFn](startNode, secondNode, (x) => !!x));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return edges;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type GetPathToNodeProps = {
|
|
48
|
+
graph: Graph;
|
|
49
|
+
undirectedGraph: Graph;
|
|
50
|
+
selectedNode: string;
|
|
51
|
+
rootNodeUri: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const getPathToNode = ({
|
|
55
|
+
graph,
|
|
56
|
+
undirectedGraph,
|
|
57
|
+
selectedNode,
|
|
58
|
+
rootNodeUri
|
|
59
|
+
}: GetPathToNodeProps): GraphPathType => {
|
|
60
|
+
if (graph && undirectedGraph && rootNodeUri && selectedNode && rootNodeUri !== selectedNode) {
|
|
61
|
+
try {
|
|
62
|
+
const nodes = bidirectional(undirectedGraph, rootNodeUri, selectedNode);
|
|
63
|
+
const edges = edgePathFromNodePath(graph, nodes);
|
|
64
|
+
return nodes ? {edges, nodes} : {};
|
|
65
|
+
} catch (e) {
|
|
66
|
+
//if there is no node, we return empty object
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {};
|
|
70
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import Graph from 'graphology';
|
|
2
|
+
import {
|
|
3
|
+
always,
|
|
4
|
+
append,
|
|
5
|
+
chain,
|
|
6
|
+
cond,
|
|
7
|
+
either,
|
|
8
|
+
equals,
|
|
9
|
+
evolve,
|
|
10
|
+
includes,
|
|
11
|
+
map,
|
|
12
|
+
pick,
|
|
13
|
+
pipe,
|
|
14
|
+
prop,
|
|
15
|
+
propEq,
|
|
16
|
+
reject,
|
|
17
|
+
T,
|
|
18
|
+
uniq,
|
|
19
|
+
without
|
|
20
|
+
} from 'ramda';
|
|
21
|
+
import {bidirectional} from 'graphology-shortest-path';
|
|
22
|
+
import {toUndirected} from 'graphology-operators';
|
|
23
|
+
import {
|
|
24
|
+
getEndObjectUri,
|
|
25
|
+
getRelationType,
|
|
26
|
+
getStartObjectUri,
|
|
27
|
+
HopEntity,
|
|
28
|
+
HopRelation,
|
|
29
|
+
HopsResponse,
|
|
30
|
+
Metadata,
|
|
31
|
+
Relation,
|
|
32
|
+
TRelationType
|
|
33
|
+
} from '@reltio/mdm-sdk';
|
|
34
|
+
|
|
35
|
+
const addRelationToHopsData = (data: HopsResponse, respondedRelation: Relation, metadata: Metadata): HopsResponse => {
|
|
36
|
+
const startEntityUri = respondedRelation.startObject.objectURI;
|
|
37
|
+
const endEntityUri = respondedRelation.endObject.objectURI;
|
|
38
|
+
const nodeUris = [startEntityUri, endEntityUri];
|
|
39
|
+
const entitiesUris = data.entities.map(prop('uri'));
|
|
40
|
+
const relationType: TRelationType = getRelationType(metadata, respondedRelation.type);
|
|
41
|
+
|
|
42
|
+
const extraEntityUri = nodeUris.find((node) => !includes(node, entitiesUris));
|
|
43
|
+
const extraEntity =
|
|
44
|
+
extraEntityUri &&
|
|
45
|
+
(respondedRelation.startObject.objectURI === extraEntityUri
|
|
46
|
+
? respondedRelation.startObject
|
|
47
|
+
: respondedRelation.endObject);
|
|
48
|
+
|
|
49
|
+
const extraEntityFormatted = extraEntity && {
|
|
50
|
+
type: extraEntity.type,
|
|
51
|
+
label: extraEntity.label,
|
|
52
|
+
uri: extraEntity.objectURI,
|
|
53
|
+
traversedRelations: 0,
|
|
54
|
+
untraversedRelations: 1
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const relation: HopRelation = {
|
|
58
|
+
...pick(['uri', 'type', 'attributes', 'startDate', 'endDate', 'crosswalks', 'direction'], respondedRelation),
|
|
59
|
+
startObject: pick(['objectURI', 'directionalLabel'], respondedRelation.startObject),
|
|
60
|
+
endObject: pick(['objectURI', 'directionalLabel'], respondedRelation.endObject),
|
|
61
|
+
direction: relationType?.direction
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const updateTraversedRelationsCount = (entity) => {
|
|
65
|
+
if (entity.uri === startEntityUri || entity.uri === endEntityUri) {
|
|
66
|
+
return {
|
|
67
|
+
...entity,
|
|
68
|
+
traversedRelations: entity.traversedRelations + 1
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return entity;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const newData = {
|
|
75
|
+
entities: (extraEntityFormatted ? data.entities.concat([extraEntityFormatted]) : data.entities).map(
|
|
76
|
+
updateTraversedRelationsCount
|
|
77
|
+
),
|
|
78
|
+
relations: (data.relations || []).concat([relation])
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return newData;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const removeRelationFromHopsData = (
|
|
85
|
+
entityUri: string,
|
|
86
|
+
relationUri: string,
|
|
87
|
+
graph: Graph,
|
|
88
|
+
data: HopsResponse
|
|
89
|
+
): {updatedData: HopsResponse; removedEntitiesUris: string[]} => {
|
|
90
|
+
const relation = data.relations.find(propEq('uri', relationUri));
|
|
91
|
+
const startNodeId: string = getStartObjectUri(relation);
|
|
92
|
+
const endNodeId: string = getEndObjectUri(relation);
|
|
93
|
+
const undirectedGraph = toUndirected(graph);
|
|
94
|
+
const isolatedNodeId: string = cond([
|
|
95
|
+
[() => !bidirectional(undirectedGraph, entityUri, startNodeId), always(startNodeId)],
|
|
96
|
+
[() => !bidirectional(undirectedGraph, entityUri, endNodeId), always(endNodeId)],
|
|
97
|
+
[T, always(null)]
|
|
98
|
+
])();
|
|
99
|
+
|
|
100
|
+
const updateTraversedRelationsCount = (entity) => {
|
|
101
|
+
if (entity.uri === startNodeId || entity.uri === endNodeId) {
|
|
102
|
+
return {
|
|
103
|
+
...entity,
|
|
104
|
+
traversedRelations: entity.traversedRelations - 1
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return entity;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const dataWithoutRelation: HopsResponse = evolve({
|
|
111
|
+
entities: map(updateTraversedRelationsCount),
|
|
112
|
+
relations: reject(propEq('uri', relationUri))
|
|
113
|
+
})(data);
|
|
114
|
+
const {updatedData, removedEntitiesUris} = isolatedNodeId
|
|
115
|
+
? removeIsolatedSubgraph(isolatedNodeId, dataWithoutRelation)
|
|
116
|
+
: {
|
|
117
|
+
updatedData: dataWithoutRelation,
|
|
118
|
+
removedEntitiesUris: []
|
|
119
|
+
};
|
|
120
|
+
return {updatedData, removedEntitiesUris};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const removeIsolatedSubgraph = (isolatedNodeId: string, data: HopsResponse) => {
|
|
124
|
+
const isolatedRelations = findSubgraphRelations(isolatedNodeId, data);
|
|
125
|
+
const isolatedEntitiesUris: string[] = pipe(
|
|
126
|
+
getAllRelatedEntitiesUris,
|
|
127
|
+
append(isolatedNodeId),
|
|
128
|
+
uniq
|
|
129
|
+
)(isolatedRelations);
|
|
130
|
+
const updatedData: HopsResponse = evolve({
|
|
131
|
+
relations: reject((relation) => isolatedRelations.includes(relation)),
|
|
132
|
+
entities: reject((entity) => isolatedEntitiesUris.includes(entity.uri))
|
|
133
|
+
})(data);
|
|
134
|
+
return {
|
|
135
|
+
updatedData,
|
|
136
|
+
removedEntitiesUris: isolatedEntitiesUris
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const findSubgraphRelations = (
|
|
141
|
+
nodeId: string,
|
|
142
|
+
data: HopsResponse,
|
|
143
|
+
foundRelations: HopRelation[] = []
|
|
144
|
+
): HopRelation[] => {
|
|
145
|
+
const relations = data.relations
|
|
146
|
+
.filter((relation) => !foundRelations.includes(relation))
|
|
147
|
+
.filter(either(pipe(getStartObjectUri, equals(nodeId)), pipe(getEndObjectUri, equals(nodeId))));
|
|
148
|
+
foundRelations.push(...relations);
|
|
149
|
+
const relatedNodes: string[] = pipe(getAllRelatedEntitiesUris, without([nodeId]))(relations);
|
|
150
|
+
relatedNodes.forEach((relatedNodeId) => findSubgraphRelations(relatedNodeId, data, foundRelations));
|
|
151
|
+
return foundRelations;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const getAllRelatedEntitiesUris = (relations: HopRelation[]): string[] =>
|
|
155
|
+
pipe(
|
|
156
|
+
chain((relation) => [getStartObjectUri(relation), getEndObjectUri(relation)]),
|
|
157
|
+
uniq
|
|
158
|
+
)(relations);
|
|
159
|
+
|
|
160
|
+
const mergeHopsData = (data: HopsResponse, newData: HopsResponse, hopsEntityUri: string) => {
|
|
161
|
+
const {entities: hopsEntities = [], relations: hopsRelations = []} = newData;
|
|
162
|
+
|
|
163
|
+
const newEntities = hopsEntities.reduce(
|
|
164
|
+
(entities: HopEntity[], entity: HopEntity): HopEntity[] => {
|
|
165
|
+
if (!entities.some(({uri}) => uri === entity.uri)) {
|
|
166
|
+
entities.push(entity);
|
|
167
|
+
} else if (entity.uri === hopsEntityUri) {
|
|
168
|
+
const index = entities.findIndex(({uri}) => uri === hopsEntityUri);
|
|
169
|
+
|
|
170
|
+
entities[index] = {
|
|
171
|
+
...entities[index],
|
|
172
|
+
traversedRelations: entity.traversedRelations,
|
|
173
|
+
untraversedRelations: entity.untraversedRelations
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return entities;
|
|
177
|
+
},
|
|
178
|
+
[...(data.entities || [])]
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const newRelations = hopsRelations.reduce(
|
|
182
|
+
(relations: HopRelation[], relation: HopRelation): HopRelation[] => {
|
|
183
|
+
if (!relations.some(({uri}) => uri === relation.uri)) {
|
|
184
|
+
relations.push(relation);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return relations;
|
|
188
|
+
},
|
|
189
|
+
[...(data.relations || [])]
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
entities: newEntities,
|
|
194
|
+
relations: newRelations
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export {addRelationToHopsData, removeRelationFromHopsData, mergeHopsData};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {HopsResponse, RelationTypeDirection} from '@reltio/mdm-sdk';
|
|
2
|
+
import {Node, Edge, GraphologyGraphData} from '../types/graphDataTypes';
|
|
3
|
+
|
|
4
|
+
const processResponseToGraph = (data: HopsResponse): GraphologyGraphData => {
|
|
5
|
+
const nodesSet = new Set<string>();
|
|
6
|
+
const relationsSet = new Set<string>();
|
|
7
|
+
data.entities.forEach((entity) => nodesSet.add(entity.uri));
|
|
8
|
+
const filteredRelations =
|
|
9
|
+
data.relations?.filter(
|
|
10
|
+
(relation) => nodesSet.has(relation.startObject.objectURI) && nodesSet.has(relation.endObject.objectURI)
|
|
11
|
+
) || [];
|
|
12
|
+
filteredRelations.forEach((relation) => {
|
|
13
|
+
relationsSet.add(
|
|
14
|
+
`${relation.startObject.objectURI}--${relation.endObject.objectURI}--${relation.uri}--${relation.type}--${relation.direction}`
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
const nodes: Node[] = data.entities.map((entity) => ({
|
|
18
|
+
id: entity.uri,
|
|
19
|
+
name: entity.label,
|
|
20
|
+
entityTypeUri: entity.type,
|
|
21
|
+
traversedRelationsCount: entity.traversedRelations,
|
|
22
|
+
untraversedRelationsCount: entity.untraversedRelations
|
|
23
|
+
}));
|
|
24
|
+
const edges: Edge[] = [];
|
|
25
|
+
relationsSet.forEach((relationKey) => {
|
|
26
|
+
const [from, to, key, relationTypeUri, direction] = relationKey.split('--');
|
|
27
|
+
edges.push({from, to, key, relationTypeUri, direction: direction as RelationTypeDirection});
|
|
28
|
+
});
|
|
29
|
+
return {nodes, edges};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default processResponseToGraph;
|
package/tsconfig.json
ADDED