Skip to content

Commit

Permalink
Rares/fix npe on migration (#2930)
Browse files Browse the repository at this point in the history
# What this PR does

Fixes the issue described at #2908 

## Which issue(s) this PR fixes

#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)
  • Loading branch information
teodosii authored Aug 31, 2023
1 parent 8bfe690 commit 8985238
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions grafana-plugin/src/pages/integration/Integration.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
11 changes: 7 additions & 4 deletions grafana-plugin/src/pages/integration/Integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 8985238

Please sign in to comment.