Skip to content

Commit

Permalink
updated field mappings service; abort detector creation when mapping …
Browse files Browse the repository at this point in the history
…fails (#752) (#768)

Signed-off-by: Amardeepsingh Siglani <[email protected]>
(cherry picked from commit 1419650)

Co-authored-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and amsiglan authored Oct 25, 2023
1 parent e74f599 commit 189ab3b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion public/pages/CreateDetector/containers/CreateDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { NotificationsStart } from 'opensearch-dashboards/public';
import { getPlugins } from '../../../utils/helpers';
import { Detector, DetectorCreationStep } from '../../../../types';
import { DataStore } from '../../../store/DataStore';
import { errorNotificationToast } from '../../../utils/helpers';

interface CreateDetectorProps extends RouteComponentProps {
isEdit: boolean;
Expand Down Expand Up @@ -107,7 +108,7 @@ export default class CreateDetector extends Component<CreateDetectorProps, Creat
this.setState({ fieldMappings });
};

onCreateClick = () => {
onCreateClick = async () => {
const { creatingDetector, detector, fieldMappings } = this.state;
if (creatingDetector) {
return;
Expand All @@ -121,6 +122,19 @@ export default class CreateDetector extends Component<CreateDetectorProps, Creat
fieldMappings
);

const fieldMappingRes = await fieldsMappingPromise;

if (!fieldMappingRes.ok) {
errorNotificationToast(
this.props.notifications,
'create',
'detector',
'Invalid field mappings.'
);
this.setState({ creatingDetector: false });
return;
}

const createDetectorPromise = this.props.services.detectorsService.createDetector(detector);

// set detector pending state, this will be used in detector details page
Expand Down
4 changes: 4 additions & 0 deletions public/services/FieldMappingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export default class FieldMappingService {
properties: {},
};
fieldMappings.forEach((mapping) => {
if (mapping.ruleFieldName === mapping.indexFieldName) {
return;
}

alias_mappings.properties[mapping.ruleFieldName] = {
type: 'alias',
path: mapping.indexFieldName,
Expand Down

0 comments on commit 189ab3b

Please sign in to comment.