Fix bug where new alert causes type error

pull/10616/head
Iris Scholten 2018-05-15 16:37:03 -07:00
parent 3e4a94c87f
commit f7754fc5dd
1 changed files with 17 additions and 9 deletions

View File

@ -117,9 +117,9 @@ class RuleHandlers extends PureComponent<Props, State> {
? 'rule-section--row rule-section--row-first rule-section--border-bottom'
: 'rule-section--row rule-section--row-first rule-section--row-last'
const selectedHandlerWithText: HandlerWithText = this.mapWithNicknames([
selectedHandler,
])[0]
const selectedHandlerWithText: HandlerWithText = this.addNicknameText(
selectedHandler
)
return (
<div className="rule-section">
@ -261,7 +261,7 @@ class RuleHandlers extends PureComponent<Props, State> {
}
private getNickname = (handler: Handler): string => {
const configType: AlertTypes = handler.type
const configType: AlertTypes = _.get(handler, 'type')
if (configType === 'slack') {
const workspace: string = _.get<Handler, string>(handler, 'workspace')
@ -275,14 +275,22 @@ class RuleHandlers extends PureComponent<Props, State> {
return undefined
}
private mapWithNicknames = (handlers: Handler[]): HandlerWithText[] => {
return _.map(handlers, h => {
const nickname: string = this.getNickname(h)
private addNicknameText = (handler: Handler): HandlerWithText => {
if (handler) {
const nickname: string = this.getNickname(handler)
if (nickname) {
return {...h, text: `${h.type} (${nickname})`}
return {...handler, text: `${handler.type} (${nickname})`}
}
return {...h, text: h.type}
return {...handler, text: handler.type}
}
return null
}
private mapWithNicknames = (handlers: Handler[]): HandlerWithText[] => {
return _.map(handlers, h => {
return this.addNicknameText(h)
})
}
}