-
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] Single Metric Viewer embeddable: add open and edit panel actions #179364
[ML] Single Metric Viewer embeddable: add open and edit panel actions #179364
Conversation
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.
Code LGTM, also tested this with some datasets.
/ci |
Pinging @elastic/ml-ui (:ml) |
@elasticmachine merge upstream |
x-pack/plugins/ml/public/application/jobs/new_job/pages/job_type/page.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/ml/public/embeddables/single_metric_viewer/single_metric_viewer_initializer.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/ml/public/ui_actions/open_in_single_metric_viewer_action.tsx
Outdated
Show resolved
Hide resolved
Did a bit of refactoring to fully decouple actions from old embeddable system and fixed a bug where the |
const isTimeBasedIndex: boolean = selectedDataView.isTimeBased(); | ||
|
||
useEffect(() => { | ||
if (!isTimeBasedIndex) { | ||
toasts.addWarning({ | ||
title: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationTitle', { | ||
defaultMessage: 'The data view {dataViewIndexPattern} is not based on a time series', | ||
values: { dataViewIndexPattern: selectedDataView.getIndexPattern() }, | ||
}), | ||
text: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationDescription', { | ||
defaultMessage: 'Anomaly detection only runs over time-based indices', | ||
}), | ||
}); | ||
} | ||
}, [isTimeBasedIndex, selectedDataView, toasts]); | ||
|
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.
nit: can be simplified even further, preventing access to the isTImeBased
method on each render!
const isTimeBasedIndex: boolean = selectedDataView.isTimeBased(); | |
useEffect(() => { | |
if (!isTimeBasedIndex) { | |
toasts.addWarning({ | |
title: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationTitle', { | |
defaultMessage: 'The data view {dataViewIndexPattern} is not based on a time series', | |
values: { dataViewIndexPattern: selectedDataView.getIndexPattern() }, | |
}), | |
text: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationDescription', { | |
defaultMessage: 'Anomaly detection only runs over time-based indices', | |
}), | |
}); | |
} | |
}, [isTimeBasedIndex, selectedDataView, toasts]); | |
useEffect(function warnNonTimeSeriesData() { | |
if (!selectedDataView.isTimeBased()) { | |
toasts.addWarning({ | |
title: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationTitle', { | |
defaultMessage: 'The data view {dataViewIndexPattern} is not based on a time series', | |
values: { dataViewIndexPattern: selectedDataView.getIndexPattern() }, | |
}), | |
text: i18n.translate('xpack.ml.dataViewNotBasedOnTimeSeriesNotificationDescription', { | |
defaultMessage: 'Anomaly detection only runs over time-based indices', | |
}), | |
}); | |
} | |
}, [selectedDataView, toasts]); | |
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.
There's a reliance on the isTimeBasedIndex
variable a few lines down - I considered wrapping in a useEffect but I think the addition of the function would negate any small optimization we'd get from that, in my opinion. Happy to discuss further if you feel strongly. 😄
@@ -14,7 +14,7 @@ import type { JobId, CombinedJob } from '../../../common/types/anomaly_detection | |||
*/ | |||
export function getControlsForDetector( | |||
selectedDetectorIndex: number, | |||
selectedEntities: Record<string, any>, | |||
selectedEntities: Record<string, any> | undefined, |
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 you please use the MlEntityField
type instead of any
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.
Went back to double check and the original Record<string, any>
type is correct - went back to ensure the types are correct. All types should now be correct. Updated in c39b883
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 don't think any
is correct. If you don't know the incoming type - it should be unknown
and covered with a type guard. Otherwise you should be aware of the expected type.
this.jobId = embeddableInputToSubject<JobId, SingleMetricViewerEmbeddableInput>( | ||
this.apiSubscriptions, | ||
this, | ||
'jobId' |
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.
With the already released embeddable version in 8.13, you need to provide backward compatibility.
The input prop used to be named jobIds
and contained an array of strings instead of a string.
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 PR has a change in single_metric_viewer_setup_flyout.tsx
which resolves the array to a string when setting up the panel jobId: jobIds[0],
.
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.
Good call! Going to keep the original API for now to prevent any issues c39b883
this.title = embeddableInputToSubject<string, SingleMetricViewerEmbeddableInput>( | ||
this.apiSubscriptions, | ||
this, | ||
'title' | ||
); |
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.
title
is a common prop and is handled by the embeddable framework
this.title = embeddableInputToSubject<string, SingleMetricViewerEmbeddableInput>( | |
this.apiSubscriptions, | |
this, | |
'title' | |
); |
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, it can be handled via Panel settings
but is also editable when using the Edit panel
action that has been added.
When converting to the new framework, this will be removed, but right now it's still handled by the edit action.
I will remove this when refactoring to the new framework in a follow up PR to ensure full functionality at every step.
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.
Anomaly swim lane has exactly the same - editable via Panel settings
and Edit panel
actions, but it does not duplicate title
API.
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.
Good call - removed in c39b883
x-pack/plugins/ml/public/embeddables/single_metric_viewer/single_metric_viewer_embeddable.tsx
Show resolved
Hide resolved
This has been updated and is ready for a final look/test when you get a chance, cc @walterra, @darnautov |
@elasticmachine merge upstream |
...lugins/ml/public/embeddables/single_metric_viewer/single_metric_viewer_embeddable_factory.ts
Show resolved
Hide resolved
x-pack/plugins/ml/public/ui_actions/open_in_single_metric_viewer_action.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/ml/public/ui_actions/open_in_single_metric_viewer_action.tsx
Show resolved
Hide resolved
x-pack/plugins/ml/public/ui_actions/open_in_single_metric_viewer_action.tsx
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.
Tested latest changes and LGTM
.../application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx
Outdated
Show resolved
Hide resolved
...gins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx
Outdated
Show resolved
Hide resolved
@@ -14,7 +14,7 @@ import type { JobId, CombinedJob } from '../../../common/types/anomaly_detection | |||
*/ | |||
export function getControlsForDetector( | |||
selectedDetectorIndex: number, | |||
selectedEntities: Record<string, any>, | |||
selectedEntities: Record<string, any> | undefined, |
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 don't think any
is correct. If you don't know the incoming type - it should be unknown
and covered with a type guard. Otherwise you should be aware of the expected type.
x-pack/plugins/ml/public/embeddables/single_metric_viewer/single_metric_viewer_embeddable.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/ml/public/embeddables/single_metric_viewer/single_metric_viewer_initializer.tsx
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.
Latest changes LGTM, thanks for improving types!
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: |
… set correctly for 'Open' action (#180086) ## Summary Follow up to #179364 This PR ensures the detector index is set correctly the url in the `Open in single metric viewer` action to link from dashboards to ML > Single metric viewer. ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
Summary
Part of #176651
This PR:
Screen shots
Checklist
Delete any items that are not applicable to this PR.