-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lens] Add conditional operations in Formula (#142325)
* ✨ Introduce new comparison functions * ✨ Introduce new comparison symbols into grammar * 🔧 Introduce new tinymath functions * ✨ Add comparison fn validation to formula * ♻️ Some type refactoring * ✏️ Fix wrong error message * ✅ Add more formula unit tests * ✅ Add more tests * ✅ Fix tsvb test * 🐛 Fix issue with divide by 0 * ✏️ Update testing command * ✏️ Add some more testing info * ✨ Improved grammar to handle edge cases * ✅ Improve comparison code + unit tests * ✅ Fix test * ✏️ Update documentation with latest functions * 👌 Integrate feedback * 👌 Integrate more feedback * 👌 Update doc * 🐛 Fix bug with function return type check * 🔥 remove duplicate test * [CI] Auto-commit changed files from 'node scripts/build_plugin_list_docs' * Update x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/formula/util.ts * ✏️ Fixes formula * [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Joe Reuter <[email protected]>
- Loading branch information
1 parent
e5cebd8
commit 757ab76
Showing
67 changed files
with
1,403 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/** | ||
* Performs an equality comparison between two values. | ||
* @param {number|number[]} a a number or an array of numbers | ||
* @param {number|number[]} b a number or an array of numbers | ||
* @return {boolean} Returns true if `a` and `b` are equal, false otherwise. Returns an array with the equality comparison of each element if `a` is an array. | ||
* @throws `'Missing b value'` if `b` is not provided | ||
* @throws `'Array length mismatch'` if `args` contains arrays of different lengths | ||
* @example | ||
* eq(1, 1) // returns true | ||
* eq(1, 2) // returns false | ||
* eq([1, 2], 1) // returns [true, false] | ||
* eq([1, 2], [1, 2]) // returns [true, true] | ||
*/ | ||
|
||
function eq(a, b) { | ||
if (b == null) { | ||
throw new Error('Missing b value'); | ||
} | ||
if (Array.isArray(a)) { | ||
if (!Array.isArray(b)) { | ||
return a.every((v) => v === b); | ||
} | ||
if (a.length !== b.length) { | ||
throw new Error('Array length mismatch'); | ||
} | ||
return a.every((v, i) => v === b[i]); | ||
} | ||
|
||
return a === b; | ||
} | ||
module.exports = { eq }; |
Oops, something went wrong.