-
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
[ML] Data Frame Analytics exploration page: filters improvements #91748
Changes from 3 commits
4c9f9aa
150ee8b
a349738
0649f36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,11 @@ | |
* 2.0. | ||
*/ | ||
|
||
import React, { FC, useEffect, useState } from 'react'; | ||
import React, { FC, useEffect, useMemo, useState } from 'react'; | ||
import { EuiButtonGroup, EuiCode, EuiFlexGroup, EuiFlexItem, EuiInputPopover } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { debounce } from 'lodash'; | ||
import { Dictionary } from '../../../../../../../common/types/common'; | ||
import { IIndexPattern } from '../../../../../../../../../../src/plugins/data/common/index_patterns'; | ||
import { | ||
|
@@ -59,6 +60,33 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({ | |
|
||
const searchChangeHandler = (q: Query) => setSearchInput(q); | ||
|
||
const regex = useMemo(() => new RegExp(`${filters?.columnId}\s?:\s?(true|false)`, 'g'), [ | ||
filters?.columnId, | ||
]); | ||
|
||
/** | ||
* Restoring state from the URL once on load. If a filter option is active | ||
* in the url set the corresponding options button to selected mode. | ||
*/ | ||
useEffect(function updateIdToSelectedMap() { | ||
if (filters !== undefined) { | ||
const match: string[] | null = query.query.match(regex); | ||
let filterKeyInEffect: string | undefined; | ||
|
||
if (match !== null && match[0].includes('true')) { | ||
// set { training: true } | ||
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. Can you explain how the code knows this is about the 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. Good question - the filter So for example the filter's 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. 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. 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 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. Yes, "filters" are what's available as the buttons and is passed into this component from the parent component. 🤔 Maybe this comment is more confusing than clarifying. Would it help to replace it with something like 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. Think it's fine to leave as is - just maybe update the comment above before the 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. Updated in a349738 |
||
filterKeyInEffect = Object.keys(filters.key).find((i) => filters.key[i] === true); | ||
} else if (match !== null && match[0].includes('false')) { | ||
// set { testing: true } | ||
filterKeyInEffect = Object.keys(filters.key).find((i) => filters.key[i] === false); | ||
} | ||
|
||
if (filterKeyInEffect) { | ||
setIdToSelectedMap({ [filterKeyInEffect]: true }); | ||
} | ||
} | ||
}, []); | ||
|
||
/** | ||
* Component is responsible for parsing the query string, | ||
* hence it should sync submitted query string. | ||
|
@@ -107,11 +135,10 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({ | |
}); | ||
}; | ||
|
||
const handleFilterUpdate = (optionId: string, currentIdToSelectedMap: any) => { | ||
const debouncedHandleFilterUpdate = debounce((optionId: string, currentIdToSelectedMap: any) => { | ||
let newQuery = ''; | ||
const filterValue = filters?.key[optionId]; | ||
const filterQueryString = `${filters?.columnId}:${filterValue}`; | ||
const regex = new RegExp(`${filters?.columnId}\s?:\s?(true|false)`, 'g'); | ||
|
||
// Toggling selected optionId to 'off' - remove column id query from filter | ||
if (currentIdToSelectedMap[optionId] === false) { | ||
|
@@ -140,7 +167,7 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({ | |
|
||
setSearchInput(newSearchInput); | ||
searchSubmitHandler(newSearchInput, true); | ||
}; | ||
}, 200); | ||
|
||
return ( | ||
<EuiInputPopover | ||
|
@@ -189,7 +216,7 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({ | |
onChange={(optionId: string) => { | ||
const newIdToSelectedMap = { [optionId]: !idToSelectedMap[optionId] }; | ||
setIdToSelectedMap(newIdToSelectedMap); | ||
handleFilterUpdate(optionId, newIdToSelectedMap); | ||
debouncedHandleFilterUpdate(optionId, newIdToSelectedMap); | ||
}} | ||
/> | ||
</EuiFlexItem> | ||
|
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.
is there a better way to parse the
query
? I think you can useesQuery
oresKuery
insteadThere 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.
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.