oncall-engine/grafana-plugin/src/containers/IntegrationLabelsForm/IntegrationLabelsForm.helpers.ts
Dominik Broj 94f5fce070
Further improvements on labels (#3536)
# What this PR does

## Which issue(s) this PR fixes

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-12-11 09:11:27 +00:00

20 lines
938 B
TypeScript

import { AlertReceiveChannel } from 'models/alert_receive_channel/alert_receive_channel.types';
const countNumberOfInheritedAndCustomLabels = (alert_group_labels: AlertReceiveChannel['alert_group_labels']) => {
const inheritedCount = alert_group_labels.inheritable
? Object.keys(alert_group_labels.inheritable).filter((labelKey) => alert_group_labels.inheritable?.[labelKey])
.length
: 0;
const customCount = alert_group_labels.custom?.length || 0;
return inheritedCount + customCount;
};
export const getIsTooManyLabelsWarningVisible = (
alert_group_labels: AlertReceiveChannel['alert_group_labels'],
limit = 15
) => countNumberOfInheritedAndCustomLabels(alert_group_labels) > limit;
export const getIsAddBtnDisabled = ({ custom }: AlertReceiveChannel['alert_group_labels']) => {
const lastItem = custom.at(-1);
return lastItem && (lastItem?.key.id === undefined || lastItem?.value.id === undefined);
};