-
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] Configure sorting for partition values on Single Metric Viewer #81510
Merged
darnautov
merged 34 commits into
elastic:master
from
darnautov:ML-69526-improve-partition-sorting
Nov 2, 2020
Merged
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
593c9ea
[ML] fix callout styles
darnautov beb067e
[ML] refactor timeseriesexplorer.js, add series_controls.tsx, storage…
darnautov b648467
[ML] anomalousOnly support
darnautov 149287f
[ML] sort by control
darnautov 71487fc
[ML] update query
darnautov 5defba6
[ML] sort order controls
darnautov 953e1ff
Merge remote-tracking branch 'upstream/master' into ML-69526-improve-…
darnautov e1a5c45
[ML] adjust query
darnautov 4855208
[ML] merge default and local configs, add info
darnautov d2710c9
[ML] fix types, adjust sorting logic for model plot results
darnautov fa59221
[ML] fix translation keys
darnautov 799efd0
[ML] fixed size for the icon flex item
darnautov faeaf2f
[ML] fix time range condition, refactor
darnautov 79d10e7
[ML] change info messages and the icon color
darnautov ff0fb56
Fix model plot info message
darnautov b0df9a8
[ML] functional tests
darnautov 9139d1f
[ML] rename ML_ENTITY_FIELDS_CONFIG
darnautov 1f71210
[ML] support manual input
darnautov af2f0ef
[ML] show max record score color indicator
darnautov a8415b7
Merge remote-tracking branch 'upstream/master' into ML-69526-improve-…
darnautov 56ce1ad
[ML] use :checked selector
darnautov ca7c2fc
[ML] refactor functional tests
darnautov 9f094ea
[ML] extend config with "applyTimeRange", refactor with entity_config…
darnautov 6026d41
[ML] info messages
darnautov c0b348e
[ML] remove custom message
darnautov 044768a
[ML] adjust the endpoint
darnautov 3ad0468
[ML] customOptionText
darnautov accd14a
[ML] sort by name UI tweak
darnautov a9a810e
[ML] change text
darnautov 49f3d0e
[ML] remove TODO comment
darnautov 9783cfa
[ML] fix functional test
darnautov 8728e0f
Merge branch 'master' into ML-69526-improve-partition-sorting
kibanamachine 5d4b138
[ML] move "Anomalous only"/"Apply time range" control to the bottom o…
darnautov c4203a3
[ML] update types
darnautov 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EntityFieldType } from './anomalies'; | ||
|
||
export const ML_ENTITY_FIELDS_CONFIG = 'ml.singleMetricViewer.partitionFields'; | ||
|
||
export type PartitionFieldConfig = | ||
| { | ||
/** | ||
* Relevant for jobs with enabled model plot. | ||
* If true, entity values are based on records with anomalies. | ||
* Otherwise aggregated from the model plot results. | ||
*/ | ||
anomalousOnly: boolean; | ||
/** | ||
* Relevant for jobs with disabled model plot. | ||
* If true, entity values are filtered by the active time range. | ||
* If false, the lists consist of the values from all existing records. | ||
*/ | ||
applyTimeRange: boolean; | ||
sort: { | ||
by: string; // 'anomaly_score' | 'name'; | ||
order: string; // 'asc' | 'desc'; | ||
}; | ||
} | ||
| undefined; | ||
|
||
export type PartitionFieldsConfig = | ||
| Partial<Record<EntityFieldType, PartitionFieldConfig>> | ||
| undefined; | ||
|
||
export type MlStorage = Partial<{ | ||
[ML_ENTITY_FIELDS_CONFIG]: PartitionFieldsConfig; | ||
}> | null; |
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
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/ml/public/application/contexts/ml/use_storage.ts
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,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { useCallback, useState } from 'react'; | ||
import { useMlKibana } from '../kibana'; | ||
|
||
/** | ||
* Hook for accessing and changing a value in the storage. | ||
* @param key - Storage key | ||
* @param initValue | ||
*/ | ||
export function useStorage<T>(key: string, initValue?: T): [T, (value: T) => void] { | ||
const { | ||
services: { storage }, | ||
} = useMlKibana(); | ||
|
||
const [val, setVal] = useState<T>(storage.get(key) ?? initValue); | ||
|
||
const setStorage = useCallback((value: T): void => { | ||
try { | ||
storage.set(key, value); | ||
setVal(value); | ||
} catch (e) { | ||
throw new Error('Unable to update storage with provided value'); | ||
peteharverson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}, []); | ||
|
||
return [val, setStorage]; | ||
} |
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
226 changes: 226 additions & 0 deletions
226
...gins/ml/public/application/timeseriesexplorer/components/entity_control/entity_config.tsx
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,226 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { FC, useMemo, useState } from 'react'; | ||
import { | ||
EuiButtonIcon, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiFormRow, | ||
EuiHorizontalRule, | ||
EuiIcon, | ||
EuiPopover, | ||
EuiRadioGroup, | ||
EuiRadioGroupOption, | ||
EuiSwitch, | ||
EuiToolTip, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { Entity } from './entity_control'; | ||
import { UiPartitionFieldConfig } from '../series_controls/series_controls'; | ||
import { EntityFieldType } from '../../../../../common/types/anomalies'; | ||
|
||
interface EntityConfigProps { | ||
entity: Entity; | ||
isModelPlotEnabled: boolean; | ||
config: UiPartitionFieldConfig; | ||
onConfigChange: (fieldType: EntityFieldType, config: Partial<UiPartitionFieldConfig>) => void; | ||
} | ||
|
||
export const EntityConfig: FC<EntityConfigProps> = ({ | ||
entity, | ||
isModelPlotEnabled, | ||
config, | ||
onConfigChange, | ||
}) => { | ||
const [isEntityConfigPopoverOpen, setIsEntityConfigPopoverOpen] = useState(false); | ||
|
||
const forceSortByName = isModelPlotEnabled && !config?.anomalousOnly; | ||
|
||
const sortOptions: EuiRadioGroupOption[] = useMemo(() => { | ||
return [ | ||
{ | ||
id: 'anomaly_score', | ||
label: i18n.translate('xpack.ml.timeSeriesExplorer.sortByScoreLabel', { | ||
defaultMessage: 'Anomaly score', | ||
}), | ||
disabled: forceSortByName, | ||
}, | ||
{ | ||
id: 'name', | ||
label: i18n.translate('xpack.ml.timeSeriesExplorer.sortByNameLabel', { | ||
defaultMessage: 'Name', | ||
}), | ||
}, | ||
]; | ||
}, [isModelPlotEnabled, config]); | ||
|
||
const orderOptions: EuiRadioGroupOption[] = useMemo(() => { | ||
return [ | ||
{ | ||
id: 'asc', | ||
label: i18n.translate('xpack.ml.timeSeriesExplorer.ascOptionsOrderLabel', { | ||
defaultMessage: 'asc', | ||
}), | ||
}, | ||
{ | ||
id: 'desc', | ||
label: i18n.translate('xpack.ml.timeSeriesExplorer.descOptionsOrderLabel', { | ||
defaultMessage: 'desc', | ||
}), | ||
}, | ||
]; | ||
}, []); | ||
|
||
return ( | ||
<EuiPopover | ||
ownFocus | ||
style={{ height: '40px' }} | ||
button={ | ||
<EuiButtonIcon | ||
color="text" | ||
iconSize="m" | ||
iconType="gear" | ||
aria-label={i18n.translate('xpack.ml.timeSeriesExplorer.editControlConfiguration', { | ||
defaultMessage: 'Edit field configuration', | ||
})} | ||
onClick={() => { | ||
setIsEntityConfigPopoverOpen(!isEntityConfigPopoverOpen); | ||
}} | ||
data-test-subj={`mlSingleMetricViewerEntitySelectionConfigButton_${entity.fieldName}`} | ||
/> | ||
} | ||
isOpen={isEntityConfigPopoverOpen} | ||
closePopover={() => { | ||
setIsEntityConfigPopoverOpen(false); | ||
}} | ||
> | ||
<div data-test-subj={`mlSingleMetricViewerEntitySelectionConfigPopover_${entity.fieldName}`}> | ||
<EuiFlexGroup gutterSize={'xs'} alignItems={'center'}> | ||
<EuiFlexItem grow={false}> | ||
{isModelPlotEnabled ? ( | ||
<EuiSwitch | ||
label={ | ||
<FormattedMessage | ||
id="xpack.ml.timeSeriesExplorer.anomalousOnlyLabel" | ||
defaultMessage="Anomalous only" | ||
/> | ||
} | ||
checked={config.anomalousOnly} | ||
onChange={(e) => { | ||
const isAnomalousOnly = e.target.checked; | ||
onConfigChange(entity.fieldType, { | ||
anomalousOnly: isAnomalousOnly, | ||
sort: { | ||
order: config.sort.order, | ||
by: config.sort.by, | ||
}, | ||
}); | ||
}} | ||
compressed | ||
data-test-subj={`mlSingleMetricViewerEntitySelectionConfigAnomalousOnly_${entity.fieldName}`} | ||
/> | ||
) : ( | ||
<EuiSwitch | ||
label={ | ||
<FormattedMessage | ||
id="xpack.ml.timeSeriesExplorer.applyTimeRangeLabel" | ||
defaultMessage="Apply time range" | ||
/> | ||
} | ||
checked={config.applyTimeRange} | ||
onChange={(e) => { | ||
const applyTimeRange = e.target.checked; | ||
onConfigChange(entity.fieldType, { | ||
applyTimeRange, | ||
}); | ||
}} | ||
compressed | ||
data-test-subj={`mlSingleMetricViewerEntitySelectionConfigAnomalousOnly_${entity.fieldName}`} | ||
/> | ||
)} | ||
</EuiFlexItem> | ||
|
||
<EuiFlexItem grow={false} style={{ width: '16px' }}> | ||
{isModelPlotEnabled && !config?.anomalousOnly ? ( | ||
<EuiToolTip | ||
position="top" | ||
content={ | ||
<FormattedMessage | ||
id="xpack.ml.timeSeriesExplorer.nonAnomalousResultsWithModelPlotInfo" | ||
defaultMessage="The list contains values from the model plot results." | ||
/> | ||
} | ||
> | ||
<EuiIcon tabIndex={0} type="iInCircle" color={'subdued'} /> | ||
</EuiToolTip> | ||
) : null} | ||
|
||
{!isModelPlotEnabled && !config?.applyTimeRange ? ( | ||
<EuiToolTip | ||
position="top" | ||
content={ | ||
<FormattedMessage | ||
id="xpack.ml.timeSeriesExplorer.ignoreTimeRangeInfo" | ||
defaultMessage="The list contains values from all anomalies created during the lifetime of the job." | ||
/> | ||
} | ||
> | ||
<EuiIcon tabIndex={0} type="iInCircle" color={'subdued'} /> | ||
</EuiToolTip> | ||
) : null} | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
|
||
<EuiHorizontalRule margin="s" /> | ||
<EuiFormRow | ||
label={ | ||
<FormattedMessage | ||
id="xpack.ml.timeSeriesExplorer.sortByLabel" | ||
defaultMessage="Sort by" | ||
/> | ||
} | ||
> | ||
<EuiRadioGroup | ||
options={sortOptions} | ||
idSelected={forceSortByName ? 'name' : config?.sort?.by} | ||
onChange={(id) => { | ||
onConfigChange(entity.fieldType, { | ||
sort: { | ||
order: config.sort.order, | ||
by: id, | ||
}, | ||
}); | ||
}} | ||
compressed | ||
data-test-subj={`mlSingleMetricViewerEntitySelectionConfigSortBy_${entity.fieldName}`} | ||
/> | ||
</EuiFormRow> | ||
<EuiFormRow | ||
label={ | ||
<FormattedMessage id="xpack.ml.timeSeriesExplorer.orderLabel" defaultMessage="Order" /> | ||
} | ||
> | ||
<EuiRadioGroup | ||
options={orderOptions} | ||
idSelected={config?.sort?.order} | ||
onChange={(id) => { | ||
onConfigChange(entity.fieldType, { | ||
sort: { | ||
by: config.sort.by, | ||
order: id, | ||
}, | ||
}); | ||
}} | ||
compressed | ||
data-test-subj={`mlSingleMetricViewerEntitySelectionConfigOrder_${entity.fieldName}`} | ||
/> | ||
</EuiFormRow> | ||
</div> | ||
</EuiPopover> | ||
); | ||
}; |
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.
Should this type be updated with the commented code?
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.
Yes, updated in c4203a3