Skip to content

Commit 97b1df9

Browse files
committed
proof of concept
1 parent ad110cb commit 97b1df9

File tree

7 files changed

+51
-41
lines changed

7 files changed

+51
-41
lines changed

src/application/ApplicationThunks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export const createConnectionThunk =
6868
const loggingSettings = applicationGetLoggingSettings(loggingState);
6969
const neodashMode = applicationIsStandalone(loggingState) ? 'Standalone' : 'Editor';
7070
try {
71-
const driver = createDriver(protocol, url, port, username, password, { userAgent: `neodash/v${version}` });
71+
// TODO remember the 7474 port needs to be used
72+
const driver = createDriver('http', url, port, username, password, { userAgent: `neodash/v${version}` });
7273
// eslint-disable-next-line no-console
7374
console.log('Attempting to connect...');
7475
const validateConnection = (records) => {

src/dashboard/Dashboard.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import NeoPage from '../page/Page';
77
import { forceRefreshPage } from '../page/PageActions';
88
import { createNotificationThunk } from '../page/PageThunks';
99
import { getPageNumber } from '../settings/SettingsSelectors';
10-
import { createDriver, Neo4jProvider } from '../use-neo4j';
10+
import { Neo4jProvider, createDriver } from '../use-neo4j';
1111
import NeoDashboardHeader from './header/DashboardHeader';
1212
import NeoDashboardHeaderPageList from './header/DashboardHeaderPageList';
1313
import NeoDashboardTitle from './header/DashboardTitle';
@@ -26,14 +26,9 @@ const Dashboard = ({
2626

2727
// If no driver is yet instantiated, create a new one.
2828
if (driver == undefined) {
29-
const newDriver = createDriver(
30-
connection.protocol,
31-
connection.url,
32-
connection.port,
33-
connection.username,
34-
connection.password,
35-
{ userAgent: `neodash/v${version}` }
36-
);
29+
const newDriver = createDriver('http', connection.url, connection.port, connection.username, connection.password, {
30+
userAgent: `neodash/v${version}`,
31+
});
3732
setDriver(newDriver);
3833
}
3934
const content = (

src/report/ReportQueryRunner.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { extractNodePropertiesFromRecords, extractNodeAndRelPropertiesFromRecords } from './ReportRecordProcessing';
21
import isEqual from 'lodash.isequal';
2+
import { extractNodeAndRelPropertiesFromRecords, extractNodePropertiesFromRecords } from './ReportRecordProcessing';
33

44
export enum QueryStatus {
55
NO_QUERY, // No query specified
@@ -66,8 +66,9 @@ export async function runCypherQuery(
6666
return;
6767
}
6868

69+
// we need to ensure the databse ame is set
6970
const session = database ? driver.session({ database: database }) : driver.session();
70-
const transaction = session.beginTransaction({ timeout: queryTimeLimit * 1000, connectionTimeout: 2000 });
71+
// const transaction = session.beginTransaction({ timeout: queryTimeLimit * 1000, connectionTimeout: 2000 });
7172

7273
// For usuability reasons, we can set a hard cap on the query result size by wrapping it a subquery (Neo4j 4.0 and later).
7374
// This unfortunately does not preserve ordering on the return fields.
@@ -79,17 +80,18 @@ export async function runCypherQuery(
7980
query = `CALL { ${query}} RETURN * LIMIT ${rowLimit + 1}`;
8081
}
8182
}
83+
// we use async iteratiors in workspace to archieve this, pro tip!
8284

83-
await transaction
84-
.run(query, parameters)
85+
await session
86+
// TODO seems the timeout doesn't work poreoprly eitehr
87+
.run(query, parameters) // , { timeout: queryTimeLimit * 1000, connectionTimeout: 2000 })
8588
.then((res) => {
8689
// @ts-ignore
8790
const { records } = res;
8891
// TODO - check query summary to ensure that no writes are made in safe-mode.
8992
if (records.length == 0) {
9093
setStatus(QueryStatus.NO_DATA);
9194
// console.log("TODO remove this - QUERY RETURNED NO DATA!")
92-
transaction.commit();
9395
return;
9496
}
9597

@@ -111,20 +113,16 @@ export async function runCypherQuery(
111113
if (records == null) {
112114
setStatus(QueryStatus.NO_DRAWABLE_DATA);
113115
// console.log("TODO remove this - QUERY RETURNED NO DRAWABLE DATA!")
114-
transaction.commit();
115116
return;
116117
} else if (records.length > rowLimit) {
117118
setStatus(QueryStatus.COMPLETE_TRUNCATED);
118119
setRecords(records.slice(0, rowLimit));
119120
// console.log("TODO remove this - QUERY RETURNED WAS TRUNCTURED!")
120-
transaction.commit();
121121
return;
122122
}
123123
setStatus(QueryStatus.COMPLETE);
124124
setRecords(records);
125125
// console.log("TODO remove this - QUERY WAS EXECUTED SUCCESFULLY!")
126-
127-
transaction.commit();
128126
})
129127
.catch((e) => {
130128
// setFields([]);
@@ -139,7 +137,6 @@ export async function runCypherQuery(
139137
) {
140138
setStatus(QueryStatus.TIMED_OUT);
141139
setRecords([{ error: e.message }]);
142-
transaction.rollback();
143140
return e.message;
144141
}
145142

@@ -148,7 +145,6 @@ export async function runCypherQuery(
148145
if (setRecords) {
149146
setRecords([{ error: e.message }]);
150147
}
151-
transaction.rollback();
152148
return e.message;
153149
});
154150
}

src/report/ReportRecordProcessing.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react';
21
import { Chip, Tooltip } from '@mui/material';
3-
import { GraphLabel, TextLink } from '@neo4j-ndl/react';
42
import { withStyles } from '@mui/styles';
3+
import { GraphLabel, TextLink } from '@neo4j-ndl/react';
4+
import React from 'react';
55
import {
66
getRecordType,
77
toNumber,
@@ -129,6 +129,7 @@ const HtmlTooltip = withStyles(() => ({
129129
},
130130
}))(Tooltip);
131131

132+
// TODO please antionio could you add elementId
132133
function addDirection(relationship, start) {
133134
relationship.direction = relationship.start.low == start.identity.low;
134135
return relationship;

src/use-neo4j/driver.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { Neo4jConfig, Neo4jScheme } from "./neo4j-config.interface"
1+
import { Neo4jScheme } from './neo4j-config.interface';
22

3-
import neo4j, { Config } from '../neo4j-driver-lite/neo4j-lite-web.esm'
3+
import neo4j, { Config } from '../neo4j-driver-lite/neo4j-lite-web.esm';
44

5-
export const createDriver = (scheme: Neo4jScheme, host: string, port: string | number, username?: string, password?: string, config?: Config) => {
6-
if ( !username || !password ) {
7-
return neo4j.driver(`${scheme}://${host}:${port}`)
8-
}
9-
10-
return neo4j.driver(`${scheme}://${host}:${port}`, neo4j.auth.basic(username, password), config)
11-
}
5+
export const createDriver = (
6+
scheme: Neo4jScheme,
7+
host: string,
8+
port: string | number,
9+
username?: string,
10+
password?: string,
11+
config?: Config
12+
) => {
13+
if (!username || !password) {
14+
return neo4j.driver(`${scheme}://${host}:${port}`);
15+
}
1216

17+
const url = `${scheme}://${host}:${port}`;
18+
return neo4j.driver(url, neo4j.auth.basic(username, password), config);
19+
};
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
export type Neo4jScheme = 'neo4j' | 'neo4j+s' | 'neo4j+scc' | 'bolt' | 'bolt+s' | 'bolt+scc'
1+
export type Neo4jScheme =
2+
| 'neo4j'
3+
| 'neo4j+s'
4+
| 'neo4j+scc'
5+
| 'bolt'
6+
| 'bolt+s'
7+
| 'bolt+scc'
8+
| 'http'
9+
| 'https'
10+
| 'http+s'
11+
| 'https+s';
212

313
export interface Neo4jConfig {
4-
scheme: Neo4jScheme;
5-
host: string;
6-
port: number | string;
7-
username: string | undefined;
8-
password: string | undefined;
9-
database?: string | undefined;
14+
scheme: Neo4jScheme;
15+
host: string;
16+
port: number | string;
17+
username: string | undefined;
18+
password: string | undefined;
19+
database?: string | undefined;
1020
}
1121

12-
export const LOCAL_STORAGE_KEY = '$$charts::config'
22+
export const LOCAL_STORAGE_KEY = '$$charts::config';

src/use-neo4j/neo4j.provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const Neo4jProvider: React.FC<Neo4jProviderProps> = (props: Neo4jProvider
4242
setDatabase(database);
4343
setAuthenticating(true);
4444

45-
const newDriver = createDriver(config.scheme, config.host, config.port, config.username, config.password);
45+
const newDriver = createDriver('http', config.host, config.port, config.username, config.password);
4646

4747
newDriver
4848
.verifyConnectivity()

0 commit comments

Comments
 (0)