@@ -4,7 +4,17 @@ import React, { useEffect, useState } from 'react';
44import { GrafanaTheme2 } from '@grafana/data' ;
55import { selectors } from '@grafana/e2e-selectors' ;
66import { config , locationService } from '@grafana/runtime' ;
7- import { Button , ButtonGroup , Dropdown , Icon , Menu , ToolbarButton , ToolbarButtonRow , useStyles2 } from '@grafana/ui' ;
7+ import {
8+ Badge ,
9+ Button ,
10+ ButtonGroup ,
11+ Dropdown ,
12+ Icon ,
13+ Menu ,
14+ ToolbarButton ,
15+ ToolbarButtonRow ,
16+ useStyles2 ,
17+ } from '@grafana/ui' ;
818import { AppChromeUpdate } from 'app/core/components/AppChrome/AppChromeUpdate' ;
919import { NavToolbarSeparator } from 'app/core/components/AppChrome/NavToolbar/NavToolbarSeparator' ;
1020import { contextSrv } from 'app/core/core' ;
@@ -51,7 +61,7 @@ export function ToolbarActions({ dashboard }: Props) {
5161
5262 const canSaveAs = contextSrv . hasEditPermissionInFolders ;
5363 const toolbarActions : ToolbarAction [ ] = [ ] ;
54- const buttonWithExtraMargin = useStyles2 ( getStyles ) ;
64+ const styles = useStyles2 ( getStyles ) ;
5565 const isEditingPanel = Boolean ( editPanel ) ;
5666 const isViewingPanel = Boolean ( viewPanelScene ) ;
5767 const isEditingLibraryPanel = useEditingLibraryPanel ( editPanel ) ;
@@ -88,6 +98,24 @@ export function ToolbarActions({ dashboard }: Props) {
8898 } ,
8999 } ) ;
90100
101+ if ( meta . publicDashboardEnabled ) {
102+ toolbarActions . push ( {
103+ group : 'icon-actions' ,
104+ condition : uid && Boolean ( meta . canStar ) && isShowingDashboard && ! isEditing ,
105+ render : ( ) => {
106+ return (
107+ < Badge
108+ color = "blue"
109+ text = "Public"
110+ key = "public-dashboard-button-badge"
111+ className = { styles . publicBadge }
112+ data-testid = { selectors . pages . Dashboard . DashNav . publicDashboardTag }
113+ />
114+ ) ;
115+ } ,
116+ } ) ;
117+ }
118+
91119 const isDevEnv = config . buildInfo . env === 'development' ;
92120
93121 toolbarActions . push ( {
@@ -280,7 +308,7 @@ export function ToolbarActions({ dashboard }: Props) {
280308 key = "share-dashboard-button"
281309 tooltip = { t ( 'dashboard.toolbar.share' , 'Share dashboard' ) }
282310 size = "sm"
283- className = { buttonWithExtraMargin }
311+ className = { styles . buttonWithExtraMargin }
284312 fill = "outline"
285313 onClick = { ( ) => {
286314 DashboardInteractions . toolbarShareClick ( ) ;
@@ -302,7 +330,7 @@ export function ToolbarActions({ dashboard }: Props) {
302330 } }
303331 tooltip = "Enter edit mode"
304332 key = "edit"
305- className = { buttonWithExtraMargin }
333+ className = { styles . buttonWithExtraMargin }
306334 variant = "primary"
307335 size = "sm"
308336 >
@@ -427,7 +455,7 @@ export function ToolbarActions({ dashboard }: Props) {
427455 DashboardInteractions . toolbarSaveClick ( ) ;
428456 dashboard . openSaveDrawer ( { } ) ;
429457 } }
430- className = { buttonWithExtraMargin }
458+ className = { styles . buttonWithExtraMargin }
431459 tooltip = "Save changes"
432460 key = "save"
433461 size = "sm"
@@ -446,7 +474,7 @@ export function ToolbarActions({ dashboard }: Props) {
446474 DashboardInteractions . toolbarSaveClick ( ) ;
447475 dashboard . openSaveDrawer ( { saveAsCopy : true } ) ;
448476 } }
449- className = { buttonWithExtraMargin }
477+ className = { styles . buttonWithExtraMargin }
450478 tooltip = "Save as copy"
451479 key = "save"
452480 size = "sm"
@@ -480,7 +508,7 @@ export function ToolbarActions({ dashboard }: Props) {
480508 ) ;
481509
482510 return (
483- < ButtonGroup className = { buttonWithExtraMargin } key = "save" >
511+ < ButtonGroup className = { styles . buttonWithExtraMargin } key = "save" >
484512 < Button
485513 onClick = { ( ) => {
486514 DashboardInteractions . toolbarSaveClick ( ) ;
@@ -565,5 +593,14 @@ interface ToolbarAction {
565593}
566594
567595function getStyles ( theme : GrafanaTheme2 ) {
568- return css ( { margin : theme . spacing ( 0 , 0.5 ) } ) ;
596+ return {
597+ buttonWithExtraMargin : css ( {
598+ margin : theme . spacing ( 0 , 0.5 ) ,
599+ } ) ,
600+ publicBadge : css ( {
601+ color : 'grey' ,
602+ backgroundColor : 'transparent' ,
603+ border : '1px solid' ,
604+ } ) ,
605+ } ;
569606}
0 commit comments