Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Fix callout when error creating detector (#130)
Browse files Browse the repository at this point in the history
* Fix callout when error creating detector
  • Loading branch information
ohltyler authored May 12, 2020
1 parent 7f60a09 commit e9f63a6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions public/pages/createDetector/containers/CreateDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
searchDetector,
updateDetector,
} from '../../../redux/reducers/ad';
import { BREADCRUMBS } from '../../../utils/constants';
import { BREADCRUMBS, MAX_DETECTORS } from '../../../utils/constants';
import { getErrorMessage, validateName } from '../../../utils/utils';
import { DetectorInfo } from '../components/DetectorInfo';
import { useFetchDetectorInfo } from '../hooks/useFetchDetectorInfo';
Expand Down Expand Up @@ -119,9 +119,17 @@ export function CreateDetector(props: CreateADProps) {
`/detectors/${detectorResp.data.response.id}/configurations/`
);
} catch (err) {
toastNotifications.addDanger(
getErrorMessage(err, 'There was a problem creating detector')
const resp = await dispatch(
searchDetector({ query: { bool: { must_not: { match: { name: "" } } } } })
);
const totalDetectors = resp.data.response.totalDetectors;
if (totalDetectors === MAX_DETECTORS) {
toastNotifications.addDanger('Cannot create detector - limit of ' + MAX_DETECTORS + ' detectors reached')
} else {
toastNotifications.addDanger(
getErrorMessage(err, 'There was a problem creating detector')
);
}
}
};

Expand Down Expand Up @@ -153,7 +161,7 @@ export function CreateDetector(props: CreateADProps) {
},
} = props;
if (isEmpty(detectorName)) {
throw 'Detector name can not be empty';
throw 'Detector name cannot be empty';
} else {
const error = validateName(detectorName);
if (error) {
Expand Down

0 comments on commit e9f63a6

Please sign in to comment.