From 6ff569bd93951b739e9310001d3799911bced063 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Tue, 16 Apr 2024 14:38:24 +0200 Subject: [PATCH] reuse CreateDataViewButton --- .../create_data_view_button.tsx | 6 +- .../source_selection/source_selection.tsx | 7 +- .../new_job/pages/index_or_search/page.tsx | 4 +- .../test_models/models/index_input.tsx | 77 ++++++++++++++----- 4 files changed, 68 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/ml/public/application/components/create_data_view_button/create_data_view_button.tsx b/x-pack/plugins/ml/public/application/components/create_data_view_button/create_data_view_button.tsx index 069b5589eb058..02c56fb4008e5 100644 --- a/x-pack/plugins/ml/public/application/components/create_data_view_button/create_data_view_button.tsx +++ b/x-pack/plugins/ml/public/application/components/create_data_view_button/create_data_view_button.tsx @@ -8,13 +8,14 @@ import { EuiButton } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import React, { useCallback, useEffect, useRef } from 'react'; +import { type DataView } from '@kbn/data-plugin/common'; import { useMlKibana } from '../../contexts/kibana'; export const CreateDataViewButton = ({ onDataViewCreated, allowAdHocDataView = false, }: { - onDataViewCreated: (id: string, type: string, name?: string) => void; + onDataViewCreated: (dataView: DataView) => void; allowAdHocDataView?: boolean; }) => { const { dataViewEditor } = useMlKibana().services; @@ -25,10 +26,9 @@ export const CreateDataViewButton = ({ closeDataViewEditorRef.current = dataViewEditor?.openEditor({ onSave: async (dataView) => { if (dataView.id && onDataViewCreated) { - onDataViewCreated(dataView.id, 'index-pattern', dataView.name); + onDataViewCreated(dataView); } }, - allowAdHocDataView, }); }, [onDataViewCreated, dataViewEditor, allowAdHocDataView]); diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx index 4c1530de60825..4c8bb7c3a6382 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/source_selection/source_selection.tsx @@ -160,7 +160,12 @@ export const SourceSelection: FC = () => { uiSettings, }} > - + { + onSearchSelected(dataView.id!, 'index-pattern', dataView.getIndexPattern()); + }} + allowAdHocDataView={true} + /> diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/index_or_search/page.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/index_or_search/page.tsx index b1ed10c3f121e..972b8dc09e3ef 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/index_or_search/page.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/index_or_search/page.tsx @@ -89,7 +89,9 @@ export const Page: FC = ({ > { + onObjectSelection(dataView.id!, 'index-pattern', dataView.getIndexPattern()); + }} allowAdHocDataView={true} /> {extraButtons ? extraButtons : null} diff --git a/x-pack/plugins/ml/public/application/model_management/test_models/models/index_input.tsx b/x-pack/plugins/ml/public/application/model_management/test_models/models/index_input.tsx index bf1823e2ab3cd..b2dbfc5c4c67a 100644 --- a/x-pack/plugins/ml/public/application/model_management/test_models/models/index_input.tsx +++ b/x-pack/plugins/ml/public/application/model_management/test_models/models/index_input.tsx @@ -6,7 +6,8 @@ */ import type { FC } from 'react'; -import React, { useState, useMemo, useEffect, useCallback } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; +import { FormattedMessage } from '@kbn/i18n-react'; import useObservable from 'react-use/lib/useObservable'; import { firstValueFrom } from 'rxjs'; @@ -15,14 +16,17 @@ import { EuiAccordion, EuiCode, EuiCodeBlock, + EuiFlexGroup, + EuiFlexItem, EuiFormRow, - EuiSpacer, EuiSelect, + EuiSpacer, EuiText, } from '@elastic/eui'; import { isPopulatedObject } from '@kbn/ml-is-populated-object'; import { i18n } from '@kbn/i18n'; +import { CreateDataViewButton } from '../../../components/create_data_view_button'; import { useMlKibana } from '../../../contexts/kibana'; import { RUNNING_STATE } from './inference_base'; import type { InferrerType } from '.'; @@ -45,6 +49,7 @@ export const InferenceInputFormIndexControls: FC = ({ setSelectedDataViewId, selectedField, setSelectedField, + setDataViewListItems, } = data; const runningState = useObservable(inferrer.getRunningState$(), inferrer.getRunningState()); @@ -53,27 +58,56 @@ export const InferenceInputFormIndexControls: FC = ({ return ( <> - - {disableIndexSelection ? ( - - - {dataViewListItems.find((item) => item.value === selectedDataViewId)?.text} - - - ) : ( - { - inferrer.setSelectedDataViewId(e.target.value); - setSelectedDataViewId(e.target.value); - }} - hasNoInitialSelection={true} - disabled={runningState === RUNNING_STATE.RUNNING} + + + + } fullWidth + > + {disableIndexSelection ? ( + + + {dataViewListItems.find((item) => item.value === selectedDataViewId)?.text} + + + ) : ( + { + inferrer.setSelectedDataViewId(e.target.value); + setSelectedDataViewId(e.target.value); + }} + hasNoInitialSelection={true} + disabled={runningState === RUNNING_STATE.RUNNING} + fullWidth + /> + )} + + + + { + setDataViewListItems((prev) => { + return [ + ...prev, + { + text: dataView.getIndexPattern(), + value: dataView.id!, + }, + ]; + }); + }} /> - )} - + + +