Skip to content

Commit 3f62629

Browse files
xnikhil08MarkLogic Builder
authored andcommitted
DHFPROD-8506: In explore, right side panel must be closed on changes
1 parent 7c7bdfe commit 3f62629

File tree

6 files changed

+84
-47
lines changed

6 files changed

+84
-47
lines changed

marklogic-data-hub-central/ui/src/components/explore/graph-view-explore.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import {faFileExport} from "@fortawesome/free-solid-svg-icons";
1414
type Props = {
1515
entityTypeInstances: any;
1616
graphView: any;
17-
coords: any[];
18-
setCoords: (coords: any[]) => void;
1917
hubCentralConfig: any;
18+
setGraphPageInfo: (pageInfo: any) => void;
2019
};
2120

2221
const GraphViewExplore: React.FC<Props> = (props) => {
22+
const {entityTypeInstances, graphView, hubCentralConfig, setGraphPageInfo} = props;
2323

2424
const [viewRelationshipLabels, toggleRelationShipLabels] = useState(true);
2525
const [exportPngButtonClicked, setExportPngButtonClicked] = useState(false);
@@ -87,7 +87,7 @@ const GraphViewExplore: React.FC<Props> = (props) => {
8787
const relationshipsToggle = <span>{HCSwitch}</span>;
8888

8989
const graphViewExploreMainPanel = (
90-
!Object.keys(props.entityTypeInstances).length
90+
!Object.keys(entityTypeInstances).length
9191
? <span></span>
9292
: (<div className={styles.graphViewExploreContainer}>
9393
<div className={styles.graphHeader}>
@@ -97,14 +97,13 @@ const GraphViewExplore: React.FC<Props> = (props) => {
9797
<div className={styles.borderBelowHeader}></div>
9898
<div>
9999
<GraphVisExplore
100-
entityTypeInstances={props.entityTypeInstances}
101-
graphView={props.graphView}
102-
coords={props.coords}
103-
setCoords={props.setCoords}
104-
hubCentralConfig={props.hubCentralConfig}
100+
entityTypeInstances={entityTypeInstances}
101+
graphView={graphView}
102+
hubCentralConfig={hubCentralConfig}
105103
viewRelationshipLabels={viewRelationshipLabels}
106104
exportPngButtonClicked = {exportPngButtonClicked}
107105
setExportPngButtonClicked = {setExportPngButtonClicked}
106+
setGraphPageInfo = {setGraphPageInfo}
108107
/>
109108
</div>
110109
</div>
@@ -116,7 +115,7 @@ const GraphViewExplore: React.FC<Props> = (props) => {
116115
};
117116

118117
const sidePanel = (<div>
119-
<GraphExploreSidePanel onCloseSidePanel={onCloseSidePanel} graphView={props.graphView}/>
118+
<GraphExploreSidePanel onCloseSidePanel={onCloseSidePanel} graphView={graphView}/>
120119
</div>);
121120

122121
return (

marklogic-data-hub-central/ui/src/components/explore/graph-vis-explore/graph-vis-explore.tsx

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,27 @@ import TableViewGroupNodes from "../table-view-group-nodes/table-view-group-node
1717
type Props = {
1818
entityTypeInstances: any;
1919
graphView: any;
20-
coords: any[];
21-
setCoords: (coords: any[]) => void;
2220
hubCentralConfig: any;
2321
viewRelationshipLabels: any;
2422
exportPngButtonClicked: boolean;
2523
setExportPngButtonClicked: any;
24+
setGraphPageInfo: (pageInfo: any) => void;
2625
};
2726

2827
const GraphVisExplore: React.FC<Props> = (props) => {
28+
const {
29+
entityTypeInstances,
30+
graphView,
31+
hubCentralConfig,
32+
viewRelationshipLabels,
33+
exportPngButtonClicked,
34+
setExportPngButtonClicked,
35+
setGraphPageInfo
36+
} = props;
2937
const [expandedNodeData, setExpandedNodeData] = useState({});
3038
let graphData = {nodes: [], edges: []};
31-
32-
const coordinatesExist = () => {
33-
let coordsExist = !!props.coords;
34-
return coordsExist;
35-
};
3639
const [menuPosition, setMenuPosition] = useState<{ x: number, y: number }>({x: 0, y: 0});
37-
const [physicsEnabled, setPhysicsEnabled] = useState(!coordinatesExist());
40+
const [physicsEnabled, setPhysicsEnabled] = useState(false);
3841
const [contextMenuVisible, setContextMenuVisible] = useState(false);
3942
const [clickedNode, setClickedNode] = useState({});
4043
const [hasStabilized, setHasStabilized] = useState(false);
@@ -108,7 +111,7 @@ const GraphVisExplore: React.FC<Props> = (props) => {
108111
};
109112

110113
useEffect(() => {
111-
if (Object.keys(props.entityTypeInstances).length && network) {
114+
if (Object.keys(entityTypeInstances).length && network) {
112115

113116
initializeGraphData();
114117

@@ -125,10 +128,10 @@ const GraphVisExplore: React.FC<Props> = (props) => {
125128
setGraphDataLoaded(false);
126129
};
127130

128-
}, [props.entityTypeInstances, props.viewRelationshipLabels]);
131+
}, [entityTypeInstances, viewRelationshipLabels]);
129132

130133
useEffect(() => {
131-
if (network && props.graphView) {
134+
if (network && graphView) {
132135
let nodes = getNodes() || [];
133136
let edges = getEdges() || [];
134137
updateNodesData(nodes);
@@ -147,19 +150,19 @@ const GraphVisExplore: React.FC<Props> = (props) => {
147150
setExpandedNodeData({});
148151
};
149152

150-
}, [network, props.graphView]);
153+
}, [network, graphView]);
151154

152155
useEffect(() => {
153-
if (props.exportPngButtonClicked) {
156+
if (exportPngButtonClicked) {
154157
let canvas = document.getElementsByClassName("vis-network")[0]["canvas"];
155158
let link = document.createElement("a");
156159
link.href = canvas.toDataURL();
157160
link.setAttribute("download", "graph-view-explore");
158161
document.body.appendChild(link);
159162
link.click();
160-
props.setExportPngButtonClicked(false);
163+
setExportPngButtonClicked(false);
161164
}
162-
}, [props.exportPngButtonClicked]);
165+
}, [exportPngButtonClicked]);
163166

164167
useLayoutEffect(() => {
165168
if (network) {
@@ -173,11 +176,11 @@ const GraphVisExplore: React.FC<Props> = (props) => {
173176
}, [network, graphData]);
174177

175178
const iconExistsForEntity = (entityName) => {
176-
return (!props.hubCentralConfig?.modeling?.entities[entityName]?.icon ? false : true);
179+
return (!hubCentralConfig?.modeling?.entities[entityName]?.icon ? false : true);
177180
};
178181

179182
const colorExistsForEntity = (entityName) => {
180-
return (!props.hubCentralConfig?.modeling?.entities[entityName]?.color ? false : true);
183+
return (!hubCentralConfig?.modeling?.entities[entityName]?.color ? false : true);
181184
};
182185

183186
const setUserPreferences = () => {
@@ -206,7 +209,7 @@ const GraphVisExplore: React.FC<Props> = (props) => {
206209
if (parentNode && expandedNodeData[expandId]) {
207210
selectedEntityExists = expandedNodeData[expandId]?.nodes?.some(node => node.id === entityInstanceId);
208211
} else {
209-
selectedEntityExists = props.entityTypeInstances?.nodes?.some(node => node.id === entityInstanceId);
212+
selectedEntityExists = entityTypeInstances?.nodes?.some(node => node.id === entityInstanceId);
210213
}
211214
if (selectedEntityExists) {
212215
setPhysicsEnabled(false);
@@ -216,7 +219,7 @@ const GraphVisExplore: React.FC<Props> = (props) => {
216219
}
217220
} else if (network && entityInstanceId && !graphDataLoaded && savedNode) { //case where exploring from table/snippet view
218221
let instanceId = entityInstanceId.split("-")[1];
219-
let selectedEntity = props.entityTypeInstances?.nodes?.find(node => node.id.includes(instanceId));
222+
let selectedEntity = entityTypeInstances?.nodes?.find(node => node.id.includes(instanceId));
220223
if (selectedEntity) {
221224
setPhysicsEnabled(false);
222225
network.selectNodes([selectedEntity.id]);
@@ -260,11 +263,11 @@ const GraphVisExplore: React.FC<Props> = (props) => {
260263
let nodes;
261264
let nodeObj = groupNodes;
262265
let leafNodesObj = leafNodes;
263-
let entityInstNodes = props.entityTypeInstances?.nodes?.slice();
266+
let entityInstNodes = entityTypeInstances?.nodes?.slice();
264267
entityInstNodes = !nodesToExpand ? entityInstNodes : nodesToExpand;
265268
nodes = entityInstNodes?.map((e) => {
266269
let entityType = e.group.split("/").pop();
267-
let entity = props.hubCentralConfig?.modeling?.entities[entityType];
270+
let entity = hubCentralConfig?.modeling?.entities[entityType];
268271
let nodeId = e.id;
269272
if (e.count > 1) {
270273
if (!nodeObj.hasOwnProperty(nodeId)) {
@@ -410,7 +413,7 @@ const GraphVisExplore: React.FC<Props> = (props) => {
410413
const getEdges = (edgesToExpand?: any) => {
411414
let edges: any = [];
412415
let predicatesObject = predicates;
413-
let edgesFinal: any = props.entityTypeInstances?.edges?.slice();
416+
let edgesFinal: any = entityTypeInstances?.edges?.slice();
414417
edgesFinal = !edgesToExpand ? edgesFinal : edgesToExpand;
415418
edges = edgesFinal?.map((edge, i) => {
416419
if (!predicatesObject.hasOwnProperty(edge.id)) {
@@ -419,7 +422,7 @@ const GraphVisExplore: React.FC<Props> = (props) => {
419422
return {
420423
...edge,
421424
id: edge.id,
422-
label: props.viewRelationshipLabels ? edge.label : "",
425+
label: viewRelationshipLabels ? edge.label : "",
423426
arrows: {
424427
to: {
425428
enabled: false,
@@ -474,6 +477,7 @@ const GraphVisExplore: React.FC<Props> = (props) => {
474477
network.body.data.nodes.remove(graphDataTemp.nodes);
475478
updateNodesData(graphDataTemp.nodes);
476479
updateEdgesData(graphDataTemp.edges);
480+
updateGraphPageInfo();
477481
};
478482

479483
const handleTableViewRecords = (exceededThreshold?: string) => {
@@ -514,6 +518,14 @@ const GraphVisExplore: React.FC<Props> = (props) => {
514518
setLeafNodes(leafNodeObj);
515519
};
516520

521+
const updateGraphPageInfo = () => {
522+
let pageInfo = {
523+
pageLength: network.body.data.nodes.length,
524+
total: entityTypeInstances?.total
525+
};
526+
setGraphPageInfo(pageInfo);
527+
};
528+
517529
const handleGroupNodeExpand = async (payloadData) => {
518530
setContextMenuVisible(false);
519531
let payload = {
@@ -577,6 +589,7 @@ const GraphVisExplore: React.FC<Props> = (props) => {
577589
network.body.data.edges.remove(graphEdgesDataTemp);
578590
let removedNode = getNodes([groupNodes[removedNodeIRI]]);
579591
updateNodesData(removedNode);
592+
updateGraphPageInfo();
580593
} catch (error) {
581594
handleError(error);
582595
}
@@ -635,6 +648,7 @@ const GraphVisExplore: React.FC<Props> = (props) => {
635648
network.body.data.nodes.remove(graphNodesDataTemp);
636649
network.body.data.nodes.remove(nodesToDelete);
637650
network.body.data.edges.remove(graphEdgesDataTemp);
651+
updateGraphPageInfo();
638652
} catch (error) {
639653
handleError(error);
640654
}
@@ -669,6 +683,7 @@ const GraphVisExplore: React.FC<Props> = (props) => {
669683
network.body.data.nodes.update(nodes);
670684
network.body.data.edges.update(edges);
671685
await updateGroupAndLeafNodesDataset(response.data.nodes);
686+
updateGraphPageInfo();
672687
}
673688
} catch (error) {
674689
handleError(error);
@@ -820,8 +835,8 @@ const GraphVisExplore: React.FC<Props> = (props) => {
820835
expandedInstanceInfo["edgeObject"] = expandedNodeData[parentNodeExpandId].edges.find(edge => edge.id === edgeIdFrom);
821836
expandedInstanceInfo["parentNodeExpandId"] = parentNodeExpandId;
822837
} else {
823-
expandedInstanceInfo["nodeObject"] = props.entityTypeInstances.nodes.find(node => node.id === nodeId);
824-
expandedInstanceInfo["edgeObject"] = props.entityTypeInstances.edges.find(edge => edge.id === edgeIdFrom);
838+
expandedInstanceInfo["nodeObject"] = entityTypeInstances.nodes.find(node => node.id === nodeId);
839+
expandedInstanceInfo["edgeObject"] = entityTypeInstances.edges.find(edge => edge.id === edgeIdFrom);
825840
}
826841
return expandedInstanceInfo;
827842
};
@@ -989,9 +1004,7 @@ const GraphVisExplore: React.FC<Props> = (props) => {
9891004
let positions = network.getPositions();
9901005
// When graph is stabilized, nodePositions no longer empty
9911006
if (positions && Object.keys(positions).length) {
992-
// saveUnsavedCoords();
9931007
setHasStabilized(true);
994-
//props.setCoords(positions);
9951008
if (physicsEnabled) {
9961009
setPhysicsEnabled(false);
9971010
return false;

marklogic-data-hub-central/ui/src/components/results-tabular-view/results-tabular-view.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ const ResultsTabularView = (props) => {
289289
};
290290

291291
const navigateToGraphView = (item) => {
292+
item["navigatingFromOtherView"] = true;
292293
setSavedNode(item);
293294
let primaryKeyValue = item.primaryKey?.propertyValue;
294295
setGraphViewOptions(`${item.entityName}-${primaryKeyValue}`);

marklogic-data-hub-central/ui/src/components/search-result/search-result.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const SearchResult: React.FC<Props> = (props) => {
7676
toggleShow(!show);
7777
}
7878
const navigateToGraphView = (item) => {
79+
item["navigatingFromOtherView"] = true;
7980
setSavedNode(item);
8081
setGraphViewOptions(`${item.entityName}-${primaryKeyValue}`);
8182
props.handleViewChange("graph");

marklogic-data-hub-central/ui/src/pages/Browse.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ describe("Explorer Browse page tests ", () => {
5757
greyedOptions: defaultSearchOptions,
5858
setRelatedEntityTypeIds: jest.fn(),
5959
setEntity: jest.fn(),
60-
applySaveQuery: jest.fn()
60+
applySaveQuery: jest.fn(),
61+
savedNode: undefined,
62+
setSavedNode: jest.fn()
6163
}}>
6264
<Browse />
6365
</SearchContext.Provider></MemoryRouter>);
@@ -76,7 +78,9 @@ describe("Explorer Browse page tests ", () => {
7678
greyedOptions: defaultSearchOptions,
7779
setRelatedEntityTypeIds: jest.fn(),
7880
setEntity: jest.fn(),
79-
applySaveQuery: jest.fn()
81+
applySaveQuery: jest.fn(),
82+
savedNode: undefined,
83+
setSavedNode: jest.fn()
8084
}}>
8185
<Browse />
8286
</SearchContext.Provider></MemoryRouter>);

0 commit comments

Comments
 (0)