[8.x] Revert [ML] AIOps: Use package instead of context for using field stats flyout (#194517) (#195860) (#195930)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Revert [ML] AIOps: Use package instead of context for using field
stats flyout (#194517)
(#195860)](https://github.com/elastic/kibana/pull/195860)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Walter
Rafelsberger","email":"walter.rafelsberger@elastic.co"},"sourceCommit":{"committedDate":"2024-10-11T14:15:53Z","message":"Revert
[ML] AIOps: Use package instead of context for using field stats flyout
(#194517) (#195860)\n\n## Summary\r\n\r\nThis reverts #194517 ([ML]
AIOps: Use package instead of context for\r\nusing field stats flyout)
committed in\r\neebfba4f9bfe2592ce92d35aed9cf3c0c8540130.\r\n\r\nThe PR
refactored how `FieldStatsFlyout` is passed in as a dependency
to\r\nchange point detection. Unfortunately the refactor caused the
dropdown\r\nto select the split field to break when used in the flyout
for the\r\noptions of the change point detection embeddable.\r\n\r\nThis
revert is done to restore the original behavior. In a follow up
I\r\nwill revisit the refactor to work properly.\r\n\r\n###
Checklist\r\n\r\n- [x] This was checked for breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)","sha":"37a420b950aa7ced58360283ec4a4e63d5d410f8","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug",":ml","release_note:skip","v9.0.0","Feature:ML/AIOps","v8.16.0","backport:version"],"title":"Revert
[ML] AIOps: Use package instead of context for using field stats flyout
(#194517)","number":195860,"url":"https://github.com/elastic/kibana/pull/195860","mergeCommit":{"message":"Revert
[ML] AIOps: Use package instead of context for using field stats flyout
(#194517) (#195860)\n\n## Summary\r\n\r\nThis reverts #194517 ([ML]
AIOps: Use package instead of context for\r\nusing field stats flyout)
committed in\r\neebfba4f9bfe2592ce92d35aed9cf3c0c8540130.\r\n\r\nThe PR
refactored how `FieldStatsFlyout` is passed in as a dependency
to\r\nchange point detection. Unfortunately the refactor caused the
dropdown\r\nto select the split field to break when used in the flyout
for the\r\noptions of the change point detection embeddable.\r\n\r\nThis
revert is done to restore the original behavior. In a follow up
I\r\nwill revisit the refactor to work properly.\r\n\r\n###
Checklist\r\n\r\n- [x] This was checked for breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)","sha":"37a420b950aa7ced58360283ec4a4e63d5d410f8"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195860","number":195860,"mergeCommit":{"message":"Revert
[ML] AIOps: Use package instead of context for using field stats flyout
(#194517) (#195860)\n\n## Summary\r\n\r\nThis reverts #194517 ([ML]
AIOps: Use package instead of context for\r\nusing field stats flyout)
committed in\r\neebfba4f9bfe2592ce92d35aed9cf3c0c8540130.\r\n\r\nThe PR
refactored how `FieldStatsFlyout` is passed in as a dependency
to\r\nchange point detection. Unfortunately the refactor caused the
dropdown\r\nto select the split field to break when used in the flyout
for the\r\noptions of the change point detection embeddable.\r\n\r\nThis
revert is done to restore the original behavior. In a follow up
I\r\nwill revisit the refactor to work properly.\r\n\r\n###
Checklist\r\n\r\n- [x] This was checked for breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)","sha":"37a420b950aa7ced58360283ec4a4e63d5d410f8"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Walter Rafelsberger <walter.rafelsberger@elastic.co>
This commit is contained in:
Kibana Machine 2024-10-12 03:06:33 +11:00 committed by GitHub
parent 2fe8ae92d5
commit 206041f16d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 36 additions and 8 deletions

View file

@ -37,7 +37,6 @@ import {
CHANGE_POINT_DETECTION_VIEW_TYPE,
EMBEDDABLE_CHANGE_POINT_CHART_TYPE,
} from '@kbn/aiops-change-point-detection/constants';
import { FieldStatsFlyoutProvider } from '@kbn/ml-field-stats-flyout';
import type { ChangePointEmbeddableRuntimeState } from '../../embeddables/change_point_chart/types';
import { MaxSeriesControl } from './max_series_control';
import { useCasesModal } from '../../hooks/use_cases_modal';
@ -639,7 +638,7 @@ export const FieldsControls: FC<PropsWithChildren<FieldsControlsProps>> = ({
}) => {
const { splitFieldsOptions, combinedQuery } = useChangePointDetectionContext();
const { dataView } = useDataSource();
const { data, uiSettings, fieldFormats, charts } = useAiopsAppContext();
const { data, uiSettings, fieldFormats, charts, fieldStats } = useAiopsAppContext();
const timefilter = useTimefilter();
// required in order to trigger state updates
useTimeRangeUpdates();
@ -655,6 +654,8 @@ export const FieldsControls: FC<PropsWithChildren<FieldsControlsProps>> = ({
};
}, [uiSettings, data, fieldFormats, charts]);
const FieldStatsFlyoutProvider = fieldStats!.FieldStatsFlyoutProvider;
const onChangeFn = useCallback(
(field: keyof FieldConfig, value: string) => {
const result = { ...fieldConfig, [field]: value };

View file

@ -8,8 +8,8 @@
import React, { type FC, useCallback, useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiComboBox, type EuiComboBoxOptionOption, EuiFormRow } from '@elastic/eui';
import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout';
import { useChangePointDetectionControlsContext } from './change_point_detection_context';
import { useAiopsAppContext } from '../../hooks/use_aiops_app_context';
interface MetricFieldSelectorProps {
value: string;
@ -19,9 +19,10 @@ interface MetricFieldSelectorProps {
export const MetricFieldSelector: FC<MetricFieldSelectorProps> = React.memo(
({ value, onChange, inline = true }) => {
const { fieldStats } = useAiopsAppContext();
const { metricFieldOptions } = useChangePointDetectionControlsContext();
const { renderOption, closeFlyout } = useFieldStatsTrigger();
const { renderOption, closeFlyout } = fieldStats?.useFieldStatsTrigger() ?? {};
const options = useMemo<Array<EuiComboBoxOptionOption<string>>>(() => {
return metricFieldOptions.map((v) => {

View file

@ -9,7 +9,7 @@ import type { FC } from 'react';
import React, { useMemo, useCallback } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiComboBox, type EuiComboBoxOptionOption, EuiFormRow } from '@elastic/eui';
import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout';
import { useAiopsAppContext } from '../../hooks/use_aiops_app_context';
import { useChangePointDetectionControlsContext } from './change_point_detection_context';
interface SplitFieldSelectorProps {
@ -20,7 +20,8 @@ interface SplitFieldSelectorProps {
export const SplitFieldSelector: FC<SplitFieldSelectorProps> = React.memo(
({ value, onChange, inline = true }) => {
const { renderOption, closeFlyout } = useFieldStatsTrigger();
const { fieldStats } = useAiopsAppContext();
const { renderOption, closeFlyout } = fieldStats?.useFieldStatsTrigger() ?? {};
const { splitFieldsOptions } = useChangePointDetectionControlsContext();

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { createContext, useContext } from 'react';
import { createContext, type FC, type PropsWithChildren, useContext } from 'react';
import type { ObservabilityAIAssistantPublicStart } from '@kbn/observability-ai-assistant-plugin/public';
import type { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
@ -24,6 +24,13 @@ import type {
ThemeServiceStart,
} from '@kbn/core/public';
import type { LensPublicStart } from '@kbn/lens-plugin/public';
import { type EuiComboBoxProps } from '@elastic/eui/src/components/combo_box/combo_box';
import { type DataView } from '@kbn/data-views-plugin/common';
import type {
FieldStatsProps,
FieldStatsServices,
} from '@kbn/unified-field-list/src/components/field_stats';
import type { TimeRange as TimeRangeMs } from '@kbn/ml-date-picker';
import type { EmbeddableStart } from '@kbn/embeddable-plugin/public';
import type { CasesPublicStart } from '@kbn/cases-plugin/public';
import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
@ -104,6 +111,23 @@ export interface AiopsAppContextValue {
* Internationalisation service
*/
i18n: CoreStart['i18n'];
/**
* Deps for unified fields stats.
*/
fieldStats?: {
useFieldStatsTrigger: () => {
renderOption: EuiComboBoxProps<string>['renderOption'];
closeFlyout: () => void;
};
FieldStatsFlyoutProvider: FC<
PropsWithChildren<{
dataView: DataView;
fieldStatsServices: FieldStatsServices;
timeRangeMs?: TimeRangeMs;
dslQuery?: FieldStatsProps['dslQuery'];
}>
>;
};
embeddable?: EmbeddableStart;
cases?: CasesPublicStart;
isServerless?: boolean;

View file

@ -79,7 +79,6 @@
"@kbn/observability-ai-assistant-plugin",
"@kbn/ui-theme",
"@kbn/apm-utils",
"@kbn/ml-field-stats-flyout",
],
"exclude": [
"target/**/*",

View file

@ -14,6 +14,7 @@ import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { ChangePointDetection } from '@kbn/aiops-plugin/public';
import { AIOPS_EMBEDDABLE_ORIGIN } from '@kbn/aiops-common/constants';
import { useFieldStatsTrigger, FieldStatsFlyoutProvider } from '@kbn/ml-field-stats-flyout';
import { useDataSource } from '../contexts/ml/data_source_context';
import { useMlKibana } from '../contexts/kibana';
@ -72,6 +73,7 @@ export const ChangePointDetectionPage: FC = () => {
'unifiedSearch',
'usageCollection',
]),
fieldStats: { useFieldStatsTrigger, FieldStatsFlyoutProvider },
}}
/>
) : null}