Skip to content
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

[ML] Data Frame Analytics exploration page: filters improvements #91748

Merged

Conversation

alvarezmelissa87
Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 commented Feb 17, 2021

Summary

Fixes #84500

  • Training / Testing filter toggle resolves state from the active query - toggle state now reflects query when page is opened / refreshed
  • Training / Testing filter toggle wrapped in a debounce

DFA_EXAMPLE

Checklist

Delete any items that are not applicable to this PR.

  • Any UI touched in this PR is usable by keyboard only (learn more about keyboard accessibility)
  • Any UI touched in this PR does not create any new axe failures (run axe in browser: FF, Chrome)

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

let filterKeyInEffect: string | undefined;

if (match !== null && match[0].includes('true')) {
// set { training: true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain how the code knows this is about the training attribute? Or is this just an example and it's applicable to attributes in general?

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Feb 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question - the filter key property (filters are passed in as props) shows what field value the filter option corresponds to to be 'selected'

So for example the filter's columnId is ml.is_training'and the key for Training is training: true - so ml.is_training value would betrue. The key for Testing is testing: false meaning ml.is_training value should be false when this is selected.

So right now it would only work with filters where the column id value is a boolean. It is only used in dfa exploration right now, though so that should be fine as these are just quick filters and it is unlikely we would add quick filters for non boolean field values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh so "filter" refers to what's available as the buttons and not something derived from the free text query is that correct, that's why it can only be training?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, "filters" are what's available as the buttons and is passed into this component from the parent component.
training is just an example since that's the only current value is but it would be whatever is passed in as a filter.

🤔 Maybe this comment is more confusing than clarifying. Would it help to replace it with something like <filter_key_value: true> ? Or remove it entirely and add a comment for an example filter up by the filter type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it's fine to leave as is - just maybe update the comment above before the useEffect to emphasize this is about "restoring state from the URL once on load" or similar - I missed that and only now noticed the [] to make it trigger only once. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in a349738

@alvarezmelissa87 alvarezmelissa87 force-pushed the ml-ad-exploration-improvement branch from 02b23ec to 150ee8b Compare February 19, 2021 16:29
@@ -59,6 +60,31 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({

const searchChangeHandler = (q: Query) => setSearchInput(q);

const regex = useMemo(() => new RegExp(`${filters?.columnId}\s?:\s?(true|false)`, 'g'), []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it have filters?.columnId is the dependencies array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should - good catch 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in a349738

* If a filter option is active in the url set the corresponding options
* button to selected mode
*/
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a named function instead. It makes troubleshooting easier, as the effect callback name appears in stack trace.

Suggested change
useEffect(() => {
useEffect(function updateIdToSelectedMap() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in a349738

*/
useEffect(() => {
if (filters !== undefined) {
const match: string[] | null = query.query.match(regex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a better way to parse the query? I think you can use esQuery or esKuery instead

Copy link
Contributor Author

@alvarezmelissa87 alvarezmelissa87 Feb 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, here we just need to check the query string for the filter pattern - I'm not sure we need to parse it. Leaving as is for now as the regex check has been used for the quick filters since the beginning. Happy to revisit in the next release and do some testing around another way to parse the query.

@alvarezmelissa87
Copy link
Contributor Author

This has been updated and is ready for a final look when you get a chance. 🙏 cc @walterra, @darnautov

Copy link
Contributor

@darnautov darnautov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest changes LGTM

@walterra
Copy link
Contributor

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
ml 6.4MB 6.4MB +675.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @alvarezmelissa87

@alvarezmelissa87 alvarezmelissa87 merged commit b7f33b1 into elastic:master Feb 22, 2021
alvarezmelissa87 added a commit to alvarezmelissa87/kibana that referenced this pull request Feb 22, 2021
…stic#91748)

* exploration query bar filter reflects url query state on page load

* wrap filter handler in debounce

* add dep to memoized regex. update comment

Co-authored-by: Kibana Machine <[email protected]>
@alvarezmelissa87 alvarezmelissa87 deleted the ml-ad-exploration-improvement branch February 22, 2021 15:46
gmmorris added a commit to gmmorris/kibana that referenced this pull request Feb 22, 2021
* master:
  Ability to filter alerts by string parameters (elastic#92036)
  [APM] Fix for flaky correlations API test (elastic#91673) (elastic#92094)
  [Enterprise Search] Migrate shared role mapping components (elastic#91723)
  [file_upload] move ml Importer classes to file_upload plugin (elastic#91559)
  [Discover] Always show the "hide missing fields" toggle (elastic#91889)
  v2 migrations should exit process on corrupt saved object document (elastic#91465)
  [ML] Data Frame Analytics exploration page: filters improvements (elastic#91748)
  [ML] Data Frame Analytics: Improved error handling for scatterplot matrix. (elastic#91993)
  [coverage] speed up merging results of functional tests (elastic#92111)
  Adds a Reason indicator to the onClose handler in AddAlert and EditAlert (elastic#92149)
alvarezmelissa87 added a commit to alvarezmelissa87/kibana that referenced this pull request Feb 22, 2021
…stic#91748)

* exploration query bar filter reflects url query state on page load

* wrap filter handler in debounce

* add dep to memoized regex. update comment

Co-authored-by: Kibana Machine <[email protected]>
alvarezmelissa87 added a commit that referenced this pull request Feb 22, 2021
) (#92210)

* exploration query bar filter reflects url query state on page load

* wrap filter handler in debounce

* add dep to memoized regex. update comment

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
alvarezmelissa87 added a commit that referenced this pull request Feb 22, 2021
) (#92209)

* exploration query bar filter reflects url query state on page load

* wrap filter handler in debounce

* add dep to memoized regex. update comment

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Data Frame Analytics exploration page issues
5 participants