From c1ac8027f3cd4ac72fe8a223f7415453b0602e58 Mon Sep 17 00:00:00 2001 From: David Russell Date: Mon, 29 Jul 2024 14:04:07 +0100 Subject: [PATCH] update viz component to use routed requests --- .../VisualizationView/VisualizationView.tsx | 6 +-- src/shared/modules/cypher/cypherDuck.ts | 47 ++++++++++++++----- src/shared/rootEpic.ts | 6 ++- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/browser/modules/Stream/CypherFrame/VisualizationView/VisualizationView.tsx b/src/browser/modules/Stream/CypherFrame/VisualizationView/VisualizationView.tsx index 877147680ab..fabbf703511 100644 --- a/src/browser/modules/Stream/CypherFrame/VisualizationView/VisualizationView.tsx +++ b/src/browser/modules/Stream/CypherFrame/VisualizationView/VisualizationView.tsx @@ -37,7 +37,7 @@ import { import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata' import { deepEquals } from 'neo4j-arc/common' import { GlobalState } from 'shared/globalState' -import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck' +import { ROUTED_CYPHER_READ_REQUEST } from 'shared/modules/cypher/cypherDuck' import * as grassActions from 'shared/modules/grass/grassDuck' import { getMaxFieldItems, @@ -197,7 +197,7 @@ LIMIT ${maxNewNeighbours}` return new Promise((resolve, reject) => { this.props.bus && this.props.bus.self( - CYPHER_REQUEST, + ROUTED_CYPHER_READ_REQUEST, { query: query, queryType: NEO4J_BROWSER_USER_ACTION_QUERY }, (response: any) => { if (!response.success) { @@ -242,7 +242,7 @@ LIMIT ${maxNewNeighbours}` return new Promise(resolve => { this.props.bus && this.props.bus.self( - CYPHER_REQUEST, + ROUTED_CYPHER_READ_REQUEST, { query, params: { existingNodeIds, newNodeIds }, diff --git a/src/shared/modules/cypher/cypherDuck.ts b/src/shared/modules/cypher/cypherDuck.ts index 150fcef086e..b5d706fe3d2 100644 --- a/src/shared/modules/cypher/cypherDuck.ts +++ b/src/shared/modules/cypher/cypherDuck.ts @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -import neo4j from 'neo4j-driver' +import neo4j, { QueryResult } from 'neo4j-driver' import Rx from 'rxjs' import { @@ -46,6 +46,7 @@ import { const NAME = 'cypher' export const CYPHER_REQUEST = `${NAME}/REQUEST` +export const ROUTED_CYPHER_READ_REQUEST = `${NAME}/ROUTED_READ_REQUEST` export const ROUTED_CYPHER_WRITE_REQUEST = `${NAME}/ROUTED_WRITE_REQUEST` export const AD_HOC_CYPHER_REQUEST = `${NAME}/AD_HOC_REQUEST` export const CLUSTER_CYPHER_REQUEST = `${NAME}/CLUSTER_REQUEST` @@ -113,6 +114,22 @@ const callClusterMember = async (connection: any, action: any) => { }) }) } +const routedCypherQueryResultResolver = async ( + action: any, + promise: Promise +) => { + return promise + .then((result: any) => ({ + type: action.$$responseChannel, + success: true, + result + })) + .catch((error: any) => ({ + type: action.$$responseChannel, + success: false, + error + })) +} // Epics export const cypherRequestEpic = (some$: any) => @@ -135,7 +152,20 @@ export const cypherRequestEpic = (some$: any) => })) }) -export const routedCypherRequestEpic = (some$: any) => +export const routedCypherReadRequestEpic = (some$: any) => + some$.ofType(ROUTED_CYPHER_READ_REQUEST).mergeMap((action: any) => { + if (!action.$$responseChannel) return Rx.Observable.of(null) + + const promise = bolt.routedReadTransaction(action.query, action.params, { + ...getUserTxMetadata(action.queryType || null), + cancelable: true, + useDb: action.useDb + }) + + return routedCypherQueryResultResolver(action, promise) + }) + +export const routedCypherWriteRequestEpic = (some$: any) => some$.ofType(ROUTED_CYPHER_WRITE_REQUEST).mergeMap((action: any) => { if (!action.$$responseChannel) return Rx.Observable.of(null) @@ -148,17 +178,8 @@ export const routedCypherRequestEpic = (some$: any) => useDb: action.useDb } ) - return promise - .then((result: any) => ({ - type: action.$$responseChannel, - success: true, - result - })) - .catch((error: any) => ({ - type: action.$$responseChannel, - success: false, - error - })) + + return routedCypherQueryResultResolver(action, promise) }) export const adHocCypherRequestEpic = (some$: any, store: any) => diff --git a/src/shared/rootEpic.ts b/src/shared/rootEpic.ts index 9821797357e..e7e4f9a9d49 100644 --- a/src/shared/rootEpic.ts +++ b/src/shared/rootEpic.ts @@ -53,7 +53,8 @@ import { clusterCypherRequestEpic, cypherRequestEpic, handleForcePasswordChangeEpic, - routedCypherRequestEpic + routedCypherReadRequestEpic, + routedCypherWriteRequestEpic } from './modules/cypher/cypherDuck' import { clearMetaOnDisconnectEpic, @@ -122,7 +123,8 @@ export default combineEpics( injectDiscoveryEpic, populateEditorFromUrlEpic, adHocCypherRequestEpic, - routedCypherRequestEpic, + routedCypherReadRequestEpic, + routedCypherWriteRequestEpic, cypherRequestEpic, clusterCypherRequestEpic, clearLocalstorageEpic,