From e52e46316a101360d96579e8699912750ec6ee8e Mon Sep 17 00:00:00 2001 From: Melissa Date: Mon, 21 Mar 2022 18:03:09 -0600 Subject: [PATCH 1/5] fix model selection for exploration page --- .../components/analytics_selector/analytics_id_selector.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx index f845cff8322dd..e5c517928cc3d 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx @@ -208,7 +208,7 @@ export function AnalyticsIdSelector({ setAnalyticsId, jobsOnly = false }: Props) setSelected({ model_id: isDFA ? undefined : item.model_id, - job_id: isDFA ? item.id : undefined, + job_id: isDFA ? item.id : item.metadata?.analytics_config.id, analysis_type: analysisType, }); }, From 6845b03018628e2904b0d7ed30dbe658cc2f0525 Mon Sep 17 00:00:00 2001 From: Melissa Date: Mon, 21 Mar 2022 18:32:43 -0600 Subject: [PATCH 2/5] add selected analyticsId to url --- .../pages/analytics_exploration/page.tsx | 14 ++++++++++++++ .../data_frame_analytics/pages/job_map/page.tsx | 13 ++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/page.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/page.tsx index cd1c2dda1e27a..23b7f4c4d7438 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/page.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/page.tsx @@ -20,6 +20,7 @@ import { useMlKibana, useMlApiContext } from '../../../contexts/kibana'; import { MlPageHeader } from '../../../components/page_header'; import { AnalyticsIdSelector, AnalyticsSelectorIds } from '../components/analytics_selector'; import { AnalyticsEmptyPrompt } from '../analytics_management/components/empty_prompt'; +import { useUrlState } from '../../../util/url_state'; export const Page: FC<{ jobId: string; @@ -37,6 +38,8 @@ export const Page: FC<{ const jobIdToUse = jobId ?? analyticsId?.job_id; const analysisTypeToUse = analysisType || analyticsId?.analysis_type; + const [ , setGlobalState] = useUrlState('_g'); + const checkJobsExist = async () => { try { const { count } = await getDataFrameAnalytics(undefined, undefined, 0); @@ -51,6 +54,17 @@ export const Page: FC<{ checkJobsExist(); }, []); + useEffect(function updateUrl() { + if (analyticsId !== undefined) { + setGlobalState({ + ml: { + ...(analyticsId.analysis_type ? { analysisType: analyticsId. analysis_type } : {}), + ...(analyticsId.job_id ? { jobId: analyticsId.job_id } : {}), + }, + }); + } + }, [analyticsId?.job_id, analyticsId?.model_id]); + const getEmptyState = () => { if (jobsExist === false) { return ; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/job_map/page.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/job_map/page.tsx index efdd386ca47b3..8d4ab1e9836e1 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/job_map/page.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/job_map/page.tsx @@ -22,7 +22,7 @@ import { AnalyticsIdSelector, AnalyticsSelectorIds } from '../components/analyti import { AnalyticsEmptyPrompt } from '../analytics_management/components/empty_prompt'; export const Page: FC = () => { - const [globalState] = useUrlState('_g'); + const [globalState, setGlobalState] = useUrlState('_g'); const [isLoading, setIsLoading] = useState(false); const [jobsExist, setJobsExist] = useState(true); const { refresh } = useRefreshAnalyticsList({ isLoading: setIsLoading }); @@ -51,6 +51,17 @@ export const Page: FC = () => { checkJobsExist(); }, []); + useEffect(function updateUrl() { + if (analyticsId !== undefined) { + setGlobalState({ + ml: { + ...(analyticsId.job_id && !analyticsId.model_id ? { jobId: analyticsId.job_id } : {}), + ...(analyticsId.model_id ? { modelId: analyticsId.model_id } : {}), + }, + }); + } + }, [analyticsId?.job_id, analyticsId?.model_id]); + const getEmptyState = () => { if (jobsExist === false) { return ; From 6325e2f722b1deb6078022cb47c6f3c9a1440e6e Mon Sep 17 00:00:00 2001 From: Melissa Date: Mon, 21 Mar 2022 22:17:34 -0600 Subject: [PATCH 3/5] linting fix --- .../pages/analytics_exploration/page.tsx | 25 +++++++++++-------- .../pages/job_map/page.tsx | 23 +++++++++-------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/page.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/page.tsx index 23b7f4c4d7438..38cc37aec646c 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/page.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/page.tsx @@ -38,7 +38,7 @@ export const Page: FC<{ const jobIdToUse = jobId ?? analyticsId?.job_id; const analysisTypeToUse = analysisType || analyticsId?.analysis_type; - const [ , setGlobalState] = useUrlState('_g'); + const [, setGlobalState] = useUrlState('_g'); const checkJobsExist = async () => { try { @@ -54,16 +54,19 @@ export const Page: FC<{ checkJobsExist(); }, []); - useEffect(function updateUrl() { - if (analyticsId !== undefined) { - setGlobalState({ - ml: { - ...(analyticsId.analysis_type ? { analysisType: analyticsId. analysis_type } : {}), - ...(analyticsId.job_id ? { jobId: analyticsId.job_id } : {}), - }, - }); - } - }, [analyticsId?.job_id, analyticsId?.model_id]); + useEffect( + function updateUrl() { + if (analyticsId !== undefined) { + setGlobalState({ + ml: { + ...(analyticsId.analysis_type ? { analysisType: analyticsId.analysis_type } : {}), + ...(analyticsId.job_id ? { jobId: analyticsId.job_id } : {}), + }, + }); + } + }, + [analyticsId?.job_id, analyticsId?.model_id] + ); const getEmptyState = () => { if (jobsExist === false) { diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/job_map/page.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/job_map/page.tsx index 8d4ab1e9836e1..4f171d1108ad4 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/job_map/page.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/job_map/page.tsx @@ -51,16 +51,19 @@ export const Page: FC = () => { checkJobsExist(); }, []); - useEffect(function updateUrl() { - if (analyticsId !== undefined) { - setGlobalState({ - ml: { - ...(analyticsId.job_id && !analyticsId.model_id ? { jobId: analyticsId.job_id } : {}), - ...(analyticsId.model_id ? { modelId: analyticsId.model_id } : {}), - }, - }); - } - }, [analyticsId?.job_id, analyticsId?.model_id]); + useEffect( + function updateUrl() { + if (analyticsId !== undefined) { + setGlobalState({ + ml: { + ...(analyticsId.job_id && !analyticsId.model_id ? { jobId: analyticsId.job_id } : {}), + ...(analyticsId.model_id ? { modelId: analyticsId.model_id } : {}), + }, + }); + } + }, + [analyticsId?.job_id, analyticsId?.model_id] + ); const getEmptyState = () => { if (jobsExist === false) { From ba88ada67eaa1b61b0f9658f11394d741098d4c7 Mon Sep 17 00:00:00 2001 From: Melissa Date: Tue, 22 Mar 2022 12:16:32 -0600 Subject: [PATCH 4/5] ensure selected id can be deselected --- .../components/analytics_selector/analytics_id_selector.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx index e5c517928cc3d..0fd73ffa2be3f 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx @@ -190,11 +190,10 @@ export function AnalyticsIdSelector({ setAnalyticsId, jobsOnly = false }: Props) const selectionValue = { selectable: (item: TableItem) => { - const selectedId = selected?.job_id ?? selected?.model_id; const isDFA = isDataFrameAnalyticsConfigs(item); const itemId = isDFA ? item.id : item.model_id; const isBuiltInModel = isDFA ? false : item.tags.includes(BUILT_IN_MODEL_TAG); - return (selected === undefined || selectedId === itemId) && !isBuiltInModel; + return (selected === undefined || selected?.job_id === itemId || selected?.model_id === itemId) && !isBuiltInModel; }, onSelectionChange: (selectedItem: TableItem[]) => { const item = selectedItem[0]; From 1e7056583a4eea15e7cc9715f7023de7f3959d79 Mon Sep 17 00:00:00 2001 From: Melissa Date: Tue, 22 Mar 2022 13:35:12 -0600 Subject: [PATCH 5/5] fix linting error --- .../components/analytics_selector/analytics_id_selector.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx index 0fd73ffa2be3f..568971ba6d7e2 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/components/analytics_selector/analytics_id_selector.tsx @@ -193,7 +193,10 @@ export function AnalyticsIdSelector({ setAnalyticsId, jobsOnly = false }: Props) const isDFA = isDataFrameAnalyticsConfigs(item); const itemId = isDFA ? item.id : item.model_id; const isBuiltInModel = isDFA ? false : item.tags.includes(BUILT_IN_MODEL_TAG); - return (selected === undefined || selected?.job_id === itemId || selected?.model_id === itemId) && !isBuiltInModel; + return ( + (selected === undefined || selected?.job_id === itemId || selected?.model_id === itemId) && + !isBuiltInModel + ); }, onSelectionChange: (selectedItem: TableItem[]) => { const item = selectedItem[0];