Skip to content

Commit 20a97a0

Browse files
authored
Merge pull request #625 from neo4j-labs/fix/OptionalVariablesOnQuery
Optional variables on query
2 parents 55ffed8 + cd2f5c5 commit 20a97a0

File tree

5 files changed

+60
-115
lines changed

5 files changed

+60
-115
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"leaflet": "^1.7.1",
6868
"lodash.debounce": "^4.0.8",
6969
"lodash.isequal": "^4.5.0",
70+
"lodash.merge": "^4.6.2",
7071
"mui-color": "^2.0.0-beta.2",
7172
"mui-nested-menu": "^3.2.1",
7273
"neo4j-client-sso": "^1.2.2",

src/card/view/CardView.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { identifyStyleRuleParameters } from '../../extensions/styling/StyleRuleE
1212
import { IconButton } from '@neo4j-ndl/react';
1313
import { PlayCircleIconSolid } from '@neo4j-ndl/react/icons';
1414
import { extensionEnabled } from '../../utils/ReportUtils';
15+
import { objMerge } from '../../utils/ObjectManipulation';
16+
import { REPORT_TYPES } from '../../config/ReportConfig';
1517

1618
const NeoCardView = ({
1719
id,
@@ -46,6 +48,14 @@ const NeoCardView = ({
4648
const cardHeight = heightPx - CARD_FOOTER_HEIGHT + 23;
4749
const ref = React.useRef();
4850

51+
const settingsSelector = Object.keys(
52+
Object.fromEntries(Object.entries(REPORT_TYPES[type].settings).filter(([_, value]) => value.refresh))
53+
).reduce((obj, key) => {
54+
return Object.assign(obj, {
55+
[key]: settings[key],
56+
});
57+
}, {});
58+
4959
const [lastRunTimestamp, setLastRunTimestamp] = useState(Date.now());
5060

5161
// TODO : selectorChange should handle every case where query execution needs to be re-executed
@@ -69,9 +79,13 @@ const NeoCardView = ({
6979
localQueryVariables.push(match[1]);
7080
}
7181

72-
return Object.fromEntries(
82+
let params = Object.fromEntries(
7383
Object.entries(globalParameters).filter(([local]) => localQueryVariables.includes(local))
7484
);
85+
86+
return settings.ignoreNonDefinedParams
87+
? objMerge(Object.fromEntries(localQueryVariables.map((name) => [name, null])), params)
88+
: params;
7589
};
7690

7791
// @ts-ignore
@@ -135,7 +149,7 @@ const NeoCardView = ({
135149

136150
useEffect(() => {
137151
setSelectorChange(true);
138-
}, [query, type]);
152+
}, [query, type, JSON.stringify(settingsSelector)]);
139153

140154
// TODO - understand why CardContent is throwing a warning based on this style config.
141155
const cardContentStyle = {

src/chart/parameter/component/FreeTextParameterSelect.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ const FreeTextParameterSelectComponent = (props: ParameterSelectProps) => {
3838
return;
3939
}
4040

41-
if (value == null && clearParameterOnFieldClear) {
42-
debouncedSetParameterValue(defaultValue);
41+
if (value == '') {
42+
if (clearParameterOnFieldClear) {
43+
debouncedSetParameterValue(undefined);
44+
} else {
45+
debouncedSetParameterValue(defaultValue);
46+
}
4347
} else {
4448
debouncedSetParameterValue(value);
4549
}

src/config/ReportConfig.tsx

Lines changed: 26 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import NeoMarkdownChart from '../chart/markdown/MarkdownChart';
1313
import { SELECTION_TYPES } from './CardConfig';
1414
import NeoLineChart from '../chart/line/LineChart';
1515
import NeoScatterPlot from '../chart/scatter/ScatterPlotChart';
16+
import { objMerge, objectMap } from '../utils/ObjectManipulation';
1617

1718
// TODO: make the reportConfig a interface with not self-documented code
1819
// Use Neo4j 4.0 subqueries to limit the number of rows returned by overriding the query.
@@ -25,19 +26,14 @@ export const RUN_QUERY_DELAY_MS = 300;
2526
export const DEFAULT_ROW_LIMIT = 100;
2627

2728
// A dictionary of available reports (visualizations).
28-
export const REPORT_TYPES = {
29+
const _REPORT_TYPES = {
2930
table: {
3031
label: 'Table',
3132
helperText: 'A table will contain all returned data.',
3233
component: NeoTableChart,
3334
useReturnValuesAsFields: true,
3435
maxRecords: 1000,
3536
settings: {
36-
backgroundColor: {
37-
label: 'Background Color',
38-
type: SELECTION_TYPES.COLOR,
39-
default: '#fafafa',
40-
},
4137
transposed: {
4238
label: 'Transpose Rows & Columns',
4339
type: SELECTION_TYPES.LIST,
@@ -96,11 +92,6 @@ export const REPORT_TYPES = {
9692
type: SELECTION_TYPES.NUMBER,
9793
default: '0 (No refresh)',
9894
},
99-
description: {
100-
label: 'Report Description',
101-
type: SELECTION_TYPES.MULTILINE_TEXT,
102-
default: 'Enter markdown here...',
103-
},
10495
},
10596
},
10697
graph: {
@@ -120,11 +111,6 @@ export const REPORT_TYPES = {
120111
// between the different options (EX: if operator is false, then it must be the opposite of the setting it depends on)
121112
disabledDependency: { relationshipParticleSpeed: { dependsOn: 'relationshipParticles', operator: false } },
122113
settings: {
123-
backgroundColor: {
124-
label: 'Background Color',
125-
type: SELECTION_TYPES.COLOR,
126-
default: '#fafafa',
127-
},
128114
nodeColorScheme: {
129115
label: 'Node Color Scheme',
130116
type: SELECTION_TYPES.LIST,
@@ -316,11 +302,6 @@ export const REPORT_TYPES = {
316302
values: [true, false],
317303
default: false,
318304
},
319-
description: {
320-
label: 'Report Description',
321-
type: SELECTION_TYPES.MULTILINE_TEXT,
322-
default: 'Enter markdown here...',
323-
},
324305
},
325306
},
326307
bar: {
@@ -350,11 +331,6 @@ export const REPORT_TYPES = {
350331
},
351332
maxRecords: 250,
352333
settings: {
353-
backgroundColor: {
354-
label: 'Background Color',
355-
type: SELECTION_TYPES.COLOR,
356-
default: '#fafafa',
357-
},
358334
legend: {
359335
label: 'Show Legend',
360336
type: SELECTION_TYPES.LIST,
@@ -488,11 +464,6 @@ export const REPORT_TYPES = {
488464
type: SELECTION_TYPES.NUMBER,
489465
default: '0 (No refresh)',
490466
},
491-
description: {
492-
label: 'Report Description',
493-
type: SELECTION_TYPES.MULTILINE_TEXT,
494-
default: 'Enter markdown here...',
495-
},
496467
},
497468
},
498469
pie: {
@@ -522,11 +493,6 @@ export const REPORT_TYPES = {
522493
},
523494
maxRecords: 250,
524495
settings: {
525-
backgroundColor: {
526-
label: 'Background Color',
527-
type: SELECTION_TYPES.COLOR,
528-
default: '#fafafa',
529-
},
530496
legend: {
531497
label: 'Show Legend',
532498
type: SELECTION_TYPES.LIST,
@@ -652,11 +618,6 @@ export const REPORT_TYPES = {
652618
type: SELECTION_TYPES.NUMBER,
653619
default: '0 (No refresh)',
654620
},
655-
description: {
656-
label: 'Report Description',
657-
type: SELECTION_TYPES.MULTILINE_TEXT,
658-
default: 'Enter markdown here...',
659-
},
660621
},
661622
},
662623
line: {
@@ -683,11 +644,6 @@ export const REPORT_TYPES = {
683644
},
684645
maxRecords: 250,
685646
settings: {
686-
backgroundColor: {
687-
label: 'Background Color',
688-
type: SELECTION_TYPES.COLOR,
689-
default: '#fafafa',
690-
},
691647
legend: {
692648
label: 'Show Legend',
693649
type: SELECTION_TYPES.LIST,
@@ -839,11 +795,6 @@ export const REPORT_TYPES = {
839795
type: SELECTION_TYPES.NUMBER,
840796
default: '0 (No refresh)',
841797
},
842-
description: {
843-
label: 'Report Description',
844-
type: SELECTION_TYPES.MULTILINE_TEXT,
845-
default: 'Enter markdown here...',
846-
},
847798
},
848799
},
849800
// TODO - move to advanced visualization.
@@ -1039,11 +990,6 @@ export const REPORT_TYPES = {
1039990
component: NeoMapChart,
1040991
maxRecords: 1000,
1041992
settings: {
1042-
backgroundColor: {
1043-
label: 'Background Color',
1044-
type: SELECTION_TYPES.COLOR,
1045-
default: '#fafafa',
1046-
},
1047993
layerType: {
1048994
label: 'Layer Type',
1049995
type: SELECTION_TYPES.LIST,
@@ -1133,11 +1079,6 @@ export const REPORT_TYPES = {
11331079
values: [true, false],
11341080
default: true,
11351081
},
1136-
description: {
1137-
label: 'Report Description',
1138-
type: SELECTION_TYPES.MULTILINE_TEXT,
1139-
default: 'Enter markdown here...',
1140-
},
11411082
},
11421083
},
11431084
value: {
@@ -1146,11 +1087,6 @@ export const REPORT_TYPES = {
11461087
component: NeoSingleValueChart,
11471088
maxRecords: 1,
11481089
settings: {
1149-
backgroundColor: {
1150-
label: 'Background Color',
1151-
type: SELECTION_TYPES.COLOR,
1152-
default: '#fafafa',
1153-
},
11541090
fontSize: {
11551091
label: 'Font Size',
11561092
type: SELECTION_TYPES.NUMBER,
@@ -1214,11 +1150,6 @@ export const REPORT_TYPES = {
12141150
type: SELECTION_TYPES.NUMBER,
12151151
default: '0 (No refresh)',
12161152
},
1217-
description: {
1218-
label: 'Report Description',
1219-
type: SELECTION_TYPES.MULTILINE_TEXT,
1220-
default: 'Enter markdown here...',
1221-
},
12221153
},
12231154
},
12241155
json: {
@@ -1234,11 +1165,6 @@ export const REPORT_TYPES = {
12341165
values: ['json', 'yml'],
12351166
default: 'json',
12361167
},
1237-
backgroundColor: {
1238-
label: 'Background Color',
1239-
type: SELECTION_TYPES.COLOR,
1240-
default: '#fafafa',
1241-
},
12421168
refreshButtonEnabled: {
12431169
label: 'Refreshable',
12441170
type: SELECTION_TYPES.LIST,
@@ -1268,11 +1194,6 @@ export const REPORT_TYPES = {
12681194
type: SELECTION_TYPES.NUMBER,
12691195
default: '0 (No refresh)',
12701196
},
1271-
description: {
1272-
label: 'Report Description',
1273-
type: SELECTION_TYPES.MULTILINE_TEXT,
1274-
default: 'Enter markdown here...',
1275-
},
12761197
},
12771198
},
12781199
select: {
@@ -1285,11 +1206,6 @@ export const REPORT_TYPES = {
12851206
textOnly: true,
12861207
maxRecords: 100,
12871208
settings: {
1288-
backgroundColor: {
1289-
label: 'Background Color',
1290-
type: SELECTION_TYPES.COLOR,
1291-
default: '#fafafa',
1292-
},
12931209
multiSelector: {
12941210
label: 'Multiple Selection',
12951211
type: SELECTION_TYPES.LIST,
@@ -1369,11 +1285,6 @@ export const REPORT_TYPES = {
13691285
values: [true, false],
13701286
default: false,
13711287
},
1372-
description: {
1373-
label: 'Report Description',
1374-
type: SELECTION_TYPES.MULTILINE_TEXT,
1375-
default: 'Enter markdown here...',
1376-
},
13771288
},
13781289
},
13791290
iframe: {
@@ -1387,11 +1298,6 @@ export const REPORT_TYPES = {
13871298
maxRecords: 1,
13881299
allowScrolling: true,
13891300
settings: {
1390-
backgroundColor: {
1391-
label: 'Background Color',
1392-
type: SELECTION_TYPES.COLOR,
1393-
default: '#fafafa',
1394-
},
13951301
replaceGlobalParameters: {
13961302
label: 'Replace global parameters in URL',
13971303
type: SELECTION_TYPES.LIST,
@@ -1410,11 +1316,6 @@ export const REPORT_TYPES = {
14101316
values: [true, false],
14111317
default: false,
14121318
},
1413-
description: {
1414-
label: 'Report Description',
1415-
type: SELECTION_TYPES.MULTILINE_TEXT,
1416-
default: 'Enter markdown here...',
1417-
},
14181319
},
14191320
},
14201321
text: {
@@ -1427,11 +1328,6 @@ export const REPORT_TYPES = {
14271328
maxRecords: 1,
14281329
allowScrolling: true,
14291330
settings: {
1430-
backgroundColor: {
1431-
label: 'Background Color',
1432-
type: SELECTION_TYPES.COLOR,
1433-
default: '#fafafa',
1434-
},
14351331
replaceGlobalParameters: {
14361332
label: 'Replace global parameters in Markdown',
14371333
type: SELECTION_TYPES.LIST,
@@ -1450,11 +1346,30 @@ export const REPORT_TYPES = {
14501346
values: [true, false],
14511347
default: false,
14521348
},
1453-
description: {
1454-
label: 'Report Description',
1455-
type: SELECTION_TYPES.MULTILINE_TEXT,
1456-
default: 'Enter markdown here...',
1457-
},
14581349
},
14591350
},
14601351
};
1352+
1353+
export const COMMON_REPORT_SETTINGS = {
1354+
backgroundColor: {
1355+
label: 'Background Color',
1356+
type: SELECTION_TYPES.COLOR,
1357+
default: '#fafafa',
1358+
},
1359+
description: {
1360+
label: 'Selector Description',
1361+
type: SELECTION_TYPES.MULTILINE_TEXT,
1362+
default: 'Enter markdown here...',
1363+
},
1364+
ignoreNonDefinedParams: {
1365+
label: 'Ignore undefined parameters',
1366+
type: SELECTION_TYPES.LIST,
1367+
values: [true, false],
1368+
default: false,
1369+
refresh: true,
1370+
},
1371+
};
1372+
1373+
export const REPORT_TYPES = objectMap(_REPORT_TYPES, (value: any) => {
1374+
return objMerge({ settings: COMMON_REPORT_SETTINGS }, value);
1375+
});

src/utils/ObjectManipulation.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
import merge from 'lodash.merge';
2+
13
export const update = (state, mutations) => Object.assign({}, state, mutations);
4+
export const objMerge = (a, b) => merge({}, a, b);
5+
6+
// returns a new object with the values at each key mapped using mapFn(value)
7+
export const objectMap = (object, mapFn) => {
8+
return Object.keys(object).reduce((result, key) => {
9+
result[key] = mapFn(object[key]);
10+
return result;
11+
}, {});
12+
};

0 commit comments

Comments
 (0)