Skip to content

Commit

Permalink
Wait for field mapping creation to succeed before detector creation A…
Browse files Browse the repository at this point in the history
…PI call (#317) (#327)

* create detector if mapping creation succeeds

Signed-off-by: Amardeepsingh Siglani <[email protected]>

* updated creation api call sequence

Signed-off-by: Amardeepsingh Siglani <[email protected]>

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

Co-authored-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and amsiglan authored Jan 10, 2023
1 parent c93fd8e commit 4c5f5dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions public/pages/CreateDetector/containers/CreateDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,28 @@ export default class CreateDetector extends Component<CreateDetectorProps, Creat
errorNotificationToast(
this.props.notifications,
'create',
'field mappings',
createMappingsRes.error
);
}

const createDetectorRes = await this.props.services.detectorsService.createDetector(detector);
if (createDetectorRes.ok) {
successNotificationToast(
this.props.notifications,
'created',
`detector, "${detector.name}"`
'detector',
'Double check the field mappings and try again.'
);
this.props.history.push(`${ROUTES.DETECTOR_DETAILS}/${createDetectorRes.response._id}`);
} else {
errorNotificationToast(
this.props.notifications,
'create',
'detector',
createDetectorRes.error
const createDetectorRes = await this.props.services.detectorsService.createDetector(
detector
);
if (createDetectorRes.ok) {
successNotificationToast(
this.props.notifications,
'created',
`detector, "${detector.name}"`
);
this.props.history.push(`${ROUTES.DETECTOR_DETAILS}/${createDetectorRes.response._id}`);
} else {
errorNotificationToast(
this.props.notifications,
'create',
'detector',
createDetectorRes.error
);
}
}
} catch (error: any) {
errorNotificationToast(this.props.notifications, 'create', 'detector', error);
Expand Down
2 changes: 1 addition & 1 deletion public/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const NAME_REGEX = new RegExp(/^[a-zA-Z0-9 _-]{5,50}$/);

// This regex pattern support MIN to MAX character limit, capital and lowercase letters,
// numbers 0-9, hyphens, spaces, and underscores.
export const AUTHOR_REGEX = new RegExp(/^[a-zA-Z0-9 _,-]{5,50}$/);
export const AUTHOR_REGEX = new RegExp(/^[a-zA-Z0-9 _,-.]{5,50}$/);

/**
* Validates a string against NAME_REGEX.
Expand Down

0 comments on commit 4c5f5dc

Please sign in to comment.