-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Dashboard] [Controls] Improve async controls flyout behaviour #154004
Merged
Heenawter
merged 11 commits into
elastic:main
from
Heenawter:improve-async-controls-flyout-behaviour_2023-03-28
Apr 5, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fc0ea21
Remove unnecessary wrapper for popover
Heenawter b68982a
Speed up field registry creation with promises
Heenawter cf520af
Clean up using `useAsync`
Heenawter 4a18b61
Clean up
Heenawter 2ca669b
Improve loading state
Heenawter 3b1d23a
Remove unnecessary `?` check
Heenawter 1622dd4
Merge branch 'main' into improve-async-controls-flyout-behaviour_2023…
Heenawter 9d29b33
Return a single large promise
Heenawter afb1718
Switched to `for` loop
Heenawter 8e852cb
Make loading message fill vertical space
Heenawter c9be3a2
Merge branch 'main' into improve-async-controls-flyout-behaviour_2023…
Heenawter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import deepEqual from 'fast-deep-equal'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { DataViewField } from '@kbn/data-views-plugin/common'; | ||
import { lazyLoadReduxEmbeddablePackage } from '@kbn/presentation-util-plugin/public'; | ||
import { EmbeddableFactoryDefinition, IContainer } from '@kbn/embeddable-plugin/public'; | ||
|
||
|
@@ -21,7 +22,7 @@ import { | |
OPTIONS_LIST_CONTROL, | ||
} from '../../../common/options_list/types'; | ||
import { OptionsListEditorOptions } from '../components/options_list_editor_options'; | ||
import { ControlEmbeddable, DataControlField, IEditableControlFactory } from '../../types'; | ||
import { ControlEmbeddable, IEditableControlFactory } from '../../types'; | ||
|
||
export class OptionsListEmbeddableFactory | ||
implements EmbeddableFactoryDefinition, IEditableControlFactory<OptionsListEmbeddableInput> | ||
|
@@ -57,15 +58,13 @@ export class OptionsListEmbeddableFactory | |
return newInput; | ||
}; | ||
|
||
public isFieldCompatible = (dataControlField: DataControlField) => { | ||
if ( | ||
!dataControlField.field.spec.scripted && | ||
((dataControlField.field.aggregatable && dataControlField.field.type === 'string') || | ||
dataControlField.field.type === 'boolean' || | ||
dataControlField.field.type === 'ip') | ||
) { | ||
dataControlField.compatibleControlTypes.push(this.type); | ||
} | ||
public isFieldCompatible = (field: DataViewField) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice cleanup! |
||
return ( | ||
!field.spec.scripted && | ||
((field.aggregatable && field.type === 'string') || | ||
field.type === 'boolean' || | ||
field.type === 'ip') | ||
); | ||
}; | ||
|
||
public controlEditorOptionsComponent = OptionsListEditorOptions; | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
for ... of
is not much better. How about an imperative for loop, the one with the iteratorfor(i=0; i<length;i++)
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 did some performance testing of all 3 options:
.forEach
with a callback - took11.64ms
on average over 5 triesfor ... of
for loop - took12.52ms
on average over 5 triesfor(let i=0....)
imperative for loop - took12.80ms
on average over 5 tries.So it seems like the imperative for loop is actually the worst of the three, although the differences here are so minimal I'm sure all three options would average out to be more-or-less equivalent over 100+ tests instead of 5 (for example, in my tests for the imperative for loop there was one run that randomly took
17.9ms
- doing more iterations would eliminate this variance).I'm wondering if it is worth going this deep over such minimal improvements (
~1ms
for10,000
fields), though? I'm in favour of sticking with readability in a situation like this, and I personally vote for thefor ... of
loop in this case because it matches the style of the internal factory loop. 🤷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.
right, looking at https://leanylabs.com/blog/js-forEach-map-reduce-vs-for-for_of/
for..in
and a traditionalfor
loop have about the same performance, withfor..in
having slightly better performance.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.
Was just going to link the same article 😆 Awesome, thanks!
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 was reading that one too hahaha.