| 
									
										
										
										
											2021-04-01 20:15:23 +08:00
										 |  |  | import { css } from '@emotion/css'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { selectors } from '@grafana/e2e-selectors'; | 
					
						
							| 
									
										
										
										
											2022-11-03 21:54:18 +08:00
										 |  |  | import { ToolbarButton, ButtonGroup } from '@grafana/ui'; | 
					
						
							| 
									
										
										
										
											2025-04-03 16:26:24 +08:00
										 |  |  | import { t } from 'app/core/internationalization'; | 
					
						
							| 
									
										
										
										
											2022-09-19 17:49:35 +08:00
										 |  |  | import { useDispatch, useSelector } from 'app/types'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-06 23:01:51 +08:00
										 |  |  | import { PanelModel } from '../../state/PanelModel'; | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  | import { getPanelPluginWithFallback } from '../../state/selectors'; | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-24 23:03:26 +08:00
										 |  |  | import { updatePanelEditorUIState } from './state/actions'; | 
					
						
							|  |  |  | import { toggleVizPicker } from './state/reducers'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  | type Props = { | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |   panel: PanelModel; | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-03 21:54:18 +08:00
										 |  |  | export const VisualizationButton = ({ panel }: Props) => { | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  |   const dispatch = useDispatch(); | 
					
						
							|  |  |  |   const plugin = useSelector(getPanelPluginWithFallback(panel.type)); | 
					
						
							| 
									
										
										
										
											2022-09-19 17:49:35 +08:00
										 |  |  |   const isPanelOptionsVisible = useSelector((state) => state.panelEditor.ui.isPanelOptionsVisible); | 
					
						
							|  |  |  |   const isVizPickerOpen = useSelector((state) => state.panelEditor.isVizPickerOpen); | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const onToggleOpen = () => { | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  |     dispatch(toggleVizPicker(!isVizPickerOpen)); | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const onToggleOptionsPane = () => { | 
					
						
							| 
									
										
										
										
											2022-11-24 23:03:26 +08:00
										 |  |  |     dispatch(updatePanelEditorUIState({ isPanelOptionsVisible: !isPanelOptionsVisible })); | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!plugin) { | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className={styles.wrapper}> | 
					
						
							|  |  |  |       <ButtonGroup> | 
					
						
							|  |  |  |         <ToolbarButton | 
					
						
							|  |  |  |           className={styles.vizButton} | 
					
						
							| 
									
										
										
										
											2025-04-03 16:26:24 +08:00
										 |  |  |           tooltip={t( | 
					
						
							|  |  |  |             'dashboard.visualization-button.tooltip-click-to-change-visualization', | 
					
						
							|  |  |  |             'Click to change visualization' | 
					
						
							|  |  |  |           )} | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |           imgSrc={plugin.meta.info.logos.small} | 
					
						
							|  |  |  |           isOpen={isVizPickerOpen} | 
					
						
							|  |  |  |           onClick={onToggleOpen} | 
					
						
							| 
									
										
										
										
											2023-05-17 23:20:38 +08:00
										 |  |  |           data-testid={selectors.components.PanelEditor.toggleVizPicker} | 
					
						
							| 
									
										
										
										
											2025-04-03 16:26:24 +08:00
										 |  |  |           aria-label={t('dashboard.visualization-button.aria-label-change-visualization', 'Change visualization')} | 
					
						
							| 
									
										
										
										
											2022-09-12 21:45:14 +08:00
										 |  |  |           variant="canvas" | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |           fullWidth | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           {plugin.meta.name} | 
					
						
							|  |  |  |         </ToolbarButton> | 
					
						
							|  |  |  |         <ToolbarButton | 
					
						
							| 
									
										
										
										
											2025-04-16 16:25:18 +08:00
										 |  |  |           tooltip={ | 
					
						
							|  |  |  |             isPanelOptionsVisible | 
					
						
							|  |  |  |               ? t('dashboard.visualization-button.tooltip-close', 'Close options pane') | 
					
						
							|  |  |  |               : t('dashboard.visualization-button.tooltip-show', 'Show options pane') | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |           icon={isPanelOptionsVisible ? 'angle-right' : 'angle-left'} | 
					
						
							|  |  |  |           onClick={onToggleOptionsPane} | 
					
						
							| 
									
										
										
										
											2022-09-12 21:45:14 +08:00
										 |  |  |           variant="canvas" | 
					
						
							| 
									
										
										
										
											2023-05-17 23:20:38 +08:00
										 |  |  |           data-testid={selectors.components.PanelEditor.toggleVizOptions} | 
					
						
							| 
									
										
										
										
											2025-04-16 16:25:18 +08:00
										 |  |  |           aria-label={ | 
					
						
							|  |  |  |             isPanelOptionsVisible | 
					
						
							|  |  |  |               ? t('dashboard.visualization-button.aria-label-close', 'Close options pane') | 
					
						
							|  |  |  |               : t('dashboard.visualization-button.aria-label-show', 'Show options pane') | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |         /> | 
					
						
							|  |  |  |       </ButtonGroup> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  | VisualizationButton.displayName = 'VisualizationTab'; | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-03 21:54:18 +08:00
										 |  |  | const styles = { | 
					
						
							| 
									
										
										
										
											2024-04-26 03:18:02 +08:00
										 |  |  |   wrapper: css({ | 
					
						
							|  |  |  |     display: 'flex', | 
					
						
							|  |  |  |     flexDirection: 'column', | 
					
						
							|  |  |  |   }), | 
					
						
							|  |  |  |   vizButton: css({ | 
					
						
							|  |  |  |     textAlign: 'left', | 
					
						
							|  |  |  |   }), | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | }; |