2022-09-22 09:35:04 -03:00
|
|
|
import { getConfig } from 'app/core/config';
|
|
|
|
|
import { VariableModel } from 'app/features/variables/types';
|
|
|
|
|
|
2022-12-01 10:02:10 -06:00
|
|
|
import { PanelModel } from '../../../state';
|
|
|
|
|
|
|
|
|
|
import { supportedDatasources } from './SupportedPubdashDatasources';
|
|
|
|
|
|
2023-02-28 09:02:23 -03:00
|
|
|
export enum PublicDashboardShareType {
|
|
|
|
|
PUBLIC = 'public',
|
|
|
|
|
EMAIL = 'email',
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-24 12:36:29 -03:00
|
|
|
export interface PublicDashboardSettings {
|
2022-10-21 13:42:14 -06:00
|
|
|
annotationsEnabled: boolean;
|
2022-09-22 09:35:04 -03:00
|
|
|
isEnabled: boolean;
|
2023-01-18 10:54:19 -03:00
|
|
|
timeSelectionEnabled: boolean;
|
2022-09-22 09:35:04 -03:00
|
|
|
}
|
|
|
|
|
|
2023-02-24 12:36:29 -03:00
|
|
|
export interface PublicDashboard extends PublicDashboardSettings {
|
|
|
|
|
accessToken?: string;
|
|
|
|
|
uid: string;
|
|
|
|
|
dashboardUid: string;
|
|
|
|
|
timeSettings?: object;
|
2023-02-28 09:02:23 -03:00
|
|
|
share: PublicDashboardShareType;
|
2023-03-02 19:15:56 -03:00
|
|
|
recipients?: Array<{ uid: string; recipient: string }>;
|
2022-09-22 09:35:04 -03:00
|
|
|
}
|
|
|
|
|
|
2023-04-27 14:20:03 -03:00
|
|
|
export interface SessionDashboard {
|
|
|
|
|
dashboardTitle: string;
|
|
|
|
|
dashboardUid: string;
|
|
|
|
|
publicDashboardAccessToken: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SessionUser {
|
|
|
|
|
email: string;
|
|
|
|
|
firstSeenAtAge: string;
|
|
|
|
|
totalDashboards: number;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-22 09:35:04 -03:00
|
|
|
// Instance methods
|
|
|
|
|
export const dashboardHasTemplateVariables = (variables: VariableModel[]): boolean => {
|
|
|
|
|
return variables.length > 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const publicDashboardPersisted = (publicDashboard?: PublicDashboard): boolean => {
|
|
|
|
|
return publicDashboard?.uid !== '' && publicDashboard?.uid !== undefined;
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-01 10:02:10 -06:00
|
|
|
/**
|
|
|
|
|
* Get unique datasource names from all panels that are not currently supported by public dashboards.
|
|
|
|
|
*/
|
|
|
|
|
export const getUnsupportedDashboardDatasources = (panels: PanelModel[]): string[] => {
|
|
|
|
|
let unsupportedDS = new Set<string>();
|
|
|
|
|
|
|
|
|
|
for (const panel of panels) {
|
|
|
|
|
for (const target of panel.targets) {
|
|
|
|
|
let ds = target?.datasource?.type;
|
|
|
|
|
if (ds && !supportedDatasources.has(ds)) {
|
|
|
|
|
unsupportedDS.add(ds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Array.from(unsupportedDS).sort();
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-22 09:35:04 -03:00
|
|
|
/**
|
|
|
|
|
* Generate the public dashboard url. Uses the appUrl from the Grafana boot config, so urls will also be correct
|
|
|
|
|
* when Grafana is hosted on a subpath.
|
|
|
|
|
*
|
|
|
|
|
* All app urls from the Grafana boot config end with a slash.
|
|
|
|
|
*
|
2023-04-27 14:20:03 -03:00
|
|
|
* @param accessToken
|
2022-09-22 09:35:04 -03:00
|
|
|
*/
|
2023-04-27 14:20:03 -03:00
|
|
|
export const generatePublicDashboardUrl = (accessToken: string): string => {
|
|
|
|
|
return `${getConfig().appUrl}public-dashboards/${accessToken}`;
|
2022-09-22 09:35:04 -03:00
|
|
|
};
|
2023-02-28 09:02:23 -03:00
|
|
|
|
2023-05-08 16:51:42 -03:00
|
|
|
export const generatePublicDashboardConfigUrl = (dashboardUid: string): string => {
|
|
|
|
|
return `/d/${dashboardUid}?shareView=public-dashboard`;
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-28 09:02:23 -03:00
|
|
|
export const validEmailRegex = /^[A-Z\d._%+-]+@[A-Z\d.-]+\.[A-Z]{2,}$/i;
|