Skip to content

Commit 5ffb61d

Browse files
committed
Extended developer guide
1 parent b07d5d2 commit 5ffb61d

File tree

3 files changed

+95
-10
lines changed

3 files changed

+95
-10
lines changed

doc/developer-guide.md

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ There are three options for running NeoDash:
2020
If you're using Neo4j Desktop, you can install NeoDash from the [Graph App Gallery](when).
2121
NeoDash will automatically connect to your active database.
2222

23+
![Graph App Gallery](./img/graphapp.png)
2324
#### 2. Online
2425
The latest version of NeoDash will always be available at https://nielsdejong.nl/neodash.
2526
Your database credentials will only be cached in your browser.
@@ -28,37 +29,121 @@ Your database credentials will only be cached in your browser.
2829
To build the application for running in your own environment, take the following steps:
2930

3031
- clone or download this repository.
31-
- Install `npm`.
32+
- [Install](https://www.npmjs.com/get-npm) `npm`.
3233
- navigate to the directory of the repository.
3334
- run `npm install` to install dependencies.
34-
- run `npm run-script build` to build the application. The app will be built to the `dist` folder.
35+
- run `npm run-script build` to build the application. The web app will be deployed to the `dist` folder.
3536
- Use your favourite web server (`apache` or `nginx`) to host the `dist` folder.
3637

37-
Ensure that the `PUBLIC_URL` environment variable is set to where you are hosting the application.
38+
> Ensure that the `PUBLIC_URL` environment variable is set to where you are hosting the application. This needs to be specified before building in the `.env` file.
3839
3940

4041
## Extending NeoDash
4142
NeoDash can be extended to support other visualizations and report types.
4243
This section will provide some instructions on how to extend the application to fit your needs.
4344

45+
### Class Hierarchy
46+
The image below expresses the high level structure of the application's components.
47+
![Class Hierarchy](./img/class-hierarchy.png)
48+
49+
- `index.js` is a basic webpage embedding NeoDash.
50+
- `NeoDash.js` is the dashboard builder class. It contains references to each of the dashboard elements (**cards**), as well as methods to create/re-order the cards. `NeoDash.js` also handles setting up the Neo4j connection and storing/loading reports.
51+
- `NeoCard.js` is a single report element. A `NeoCard` always has a single `NeoReport` (the visualization/report) and a single `NeoFooter` (table pagination, other buttons). The settings pop-up for a dashboard element is defined in `NeoSettings.js`. `NeoCard.js` handles generic operators for all dashboard elements (resizing, refreshing, ...)
52+
- `NeoReport.js` is an base class that different visualizations/reports can inherit. It handles running Cypher queries and generating a result object for the reports to visualize.
53+
- `NeoFooter.js` is the small strip that sits under a `NeoReport`. It handles simple configuration edits for the reports (e.g. choosing which variables to render).
54+
55+
The `component` folder contains reusable components (buttons, textboxes, etc.) that can be used by any of the elements in the class hierarchy.
56+
4457
### Adding a new report type
45-
#### 1. Clone and run the application in development mode
46-
NeoDash is built with React, and uses the `npm` package manager.
47-
Dependencies are specified in `package.json`.
58+
To add your own report type to NeoDash, follow the following steps:
4859

49-
NeoDash can be installed using npm:
60+
#### 1. Clone and run the application in development mode
61+
NeoDash is built with React, and uses the `npm` package manager. Dependencies are specified in `package.json`.
62+
After cloning, navigate to the main folder and install NeoDash using npm:
5063
- `npm install`
5164

52-
Running the application in development mode:
65+
Then, run the application in development mode:
5366
- `npm start`
5467

5568

56-
5769
#### 2. Adding the new report type
70+
Create a new javascript file in the `card/report` folder. Add the following skeleton code:
71+
```
72+
import React from "react";
73+
import NeoReport from "./NeoReport";
74+
75+
class NeoTestReport extends NeoReport {
76+
constructor(props) {
77+
super(props);
78+
}
79+
80+
render() {
81+
let rendered = super.render();
82+
if (rendered) {
83+
return rendered;
84+
}
85+
return <p>{JSON.stringify(this.state.data)}</p>;
86+
}
87+
}
88+
89+
export default (NeoTestReport);
90+
```
91+
92+
This basic report will render your results as a basic text paragraph. Next, also add a new footer class to a file in the `card/footer` directory:
93+
```
94+
import React from "react";
95+
import NeoFooter from "./NeoFooter";
96+
97+
class NeoTestFooter extends NeoFooter {
98+
constructor(props) {
99+
super(props);
100+
}
101+
102+
render() {
103+
return (<p>I'm a footer</p>);
104+
}
105+
}
106+
107+
export default (NeoTestFooter);
108+
```
58109

59110
#### 3. Making the new type selectable
111+
Next, you'll want to make your new report & footer selectable.
112+
113+
In `NeoCard.js`, import your new classes `NeoTestReport` and `NeoTestFooter`, then add the following new method:
114+
```
115+
setCardTypeToTest() {
116+
this.state.content =
117+
<NeoTestReport
118+
connection={this.props.connection}
119+
query={this.state.query}
120+
params={this.state.parsedParameters}
121+
data={this.state.data}
122+
stateChanged={this.stateChanged}
123+
refresh={this.state.refresh}/>
124+
this.state.action = <NeoTestFooter data={this.state.data} />;
125+
}
126+
```
127+
128+
Then, in the same file, edit `updateReportComponent(state)` and add the following if-statement:
129+
```
130+
if (this.state.type === 'test') {
131+
this.setCardTypeToTest();
132+
}
133+
```
134+
135+
Finally, we need to add 'test' to be a selectable option in the report settings view.
136+
In `NeoCardSettings.js`, add the following entry to the `vizOptions` dictionary:
137+
```
138+
'test': 'Test'
139+
```
140+
141+
Now, you can run your application in development mode and the new report type will be selectable in the card settings.
142+
For more advanced examples, like handling updates from the footer, see the other implemented reports.
60143

61144
#### 4. Build the application
145+
After you're done with development, build your application:
146+
- `npm run-script build`
62147

63148
## Contributing
64-
If you're extending the application, please consider contributing to the repository by creating a [pull request](https://github.com/nielsdejong/neodash/pulls).
149+
If you're extending NeoDash, please consider contributing to the repository by creating a [pull request](https://github.com/nielsdejong/neodash/pulls).

doc/img/class-hierarchy.png

71.6 KB
Loading

doc/img/graphapp.png

281 KB
Loading

0 commit comments

Comments
 (0)