diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 0c1dd964a4e..ef1c282b2cb 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -1604,11 +1604,6 @@ "count": 1 } }, - "public/app/features/alerting/unified/components/contact-points/utils.ts": { - "no-restricted-syntax": { - "count": 1 - } - }, "public/app/features/alerting/unified/components/create-folder/CreateNewFolder.tsx": { "no-restricted-syntax": { "count": 1 diff --git a/packages/grafana-alerting/src/index.ts b/packages/grafana-alerting/src/index.ts index e7e8f4b22d2..e87de3f4e8e 100644 --- a/packages/grafana-alerting/src/index.ts +++ b/packages/grafana-alerting/src/index.ts @@ -11,8 +11,32 @@ export { AlertLabels } from './grafana/rules/components/labels/AlertLabels'; export { AlertLabel } from './grafana/rules/components/labels/AlertLabel'; // keep label utils internal to the app for now +/** + * Notification policies and label matching + */ +export { + useMatchInstancesToRouteTrees, + matchInstancesToRouteTrees, + type RouteMatch, + type InstanceMatchResult, +} from './grafana/notificationPolicies/hooks/useMatchPolicies'; + +export { + type TreeMatch, + type RouteMatchResult, + matchInstancesToRoute, + findMatchingRoutes, + getInheritedProperties, + computeInheritedTree, +} from './grafana/notificationPolicies/utils'; + +export { USER_DEFINED_TREE_NAME } from './grafana/notificationPolicies/consts'; +export * from './grafana/notificationPolicies/types'; + +/** + * Labels and matchers + */ +export { type LabelMatcher, type Label } from './grafana/matchers/types'; + // Utilities export { base64UrlEncode } from './grafana/api/util'; - -// This is a dummy export so typescript doesn't error importing an "empty module" -export const index = {}; diff --git a/packages/grafana-alerting/src/unstable.ts b/packages/grafana-alerting/src/unstable.ts index 1aa47bae5d5..e033b55437c 100644 --- a/packages/grafana-alerting/src/unstable.ts +++ b/packages/grafana-alerting/src/unstable.ts @@ -8,24 +8,6 @@ export { useListContactPoints } from './grafana/contactPoints/hooks/v0alpha1/use export { ContactPointSelector } from './grafana/contactPoints/components/ContactPointSelector/ContactPointSelector'; export { getContactPointDescription } from './grafana/contactPoints/utils'; -// Notification Policies -export { - useMatchInstancesToRouteTrees, - matchInstancesToRouteTrees, - type RouteMatch, - type InstanceMatchResult, -} from './grafana/notificationPolicies/hooks/useMatchPolicies'; -export { - type TreeMatch, - type RouteMatchResult, - matchInstancesToRoute, - findMatchingRoutes, - getInheritedProperties, - computeInheritedTree, -} from './grafana/notificationPolicies/utils'; -export { USER_DEFINED_TREE_NAME } from './grafana/notificationPolicies/consts'; -export * from './grafana/notificationPolicies/types'; - // Rules export { StateText } from './grafana/rules/components/state/StateText'; export { StateIcon } from './grafana/rules/components/state/StateIcon'; diff --git a/public/app/features/alerting/unified/components/contact-points/utils.ts b/public/app/features/alerting/unified/components/contact-points/utils.ts index 7c75e015412..d2cc43901c1 100644 --- a/public/app/features/alerting/unified/components/contact-points/utils.ts +++ b/public/app/features/alerting/unified/components/contact-points/utils.ts @@ -1,7 +1,7 @@ import { difference, groupBy, take, trim, upperFirst } from 'lodash'; import { ReactNode } from 'react'; -import { computeInheritedTree } from '@grafana/alerting/unstable'; +import { computeInheritedTree } from '@grafana/alerting'; import { t } from '@grafana/i18n'; import { NotifierDTO, NotifierStatus, ReceiversStateDTO } from 'app/features/alerting/unified/types/alerting'; import { canAdminEntity, shouldUseK8sApi } from 'app/features/alerting/unified/utils/k8s/utils'; @@ -23,6 +23,7 @@ import { ReceiverPluginMetadata, getOnCallMetadata } from '../receivers/grafanaA import { RECEIVER_META_KEY, RECEIVER_PLUGIN_META_KEY, RECEIVER_STATUS_KEY } from './constants'; const AUTOGENERATED_RECEIVER_POLICY_MATCHER_KEY = '__grafana_receiver__'; +const collator = new Intl.Collator(); // TODO we should really add some type information to these receiver settings... export function getReceiverDescription(receiver: ReceiverConfigWithMetadata): ReactNode | undefined { @@ -168,7 +169,7 @@ export function enhanceContactPointsWithMetadata({ }; }); - return enhanced.sort((a, b) => a.name.localeCompare(b.name)); + return enhanced.sort((a, b) => collator.compare(a.name, b.name)); } function getContactPointIdentifier(contactPoint: Receiver): string { diff --git a/public/app/features/alerting/unified/components/notification-policies/NotificationPoliciesList.tsx b/public/app/features/alerting/unified/components/notification-policies/NotificationPoliciesList.tsx index 72dace0fc9d..448c409b673 100644 --- a/public/app/features/alerting/unified/components/notification-policies/NotificationPoliciesList.tsx +++ b/public/app/features/alerting/unified/components/notification-policies/NotificationPoliciesList.tsx @@ -2,7 +2,7 @@ import { defaults } from 'lodash'; import { useEffect, useMemo, useState } from 'react'; import { useAsyncFn } from 'react-use'; -import { computeInheritedTree } from '@grafana/alerting/unstable'; +import { computeInheritedTree } from '@grafana/alerting'; import { Trans, t } from '@grafana/i18n'; import { Alert, Button, Stack } from '@grafana/ui'; import { useAppNotification } from 'app/core/copy/appNotification'; diff --git a/public/app/features/alerting/unified/components/notification-policies/Policy.tsx b/public/app/features/alerting/unified/components/notification-policies/Policy.tsx index abd12efd135..3f80f6cd902 100644 --- a/public/app/features/alerting/unified/components/notification-policies/Policy.tsx +++ b/public/app/features/alerting/unified/components/notification-policies/Policy.tsx @@ -5,8 +5,7 @@ import * as React from 'react'; import { FC, Fragment, ReactNode, useState } from 'react'; import { useToggle } from 'react-use'; -import { InheritableProperties } from '@grafana/alerting/internal'; -import { AlertLabel, getInheritedProperties } from '@grafana/alerting/unstable'; +import { AlertLabel, getInheritedProperties } from '@grafana/alerting'; import { GrafanaTheme2 } from '@grafana/data'; import { Trans, t } from '@grafana/i18n'; import { @@ -55,6 +54,8 @@ import { TimingOptions } from './timingOptions'; const POLICIES_PER_PAGE = 20; +type InheritableProperties = ReturnType; + interface PolicyComponentProps { receivers?: Receiver[]; contactPointsState?: ReceiversState; diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/JourneyPolicyCard.test.tsx b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/JourneyPolicyCard.test.tsx index ab8bd49ede0..17a3faa4097 100644 --- a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/JourneyPolicyCard.test.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/JourneyPolicyCard.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from '@testing-library/react'; -import { LabelMatcher, RouteWithID } from '@grafana/alerting/unstable'; +import { LabelMatcher, RouteWithID } from '@grafana/alerting'; import { JourneyPolicyCard } from './JourneyPolicyCard'; diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/JourneyPolicyCard.tsx b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/JourneyPolicyCard.tsx index bab2fb31e8e..addf315a88d 100644 --- a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/JourneyPolicyCard.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/JourneyPolicyCard.tsx @@ -1,6 +1,6 @@ import { css } from '@emotion/css'; -import { RouteWithID } from '@grafana/alerting/unstable'; +import { RouteWithID } from '@grafana/alerting'; import { GrafanaTheme2 } from '@grafana/data'; import { Trans } from '@grafana/i18n'; import { Icon, Stack, Text, Tooltip, useStyles2 } from '@grafana/ui'; diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPolicyDrawer.tsx b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPolicyDrawer.tsx index e43bb432b82..48154eb455b 100644 --- a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPolicyDrawer.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPolicyDrawer.tsx @@ -1,6 +1,6 @@ import { Fragment, useState } from 'react'; -import { AlertLabel, RouteMatchResult, RouteWithID } from '@grafana/alerting/unstable'; +import { AlertLabel, RouteMatchResult, RouteWithID } from '@grafana/alerting'; import { Trans } from '@grafana/i18n'; import { Button, Drawer, Text, TextLink } from '@grafana/ui'; diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationRoute.tsx b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationRoute.tsx index 67bdce2d4d2..2896f9c2823 100644 --- a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationRoute.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationRoute.tsx @@ -1,6 +1,6 @@ import { css } from '@emotion/css'; -import { AlertLabels, RouteMatchResult, RouteWithID } from '@grafana/alerting/unstable'; +import { AlertLabels, RouteMatchResult, RouteWithID } from '@grafana/alerting'; import { GrafanaTheme2 } from '@grafana/data'; import { Trans } from '@grafana/i18n'; import { Text, useStyles2 } from '@grafana/ui'; diff --git a/public/app/features/alerting/unified/routeGroupsMatcher.ts b/public/app/features/alerting/unified/routeGroupsMatcher.ts index 1a75c5be57c..5a89fb6623e 100644 --- a/public/app/features/alerting/unified/routeGroupsMatcher.ts +++ b/public/app/features/alerting/unified/routeGroupsMatcher.ts @@ -1,4 +1,4 @@ -import { InstanceMatchResult, matchInstancesToRoute } from '@grafana/alerting/unstable'; +import { InstanceMatchResult, matchInstancesToRoute } from '@grafana/alerting'; import { AlertmanagerGroup, RouteWithID } from '../../../plugins/datasource/alertmanager/types'; import { Labels } from '../../../types/unified-alerting-dto'; diff --git a/public/app/features/alerting/unified/utils/notification-policies.ts b/public/app/features/alerting/unified/utils/notification-policies.ts index 28f5dc8d9c0..89d212266ca 100644 --- a/public/app/features/alerting/unified/utils/notification-policies.ts +++ b/public/app/features/alerting/unified/utils/notification-policies.ts @@ -1,4 +1,4 @@ -import { findMatchingRoutes } from '@grafana/alerting/unstable'; +import { findMatchingRoutes } from '@grafana/alerting'; import { AlertmanagerGroup, Route, RouteWithID } from 'app/plugins/datasource/alertmanager/types'; import { normalizeMatchers, unquoteWithUnescape } from './matchers'; diff --git a/public/app/features/alerting/unified/utils/routeAdapter.test.ts b/public/app/features/alerting/unified/utils/routeAdapter.test.ts index 7f0239ca621..d501aef2ee0 100644 --- a/public/app/features/alerting/unified/utils/routeAdapter.test.ts +++ b/public/app/features/alerting/unified/utils/routeAdapter.test.ts @@ -1,7 +1,7 @@ import { Factory } from 'fishery'; +import { RouteWithID as AlertingRouteWithID } from '@grafana/alerting'; import { RouteFactory } from '@grafana/alerting/testing'; -import { RouteWithID as AlertingRouteWithID } from '@grafana/alerting/unstable'; import { MatcherOperator, ObjectMatcher, Route, RouteWithID } from 'app/plugins/datasource/alertmanager/types'; import { routeAdapter } from './routeAdapter'; diff --git a/public/app/features/alerting/unified/utils/routeAdapter.ts b/public/app/features/alerting/unified/utils/routeAdapter.ts index e08c2fb7486..c5dda65a3fa 100644 --- a/public/app/features/alerting/unified/utils/routeAdapter.ts +++ b/public/app/features/alerting/unified/utils/routeAdapter.ts @@ -1,8 +1,5 @@ -import { - Route as AlertingRoute, - RouteWithID as AlertingRouteWithID, - type LabelMatcher, -} from '@grafana/alerting/unstable'; +import { Route as AlertingRoute, RouteWithID as AlertingRouteWithID } from '@grafana/alerting'; +import { type LabelMatcher } from '@grafana/alerting/unstable'; import { MatcherOperator, type ObjectMatcher,