The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/dashboard-scene/sharing/ShareButton/utils.ts

48 lines
1.6 KiB

import { VizPanel } from '@grafana/scenes';
import { createAndCopyShareDashboardLink } from 'app/core/utils/shortLinks';
import { getTrackingSource } from 'app/features/dashboard/components/ShareModal/utils';
import store from '../../../../core/store';
import { DashboardScene } from '../../scene/DashboardScene';
import { DashboardInteractions } from '../../utils/interactions';
export type ShareLinkConfiguration = {
useAbsoluteTimeRange: boolean;
useShortUrl: boolean;
theme: string;
};
const DEFAULT_SHARE_LINK_CONFIGURATION: ShareLinkConfiguration = {
useAbsoluteTimeRange: true,
useShortUrl: true,
theme: 'current',
};
export const buildShareUrl = async (dashboard: DashboardScene, panel?: VizPanel) => {
const { useAbsoluteTimeRange, useShortUrl, theme } = getShareLinkConfiguration();
DashboardInteractions.shareLinkCopied({
currentTimeRange: useAbsoluteTimeRange,
theme,
shortenURL: useShortUrl,
shareResource: getTrackingSource(panel?.getRef()),
});
return await createAndCopyShareDashboardLink(dashboard, {
useAbsoluteTimeRange,
theme,
useShortUrl,
});
};
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);
}