Skip to content

Commit 376a7a4

Browse files
authored
Merge pull request #413 from neo4j-labs/fixNodeValHandling
Added support for handling nodes as dashboard parameters
2 parents 37c348c + d0c74c7 commit 376a7a4

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ This release is a feature-rich package with a variety of new features and bug fi
3636
- Integrated the official released version of the Neo4j Cypher editor component. ([@jharris4](https://github.com/jharris4), [#365](https://github.com/neo4j-labs/neodash/pull/365))
3737
- Fixed hot-module replacement inside webpack configuration. ([@konsalex](https://github.com/konsalex), [#396](https://github.com/neo4j-labs/neodash/pull/396))
3838
- Fixed husky pre-commit hook not triggering correctly on Windows environments. ([@bastienhubert](https://github.com/bastienhubert), [#342](https://github.com/neo4j-labs/neodash/issues/342))
39+
- Add support for using complex objects in markdown, iframes and report titles. ([@BennuFire](https://github.com/bennufire), [#413](https://github.com/neo4j-labs/neodash/pull/413))
40+
3941

4042
## NeoDash 2.2.3
4143
This releases fixes a small set of bugs that slipped through the 2.2.3 release, and adds some minor features:

docs/modules/ROOT/pages/user-guide/reports/markdown.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ text, to be renderer as rich HTML. This lets you turn your dashboards
66
into a storybook with textual descriptions, hyperlinks, images and
77
videos.
88

9+
To use dashboard parameters in Markdown, turn on the `Replace global parameters in Markdown` setting.
10+
Then, include a variable surrounded by backticks inside the markdown string. For example:
11+
12+
```
13+
== This is a title
14+
My variable is equal to `$neodash_person_object['name']`
15+
```
16+
17+
918
== Examples
1019

1120
=== Basic Markdown

release-notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ This release is a feature-rich package with a variety of new features and bug fi
3535
- Added handler for mulitple report actions to be executed on the same event. ([@BennuFire](https://github.com/BennuFire), [#324](https://github.com/neo4j-labs/neodash/issues/324))
3636
- Integrated the official released version of the Neo4j Cypher editor component. ([@jharris4](https://github.com/jharris4), [#365](https://github.com/neo4j-labs/neodash/pull/365))
3737
- Fixed hot-module replacement inside webpack configuration. ([@konsalex](https://github.com/konsalex), [#396](https://github.com/neo4j-labs/neodash/pull/396))
38-
- Fixed husky pre-commit hook not triggering correctly on Windows environments. ([@bastienhubert](https://github.com/bastienhubert), [#342](https://github.com/neo4j-labs/neodash/issues/342))
38+
- Fixed husky pre-commit hook not triggering correctly on Windows environments. ([@bastienhubert](https://github.com/bastienhubert), [#342](https://github.com/neo4j-labs/neodash/issues/342))
39+
- Add support for using complex objects in markdown, iframes and report titles. ([@BennuFire](https://github.com/bennufire), [#413](https://github.com/neo4j-labs/neodash/pull/413))

src/card/view/CardViewHeader.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import ImageIcon from '@material-ui/icons/Image';
1515
import CloseIcon from '@material-ui/icons/Close';
1616
import ReactMarkdown from 'react-markdown';
1717
import gfm from 'remark-gfm';
18+
import { replaceDashboardParameters } from '../../chart/ChartUtils';
1819

1920
const NeoCardViewHeader = ({
2021
title,
@@ -37,13 +38,8 @@ const NeoCardViewHeader = ({
3738
const [descriptionModalOpen, setDescriptionModalOpen] = React.useState(false);
3839

3940
function replaceParamsOnString(s, p) {
40-
let parsed = `${s} `;
41-
for (const [key, value] of Object.entries(p)) {
42-
// TODO: make this a regex.
43-
parsed = parsed.replace(`$${key} `, `${value} `);
44-
parsed = parsed.replace(`$${key},`, `${value},`);
45-
parsed = parsed.replace(`$${key}.`, `${value}.`);
46-
}
41+
let parsed: string;
42+
parsed = replaceDashboardParameters(s, p);
4743
return parsed;
4844
}
4945

src/chart/ChartUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ export function replaceDashboardParameters(str, parameters) {
208208
let newString = str.replace(rx, parameterElementReplacer);
209209

210210
Object.keys(parameters).forEach((key) => {
211-
newString = newString.replaceAll(`$${key}`, parameters[key] !== null ? parameters[key] : '');
211+
let valueRender = RenderSubValue(parameters[key]);
212+
newString = newString.replaceAll(`$${key} `, `${valueRender} `);
213+
newString = newString.replaceAll(`$${key},`, `${valueRender},`);
214+
newString = newString.replaceAll(`$${key}.`, `${valueRender}.`);
215+
newString = newString.replaceAll(`$${key})`, `${valueRender})`);
212216
});
213217

214218
return newString;

src/settings/SettingsThunks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { setSessionParameters } from '../application/ApplicationActions';
22
import { hardResetCardSettings } from '../card/CardActions';
3-
import { castToNeo4jDate, isCastableToNeo4jDate } from '../chart/ChartUtils';
3+
import { castToNeo4jDate, isCastableToNeo4jDate, valueIsNode } from '../chart/ChartUtils';
44
import { createNotificationThunk } from '../page/PageThunks';
55
import { updateDashboardSetting } from './SettingsActions';
66

@@ -29,7 +29,8 @@ export const updateGlobalParameterThunk = (key, value) => (dispatch: any, getSta
2929
const { settings } = getState().dashboard;
3030
const parameters = settings.parameters ? settings.parameters : {};
3131
if (value !== undefined) {
32-
parameters[key] = value;
32+
let valueFinal = valueIsNode(value) ? Object.assign({}, value) : value;
33+
parameters[key] = valueFinal;
3334
} else {
3435
delete parameters[key];
3536
}

0 commit comments

Comments
 (0)