From 994775a66f6bb042de23e44fec193a93777f70d1 Mon Sep 17 00:00:00 2001 From: Amit Galitzky Date: Fri, 30 Aug 2024 16:04:12 -0700 Subject: [PATCH] changing removed index check Signed-off-by: Amit Galitzky --- .../components/Datasource/DataSource.tsx | 12 +++++++----- server/routes/opensearch.ts | 2 -- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/public/pages/DefineDetector/components/Datasource/DataSource.tsx b/public/pages/DefineDetector/components/Datasource/DataSource.tsx index 2ea601e9..ed294f0f 100644 --- a/public/pages/DefineDetector/components/Datasource/DataSource.tsx +++ b/public/pages/DefineDetector/components/Datasource/DataSource.tsx @@ -175,7 +175,7 @@ export function DataSource(props: DataSourceProps) { } }, 300); - const handleIndexNameChange = (selectedOptions: any) => { + const handleIndexNameChange = (selectedOptions: any, oldOptions: { label: string }[] = props.formikProps.values.index) => { const indexNames = selectedOptions; setIndexNames(indexNames); if (indexNames.length > 0) { @@ -184,7 +184,7 @@ export function DataSource(props: DataSourceProps) { ); dispatch(getMappings(indices, dataSourceId)); } - if (isSelectedOptionIndexRemoved()) { + if (isSelectedOptionIndexRemoved(selectedOptions, oldOptions)) { if (props.setNewIndexSelected) { props.setNewIndexSelected(true); } @@ -199,10 +199,12 @@ export function DataSource(props: DataSourceProps) { newSelectedOptions: { label: string }[] = indexNames, oldSelectedOptions: { label: string }[] = props.formikProps.values.index ) => { + if (_.isEmpty(oldSelectedOptions) && _.isEmpty(newSelectedOptions)) { + return false; + } const newSelectedOptionsSet = new Set(newSelectedOptions); const indexRemoved: boolean = - !(newSelectedOptions && oldSelectedOptions) || - oldSelectedOptions.some((value) => !newSelectedOptionsSet.has(value)); + oldSelectedOptions.some((value) => !newSelectedOptionsSet.has(value)); return indexRemoved; }; @@ -316,7 +318,7 @@ export function DataSource(props: DataSourceProps) { INITIAL_MODEL_CONFIGURATION_VALUES ); } - handleIndexNameChange(options); + handleIndexNameChange(options, field.value); }} selectedOptions={field.value} isClearable={false} diff --git a/server/routes/opensearch.ts b/server/routes/opensearch.ts index 6ee5fc02..65f1e3a7 100644 --- a/server/routes/opensearch.ts +++ b/server/routes/opensearch.ts @@ -427,10 +427,8 @@ export default class OpenSearchService { path: remoteIndices.toString() + '/_field_caps?fields=*&include_unmapped', }); - console.log("fieldCapsResponse: " + JSON.stringify(fieldCapsResponse)) remoteMappings = convertFieldCapsToMappingStructure(fieldCapsResponse); } - console.log("remoteMappings: " + JSON.stringify(remoteMappings)) Object.assign(mappings, remoteMappings); return opensearchDashboardsResponse.ok({