Skip to content

Commit 209e7fb

Browse files
committed
merge: merge branch 'THU/default_vs_dynamic_values_PROD-14387'
2 parents a039d44 + 277778d commit 209e7fb

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

doc/scenarioParametersConfiguration.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,11 @@ parameters:
206206
query: 'MATCH(n:Customer) RETURN n.id as id'
207207
resultKey: id
208208
```
209+
209210
### Dynamic values for int and number parameters
210-
Initial value for **int** and **number** parameters can be fetched dynamically from the scenario dataset. This feature
211-
is supported for numeric inputs, but it is not yet available for **SLIDER** subtype.
211+
212+
An initial value for **int** and **number** parameters can be fetched dynamically from the scenario dataset. This
213+
feature is supported for numeric inputs, but it is not yet available for the **SLIDER** subtype.
212214

213215
To configure the feature, you have to define `options.dynamicValues`, an object with the following keys:
214216

@@ -220,6 +222,9 @@ To configure the feature, you have to define `options.dynamicValues`, an object
220222
- `resultKey`: the alias defined in your query after `as` keyword, any string of your choice; providing this value is
221223
required for the webapp to parse the cypher query results, and retrieve the actual value to display in the input
222224

225+
Please note that you must not define both `defaultValue` and `options.dynamicValues`. Defining both of these options
226+
will lead to undefined behavior (in most cases, the cypher query will be ignored).
227+
223228
Configuration example :
224229

225230
```yaml
@@ -229,7 +234,7 @@ parameters:
229234
fr: Customers
230235
en: Customers
231236
varType: int
232-
defaultValue: 10 # if a default value is defined, it will be displayed in case if the cypher query fails
237+
defaultValue: null # reminder that defaultValue must not be defined, otherwise the cypher query may be ignored
233238
options:
234239
dynamicValues:
235240
type: cypher
@@ -329,38 +334,43 @@ parameters:
329334
canChangeRowsNumber: false
330335
dateFormat: 'dd/MM/yyyy'
331336
```
337+
332338
#### Data source
339+
333340
By default, the table component is empty but if you want to display some data, you can define either a default or dynamic
334341
value for the parameter. You can provide the id of an existing dataset in the `defaultValue` property of the parameter
335342
description (this dataset must be a CSV file, with values separated by commas). If you want to fetch data from scenario's
336343
dataset, you can use `dynamicValues` option that uses a cypher query to retrieve data from twingraph dataset.
337344

338345
_Note: only a **cypher** query from **twingraph** dataset is supported_
339346

340-
341347
`dynamicValues` is an object with the following keys:
342348

343349
- `query`: the cypher query to run on a twingraph dataset; this query must retrieve a list of property values of the
344-
graph elements, and return them with an alias (example: `MATCH(n:Customer) WITH {name: n.name, age: n.age} as alias
350+
graph elements, and return them with an alias (example: `MATCH(n:Customer) WITH {name: n.name, age: n.age} as alias
345351
RETURN alias`). Names of the properties must correspond to the `field` key in columns definition.
346352
- `resultKey`: the alias defined in your query after `as` keyword, any string of your choice; providing this value is required for the webapp to parse the cypher
347353
query results, and retrieve values to display in the table
348354

349355
Example of typical queries:
350356

351357
_Retrieve nodes from dataset, e.g., all customers list displayed in a table with two columns: name and satisfaction_
358+
352359
```yaml
353360
query: 'MATCH(customer: Customer) WITH {name: customer.id, satisfaction: customer.Satisfaction} as rows RETURN rows',
354361
resultKey: 'rows'
355362
```
363+
356364
_Retrieve edges from dataset, e.g. relationship between all bars and customers displayed in a table with three columns:
357365
bar, customer and relation_
366+
358367
```yaml
359368
query: 'MATCH (b:Bar)-[r]->(c:Customer) WITH {bar: b.id, customer: c.id, relation: r.name } as rows RETURN rows',
360369
resultKey: 'rows'
361370
```
362371

363372
Complete example:
373+
364374
```yaml
365375
parameters:
366376
- id: 'customers'
@@ -387,7 +397,7 @@ parameters:
387397
canChangeRowsNumber: false
388398
```
389399

390-
_Known issue: Dynamic parameters are not saved as scenario parameters if they weren't displayed.
400+
_Known issue: Dynamic parameters are not saved as scenario parameters if they weren't displayed.
391401
In order to save it, users need to open the parameter's tab that will trigger the query_
392402

393403
#### Columns definition

src/utils/SolutionsUtils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ const patchIncompatibleValuesInSolution = (solution) => {
153153
);
154154
parameter.options.canChangeRowsNumber = false;
155155
}
156+
} else if (parameter.varType === 'int' || parameter.varType === 'number') {
157+
if (parameter.defaultValue != null && parameter.options?.dynamicValues != null) {
158+
console.warn(
159+
`In solution configuration, the parameter "${parameter.id}" is defined with ` +
160+
'both options "defaultValue" and "options.dynamicValues": the dynamic query may be ignored.'
161+
);
162+
}
156163
}
157164
});
158165
};

0 commit comments

Comments
 (0)