Rares/fix npe on migration (#2930)

# What this PR does

Fixes the issue described at #2908 

## Which issue(s) this PR fixes

https://github.com/grafana/oncall/issues/2908

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
This commit is contained in:
Rares Mardare 2023-08-31 14:21:05 +03:00 committed by GitHub
parent 8bfe690b23
commit 898523895a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 9 deletions

View file

@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix issue with helm chart when specifying `broker.type=rabbitmq` where Redis environment variables
were not longer being injected @joeyorlando ([#2927](https://github.com/grafana/oncall/pull/2927))
- Fixed NPE when migrating legacy Grafana Alerting integrations
([#2908](https://github.com/grafana/oncall/issues/2908))
## v1.3.29 (2023-08-29)

View file

@ -93,7 +93,7 @@ const IntegrationForm = observer((props: IntegrationFormProps) => {
const extraGFormProps: { customFieldSectionRenderer?: React.FC<CustomFieldSectionRendererProps> } = {};
if (selectedOption && IntegrationHelper.isGrafanaAlerting(selectedOption.value)) {
if (selectedOption && IntegrationHelper.isSpecificIntegration(selectedOption.value, 'grafana_alerting')) {
extraGFormProps.customFieldSectionRenderer = CustomFieldSectionRenderer;
}
@ -205,7 +205,7 @@ const IntegrationForm = observer((props: IntegrationFormProps) => {
return;
}
if (!IntegrationHelper.isGrafanaAlerting(selectedOption.value)) {
if (!IntegrationHelper.isSpecificIntegration(selectedOption.value, 'grafana_alerting')) {
return pushHistory(response.id);
}

View file

@ -14,16 +14,16 @@ import { AppFeature } from 'state/features';
import { MAX_CHARACTERS_COUNT, TEXTAREA_ROWS_COUNT } from './IntegrationCommon.config';
const IntegrationHelper = {
isGrafanaAlerting: (alertReceiveChannel: AlertReceiveChannel | string) => {
isSpecificIntegration: (alertReceiveChannel: AlertReceiveChannel | string, name: string) => {
if (!alertReceiveChannel) {
return false;
}
if (typeof alertReceiveChannel === 'string') {
return alertReceiveChannel === 'grafana_alerting';
return name === alertReceiveChannel;
}
return alertReceiveChannel.integration === 'grafana_alerting';
return name === alertReceiveChannel.integration;
},
getFilteredTemplate: (template: string, isTextArea: boolean): string => {

View file

@ -325,7 +325,7 @@ class Integration extends React.Component<IntegrationProps, IntegrationState> {
}
renderContactPointsWarningMaybe(alertReceiveChannel: AlertReceiveChannel) {
if (IntegrationHelper.isGrafanaAlerting(alertReceiveChannel)) {
if (IntegrationHelper.isSpecificIntegration(alertReceiveChannel, 'grafana_alerting')) {
return (
<div className={cx('u-padding-top-md')}>
<Alert
@ -358,9 +358,12 @@ class Integration extends React.Component<IntegrationProps, IntegrationState> {
const alertReceiveChannel = alertReceiveChannelStore.items[id];
const contactPoints = alertReceiveChannelStore.connectedContactPoints[id];
const isAlerting = IntegrationHelper.isSpecificIntegration(alertReceiveChannel, 'grafana_alerting');
const isLegacyAlerting = IntegrationHelper.isSpecificIntegration(alertReceiveChannel, 'legacy_grafana_alerting');
return [
IntegrationHelper.isGrafanaAlerting(alertReceiveChannel) && {
isHidden: contactPoints === null || contactPoints === undefined,
(isAlerting || isLegacyAlerting) && {
isHidden: isLegacyAlerting || contactPoints === null || contactPoints === undefined,
isCollapsible: false,
customIcon: 'grafana',
canHoverIcon: false,
@ -709,7 +712,7 @@ class Integration extends React.Component<IntegrationProps, IntegrationState> {
async loadExtraData(id: AlertReceiveChannel['id']) {
const { alertReceiveChannelStore } = this.props.store;
if (IntegrationHelper.isGrafanaAlerting(alertReceiveChannelStore.items[id])) {
if (IntegrationHelper.isSpecificIntegration(alertReceiveChannelStore.items[id], 'grafana_alerting')) {
// this will be delayed and not awaitable so that we don't delay the whole page load
return await alertReceiveChannelStore.updateConnectedContactPoints(id);
}