2024-06-12 17:02:06 -03:00
|
|
|
import { VizPanel } from '@grafana/scenes';
|
2024-06-24 16:31:42 -03:00
|
|
|
import { createAndCopyShareDashboardLink } from 'app/core/utils/shortLinks';
|
2024-06-12 17:02:06 -03:00
|
|
|
import { getTrackingSource } from 'app/features/dashboard/components/ShareModal/utils';
|
|
|
|
|
|
2024-06-24 16:31:42 -03:00
|
|
|
import store from '../../../../core/store';
|
2024-06-12 17:02:06 -03:00
|
|
|
import { DashboardScene } from '../../scene/DashboardScene';
|
|
|
|
|
import { DashboardInteractions } from '../../utils/interactions';
|
|
|
|
|
|
2024-06-24 16:31:42 -03:00
|
|
|
export type ShareLinkConfiguration = {
|
|
|
|
|
useAbsoluteTimeRange: boolean;
|
|
|
|
|
useShortUrl: boolean;
|
|
|
|
|
theme: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const DEFAULT_SHARE_LINK_CONFIGURATION: ShareLinkConfiguration = {
|
|
|
|
|
useAbsoluteTimeRange: true,
|
|
|
|
|
useShortUrl: true,
|
|
|
|
|
theme: 'current',
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-12 17:02:06 -03:00
|
|
|
export const buildShareUrl = async (dashboard: DashboardScene, panel?: VizPanel) => {
|
2024-06-24 16:31:42 -03:00
|
|
|
const { useAbsoluteTimeRange, useShortUrl, theme } = getShareLinkConfiguration();
|
2024-06-12 17:02:06 -03:00
|
|
|
DashboardInteractions.shareLinkCopied({
|
2024-06-24 16:31:42 -03:00
|
|
|
currentTimeRange: useAbsoluteTimeRange,
|
|
|
|
|
theme,
|
|
|
|
|
shortenURL: useShortUrl,
|
2024-06-12 17:02:06 -03:00
|
|
|
shareResource: getTrackingSource(panel?.getRef()),
|
|
|
|
|
});
|
2024-06-24 16:31:42 -03:00
|
|
|
return await createAndCopyShareDashboardLink(dashboard, {
|
|
|
|
|
useAbsoluteTimeRange,
|
|
|
|
|
theme,
|
|
|
|
|
useShortUrl,
|
|
|
|
|
});
|
2024-06-12 17:02:06 -03:00
|
|
|
};
|
2024-06-24 16:31:42 -03:00
|
|
|
|
|
|
|
|
const SHARE_LINK_CONFIGURATION = 'grafana.dashboard.link.shareConfiguration';
|
|
|
|
|
// Function that returns share link configuration from local storage
|
|
|
|
|
export function getShareLinkConfiguration(): ShareLinkConfiguration {
|
|
|
|
|
if (store.exists(SHARE_LINK_CONFIGURATION)) {
|
|
|
|
|
return store.getObject(SHARE_LINK_CONFIGURATION) || DEFAULT_SHARE_LINK_CONFIGURATION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DEFAULT_SHARE_LINK_CONFIGURATION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function updateShareLinkConfiguration(config: ShareLinkConfiguration) {
|
|
|
|
|
store.setObject(SHARE_LINK_CONFIGURATION, config);
|
|
|
|
|
}
|