-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Lens] Formula editor #99297
[Lens] Formula editor #99297
Conversation
…a into lens/formula-error-handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
telemetry schema changes LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One-line change to kbn-monaco
imports LGTM. Didn't test locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 1 NIT to add a description to the formula
field in the schema. If you have no more changes to the PR feel free to merge and address the descriptions later on in a future PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppServices change in data table expression function LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presentation team changes LGTM. Code only review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Extremely impressive job on this PR, @wylieconlon (and all others that contributed). I've left a few comments and suggestions below.
Additionally, per a previous question, I mentioned in the design notes that it would be desirable to not allow the height of an X/Y visualization to exceed its width in full screen mode, as that could yield a chart with some deceptive peaks and valleys. Is this a concern we wish to address in this PR? Or is this concern a non-issue?
|
||
.lnsFormula__editorContent { | ||
position: relative; | ||
height: 201px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why give a height
style to the element containing the Monaco editor here? Wouldn't it be better to just leave it dimensionless and let it conform to the height of the editor? If so, I suggest removing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichaelMarcialis Adding an exact height solves a few of the problems we ran into in Monaco:
- Improves performance, especially performance of opening the initial editor
- Prevents the monaco empty state from flashing
I could not find a way to get both a dynamic height and good performance.
|
||
.lnsIndexPatternDimensionEditor-isFullscreen .lnsFormula__editorContent { | ||
flex: 1; | ||
min-height: 201px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here. Is the min-height
style needed? If not, I suggest removing and letting flexbox determine the height for the editor space.
position="top" | ||
> | ||
<EuiButtonIcon | ||
iconType="bolt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This EuiButtonIcon
for disabling and enabling word wrap is still using the bolt
icon. This should be updated to wordWrapDisabled
and wordWrap
respectively (assuming these new icons are now available in Kibana).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will follow up to update the icons once they are ready in EUI, but they aren't yet.
setIsHelpOpen(!isFullscreen); | ||
trackUiEvent('toggle_formula_fullscreen'); | ||
}} | ||
iconType={isFullscreen ? 'bolt' : 'fullScreen'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This EuiButtonEmpty
for collapsing or exiting full screen mode is still using the bolt
icon. This should be updated to fullScreenExit
(assuming this new icon is now available in Kibana).
color="text" | ||
onClick={() => setIsHelpOpen(!isHelpOpen)} | ||
> | ||
<EuiIcon type="help" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This EuiIcon
is still using the help
icon. This should be updated to documentation
(assuming this new icon is now available in Kibana).
...lens/public/indexpattern_datasource/operations/definitions/formula/editor/formula_editor.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx
Outdated
Show resolved
Hide resolved
<EuiCallOut | ||
size="s" | ||
title={i18n.translate('xpack.lens.indexPattern.formulaWarning', { | ||
defaultMessage: 'Staged formula', | ||
})} | ||
color="warning" | ||
> | ||
<p> | ||
{i18n.translate('xpack.lens.indexPattern.formulaWarningText', { | ||
defaultMessage: 'Picking a quick function will erase your formula.', | ||
})} | ||
</p> | ||
</EuiCallOut> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The placement of this callout feels awkward currently. Assuming we can migrate the EuiTabs
to the flyout header (per my previous comment), could we make this callout flush with the container, as shown in the EUI docs example for applying a banner to an EuiFlyout
?
The wording here also feels like it could use some tweaking. Perhaps the title could be Formula currently applied
and subsequent text could be Select a quick function to overwrite your formula.
? Thoughts, @KOTungseth?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the callout flush, but I don't think I can easily make this a sticky header like the example you gave. If there is a CSS-only solution to this problem I'm happy to implement one, but for this component we don't have any access to the flyout react component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making that change. Can we also make the following changes to this EuiCallout
?
- Apply a prop of
iconType="alert"
for added emphasis. - Apply a style of
border: none;
to match style with similar EUI usage.
Also, any thoughts on those suggested text changes? We can of course update the text in a later PR as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the suggested language, matches the tone of the docs by avoiding "X will Y" type sentences in favor of "To Y, do X"
...lens/public/indexpattern_datasource/operations/definitions/formula/editor/formula_editor.tsx
Outdated
Show resolved
Hide resolved
...lens/public/indexpattern_datasource/operations/definitions/formula/editor/formula_editor.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added one last nitpick below and replied to a previous comment above. Once those are addressed, this looks good from my perspective. Approving now to avoid holding you up. Thanks!
<EuiButtonEmpty | ||
color={errorCount ? 'danger' : 'warning'} | ||
className="lnsFormula__editorError" | ||
iconType="alert" | ||
size="xs" | ||
onClick={() => { | ||
setIsWarningOpen(!isWarningOpen); | ||
}} | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a prop of flush="right"
to this EuiButtonEmpty
to align correctly?
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
* 💄 Hack to fix suggestion box * 🐛 Fix validation messages * 🐛 Relax operations check for managedReferences * Change completion params * 🏷️ Fix missing arg issue * ✨ Add more tinymath fns * 🐛 Improved validation around math operations + multiple named arguments * 🐛 Use new onError feature in math expression * ♻️ Refactor namedArguments validation * 🐛 Fix circular dependency issue in tests + minor fixes * Move formula into a tab * 🔥 Leftovers from previous merge * ✨ Move over namedArgs from previous function * ✅ Add tests for transferable scenarios * ✅ Fixed broken test * ✨ Use custom label for axis * Allow switching back and forth to formula tab * Add a section for the function reference * Add modal editor and markdown docs * Change the way math nodes are validated * Use custom portal to fix monaco positioning * Fix model sharing issues * Provide signature help * 🐛 Fix small test issue * 🐛 Mark pow arguments as required * 🐛 validate on first render only if a formula is present * 🔥 Remove log10 fn for now * ✨ Improved math validation + add tests for math functions * Fix mount/unmount issues with Monaco * [Lens] Fully unmount React when flyout closes * Fix bug with editor frame unmounting * Fix type * Add tests for monaco providers, add hover provider * Add test for last_value * Usability improvements * Add KQL and Lucene named parameters * Add kql, lucene completion and validation * Fix autocomplete on weird characters and properly connect KQL * Highlight functions that have additional requirements after validating * Fix type error and move help text to popover * Fix escape characters inside KQL * 🐛 Fix dataType issue when moving over to Formula * Automatically insert single quotes on every named param * Only insert single quotes when typing kql= or lucene= * Reorganize help popover * Fix merge issues * Update grammar for formulas * Fix bad merge * Rough fullscreen mode * Type updates * Pass through fullscreen state * Remove more chrome from full screen mode * Fix minor bugs in formula typing * 🐛 Decouple column order of references and output * 🔧 Fix tests and types * ✅ Add first functional test * Fix copying formulas and empty formula * Trigger suggestion prompt when hitting enter on function or typing kql= * 🐛 Prevent flyout from closing while interacting with monaco * refactoring * move main column generation into parse module * fix tests * refactor small formula styles and markup * documentation * adjustments in formula footer * Formula refactoring (elastic#12) * refactoring * move main column generation into parse module * fix tests * more style and markup tweak for custom formula * Fix tests * [Expressions] Use table column ID instead of name when set * [Lens] Create managedReference type for formulas * Fix test failures * Fix i18n types * fix fullscreen flex issues * Delete managedReference when replacing * refactor css and markup; add button placeholders * [Lens] Formulas * Tests for formula Co-authored-by: Marco Liberati <[email protected]> * added error count placeholder * Add tooltips * Refactoring from code review * Fix some editor issues * Update ID matching to match by name sometimes * Improve performance of Monaco, fix formulas with 0, update labels * Improve performance of full screen toggle * Fix formula tests * fix stuff * Add an extra case to prevent insertion of duplicate column * Simplify logic and add test for output ID * add telemetry for Lens formula (elastic#15) * Respond to review comments * ✨ Improve the signatures with better documentation and examples * adjust border styles to account for docs collapse * refactor docs markup; restructure docs obj; styles * Fix formula auto reordering (elastic#18) * fix formula auto reordering * add unit test * Fix and improve suggestion experience in Formula (elastic#19) * ✨ Revisit documentation and suggestions * 👌 Integrated feedback * ✨ Add query validation for quotes * Usability updates & type fixes * add search to formula * fix form styles to match designs * fix text styles; revert to Markdown for control * 👌 Integrated more feedback * improve search * improve suggestions * improve suggestions even more * 🐛 Fix i18n issues (elastic#22) * Persist formula on leave, fix fullscreen and popovers * Fix documentation tests * 🏷️ fix type issue * 🐛 Remove hidden operations from valid functions list * 🐛 Fix empty string query edge case * 🐛 Enable more suggestions + extends validation * Fix tests that depended on setState being called without function * Error state and text wrapping updates * ✨ Add new module to CodeEditor for brackets matching (elastic#25) * Fix type * show warning * keep current quick function * ✨ Improve suggestions within kql query * 📷 Fix snapshot editor test * 🐛 Improved suggestion for single quote and refactored debounce * Fix lodash usage * Fix tests * Revert "keep current quick function" This reverts commit ed47705. * Improve performance of dispatch by using timeout * Improve memoization of datapanel * Fix escape characters * fix reduced suggestions * fix responsiveness * fix unit test * Fix autocomplete on nested math * Show errors and warnings on first render * fix transposing column crash * Update comment * 🐛 Fix field error message * fix test types * 📝 Fix i18n name * 💄 Manage wordwrap via react component * Fix selector for palettes that interferes with quick functions * Use word wrapping by default * Errors for managed references are handled at the top level * 🐛 Move the cursor just next to new inserted text * ⚗️ First pass for performance * 🐛 Fix unwanted change * ⚡ Memoize as many combobox props as possible * ⚡ More memoization * Show errors in hover * Use temporary invalid state when moving away from formula * Remove setActiveDimension and shouldClose, fixed by async setters * Fix test dependency * do not show quick functions tab * increase documentation popover width * fix functional test * Call setActiveDimension when updating visualization * Simplify handling of flyout with incomplete columns * Fix test issues * add description to formula telemetry * fix schema * Update from design feedback * More review comments * Hide callout border from v7 theme Co-authored-by: dej611 <[email protected]> Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Joe Reuter <[email protected]> Co-authored-by: Michael Marcialis <[email protected]> Co-authored-by: Joe Reuter <[email protected]> Co-authored-by: Marco Liberati <[email protected]> Co-authored-by: Marco Liberati <[email protected]>
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
* 💄 Hack to fix suggestion box * 🐛 Fix validation messages * 🐛 Relax operations check for managedReferences * Change completion params * 🏷️ Fix missing arg issue * ✨ Add more tinymath fns * 🐛 Improved validation around math operations + multiple named arguments * 🐛 Use new onError feature in math expression * ♻️ Refactor namedArguments validation * 🐛 Fix circular dependency issue in tests + minor fixes * Move formula into a tab * 🔥 Leftovers from previous merge * ✨ Move over namedArgs from previous function * ✅ Add tests for transferable scenarios * ✅ Fixed broken test * ✨ Use custom label for axis * Allow switching back and forth to formula tab * Add a section for the function reference * Add modal editor and markdown docs * Change the way math nodes are validated * Use custom portal to fix monaco positioning * Fix model sharing issues * Provide signature help * 🐛 Fix small test issue * 🐛 Mark pow arguments as required * 🐛 validate on first render only if a formula is present * 🔥 Remove log10 fn for now * ✨ Improved math validation + add tests for math functions * Fix mount/unmount issues with Monaco * [Lens] Fully unmount React when flyout closes * Fix bug with editor frame unmounting * Fix type * Add tests for monaco providers, add hover provider * Add test for last_value * Usability improvements * Add KQL and Lucene named parameters * Add kql, lucene completion and validation * Fix autocomplete on weird characters and properly connect KQL * Highlight functions that have additional requirements after validating * Fix type error and move help text to popover * Fix escape characters inside KQL * 🐛 Fix dataType issue when moving over to Formula * Automatically insert single quotes on every named param * Only insert single quotes when typing kql= or lucene= * Reorganize help popover * Fix merge issues * Update grammar for formulas * Fix bad merge * Rough fullscreen mode * Type updates * Pass through fullscreen state * Remove more chrome from full screen mode * Fix minor bugs in formula typing * 🐛 Decouple column order of references and output * 🔧 Fix tests and types * ✅ Add first functional test * Fix copying formulas and empty formula * Trigger suggestion prompt when hitting enter on function or typing kql= * 🐛 Prevent flyout from closing while interacting with monaco * refactoring * move main column generation into parse module * fix tests * refactor small formula styles and markup * documentation * adjustments in formula footer * Formula refactoring (#12) * refactoring * move main column generation into parse module * fix tests * more style and markup tweak for custom formula * Fix tests * [Expressions] Use table column ID instead of name when set * [Lens] Create managedReference type for formulas * Fix test failures * Fix i18n types * fix fullscreen flex issues * Delete managedReference when replacing * refactor css and markup; add button placeholders * [Lens] Formulas * Tests for formula Co-authored-by: Marco Liberati <[email protected]> * added error count placeholder * Add tooltips * Refactoring from code review * Fix some editor issues * Update ID matching to match by name sometimes * Improve performance of Monaco, fix formulas with 0, update labels * Improve performance of full screen toggle * Fix formula tests * fix stuff * Add an extra case to prevent insertion of duplicate column * Simplify logic and add test for output ID * add telemetry for Lens formula (#15) * Respond to review comments * ✨ Improve the signatures with better documentation and examples * adjust border styles to account for docs collapse * refactor docs markup; restructure docs obj; styles * Fix formula auto reordering (#18) * fix formula auto reordering * add unit test * Fix and improve suggestion experience in Formula (#19) * ✨ Revisit documentation and suggestions * 👌 Integrated feedback * ✨ Add query validation for quotes * Usability updates & type fixes * add search to formula * fix form styles to match designs * fix text styles; revert to Markdown for control * 👌 Integrated more feedback * improve search * improve suggestions * improve suggestions even more * 🐛 Fix i18n issues (#22) * Persist formula on leave, fix fullscreen and popovers * Fix documentation tests * 🏷️ fix type issue * 🐛 Remove hidden operations from valid functions list * 🐛 Fix empty string query edge case * 🐛 Enable more suggestions + extends validation * Fix tests that depended on setState being called without function * Error state and text wrapping updates * ✨ Add new module to CodeEditor for brackets matching (#25) * Fix type * show warning * keep current quick function * ✨ Improve suggestions within kql query * 📷 Fix snapshot editor test * 🐛 Improved suggestion for single quote and refactored debounce * Fix lodash usage * Fix tests * Revert "keep current quick function" This reverts commit ed47705. * Improve performance of dispatch by using timeout * Improve memoization of datapanel * Fix escape characters * fix reduced suggestions * fix responsiveness * fix unit test * Fix autocomplete on nested math * Show errors and warnings on first render * fix transposing column crash * Update comment * 🐛 Fix field error message * fix test types * 📝 Fix i18n name * 💄 Manage wordwrap via react component * Fix selector for palettes that interferes with quick functions * Use word wrapping by default * Errors for managed references are handled at the top level * 🐛 Move the cursor just next to new inserted text * ⚗️ First pass for performance * 🐛 Fix unwanted change * ⚡ Memoize as many combobox props as possible * ⚡ More memoization * Show errors in hover * Use temporary invalid state when moving away from formula * Remove setActiveDimension and shouldClose, fixed by async setters * Fix test dependency * do not show quick functions tab * increase documentation popover width * fix functional test * Call setActiveDimension when updating visualization * Simplify handling of flyout with incomplete columns * Fix test issues * add description to formula telemetry * fix schema * Update from design feedback * More review comments * Hide callout border from v7 theme Co-authored-by: dej611 <[email protected]> Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Joe Reuter <[email protected]> Co-authored-by: Michael Marcialis <[email protected]> Co-authored-by: Joe Reuter <[email protected]> Co-authored-by: Marco Liberati <[email protected]> Co-authored-by: Marco Liberati <[email protected]> Co-authored-by: Wylie Conlon <[email protected]> Co-authored-by: dej611 <[email protected]> Co-authored-by: Joe Reuter <[email protected]> Co-authored-by: Michael Marcialis <[email protected]> Co-authored-by: Joe Reuter <[email protected]> Co-authored-by: Marco Liberati <[email protected]> Co-authored-by: Marco Liberati <[email protected]>
Release note
Lens formulas let you do math using a combination of Elasticsearch aggregations and math functions. For example, find the error rate by typing
count(kql='http.response.status_code >= 400 AND http.response.status_code < 600') / count()
.Known issues that are not blocking
\'
does not replace word, for examplecategory.keyword: Men's
will becomeMen's "Men's Clothing"
category.keyword
is suggested twice## Fixed issues
General issues:0
, like subtracting 0 creates NaN, likecount() - 0
, taking to the 0th power, etcmath()
orformula()
as valid function names, as they are hidden operations @dej611\'
@dej611 ( [Formula] Fix cursor move on quote escape wylieconlon/kibana#36 )reduced
suggestion crashes Lens when using moving average @flash1293count() - 5 + average(
does not suggest fields.moving_average(|)
)[ ] Scrollbar appears and disappears while typing (not reproduceable)min()
:The first argument for min should be a field name. Found
@dej611 ( [Formula] Fix missing field error for function message wylieconlon/kibana#34 )Validation:
Text input:
a.b.c
should not get completed toa.a.b.c
moving_av
and then delete and start typing.matchBrackets: 'always'
@dej611:
@dej611count()
Checklist
For maintainers