diff --git a/.betterer.results b/.betterer.results index 796548a475e..842d1803312 100644 --- a/.betterer.results +++ b/.betterer.results @@ -3082,9 +3082,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not re-export imported variable (\`./VersionHistoryButtons\`)", "3"], [0, 0, 0, "Do not re-export imported variable (\`./VersionHistoryComparison\`)", "4"] ], - "public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.tsx:5381": [ - [0, 0, 0, "No untranslated strings. Wrap text with ", "0"] - ], "public/app/features/dashboard-scene/sharing/ShareExportTab.tsx:5381": [ [0, 0, 0, "No untranslated strings. Wrap text with ", "0"] ], diff --git a/public/app/core/utils/shortLinks.ts b/public/app/core/utils/shortLinks.ts index 74ebbfbeb44..13d162967a2 100644 --- a/public/app/core/utils/shortLinks.ts +++ b/public/app/core/utils/shortLinks.ts @@ -9,6 +9,9 @@ import { DashboardScene } from 'app/features/dashboard-scene/scene/DashboardScen import { getDashboardUrl } from 'app/features/dashboard-scene/utils/urlBuilders'; import { dispatch } from 'app/store/store'; +import { ShareLinkConfiguration } from '../../features/dashboard-scene/sharing/ShareButton/utils'; +import { t } from '../internationalization'; + import { copyStringToClipboard } from './explore'; function buildHostUrl() { @@ -42,20 +45,21 @@ export const createAndCopyShortLink = async (path: string) => { } }; -export const createAndCopyDashboardShortLink = async ( +export const createAndCopyShareDashboardLink = async ( dashboard: DashboardScene, - opts: { useAbsoluteTimeRange: boolean; theme: string }, + opts: ShareLinkConfiguration, panel?: VizPanel ) => { - const shareUrl = await createDashboardShareUrl(dashboard, opts, panel); - await createAndCopyShortLink(shareUrl); + const shareUrl = createDashboardShareUrl(dashboard, opts, panel); + if (opts.useShortUrl) { + return await createAndCopyShortLink(shareUrl); + } else { + copyStringToClipboard(shareUrl); + dispatch(notifyApp(createSuccessNotification(t('link.share.copy-to-clipboard', 'Link copied to clipboard')))); + } }; -export const createDashboardShareUrl = async ( - dashboard: DashboardScene, - opts: { useAbsoluteTimeRange: boolean; theme: string }, - panel?: VizPanel -) => { +export const createDashboardShareUrl = (dashboard: DashboardScene, opts: ShareLinkConfiguration, panel?: VizPanel) => { const location = locationService.getLocation(); const timeRange = sceneGraph.getTimeRange(panel ?? dashboard); diff --git a/public/app/features/dashboard-scene/scene/NavToolbarActions.tsx b/public/app/features/dashboard-scene/scene/NavToolbarActions.tsx index 28e2902509d..051c473f411 100644 --- a/public/app/features/dashboard-scene/scene/NavToolbarActions.tsx +++ b/public/app/features/dashboard-scene/scene/NavToolbarActions.tsx @@ -321,7 +321,7 @@ export function ToolbarActions({ dashboard }: Props) { fill="outline" onClick={() => { DashboardInteractions.toolbarShareClick(); - dashboard.showModal(new ShareModal({ dashboardRef: dashboard.getRef() })); + dashboard.showModal(new ShareModal({})); }} data-testid={selectors.components.NavToolbar.shareDashboard} > diff --git a/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx b/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx index d33ed831670..24a0314c676 100644 --- a/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx +++ b/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx @@ -84,7 +84,7 @@ export function panelMenuBehavior(menu: VizPanelMenu, isRepeat = false) { iconClassName: 'share-alt', onClick: () => { DashboardInteractions.panelMenuItemClicked('share'); - dashboard.showModal(new ShareModal({ panelRef: panel.getRef(), dashboardRef: dashboard.getRef() })); + dashboard.showModal(new ShareModal({ panelRef: panel.getRef() })); }, shortcut: 'p s', }); @@ -139,7 +139,6 @@ export function panelMenuBehavior(menu: VizPanelMenu, isRepeat = false) { dashboard.showModal( new ShareModal({ panelRef: panel.getRef(), - dashboardRef: dashboard.getRef(), activeTab: shareDashboardType.libraryPanel, }) ); diff --git a/public/app/features/dashboard-scene/scene/keyboardShortcuts.ts b/public/app/features/dashboard-scene/scene/keyboardShortcuts.ts index dfa49e6625a..f0edd586360 100644 --- a/public/app/features/dashboard-scene/scene/keyboardShortcuts.ts +++ b/public/app/features/dashboard-scene/scene/keyboardShortcuts.ts @@ -60,7 +60,7 @@ export function setupKeyboardShortcuts(scene: DashboardScene) { keybindings.addBinding({ key: 'p s', onTrigger: withFocusedPanel(scene, async (vizPanel: VizPanel) => { - scene.showModal(new ShareModal({ panelRef: vizPanel.getRef(), dashboardRef: scene.getRef() })); + scene.showModal(new ShareModal({ panelRef: vizPanel.getRef() })); }), }); diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.test.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.test.tsx index 3fec88b051c..ac1b76fb655 100644 --- a/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.test.tsx +++ b/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.test.tsx @@ -24,16 +24,6 @@ describe('ShareButton', () => { expect(await screen.findByTestId(selector.shareLink)).toBeInTheDocument(); expect(await screen.findByTestId(selector.arrowMenu)).toBeInTheDocument(); }); - - it('should call createAndCopyDashboardShortLink when share link clicked', async () => { - setup(); - - const shareLink = await screen.findByTestId(selector.shareLink); - - await userEvent.click(shareLink); - expect(createAndCopyDashboardShortLinkMock).toHaveBeenCalled(); - }); - it('should render menu when arrow button clicked', async () => { setup(); diff --git a/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.tsx b/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.tsx index 01fcf60706b..6a79cbdb0da 100644 --- a/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.tsx +++ b/public/app/features/dashboard-scene/sharing/ShareButton/ShareButton.tsx @@ -4,6 +4,7 @@ import { useAsyncFn } from 'react-use'; import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; import { VizPanel } from '@grafana/scenes'; import { Button, ButtonGroup, Dropdown } from '@grafana/ui'; +import { t, Trans } from 'app/core/internationalization'; import { DashboardScene } from '../../scene/DashboardScene'; import { DashboardInteractions } from '../../utils/interactions'; @@ -32,8 +33,13 @@ export default function ShareButton({ dashboard, panel }: { dashboard: Dashboard return ( -