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) (#819)

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
(cherry picked from commit 1419650)

Co-authored-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
opensearch-trigger-bot[bot] and amsiglan committed Dec 6, 2023
1 parent 56e9a25 commit 8c0e1af
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 @@ -32,6 +32,7 @@ import { NotificationsStart } from 'opensearch-dashboards/public';
import { getPlugins } from '../../../utils/helpers';
import { Detector } from '../../../../types';
import { DataStore } from '../../../store/DataStore';
import { errorNotificationToast } from '../../../utils/helpers';

interface CreateDetectorProps extends RouteComponentProps {
isEdit: boolean;
Expand Down Expand Up @@ -109,7 +110,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 @@ -123,6 +124,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 8c0e1af

Please sign in to comment.