I'd like to dynamically set the value for the gauge according to the source data. How do I access the source data that has a variable named 'func'. Appreciate your advice.
if (params._source['func'] == 'secret1') {
params.A / 1
} else if (params._source['func'] == 'secret2') {
params.A / 10
} else {
params.A / 100
}
jsanz
(Jorge Sanz)
October 24, 2022, 11:49am
2
Conditionals will come to Lens formula in 8.6
:
elastic:main
← dej611:feature/94603
opened 11:12AM - 30 Sep 22 UTC
## Summary
Fixes #94603
* Tinymath package
* [x] Add new comparison ope… ration: `lt`, `gt`, `eq`, `lte`, `gte`
* [x] Add new functions documentation
* [x] Generate new `functions.md` page
* [x] Add new `ifelse` operation
* The `ifelse` name is a placeholder. Possible alternatives are: `ifElse`, `when`, `ifThen`, or make your proposal. :)
* [x] Add new operation documentation
* [x] Add tests for new functions
* [x] Make grammar accept comparison symbols: `>`, `<`, `==`, `>=`, `<=`
* to test it I recommend copy the `grammar.peggy` content into this web site to test the resulting AST: https://peggyjs.org/online.html
* [x] Add tests for backward compatibility and new features in grammar
* Lens side
* [x] Enable new functions in Formula (comparison + `ifelse`)
* Validation
* [x] Make validation work for different returning types
* [x] Make validation fail for comparison only expressions
* [x] Make validation fail if non-comparison condition passed to `ifelse` function
* [x] Add new validation tests
* [x] Add documentation for new operations
* New section for comparison?
### Extra fixes
* :bug: Fixed also a bug in the `divide` operation with a `divide by 0` scenario.
* :pencil2: Improved documentation about testing to avoid the `Jest esm error` message
## New grammar changes examples
```
// Not ok: math operations cannot be performed with a comparison on any end of the operation
1 + (1 > 1)
(1 > 1) + 1
((1 > 1) + 1)
5 > 1 > 2
(5 > 1) > 2
(5 > 1) + (5 > 1)
// Ok: math operations can be on either side of the comparison, and be considered as grouped
1 > 1
(1 > 1)
((1 > 1))
((1 + 1) > 1)
1 + 1 > 1 * 1 // => becomes (1 + 1) > (1 * 1) => 1 > 1
```
### Tinymath documentation
Command I've used to generate the new `functions.md` file:
```sh
npx -p jsdoc-to-markdown -c 'jsdoc2md --template packages/kbn-tinymath/docs/template/functions.hbs --private --files "packages/kbn-tinymath/src/functions/**/*.js"' > packages/kbn-tinymath/docs/functions.md
```
I couldn't make it work properly the previous command used when tinymath was in its own repo: the produced json for the documentation had the wrong function name, always set to `module.exports`.
In the `jsdoc-to-markdown` documentation it mentions that `module.exports` had to be defined *after* the actual function implementation ([which is apparently a jsdoc limitation](https://github.com/jsdoc2md/jsdoc-to-markdown/issues/91)], and after that everything worked properly. That is why some many files changed with only the exports.
## Demo
Working example:
<img width="1162" alt="Screenshot 2022-09-30 at 12 44 44" src="https://user-images.githubusercontent.com/924948/193256175-de419678-c54c-4937-8573-25bad1876e74.png">
Comparison symbols and functions working as condition:
<img width="1144" alt="Screenshot 2022-09-30 at 12 58 37" src="https://user-images.githubusercontent.com/924948/193256267-0ae2820c-eec4-4c07-af36-1e4dc1283a44.png">
<img width="1164" alt="Screenshot 2022-09-30 at 12 58 50" src="https://user-images.githubusercontent.com/924948/193256277-c521a46f-fb8f-4de2-8925-b208879d6b9a.png">
<img width="1161" alt="Screenshot 2022-09-30 at 12 59 20" src="https://user-images.githubusercontent.com/924948/193256290-24dadc9d-ef4c-41a6-9c8b-9b42f02a7472.png">
<img width="1155" alt="Screenshot 2022-09-30 at 12 59 28" src="https://user-images.githubusercontent.com/924948/193256312-5bc6c059-1035-431e-a64b-f111011f2bc8.png">
Errors:
<img width="337" alt="Screenshot 2022-09-30 at 12 55 33" src="https://user-images.githubusercontent.com/924948/193257014-616342c0-9c4b-4569-beb0-0cc7a7fd6a81.png">
<img width="337" alt="Screenshot 2022-09-30 at 12 57 44" src="https://user-images.githubusercontent.com/924948/193257018-df7a7331-81af-483a-81f5-83e64c70f6af.png">
<img width="336" alt="Screenshot 2022-09-30 at 12 58 04" src="https://user-images.githubusercontent.com/924948/193257022-f8dbebf8-0fd8-4398-a15a-7768d0496575.png">
<img width="339" alt="Screenshot 2022-09-30 at 12 58 24" src="https://user-images.githubusercontent.com/924948/193257025-140b8758-2ef2-4b46-9815-33f123d7106c.png">
<img width="350" alt="Screenshot 2022-09-30 at 17 38 29" src="https://user-images.githubusercontent.com/924948/193306583-adcf572f-b09e-4717-9394-cabf562b5d6f.png">
Documentation:
<img width="515" alt="Screenshot 2022-09-30 at 12 45 01" src="https://user-images.githubusercontent.com/924948/193257068-84b7259e-3477-43f7-8a38-f85a20287ca7.png">
### Checklist
Delete any items that are not applicable to this PR.
- [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials
- [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
### Risk Matrix
Delete this section if it is not applicable to this PR.
Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.
When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:
| Risk | Probability | Severity | Mitigation/Notes |
|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. |
| Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. |
| [See more potential risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |
### For maintainers
- [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
1 Like
system
(system)
Closed
February 11, 2023, 8:11am
6
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.