From 8c702d4a6b664073f6be01985bd8424acae63abc Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Fri, 13 Sep 2024 09:23:18 +0200 Subject: [PATCH] Plugin extensions: Make sure core features use new hooks (#92723) * use new extensions APIs across grafana core * setup setPluginLinksHook * fix tests * fix mock * fix more broken tests * use plugin components hook * remove unused func * fix tests * remove unused import --- .../components/AppChrome/AppChrome.test.tsx | 2 +- .../unified/PanelAlertTabContent.test.tsx | 6 ++-- .../alerting/unified/RuleList.test.tsx | 10 +++---- .../AlertInstanceExtensionPoint.tsx | 8 +++--- .../rule-viewer/RuleViewer.test.tsx | 6 ++-- .../rules/Filter/RulesFilter.v1.tsx | 4 +-- .../rules/RuleActionsButtons.test.tsx | 6 ++-- .../components/rules/RuleDetails.test.tsx | 10 +++---- .../RuleDetailsMatchingInstances.test.tsx | 10 +++---- .../rules/RuleListGroupView.test.tsx | 6 ++-- .../rules/RuleListStateView.test.tsx | 6 ++-- .../components/rules/RulesTable.test.tsx | 6 ++-- .../unified/home/PluginIntegrations.tsx | 10 +++---- .../plugins/useAlertingHomePageExtensions.ts | 4 +-- .../plugins/useRulePluginLinkExtensions.ts | 6 ++-- .../alerting/unified/testSetup/plugins.ts | 6 +++- .../actions/useExtensionActions.ts | 18 ++++++------ .../PanelDataAlertingTab.test.tsx | 6 ++-- .../containers/DashboardPage.test.tsx | 2 +- .../PanelHeader/PanelHeaderMenuProvider.tsx | 8 +++--- .../dashboard/utils/getPanelMenu.test.ts | 12 ++++---- public/app/features/explore/Explore.test.tsx | 10 +++---- .../extensions/ToolbarExtensionPoint.test.tsx | 28 +++++++++---------- .../extensions/ToolbarExtensionPoint.tsx | 8 +++--- .../features/explore/spec/helper/setup.tsx | 4 +-- .../scopes/tests/dashboardReload.test.ts | 2 +- .../scopes/tests/dashboardsApi.test.ts | 2 +- .../scopes/tests/dashboardsList.test.ts | 2 +- .../features/scopes/tests/featureFlag.test.ts | 2 +- .../features/scopes/tests/selector.test.ts | 2 +- public/app/features/scopes/tests/tree.test.ts | 2 +- .../features/scopes/tests/viewMode.test.ts | 2 +- .../panel/alertlist/UnifiedalertList.test.tsx | 10 +++---- 33 files changed, 115 insertions(+), 111 deletions(-) diff --git a/public/app/core/components/AppChrome/AppChrome.test.tsx b/public/app/core/components/AppChrome/AppChrome.test.tsx index 8bff93683c6..bb21306e316 100644 --- a/public/app/core/components/AppChrome/AppChrome.test.tsx +++ b/public/app/core/components/AppChrome/AppChrome.test.tsx @@ -16,7 +16,7 @@ import { AppChrome } from './AppChrome'; jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), - usePluginLinkExtensions: jest.fn().mockReturnValue({ extensions: [] }), + usePluginLinks: jest.fn().mockReturnValue({ links: [] }), })); const searchData: DataFrame = { diff --git a/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx b/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx index 339c30c2ecf..0e3b84c1c79 100644 --- a/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx +++ b/public/app/features/alerting/unified/PanelAlertTabContent.test.tsx @@ -3,7 +3,7 @@ import { byTestId, byText } from 'testing-library-selector'; import { DataSourceApi } from '@grafana/data'; import { PromOptions, PrometheusDatasource } from '@grafana/prometheus'; -import { setDataSourceSrv, setPluginExtensionsHook } from '@grafana/runtime'; +import { setDataSourceSrv, setPluginLinksHook } from '@grafana/runtime'; import * as ruleActionButtons from 'app/features/alerting/unified/components/rules/RuleActionsButtons'; import { DashboardModel, PanelModel } from 'app/features/dashboard/state'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; @@ -191,8 +191,8 @@ describe('PanelAlertTabContent', () => { AccessControlAction.AlertingRuleExternalWrite, ]); - setPluginExtensionsHook(() => ({ - extensions: [], + setPluginLinksHook(() => ({ + links: [], isLoading: false, })); diff --git a/public/app/features/alerting/unified/RuleList.test.tsx b/public/app/features/alerting/unified/RuleList.test.tsx index f57adfc8c30..32879cf4425 100644 --- a/public/app/features/alerting/unified/RuleList.test.tsx +++ b/public/app/features/alerting/unified/RuleList.test.tsx @@ -13,7 +13,7 @@ import { locationService, setAppEvents, setDataSourceSrv, - usePluginLinkExtensions, + usePluginLinks, } from '@grafana/runtime'; import appEvents from 'app/core/app_events'; import * as ruleActionButtons from 'app/features/alerting/unified/components/rules/RuleActionsButtons'; @@ -52,7 +52,7 @@ import { DataSourceType, GRAFANA_RULES_SOURCE_NAME } from './utils/datasource'; jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), getPluginLinkExtensions: jest.fn(), - usePluginLinkExtensions: jest.fn(), + usePluginLinks: jest.fn(), useReturnToPrevious: jest.fn(), })); jest.mock('./api/buildInfo'); @@ -72,7 +72,7 @@ setupPluginsExtensionsHook(); const mocks = { getAllDataSourcesMock: jest.mocked(config.getAllDataSources), getPluginLinkExtensionsMock: jest.mocked(getPluginLinkExtensions), - usePluginLinkExtensionsMock: jest.mocked(usePluginLinkExtensions), + usePluginLinksMock: jest.mocked(usePluginLinks), rulesInSameGroupHaveInvalidForMock: jest.mocked(actions.rulesInSameGroupHaveInvalidFor), api: { @@ -168,8 +168,8 @@ describe('RuleList', () => { AccessControlAction.AlertingRuleExternalWrite, ]); mocks.rulesInSameGroupHaveInvalidForMock.mockReturnValue([]); - mocks.usePluginLinkExtensionsMock.mockReturnValue({ - extensions: [ + mocks.usePluginLinksMock.mockReturnValue({ + links: [ { pluginId: 'grafana-ml-app', id: '1', diff --git a/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPoint.tsx b/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPoint.tsx index ffb42258520..5f64ef13e70 100644 --- a/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPoint.tsx +++ b/public/app/features/alerting/unified/components/extensions/AlertInstanceExtensionPoint.tsx @@ -1,7 +1,7 @@ import { ReactElement, useMemo, useState } from 'react'; import { PluginExtensionLink, PluginExtensionPoints } from '@grafana/data'; -import { usePluginLinkExtensions } from '@grafana/runtime'; +import { usePluginLinks } from '@grafana/runtime'; import { Dropdown, IconButton } from '@grafana/ui'; import { ConfirmNavigationModal } from 'app/features/explore/extensions/ConfirmNavigationModal'; import { Alert, CombinedRule } from 'app/types/unified-alerting'; @@ -21,13 +21,13 @@ export const AlertInstanceExtensionPoint = ({ }: AlertInstanceExtensionPointProps): ReactElement | null => { const [selectedExtension, setSelectedExtension] = useState(); const context = useMemo(() => ({ instance, rule }), [instance, rule]); - const { extensions } = usePluginLinkExtensions({ context, extensionPointId, limitPerPlugin: 3 }); + const { links } = usePluginLinks({ context, extensionPointId, limitPerPlugin: 3 }); - if (extensions.length === 0) { + if (links.length === 0) { return null; } - const menu = ; + const menu = ; return ( <> diff --git a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.test.tsx b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.test.tsx index 992eba0a1a2..dd7fb820990 100644 --- a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.test.tsx +++ b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.test.tsx @@ -2,7 +2,7 @@ import { within } from '@testing-library/react'; import { render, waitFor, screen, userEvent } from 'test/test-utils'; import { byText, byRole } from 'testing-library-selector'; -import { setPluginExtensionsHook } from '@grafana/runtime'; +import { setPluginLinksHook } from '@grafana/runtime'; import { setupMswServer } from 'app/features/alerting/unified/mockApi'; import { setFolderAccessControl } from 'app/features/alerting/unified/mocks/server/configure'; import { AlertManagerDataSourceJsonData } from 'app/plugins/datasource/alertmanager/types'; @@ -66,8 +66,8 @@ const ELEMENTS = { setupMswServer(); setupDataSources(mockDataSource({ type: DataSourceType.Prometheus, name: 'mimir-1' })); -setPluginExtensionsHook(() => ({ - extensions: [ +setPluginLinksHook(() => ({ + links: [ mockPluginLinkExtension({ pluginId: 'grafana-slo-app', title: 'SLO dashboard', path: '/a/grafana-slo-app' }), mockPluginLinkExtension({ pluginId: 'grafana-asserts-app', diff --git a/public/app/features/alerting/unified/components/rules/Filter/RulesFilter.v1.tsx b/public/app/features/alerting/unified/components/rules/Filter/RulesFilter.v1.tsx index b7907e7409e..cc5284231dc 100644 --- a/public/app/features/alerting/unified/components/rules/Filter/RulesFilter.v1.tsx +++ b/public/app/features/alerting/unified/components/rules/Filter/RulesFilter.v1.tsx @@ -404,8 +404,8 @@ const helpStyles = (theme: GrafanaTheme2) => ({ }); function usePluginsFilterStatus() { - const { extensions } = useAlertingHomePageExtensions(); - return { pluginsFilterEnabled: extensions.length > 0 }; + const { components } = useAlertingHomePageExtensions(); + return { pluginsFilterEnabled: components.length > 0 }; } export default RulesFilter; diff --git a/public/app/features/alerting/unified/components/rules/RuleActionsButtons.test.tsx b/public/app/features/alerting/unified/components/rules/RuleActionsButtons.test.tsx index 8c992e53a4c..4418745fbd7 100644 --- a/public/app/features/alerting/unified/components/rules/RuleActionsButtons.test.tsx +++ b/public/app/features/alerting/unified/components/rules/RuleActionsButtons.test.tsx @@ -2,7 +2,7 @@ import { produce } from 'immer'; import { render, screen, userEvent } from 'test/test-utils'; import { byLabelText, byRole } from 'testing-library-selector'; -import { config, setPluginExtensionsHook } from '@grafana/runtime'; +import { config, setPluginLinksHook } from '@grafana/runtime'; import { contextSrv } from 'app/core/services/context_srv'; import { RuleActionsButtons } from 'app/features/alerting/unified/components/rules/RuleActionsButtons'; import { setupMswServer } from 'app/features/alerting/unified/mockApi'; @@ -53,8 +53,8 @@ const getMenuContents = async () => { return [...allMenuItems, ...allLinkItems]; }; -setPluginExtensionsHook(() => ({ - extensions: [], +setPluginLinksHook(() => ({ + links: [], isLoading: false, })); diff --git a/public/app/features/alerting/unified/components/rules/RuleDetails.test.tsx b/public/app/features/alerting/unified/components/rules/RuleDetails.test.tsx index 5816c0bcf47..6d55821a49f 100644 --- a/public/app/features/alerting/unified/components/rules/RuleDetails.test.tsx +++ b/public/app/features/alerting/unified/components/rules/RuleDetails.test.tsx @@ -2,7 +2,7 @@ import { render } from 'test/test-utils'; import { byRole } from 'testing-library-selector'; import { PluginExtensionTypes } from '@grafana/data'; -import { usePluginLinkExtensions } from '@grafana/runtime'; +import { usePluginLinks } from '@grafana/runtime'; import { setupMswServer } from 'app/features/alerting/unified/mockApi'; import { useIsRuleEditable } from '../../hooks/useIsRuleEditable'; @@ -12,14 +12,14 @@ import { RuleDetails } from './RuleDetails'; jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), - usePluginLinkExtensions: jest.fn(), + usePluginLinks: jest.fn(), useReturnToPrevious: jest.fn(), })); jest.mock('../../hooks/useIsRuleEditable'); const mocks = { - usePluginLinkExtensionsMock: jest.mocked(usePluginLinkExtensions), + usePluginLinksMock: jest.mocked(usePluginLinks), useIsRuleEditable: jest.mocked(useIsRuleEditable), }; @@ -37,8 +37,8 @@ beforeAll(() => { }); beforeEach(() => { - mocks.usePluginLinkExtensionsMock.mockReturnValue({ - extensions: [ + mocks.usePluginLinksMock.mockReturnValue({ + links: [ { pluginId: 'grafana-ml-app', id: '1', diff --git a/public/app/features/alerting/unified/components/rules/RuleDetailsMatchingInstances.test.tsx b/public/app/features/alerting/unified/components/rules/RuleDetailsMatchingInstances.test.tsx index 6406d0badd2..3445374554a 100644 --- a/public/app/features/alerting/unified/components/rules/RuleDetailsMatchingInstances.test.tsx +++ b/public/app/features/alerting/unified/components/rules/RuleDetailsMatchingInstances.test.tsx @@ -4,7 +4,7 @@ import { times } from 'lodash'; import { byLabelText, byRole, byTestId } from 'testing-library-selector'; import { PluginExtensionTypes } from '@grafana/data'; -import { usePluginLinkExtensions } from '@grafana/runtime'; +import { usePluginLinks } from '@grafana/runtime'; import { CombinedRuleNamespace } from '../../../../../types/unified-alerting'; import { GrafanaAlertState, PromAlertingRuleState } from '../../../../../types/unified-alerting-dto'; @@ -16,11 +16,11 @@ import { RuleDetailsMatchingInstances } from './RuleDetailsMatchingInstances'; jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), getPluginLinkExtensions: jest.fn(), - usePluginLinkExtensions: jest.fn(), + usePluginLinks: jest.fn(), })); const mocks = { - usePluginLinkExtensionsMock: jest.mocked(usePluginLinkExtensions), + usePluginLinksMock: jest.mocked(usePluginLinks), }; const ui = { @@ -43,8 +43,8 @@ const ui = { describe('RuleDetailsMatchingInstances', () => { beforeEach(() => { - mocks.usePluginLinkExtensionsMock.mockReturnValue({ - extensions: [ + mocks.usePluginLinksMock.mockReturnValue({ + links: [ { pluginId: 'grafana-ml-app', id: '1', diff --git a/public/app/features/alerting/unified/components/rules/RuleListGroupView.test.tsx b/public/app/features/alerting/unified/components/rules/RuleListGroupView.test.tsx index caec9525c26..d049b2a0ac2 100644 --- a/public/app/features/alerting/unified/components/rules/RuleListGroupView.test.tsx +++ b/public/app/features/alerting/unified/components/rules/RuleListGroupView.test.tsx @@ -2,7 +2,7 @@ import { waitFor } from '@testing-library/react'; import { render } from 'test/test-utils'; import { byRole } from 'testing-library-selector'; -import { setPluginExtensionsHook } from '@grafana/runtime'; +import { setPluginLinksHook } from '@grafana/runtime'; import { contextSrv } from 'app/core/services/context_srv'; import { AccessControlAction } from 'app/types'; import { CombinedRuleNamespace } from 'app/types/unified-alerting'; @@ -20,8 +20,8 @@ const ui = { cloudRulesHeading: byRole('heading', { name: 'Data source-managed' }), }; -setPluginExtensionsHook(() => ({ - extensions: [], +setPluginLinksHook(() => ({ + links: [], isLoading: false, })); diff --git a/public/app/features/alerting/unified/components/rules/RuleListStateView.test.tsx b/public/app/features/alerting/unified/components/rules/RuleListStateView.test.tsx index 6aa79128c34..b14286d76a2 100644 --- a/public/app/features/alerting/unified/components/rules/RuleListStateView.test.tsx +++ b/public/app/features/alerting/unified/components/rules/RuleListStateView.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from 'test/test-utils'; -import { setPluginExtensionsHook } from '@grafana/runtime'; +import { setPluginLinksHook } from '@grafana/runtime'; import { RuleListStateView } from 'app/features/alerting/unified/components/rules/RuleListStateView'; import { mockCombinedRule, @@ -10,8 +10,8 @@ import { } from 'app/features/alerting/unified/mocks'; import { PromAlertingRuleState } from 'app/types/unified-alerting-dto'; -setPluginExtensionsHook(() => ({ - extensions: [], +setPluginLinksHook(() => ({ + links: [], isLoading: false, })); diff --git a/public/app/features/alerting/unified/components/rules/RulesTable.test.tsx b/public/app/features/alerting/unified/components/rules/RulesTable.test.tsx index 7c60e174b49..c36e6b1978c 100644 --- a/public/app/features/alerting/unified/components/rules/RulesTable.test.tsx +++ b/public/app/features/alerting/unified/components/rules/RulesTable.test.tsx @@ -1,7 +1,7 @@ import { render, userEvent, screen } from 'test/test-utils'; import { byRole } from 'testing-library-selector'; -import { setPluginExtensionsHook } from '@grafana/runtime'; +import { setPluginLinksHook } from '@grafana/runtime'; import { setupMswServer } from 'app/features/alerting/unified/mockApi'; import { AlertRuleAction, useAlertRuleAbility } from '../../hooks/useAbilities'; @@ -15,8 +15,8 @@ const mocks = { useAlertRuleAbility: jest.mocked(useAlertRuleAbility), }; -setPluginExtensionsHook(() => ({ - extensions: [], +setPluginLinksHook(() => ({ + links: [], isLoading: false, })); diff --git a/public/app/features/alerting/unified/home/PluginIntegrations.tsx b/public/app/features/alerting/unified/home/PluginIntegrations.tsx index ced46dc7e28..bb0e0cbda24 100644 --- a/public/app/features/alerting/unified/home/PluginIntegrations.tsx +++ b/public/app/features/alerting/unified/home/PluginIntegrations.tsx @@ -9,9 +9,9 @@ import { useAlertingHomePageExtensions } from '../plugins/useAlertingHomePageExt export function PluginIntegrations() { const styles = useStyles2(getStyles); - const { extensions } = useAlertingHomePageExtensions(); + const { components } = useAlertingHomePageExtensions(); - if (extensions.length === 0) { + if (components.length === 0) { return null; } @@ -21,9 +21,9 @@ export function PluginIntegrations() { Speed up your alerts creation now by using one of our tailored apps - {extensions.map((extension) => ( -
- + {components.map((Component, i) => ( +
+
))} diff --git a/public/app/features/alerting/unified/plugins/useAlertingHomePageExtensions.ts b/public/app/features/alerting/unified/plugins/useAlertingHomePageExtensions.ts index 5afd7cef697..f25dd4ae68a 100644 --- a/public/app/features/alerting/unified/plugins/useAlertingHomePageExtensions.ts +++ b/public/app/features/alerting/unified/plugins/useAlertingHomePageExtensions.ts @@ -1,8 +1,8 @@ import { PluginExtensionPoints } from '@grafana/data'; -import { usePluginComponentExtensions } from '@grafana/runtime'; +import { usePluginComponents } from '@grafana/runtime'; export function useAlertingHomePageExtensions() { - return usePluginComponentExtensions({ + return usePluginComponents({ extensionPointId: PluginExtensionPoints.AlertingHomePage, limitPerPlugin: 1, }); diff --git a/public/app/features/alerting/unified/plugins/useRulePluginLinkExtensions.ts b/public/app/features/alerting/unified/plugins/useRulePluginLinkExtensions.ts index 237dbbe8154..874bba6f8be 100644 --- a/public/app/features/alerting/unified/plugins/useRulePluginLinkExtensions.ts +++ b/public/app/features/alerting/unified/plugins/useRulePluginLinkExtensions.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react'; import { PluginExtensionPoints } from '@grafana/data'; -import { usePluginLinkExtensions } from '@grafana/runtime'; +import { usePluginLinks } from '@grafana/runtime'; import { CombinedRule } from 'app/types/unified-alerting'; import { PromRuleType } from 'app/types/unified-alerting-dto'; @@ -23,7 +23,7 @@ export interface RecordingRuleExtensionContext extends BaseRuleExtensionContext export function useRulePluginLinkExtension(rule: CombinedRule) { const ruleExtensionPoint = useRuleExtensionPoint(rule); - const { extensions } = usePluginLinkExtensions(ruleExtensionPoint); + const { links } = usePluginLinks(ruleExtensionPoint); const ruleOrigin = getRulePluginOrigin(rule); const ruleType = rule.promRule?.type; @@ -33,7 +33,7 @@ export function useRulePluginLinkExtension(rule: CombinedRule) { const { pluginId } = ruleOrigin; - return extensions.filter((extension) => extension.pluginId === pluginId); + return links.filter((link) => link.pluginId === pluginId); } export interface PluginRuleExtensionParam { diff --git a/public/app/features/alerting/unified/testSetup/plugins.ts b/public/app/features/alerting/unified/testSetup/plugins.ts index c786c087fae..93d92565750 100644 --- a/public/app/features/alerting/unified/testSetup/plugins.ts +++ b/public/app/features/alerting/unified/testSetup/plugins.ts @@ -1,5 +1,5 @@ import { PluginMeta, PluginType } from '@grafana/data'; -import { setPluginExtensionsHook } from '@grafana/runtime'; +import { setPluginComponentsHook, setPluginExtensionsHook } from '@grafana/runtime'; import { SupportedPlugin } from 'app/features/alerting/unified/types/pluginBridges'; import { mockPluginLinkExtension } from '../mocks'; @@ -15,6 +15,10 @@ export function setupPluginsExtensionsHook() { ), isLoading: false, })); + setPluginComponentsHook(() => ({ + components: [], + isLoading: false, + })); } export const plugins: PluginMeta[] = [ diff --git a/public/app/features/commandPalette/actions/useExtensionActions.ts b/public/app/features/commandPalette/actions/useExtensionActions.ts index 3861b685793..14b0c19b8cf 100644 --- a/public/app/features/commandPalette/actions/useExtensionActions.ts +++ b/public/app/features/commandPalette/actions/useExtensionActions.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react'; import { PluginExtensionCommandPaletteContext, PluginExtensionPoints } from '@grafana/data'; -import { usePluginLinkExtensions } from '@grafana/runtime'; +import { usePluginLinks } from '@grafana/runtime'; import { CommandPaletteAction } from '../types'; import { EXTENSIONS_PRIORITY } from '../values'; @@ -10,20 +10,20 @@ import { EXTENSIONS_PRIORITY } from '../values'; const context: PluginExtensionCommandPaletteContext = {}; export default function useExtensionActions(): CommandPaletteAction[] { - const { extensions } = usePluginLinkExtensions({ + const { links } = usePluginLinks({ extensionPointId: PluginExtensionPoints.CommandPalette, context, limitPerPlugin: 3, }); return useMemo(() => { - return extensions.map((extension) => ({ - section: extension.category ?? 'Extensions', + return links.map((link) => ({ + section: link.category ?? 'Extensions', priority: EXTENSIONS_PRIORITY, - id: extension.id, - name: extension.title, - target: extension.path, - perform: () => extension.onClick && extension.onClick(), + id: link.id, + name: link.title, + target: link.path, + perform: () => link.onClick && link.onClick(), })); - }, [extensions]); + }, [links]); } diff --git a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataAlertingTab.test.tsx b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataAlertingTab.test.tsx index bfc51341d6c..c315a73bcc9 100644 --- a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataAlertingTab.test.tsx +++ b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataAlertingTab.test.tsx @@ -5,7 +5,7 @@ import { byTestId } from 'testing-library-selector'; import { DataSourceApi } from '@grafana/data'; import { PromOptions, PrometheusDatasource } from '@grafana/prometheus'; -import { locationService, setDataSourceSrv, setPluginExtensionsHook } from '@grafana/runtime'; +import { locationService, setDataSourceSrv, setPluginLinksHook } from '@grafana/runtime'; import { backendSrv } from 'app/core/services/backend_srv'; import * as ruler from 'app/features/alerting/unified/api/ruler'; import * as ruleActionButtons from 'app/features/alerting/unified/components/rules/RuleActionsButtons'; @@ -50,8 +50,8 @@ jest.spyOn(ruleActionButtons, 'matchesWidth').mockReturnValue(false); jest.spyOn(ruler, 'rulerUrlBuilder'); jest.spyOn(alertingAbilities, 'useAlertRuleAbility'); -setPluginExtensionsHook(() => ({ - extensions: [], +setPluginLinksHook(() => ({ + links: [], isLoading: false, })); diff --git a/public/app/features/dashboard/containers/DashboardPage.test.tsx b/public/app/features/dashboard/containers/DashboardPage.test.tsx index 7a1f01125f0..f5557c434fa 100644 --- a/public/app/features/dashboard/containers/DashboardPage.test.tsx +++ b/public/app/features/dashboard/containers/DashboardPage.test.tsx @@ -63,7 +63,7 @@ jest.mock('app/core/core', () => ({ jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), getPluginLinkExtensions: jest.fn().mockReturnValue({ extensions: [] }), - usePluginLinkExtensions: jest.fn().mockReturnValue({ extensions: [] }), + usePluginLinks: jest.fn().mockReturnValue({ links: [] }), })); function getTestDashboard(overrides?: Partial, metaOverrides?: Partial): DashboardModel { diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuProvider.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuProvider.tsx index a3bcda64ee4..1ff72d01a27 100644 --- a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuProvider.tsx +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuProvider.tsx @@ -7,7 +7,7 @@ import { PluginExtensionPoints, getTimeZone, } from '@grafana/data'; -import { usePluginLinkExtensions } from '@grafana/runtime'; +import { usePluginLinks } from '@grafana/runtime'; import { getPanelStateForModel } from 'app/features/panel/state/selectors'; import { useSelector } from 'app/types'; @@ -29,15 +29,15 @@ export function PanelHeaderMenuProvider({ panel, dashboard, loadingState, childr const [items, setItems] = useState([]); const angularComponent = useSelector((state) => getPanelStateForModel(state, panel)?.angularComponent); const context = useMemo(() => createExtensionContext(panel, dashboard), [panel, dashboard]); - const { extensions } = usePluginLinkExtensions({ + const { links } = usePluginLinks({ extensionPointId: PluginExtensionPoints.DashboardPanelMenu, context, limitPerPlugin: 3, }); useEffect(() => { - setItems(getPanelMenu(dashboard, panel, extensions, angularComponent)); - }, [dashboard, panel, angularComponent, loadingState, setItems, extensions]); + setItems(getPanelMenu(dashboard, panel, links, angularComponent)); + }, [dashboard, panel, angularComponent, loadingState, setItems, links]); return children({ items }); } diff --git a/public/app/features/dashboard/utils/getPanelMenu.test.ts b/public/app/features/dashboard/utils/getPanelMenu.test.ts index 162f716c49b..9cb64f51d6d 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.test.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.test.ts @@ -1,7 +1,7 @@ import { Store } from 'redux'; import { PanelMenuItem, PluginExtensionLink, PluginExtensionTypes } from '@grafana/data'; -import { AngularComponent, usePluginLinkExtensions } from '@grafana/runtime'; +import { AngularComponent, usePluginLinks } from '@grafana/runtime'; import config from 'app/core/config'; import { grantUserPermissions } from 'app/features/alerting/unified/mocks'; import * as actions from 'app/features/explore/state/main'; @@ -22,16 +22,16 @@ jest.mock('app/core/services/context_srv', () => ({ jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), - setPluginExtensionsHook: jest.fn(), - usePluginLinkExtensions: jest.fn(), + setPluginLinksHook: jest.fn(), + usePluginLinks: jest.fn(), })); -const usePluginLinkExtensionsMock = jest.mocked(usePluginLinkExtensions); +const usePluginLinksMock = jest.mocked(usePluginLinks); describe('getPanelMenu()', () => { beforeEach(() => { - usePluginLinkExtensionsMock.mockRestore(); - usePluginLinkExtensionsMock.mockReturnValue({ extensions: [], isLoading: false }); + usePluginLinksMock.mockRestore(); + usePluginLinksMock.mockReturnValue({ links: [], isLoading: false }); grantUserPermissions([AccessControlAction.AlertingRuleRead, AccessControlAction.AlertingRuleUpdate]); config.unifiedAlertingEnabled = false; }); diff --git a/public/app/features/explore/Explore.test.tsx b/public/app/features/explore/Explore.test.tsx index de960e3e561..91dc7f35ec7 100644 --- a/public/app/features/explore/Explore.test.tsx +++ b/public/app/features/explore/Explore.test.tsx @@ -12,7 +12,7 @@ import { store, } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; -import { usePluginLinkExtensions } from '@grafana/runtime'; +import { usePluginLinks } from '@grafana/runtime'; import { configureStore } from 'app/store/configureStore'; import { ContentOutlineContextProvider } from './ContentOutline/ContentOutlineContext'; @@ -124,7 +124,7 @@ jest.mock('app/core/core', () => ({ jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), - usePluginLinkExtensions: jest.fn(() => ({ extensions: [] })), + usePluginLinks: jest.fn(() => ({ links: [] })), })); // for the AutoSizer component to have a width @@ -138,7 +138,7 @@ jest.mock('react-virtualized-auto-sizer', () => { }); }); -const usePluginLinkExtensionsMock = jest.mocked(usePluginLinkExtensions); +const usePluginLinksMock = jest.mocked(usePluginLinks); const setup = (overrideProps?: Partial) => { const store = configureStore({ @@ -180,8 +180,8 @@ describe('Explore', () => { }); it('should render toolbar extension point if extensions is available', async () => { - usePluginLinkExtensionsMock.mockReturnValueOnce({ - extensions: [ + usePluginLinksMock.mockReturnValueOnce({ + links: [ { id: '1', pluginId: 'grafana', diff --git a/public/app/features/explore/extensions/ToolbarExtensionPoint.test.tsx b/public/app/features/explore/extensions/ToolbarExtensionPoint.test.tsx index fde629deab4..140849eebe8 100644 --- a/public/app/features/explore/extensions/ToolbarExtensionPoint.test.tsx +++ b/public/app/features/explore/extensions/ToolbarExtensionPoint.test.tsx @@ -4,7 +4,7 @@ import { ReactNode } from 'react'; import { Provider } from 'react-redux'; import { PluginExtensionPoints, PluginExtensionTypes } from '@grafana/data'; -import { usePluginLinkExtensions } from '@grafana/runtime'; +import { usePluginLinks } from '@grafana/runtime'; import { DataQuery } from '@grafana/schema'; import { contextSrv } from 'app/core/services/context_srv'; import { configureStore } from 'app/store/configureStore'; @@ -16,13 +16,13 @@ import { ToolbarExtensionPoint } from './ToolbarExtensionPoint'; jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), - usePluginLinkExtensions: jest.fn(), + usePluginLinks: jest.fn(), })); jest.mock('app/core/services/context_srv'); const contextSrvMock = jest.mocked(contextSrv); -const usePluginLinkExtensionsMock = jest.mocked(usePluginLinkExtensions); +const usePluginLinksMock = jest.mocked(usePluginLinks); type storeOptions = { targets: DataQuery[]; @@ -54,8 +54,8 @@ function renderWithExploreStore( describe('ToolbarExtensionPoint', () => { describe('with extension points', () => { beforeAll(() => { - usePluginLinkExtensionsMock.mockReturnValue({ - extensions: [ + usePluginLinksMock.mockReturnValue({ + links: [ { pluginId: 'grafana', id: '1', @@ -100,10 +100,10 @@ describe('ToolbarExtensionPoint', () => { await userEvent.click(screen.getByRole('button', { name: 'Add' })); await userEvent.click(screen.getByRole('menuitem', { name: 'Add to dashboard' })); - const { extensions } = usePluginLinkExtensionsMock({ + const { links } = usePluginLinksMock({ extensionPointId: PluginExtensionPoints.ExploreToolbarAction, }); - const [extension] = extensions; + const [extension] = links; expect(jest.mocked(extension.onClick)).toBeCalledTimes(1); }); @@ -128,7 +128,7 @@ describe('ToolbarExtensionPoint', () => { data, }); - const [options] = usePluginLinkExtensionsMock.mock.calls[0]; + const [options] = usePluginLinksMock.mock.calls[0]; const { context } = options; expect(context).toEqual({ @@ -153,7 +153,7 @@ describe('ToolbarExtensionPoint', () => { data, }); - const [options] = usePluginLinkExtensionsMock.mock.calls[0]; + const [options] = usePluginLinksMock.mock.calls[0]; const { context } = options; expect(context).toHaveProperty('timeZone', 'browser'); @@ -162,7 +162,7 @@ describe('ToolbarExtensionPoint', () => { it('should correct extension point id when fetching extensions', async () => { renderWithExploreStore(); - const [options] = usePluginLinkExtensionsMock.mock.calls[0]; + const [options] = usePluginLinksMock.mock.calls[0]; const { extensionPointId } = options; expect(extensionPointId).toBe(PluginExtensionPoints.ExploreToolbarAction); @@ -171,8 +171,8 @@ describe('ToolbarExtensionPoint', () => { describe('with extension points without categories', () => { beforeAll(() => { - usePluginLinkExtensionsMock.mockReturnValue({ - extensions: [ + usePluginLinksMock.mockReturnValue({ + links: [ { pluginId: 'grafana', id: '1', @@ -215,7 +215,7 @@ describe('ToolbarExtensionPoint', () => { describe('without extension points', () => { beforeAll(() => { contextSrvMock.hasPermission.mockReturnValue(true); - usePluginLinkExtensionsMock.mockReturnValue({ extensions: [], isLoading: false }); + usePluginLinksMock.mockReturnValue({ links: [], isLoading: false }); }); it('should render "add to dashboard" action button if one pane is visible', async () => { @@ -233,7 +233,7 @@ describe('ToolbarExtensionPoint', () => { describe('with insufficient permissions', () => { beforeAll(() => { contextSrvMock.hasPermission.mockReturnValue(false); - usePluginLinkExtensionsMock.mockReturnValue({ extensions: [], isLoading: false }); + usePluginLinksMock.mockReturnValue({ links: [], isLoading: false }); }); it('should not render "add to dashboard" action button', async () => { diff --git a/public/app/features/explore/extensions/ToolbarExtensionPoint.tsx b/public/app/features/explore/extensions/ToolbarExtensionPoint.tsx index f12f608c2bb..399ba36ee9a 100644 --- a/public/app/features/explore/extensions/ToolbarExtensionPoint.tsx +++ b/public/app/features/explore/extensions/ToolbarExtensionPoint.tsx @@ -1,7 +1,7 @@ import { lazy, ReactElement, Suspense, useMemo, useState } from 'react'; import { type PluginExtensionLink, PluginExtensionPoints, RawTimeRange, getTimeZone } from '@grafana/data'; -import { config, usePluginLinkExtensions } from '@grafana/runtime'; +import { config, usePluginLinks } from '@grafana/runtime'; import { DataQuery, TimeZone } from '@grafana/schema'; import { Dropdown, ToolbarButton } from '@grafana/ui'; import { contextSrv } from 'app/core/services/context_srv'; @@ -26,7 +26,7 @@ export function ToolbarExtensionPoint(props: Props): ReactElement | null { const [selectedExtension, setSelectedExtension] = useState(); const [isOpen, setIsOpen] = useState(false); const context = useExtensionPointContext(props); - const { extensions } = usePluginLinkExtensions({ + const { links } = usePluginLinks({ extensionPointId: PluginExtensionPoints.ExploreToolbarAction, context: context, limitPerPlugin: 3, @@ -36,7 +36,7 @@ export function ToolbarExtensionPoint(props: Props): ReactElement | null { // If we only have the explore core extension point registered we show the old way of // adding a query to a dashboard. - if (extensions.length <= 1) { + if (links.length <= 1) { const canAddPanelToDashboard = contextSrv.hasPermission(AccessControlAction.DashboardsCreate) || contextSrv.hasPermission(AccessControlAction.DashboardsWrite); @@ -52,7 +52,7 @@ export function ToolbarExtensionPoint(props: Props): ReactElement | null { ); } - const menu = ; + const menu = ; return ( <> diff --git a/public/app/features/explore/spec/helper/setup.tsx b/public/app/features/explore/spec/helper/setup.tsx index c908d9754df..0829af1ac70 100644 --- a/public/app/features/explore/spec/helper/setup.tsx +++ b/public/app/features/explore/spec/helper/setup.tsx @@ -21,12 +21,12 @@ import { locationService, HistoryWrapper, LocationService, - setPluginExtensionsHook, setBackendSrv, getBackendSrv, getDataSourceSrv, getEchoSrv, setLocationService, + setPluginLinksHook, } from '@grafana/runtime'; import { DataSourceRef } from '@grafana/schema'; import { GrafanaContext } from 'app/core/context/GrafanaContext'; @@ -89,7 +89,7 @@ export function setupExplore(options?: SetupOptions): { request: jest.fn().mockRejectedValue(undefined), }); - setPluginExtensionsHook(() => ({ extensions: [], isLoading: false })); + setPluginLinksHook(() => ({ links: [], isLoading: false })); // Clear this up otherwise it persists data source selection // TODO: probably add test for that too diff --git a/public/app/features/scopes/tests/dashboardReload.test.ts b/public/app/features/scopes/tests/dashboardReload.test.ts index 69e2e5ae02e..161dcf58283 100644 --- a/public/app/features/scopes/tests/dashboardReload.test.ts +++ b/public/app/features/scopes/tests/dashboardReload.test.ts @@ -11,7 +11,7 @@ jest.mock('@grafana/runtime', () => ({ useChromeHeaderHeight: jest.fn(), getBackendSrv: () => ({ get: getMock }), getDataSourceSrv: () => ({ get: getDatasource, getInstanceSettings }), - usePluginLinkExtensions: jest.fn().mockReturnValue({ extensions: [] }), + usePluginLinks: jest.fn().mockReturnValue({ links: [] }), })); describe('Dashboard reload', () => { diff --git a/public/app/features/scopes/tests/dashboardsApi.test.ts b/public/app/features/scopes/tests/dashboardsApi.test.ts index 8fe9448c662..f9af59eb92f 100644 --- a/public/app/features/scopes/tests/dashboardsApi.test.ts +++ b/public/app/features/scopes/tests/dashboardsApi.test.ts @@ -12,7 +12,7 @@ jest.mock('@grafana/runtime', () => ({ useChromeHeaderHeight: jest.fn(), getBackendSrv: () => ({ get: getMock }), getDataSourceSrv: () => ({ get: getDatasource, getInstanceSettings }), - usePluginLinkExtensions: jest.fn().mockReturnValue({ extensions: [] }), + usePluginLinks: jest.fn().mockReturnValue({ links: [] }), })); const runTest = async (passScopes: boolean, kubernetesApi: boolean) => { diff --git a/public/app/features/scopes/tests/dashboardsList.test.ts b/public/app/features/scopes/tests/dashboardsList.test.ts index e3ff44e04cd..e5215a89f86 100644 --- a/public/app/features/scopes/tests/dashboardsList.test.ts +++ b/public/app/features/scopes/tests/dashboardsList.test.ts @@ -28,7 +28,7 @@ jest.mock('@grafana/runtime', () => ({ useChromeHeaderHeight: jest.fn(), getBackendSrv: () => ({ get: getMock }), getDataSourceSrv: () => ({ get: getDatasource, getInstanceSettings }), - usePluginLinkExtensions: jest.fn().mockReturnValue({ extensions: [] }), + usePluginLinks: jest.fn().mockReturnValue({ links: [] }), })); describe('Dashboards list', () => { diff --git a/public/app/features/scopes/tests/featureFlag.test.ts b/public/app/features/scopes/tests/featureFlag.test.ts index af4a7a8daf9..efe209a6f5b 100644 --- a/public/app/features/scopes/tests/featureFlag.test.ts +++ b/public/app/features/scopes/tests/featureFlag.test.ts @@ -11,7 +11,7 @@ jest.mock('@grafana/runtime', () => ({ useChromeHeaderHeight: jest.fn(), getBackendSrv: () => ({ get: getMock }), getDataSourceSrv: () => ({ get: getDatasource, getInstanceSettings }), - usePluginLinkExtensions: jest.fn().mockReturnValue({ extensions: [] }), + usePluginLinks: jest.fn().mockReturnValue({ links: [] }), })); describe('Feature flag off', () => { diff --git a/public/app/features/scopes/tests/selector.test.ts b/public/app/features/scopes/tests/selector.test.ts index 78c002df870..6435de62803 100644 --- a/public/app/features/scopes/tests/selector.test.ts +++ b/public/app/features/scopes/tests/selector.test.ts @@ -15,7 +15,7 @@ jest.mock('@grafana/runtime', () => ({ useChromeHeaderHeight: jest.fn(), getBackendSrv: () => ({ get: getMock }), getDataSourceSrv: () => ({ get: getDatasource, getInstanceSettings }), - usePluginLinkExtensions: jest.fn().mockReturnValue({ extensions: [] }), + usePluginLinks: jest.fn().mockReturnValue({ links: [] }), })); describe('Selector', () => { diff --git a/public/app/features/scopes/tests/tree.test.ts b/public/app/features/scopes/tests/tree.test.ts index a305da2eb43..2a456d73f6b 100644 --- a/public/app/features/scopes/tests/tree.test.ts +++ b/public/app/features/scopes/tests/tree.test.ts @@ -46,7 +46,7 @@ jest.mock('@grafana/runtime', () => ({ useChromeHeaderHeight: jest.fn(), getBackendSrv: () => ({ get: getMock }), getDataSourceSrv: () => ({ get: getDatasource, getInstanceSettings }), - usePluginLinkExtensions: jest.fn().mockReturnValue({ extensions: [] }), + usePluginLinks: jest.fn().mockReturnValue({ links: [] }), })); describe('Tree', () => { diff --git a/public/app/features/scopes/tests/viewMode.test.ts b/public/app/features/scopes/tests/viewMode.test.ts index 4c39cadfdd9..14337bb6eaa 100644 --- a/public/app/features/scopes/tests/viewMode.test.ts +++ b/public/app/features/scopes/tests/viewMode.test.ts @@ -14,7 +14,7 @@ jest.mock('@grafana/runtime', () => ({ useChromeHeaderHeight: jest.fn(), getBackendSrv: () => ({ get: getMock }), getDataSourceSrv: () => ({ get: getDatasource, getInstanceSettings }), - usePluginLinkExtensions: jest.fn().mockReturnValue({ extensions: [] }), + usePluginLinks: jest.fn().mockReturnValue({ links: [] }), })); describe('View mode', () => { diff --git a/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx b/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx index 5eae2645e81..e609c34d0f3 100644 --- a/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx +++ b/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx @@ -4,7 +4,7 @@ import { Provider } from 'react-redux'; import { byRole, byText } from 'testing-library-selector'; import { FieldConfigSource, getDefaultTimeRange, LoadingState, PanelProps, PluginExtensionTypes } from '@grafana/data'; -import { TimeRangeUpdatedEvent, usePluginLinkExtensions } from '@grafana/runtime'; +import { TimeRangeUpdatedEvent, usePluginLinks } from '@grafana/runtime'; import { setupMswServer } from 'app/features/alerting/unified/mockApi'; import { mockPromRulesApiResponse } from 'app/features/alerting/unified/mocks/grafanaRulerApi'; import { mockRulerRulesApiResponse } from 'app/features/alerting/unified/mocks/rulerApi'; @@ -56,12 +56,12 @@ const grafanaRuleMock = { jest.mock('@grafana/runtime', () => ({ ...jest.requireActual('@grafana/runtime'), - usePluginLinkExtensions: jest.fn(), + usePluginLinks: jest.fn(), })); jest.mock('app/features/alerting/unified/api/alertmanager'); const mocks = { - usePluginLinkExtensionsMock: jest.mocked(usePluginLinkExtensions), + usePluginLinksMock: jest.mocked(usePluginLinks), }; const fakeResponse: PromRulesResponse = { @@ -84,8 +84,8 @@ beforeEach(() => { mockRulerRulesApiResponse(server, 'grafana', { 'folder-one': [{ name: 'group1', interval: '20s', rules: [originRule] }], }); - mocks.usePluginLinkExtensionsMock.mockReturnValue({ - extensions: [ + mocks.usePluginLinksMock.mockReturnValue({ + links: [ { pluginId: 'grafana-ml-app', id: '1',