Skip to content

Commit bff9803

Browse files
committed
Finalized Neo4j Desktop integration
1 parent 5466669 commit bff9803

File tree

3 files changed

+96
-17
lines changed

3 files changed

+96
-17
lines changed

desktop-signer.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
PWD=~/IdeaProjects/grandstack-for-dummies-2/ui
12
APPNAME=NeoDash
23

4+
cd $PWD
5+
36
npm run-script build
47
npm pack
58
rm -rf ../target
@@ -13,12 +16,25 @@ cp package/dist/favicon.ico package/favicon.ico
1316
GRAPH_APP_PASSPHRASE=$( cat ../desktop.passphrase )
1417

1518
# sign the code & verify
16-
#npx @neo4j/code-signer --app ./package --private-key ../neo4j-labs-app.pem --cert ../neo4j-labs-app.cert --passphrase $GRAPH_APP_PASSPHRASE
17-
#npx @neo4j/code-signer --verify --app ./package --root-cert ../neo4j_desktop.cert
19+
npx @neo4j/code-signer --app ./package --private-key ../neo4j-labs-app.pem --cert ../neo4j-labs-app.cert --passphrase $GRAPH_APP_PASSPHRASE
20+
npx @neo4j/code-signer --verify --app ./package --root-cert ../neo4j_desktop.cert
1821

1922
# pack it back up again
2023
cd package
2124
npm pack
2225
mv ${APPNAME}*.tgz ../
2326

27+
# remove the package folder
28+
cd ../
29+
rm -rf package
30+
31+
# verify it again
32+
tar xvf ${APPNAME}*.tgz package
33+
34+
npx @neo4j/code-signer --verify \
35+
--app ./package \
36+
--root-cert ../neo4j_desktop.cert
37+
38+
rm -rf package
39+
2440
# file:///home/niels/IdeaProjects/grandstack-for-dummies-2/target/NeoDash-1.0.2.tgz

ui/src/NeoDash.js

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@ class NeoDash extends React.Component {
2222

2323
constructor(props) {
2424
super(props);
25+
26+
// Neo4j Desktop integration
27+
let neo4jDesktopApi = window.neo4jDesktopApi;
28+
if (neo4jDesktopApi){
29+
let promise = neo4jDesktopApi.getContext();
30+
let a = this;
31+
promise.then(function (context) {
32+
let desktopIntegration = new Neo4jDesktopIntegration(context);
33+
let neo4j = desktopIntegration.getActiveDatabase();
34+
if (neo4j) {
35+
36+
a.connection = {
37+
url: neo4j.connection.configuration.protocols.bolt.url,
38+
database:"",
39+
username: neo4j.connection.configuration.protocols.bolt.username,
40+
password: neo4j.connection.configuration.protocols.bolt.password,
41+
encryption: neo4j.connection.configuration.protocols.bolt.tlsLevel === "REQUIRED"
42+
}
43+
a.connect()
44+
45+
}else{
46+
a.connect()
47+
a.updateConnectionModal(a.connect, true);
48+
}
49+
});
50+
51+
}
52+
53+
// check the browser cache or use default values.
2554
this.connection = {
2655
url: (localStorage.getItem('neodash-url')) ? localStorage.getItem('neodash-url') : 'neo4j://localhost:7687',
2756
database: (localStorage.getItem('neodash-database')) ? localStorage.getItem('neodash-database') : '',
@@ -38,16 +67,22 @@ class NeoDash extends React.Component {
3867
this.stateChanged = this.stateChanged.bind(this);
3968
this.loadJson = this.loadJson.bind(this);
4069
this.connect = this.connect.bind(this);
41-
this.updateConnectionModal(this.connect, true);
70+
if(neo4jDesktopApi){
71+
// this.updateConnectionModal(this.connect, true);
72+
this.stateChanged({label: "CreateError", value: "Connecting to " + this.connection.url + "..."})
73+
// this.errorModal = null;
74+
}else{
75+
this.updateConnectionModal(this.connect, true);
76+
}
4277
}
4378

4479
componentDidMount() {
4580
this.loadJson()
4681
}
4782

83+
4884
connect(e) {
4985
try {
50-
5186
var url = this.connection.url;
5287
if (!(url.startsWith("bolt://") || url.startsWith("bolt+routing://") || url.startsWith("neo4j://"))) {
5388
url = "neo4j://" + url;
@@ -64,6 +99,7 @@ class NeoDash extends React.Component {
6499
this.session
65100
.run('return true;')
66101
.then(result => {
102+
this.errorModal = null;
67103
this.connected = true;
68104

69105

@@ -75,6 +111,8 @@ class NeoDash extends React.Component {
75111
localStorage.setItem('neodash-username', this.connection.username);
76112
localStorage.setItem('neodash-password', this.connection.password.toString());
77113
localStorage.setItem('neodash-encryption', this.connection.encryption);
114+
115+
78116
})
79117
.catch(error => {
80118
this.stateChanged({
@@ -177,18 +215,19 @@ class NeoDash extends React.Component {
177215
if (content.startsWith("Could not perform discovery. No routing servers available.")) {
178216
let encryption = this.connection.encryption;
179217
content = "Unable to connect to the specified Neo4j database. " +
180-
"The database might be unreachable, or it does not accept " + (( encryption === "on") ? "encrypted" : "unencrypted") + " connections. " + content;
218+
"The database might be unreachable, or it does not accept " + ((encryption === "on") ? "encrypted" : "unencrypted") + " connections. " + content;
181219

182220
}
183-
this.errorModal = <NeoModal header={"Error"}
184-
style={{'maxWidth': '550px'}}
185-
open={true}
186-
trigger={null}
187-
content={<p>{content}</p>}
188-
key={this.state.count}
189-
id={this.state.count}
190-
root={document.getElementById("root")}
191-
actions={[
221+
let header = (content.startsWith("Connecting to")) ? "Connecting..." : "Error";
222+
this.errorModal = <NeoModal header={header}
223+
style={{'maxWidth': '550px'}}
224+
open={true}
225+
trigger={null}
226+
content={<p>{content}</p>}
227+
key={this.state.count}
228+
id={this.state.count}
229+
root={document.getElementById("root")}
230+
actions={[
192231
<Button flat modal="close"
193232
node="button"
194233
waves="red">Close</Button>
@@ -432,5 +471,24 @@ class NeoDash extends React.Component {
432471
}
433472
}
434473

474+
class Neo4jDesktopIntegration {
475+
constructor(context) {
476+
this.desktopContext = context;
477+
}
478+
479+
getActiveDatabase() {
480+
481+
for (let pi = 0; pi < this.desktopContext.projects.length; pi++) {
482+
let prj = this.desktopContext.projects[pi];
483+
for (let gi = 0; gi < prj.graphs.length; gi++) {
484+
let grf = prj.graphs[gi];
485+
if (grf.status == 'ACTIVE') {
486+
return grf;
487+
}
488+
}
489+
}
490+
return null;
491+
}
492+
}
435493

436494
export default (NeoDash);

ui/src/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import appLogo from './logo.png'
66

77
const root = document.getElementById("root");
88
const url = "https://github.com/nielsdejong/neodash/";
9-
const link = <u><a href={"https://github.com/nielsdejong/neodash/blob/master/README.md"} style={{color: "dimgrey"}} target={"_blank"}>NeoDash 1.0.2 - Neo4j Dashboard Builder</a></u>
9+
const link = <u><a href={"https://github.com/nielsdejong/neodash/blob/master/README.md"} style={{color: "dimgrey"}}
10+
target={"_blank"}>NeoDash 1.0.2 - Neo4j Dashboard Builder</a></u>
1011
const copyrights = <div style={{textAlign: 'center', color: 'dimgrey'}}>{link}</div>;
1112
const footer = <Footer style={{backgroundColor: '#ddd'}} moreLinks={copyrights}></Footer>
1213
const logo = () => {
@@ -26,11 +27,15 @@ const Main = () => {
2627
localStorage.removeItem("neodash-dashboard")
2728
return <div><p>Cache cleared. Your latest dashboard:</p><code>{text}</code></div>
2829
}
30+
var neoDash = <NeoDash/>;
31+
2932

30-
// Else, normal rendering.
3133
return (
32-
<><NeoDash/>{footer}</>
34+
<>{neoDash}{footer}</>
3335
);
3436
};
3537

38+
39+
40+
3641
ReactDOM.render(<Main/>, root);

0 commit comments

Comments
 (0)