From 5eb3f3a3cb20b3584de0950c39e303c6b5b0214a Mon Sep 17 00:00:00 2001 From: Tom Ratcliffe Date: Thu, 27 Feb 2025 12:59:27 +0000 Subject: [PATCH] Chore: Fix some import issues in alerting code (#100962) --- .betterer.results | 31 ++----------------- .../alerting/unified/Templates.test.tsx | 4 ++- .../AlertInstanceExtensionPoint.tsx | 4 +-- .../AlertInstanceExtensionPointMenu.tsx | 2 -- .../components/receivers/TemplateEditor.tsx | 5 ++- .../form/fields/TemplateSelector.test.tsx | 6 ++-- .../QueryAndExpressionsStep.tsx | 2 +- .../unified/components/rules/ActionButton.tsx | 3 +- .../unified/components/rules/ActionIcon.tsx | 9 ++++-- .../rule-list/components/RuleListIcon.tsx | 5 +-- .../alerting/unified/state/actions.ts | 3 +- 11 files changed, 26 insertions(+), 48 deletions(-) delete mode 100644 public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPointMenu.tsx diff --git a/.betterer.results b/.betterer.results index 552f1bfd1a5..5e04d7cf375 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1494,9 +1494,6 @@ exports[`better eslint`] = { [0, 0, 0, "No untranslated strings. Wrap text with ", "2"], [0, 0, 0, "No untranslated strings. Wrap text with ", "3"] ], - "public/app/features/alerting/unified/Templates.test.tsx:5381": [ - [0, 0, 0, "\'@grafana/ui/src/components/Monaco/types\' import is restricted from being used by a pattern. Import from the public export instead.", "0"] - ], "public/app/features/alerting/unified/components/AlertLabel.tsx:5381": [ [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"] ], @@ -1731,9 +1728,6 @@ exports[`better eslint`] = { "public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPoint.tsx:5381": [ [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"] ], - "public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPointMenu.tsx:5381": [ - [0, 0, 0, "Do not re-export imported variable (\`app/features/explore/extensions/ToolbarExtensionPointMenu\`)", "0"] - ], "public/app/features/alerting/unified/components/mute-timings/MuteTimingActionsButtons.tsx:5381": [ [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"], [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "1"] @@ -1904,9 +1898,6 @@ exports[`better eslint`] = { [0, 0, 0, "No untranslated strings. Wrap text with ", "11"], [0, 0, 0, "No untranslated strings. Wrap text with ", "12"] ], - "public/app/features/alerting/unified/components/receivers/TemplateEditor.tsx:5381": [ - [0, 0, 0, "\'@grafana/ui/src/components/Monaco/types\' import is restricted from being used by a pattern. Import from the public export instead.", "0"] - ], "public/app/features/alerting/unified/components/receivers/TemplateForm.tsx:5381": [ [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"], [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "1"], @@ -2025,9 +2016,6 @@ exports[`better eslint`] = { [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"], [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "1"] ], - "public/app/features/alerting/unified/components/receivers/form/fields/TemplateSelector.test.tsx:5381": [ - [0, 0, 0, "\'@grafana/ui/src/components/Monaco/types\' import is restricted from being used by a pattern. Import from the public export instead.", "0"] - ], "public/app/features/alerting/unified/components/receivers/form/fields/TemplateSelector.tsx:5381": [ [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"], [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "1"], @@ -2301,14 +2289,13 @@ exports[`better eslint`] = { [0, 0, 0, "No untranslated strings. Wrap text with ", "8"] ], "public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx:5381": [ - [0, 0, 0, "\'@grafana/ui/src/components/Text/Text\' import is restricted from being used by a pattern. Import from the public export instead.", "0"], + [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"], [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "1"], - [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "2"], + [0, 0, 0, "No untranslated strings. Wrap text with ", "2"], [0, 0, 0, "No untranslated strings. Wrap text with ", "3"], [0, 0, 0, "No untranslated strings. Wrap text with ", "4"], [0, 0, 0, "No untranslated strings. Wrap text with ", "5"], - [0, 0, 0, "No untranslated strings. Wrap text with ", "6"], - [0, 0, 0, "No untranslated strings. Wrap text with ", "7"] + [0, 0, 0, "No untranslated strings. Wrap text with ", "6"] ], "public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/SimpleCondition.tsx:5381": [ [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"] @@ -2374,12 +2361,6 @@ exports[`better eslint`] = { "public/app/features/alerting/unified/components/rule-viewer/tabs/Routing.tsx:5381": [ [0, 0, 0, "No untranslated strings. Wrap text with ", "0"] ], - "public/app/features/alerting/unified/components/rules/ActionButton.tsx:5381": [ - [0, 0, 0, "\'@grafana/ui/src/components/Button\' import is restricted from being used by a pattern. Import from the public export instead.", "0"] - ], - "public/app/features/alerting/unified/components/rules/ActionIcon.tsx:5381": [ - [0, 0, 0, "\'@grafana/ui/src/components/Tooltip\' import is restricted from being used by a pattern. Import from the public export instead.", "0"] - ], "public/app/features/alerting/unified/components/rules/AlertInstanceDetails.tsx:5381": [ [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"] ], @@ -2817,15 +2798,9 @@ exports[`better eslint`] = { "public/app/features/alerting/unified/rule-list/components/RuleGroup.tsx:5381": [ [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"] ], - "public/app/features/alerting/unified/rule-list/components/RuleListIcon.tsx:5381": [ - [0, 0, 0, "\'@grafana/ui/src/components/Text/Text\' import is restricted from being used by a pattern. Import from the public export instead.", "0"] - ], "public/app/features/alerting/unified/state/AlertingQueryRunner.test.ts:5381": [ [0, 0, 0, "\'@grafana/runtime/src/utils/DataSourceWithBackend\' import is restricted from being used by a pattern. Import from the public export instead.", "0"] ], - "public/app/features/alerting/unified/state/actions.ts:5381": [ - [0, 0, 0, "\'@grafana/runtime/src/utils/logging\' import is restricted from being used by a pattern. Import from the public export instead.", "0"] - ], "public/app/features/alerting/unified/types/receiver-form.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] diff --git a/public/app/features/alerting/unified/Templates.test.tsx b/public/app/features/alerting/unified/Templates.test.tsx index 0e524270497..ac2ede75e76 100644 --- a/public/app/features/alerting/unified/Templates.test.tsx +++ b/public/app/features/alerting/unified/Templates.test.tsx @@ -5,7 +5,7 @@ import { Props } from 'react-virtualized-auto-sizer'; import { render, screen, waitFor, within } from 'test/test-utils'; import { byLabelText, byRole } from 'testing-library-selector'; -import { CodeEditorProps } from '@grafana/ui/src/components/Monaco/types'; +import { CodeEditor } from '@grafana/ui'; import { AppNotificationList } from 'app/core/components/AppNotifications/AppNotificationList'; import { setupMswServer } from 'app/features/alerting/unified/mockApi'; import { testWithFeatureToggles } from 'app/features/alerting/unified/test/test-utils'; @@ -14,6 +14,8 @@ import { AccessControlAction } from 'app/types'; import Templates from './Templates'; import { grantUserPermissions } from './mocks'; +type CodeEditorProps = React.ComponentProps; + jest.mock('app/core/components/AppChrome/AppChromeUpdate', () => ({ AppChromeUpdate: ({ actions }: { actions: React.ReactNode }) =>
{actions}
, })); diff --git a/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPoint.tsx b/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPoint.tsx index 5f64ef13e70..78e5eda0c3f 100644 --- a/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPoint.tsx +++ b/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPoint.tsx @@ -4,10 +4,10 @@ import { PluginExtensionLink, PluginExtensionPoints } from '@grafana/data'; import { usePluginLinks } from '@grafana/runtime'; import { Dropdown, IconButton } from '@grafana/ui'; import { ConfirmNavigationModal } from 'app/features/explore/extensions/ConfirmNavigationModal'; +// We might want to customise this in future but right now the toolbar menu from the Explore view is fine. +import { ToolbarExtensionPointMenu as AlertExtensionPointMenu } from 'app/features/explore/extensions/ToolbarExtensionPointMenu'; import { Alert, CombinedRule } from 'app/types/unified-alerting'; -import { AlertExtensionPointMenu } from './AlertInstanceExtensionPointMenu'; - interface AlertInstanceExtensionPointProps { rule?: CombinedRule; instance: Alert; diff --git a/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPointMenu.tsx b/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPointMenu.tsx deleted file mode 100644 index e9f270d7129..00000000000 --- a/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPointMenu.tsx +++ /dev/null @@ -1,2 +0,0 @@ -// We might want to customise this in future but right now the toolbar menu from the Explore view is fine. -export { ToolbarExtensionPointMenu as AlertExtensionPointMenu } from 'app/features/explore/extensions/ToolbarExtensionPointMenu'; diff --git a/public/app/features/alerting/unified/components/receivers/TemplateEditor.tsx b/public/app/features/alerting/unified/components/receivers/TemplateEditor.tsx index 6b10eae73ad..b2d003ea865 100644 --- a/public/app/features/alerting/unified/components/receivers/TemplateEditor.tsx +++ b/public/app/features/alerting/unified/components/receivers/TemplateEditor.tsx @@ -4,16 +4,15 @@ * It includes auto-complete for template data and syntax highlighting */ import { IDisposable, editor } from 'monaco-editor'; -import { useEffect, useRef } from 'react'; +import { ComponentProps, useEffect, useRef } from 'react'; import { CodeEditor } from '@grafana/ui'; -import { CodeEditorProps } from '@grafana/ui/src/components/Monaco/types'; import { registerGoTemplateAutocomplete } from './editor/autocomplete'; import goTemplateLanguageDefinition, { GO_TEMPLATE_LANGUAGE_ID } from './editor/definition'; import { registerLanguage } from './editor/register'; -type TemplateEditorProps = Omit & { +type TemplateEditorProps = Omit, 'language' | 'theme'> & { autoHeight?: boolean; }; diff --git a/public/app/features/alerting/unified/components/receivers/form/fields/TemplateSelector.test.tsx b/public/app/features/alerting/unified/components/receivers/form/fields/TemplateSelector.test.tsx index 7912649ae80..42ac031d381 100644 --- a/public/app/features/alerting/unified/components/receivers/form/fields/TemplateSelector.test.tsx +++ b/public/app/features/alerting/unified/components/receivers/form/fields/TemplateSelector.test.tsx @@ -1,7 +1,7 @@ -import { ReactNode } from 'react'; +import { ComponentProps, ReactNode } from 'react'; import { render, screen, userEvent } from 'test/test-utils'; -import { CodeEditorProps } from '@grafana/ui/src/components/Monaco/types'; +import { CodeEditor } from '@grafana/ui'; import { setupMswServer } from 'app/features/alerting/unified/mockApi'; import { grantUserPermissions } from 'app/features/alerting/unified/mocks'; import { getAlertmanagerConfig } from 'app/features/alerting/unified/mocks/server/entities/alertmanagers'; @@ -15,6 +15,8 @@ import { AccessControlAction, NotificationChannelOption } from 'app/types'; import { TemplatesPicker, getTemplateOptions } from './TemplateSelector'; import { parseTemplates } from './utils'; +type CodeEditorProps = ComponentProps; + const alertmanagerConfigMock = getAlertmanagerConfig(GRAFANA_RULES_SOURCE_NAME); jest.mock('@grafana/ui', () => ({ diff --git a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx index 2ecd8131b3b..20d3359a03e 100644 --- a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx @@ -17,10 +17,10 @@ import { Menu, MenuItem, Stack, + Text, Tooltip, useStyles2, } from '@grafana/ui'; -import { Text } from '@grafana/ui/src/components/Text/Text'; import { Trans, t } from 'app/core/internationalization'; import { isExpressionQuery } from 'app/features/expressions/guards'; import { ExpressionDatasourceUID, ExpressionQueryType, expressionTypes } from 'app/features/expressions/types'; diff --git a/public/app/features/alerting/unified/components/rules/ActionButton.tsx b/public/app/features/alerting/unified/components/rules/ActionButton.tsx index 2613be36cb1..8ccf3338f00 100644 --- a/public/app/features/alerting/unified/components/rules/ActionButton.tsx +++ b/public/app/features/alerting/unified/components/rules/ActionButton.tsx @@ -1,8 +1,7 @@ import { css, cx } from '@emotion/css'; import { GrafanaTheme2 } from '@grafana/data'; -import { useStyles2 } from '@grafana/ui'; -import { Button, ButtonProps } from '@grafana/ui/src/components/Button'; +import { Button, ButtonProps, useStyles2 } from '@grafana/ui'; type Props = Omit; diff --git a/public/app/features/alerting/unified/components/rules/ActionIcon.tsx b/public/app/features/alerting/unified/components/rules/ActionIcon.tsx index 8d198286ad8..5a3dbcc9870 100644 --- a/public/app/features/alerting/unified/components/rules/ActionIcon.tsx +++ b/public/app/features/alerting/unified/components/rules/ActionIcon.tsx @@ -1,11 +1,14 @@ +import { ComponentProps } from 'react'; + import { Button, IconName, LinkButton, Tooltip } from '@grafana/ui'; -import { PopoverContent, TooltipPlacement } from '@grafana/ui/src/components/Tooltip'; + +type TooltipProps = ComponentProps; interface Props { - tooltip: PopoverContent; + tooltip: TooltipProps['content']; icon: IconName; className?: string; - tooltipPlacement?: TooltipPlacement; + tooltipPlacement?: TooltipProps['placement']; to?: string; target?: string; onClick?: () => void; diff --git a/public/app/features/alerting/unified/rule-list/components/RuleListIcon.tsx b/public/app/features/alerting/unified/rule-list/components/RuleListIcon.tsx index cb543108054..29b714770d8 100644 --- a/public/app/features/alerting/unified/rule-list/components/RuleListIcon.tsx +++ b/public/app/features/alerting/unified/rule-list/components/RuleListIcon.tsx @@ -1,13 +1,14 @@ -import { memo } from 'react'; +import { ComponentProps, memo } from 'react'; import type { RequireAtLeastOne } from 'type-fest'; import { Icon, type IconName, Text, Tooltip } from '@grafana/ui'; -import type { TextProps } from '@grafana/ui/src/components/Text/Text'; import type { RuleHealth } from 'app/types/unified-alerting'; import { PromAlertingRuleState } from 'app/types/unified-alerting-dto'; import { isErrorHealth } from '../../components/rule-viewer/RuleViewer'; +type TextProps = ComponentProps; + interface RuleListIconProps { recording?: boolean; state?: PromAlertingRuleState; diff --git a/public/app/features/alerting/unified/state/actions.ts b/public/app/features/alerting/unified/state/actions.ts index 5b03e36fe6b..f45b7ff1dde 100644 --- a/public/app/features/alerting/unified/state/actions.ts +++ b/public/app/features/alerting/unified/state/actions.ts @@ -1,8 +1,7 @@ import { createAsyncThunk } from '@reduxjs/toolkit'; import { isEmpty } from 'lodash'; -import { locationService } from '@grafana/runtime'; -import { logMeasurement } from '@grafana/runtime/src/utils/logging'; +import { locationService, logMeasurement } from '@grafana/runtime'; import { AlertManagerCortexConfig, AlertmanagerGroup,