SharePublicDashboardUtils.ts 758 B

123456789101112131415161718192021
  1. import { getBackendSrv } from '@grafana/runtime';
  2. import { DashboardModel } from 'app/features/dashboard/state';
  3. export interface PublicDashboardConfig {
  4. isPublic: boolean;
  5. }
  6. export const dashboardCanBePublic = (dashboard: DashboardModel): boolean => {
  7. return dashboard?.templating?.list.length === 0;
  8. };
  9. export const getPublicDashboardConfig = async (dashboardUid: string) => {
  10. const url = `/api/dashboards/uid/${dashboardUid}/public-config`;
  11. return getBackendSrv().get(url);
  12. };
  13. export const savePublicDashboardConfig = async (dashboardUid: string, conf: PublicDashboardConfig) => {
  14. const payload = { isPublic: conf.isPublic };
  15. const url = `/api/dashboards/uid/${dashboardUid}/public-config`;
  16. return getBackendSrv().post(url, payload);
  17. };