Skip to content

Commit

Permalink
changing removed index check
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
  • Loading branch information
amitgalitz committed Aug 30, 2024
1 parent 9c6dfb1 commit 8c4f393
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 7 additions & 5 deletions public/pages/DefineDetector/components/Datasource/DataSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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;
};

Expand Down Expand Up @@ -316,7 +318,7 @@ export function DataSource(props: DataSourceProps) {
INITIAL_MODEL_CONFIGURATION_VALUES
);
}
handleIndexNameChange(options);
handleIndexNameChange(options, field.value);
}}
selectedOptions={field.value}
isClearable={false}
Expand Down
2 changes: 0 additions & 2 deletions server/routes/opensearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 8c4f393

Please sign in to comment.