| 
									
										
										
										
											2021-04-01 20:15:23 +08:00
										 |  |  | import { css } from '@emotion/css'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | import React, { FC } from 'react'; | 
					
						
							|  |  |  | import { useDispatch, useSelector } from 'react-redux'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  | import { GrafanaTheme } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | import { selectors } from '@grafana/e2e-selectors'; | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | import { ToolbarButton, ButtonGroup, useStyles } from '@grafana/ui'; | 
					
						
							|  |  |  | import { StoreState } from 'app/types'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | import { PanelModel } from '../../state'; | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  | import { getPanelPluginWithFallback } from '../../state/selectors'; | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | import { setPanelEditorUIState, toggleVizPicker } from './state/reducers'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  | export const VisualizationButton: FC<Props> = ({ panel }) => { | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |   const styles = useStyles(getStyles); | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  |   const dispatch = useDispatch(); | 
					
						
							|  |  |  |   const plugin = useSelector(getPanelPluginWithFallback(panel.type)); | 
					
						
							|  |  |  |   const isPanelOptionsVisible = useSelector((state: StoreState) => state.panelEditor.ui.isPanelOptionsVisible); | 
					
						
							|  |  |  |   const isVizPickerOpen = useSelector((state: StoreState) => 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 = () => { | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  |     dispatch(setPanelEditorUIState({ isPanelOptionsVisible: !isPanelOptionsVisible })); | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!plugin) { | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className={styles.wrapper}> | 
					
						
							|  |  |  |       <ButtonGroup> | 
					
						
							|  |  |  |         <ToolbarButton | 
					
						
							|  |  |  |           className={styles.vizButton} | 
					
						
							| 
									
										
										
										
											2021-04-01 23:42:57 +08:00
										 |  |  |           tooltip="Click to change visualization" | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |           imgSrc={plugin.meta.info.logos.small} | 
					
						
							|  |  |  |           isOpen={isVizPickerOpen} | 
					
						
							|  |  |  |           onClick={onToggleOpen} | 
					
						
							|  |  |  |           aria-label={selectors.components.PanelEditor.toggleVizPicker} | 
					
						
							| 
									
										
										
										
											2022-09-12 21:45:14 +08:00
										 |  |  |           variant="canvas" | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |           fullWidth | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           {plugin.meta.name} | 
					
						
							|  |  |  |         </ToolbarButton> | 
					
						
							|  |  |  |         <ToolbarButton | 
					
						
							|  |  |  |           tooltip={isPanelOptionsVisible ? 'Close options pane' : 'Show options pane'} | 
					
						
							|  |  |  |           icon={isPanelOptionsVisible ? 'angle-right' : 'angle-left'} | 
					
						
							|  |  |  |           onClick={onToggleOptionsPane} | 
					
						
							| 
									
										
										
										
											2022-09-12 21:45:14 +08:00
										 |  |  |           variant="canvas" | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  |           aria-label={selectors.components.PanelEditor.toggleVizOptions} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       </ButtonGroup> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-17 21:18:05 +08:00
										 |  |  | VisualizationButton.displayName = 'VisualizationTab'; | 
					
						
							| 
									
										
										
										
											2021-03-25 15:33:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const getStyles = (theme: GrafanaTheme) => { | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     wrapper: css`
 | 
					
						
							|  |  |  |       display: flex; | 
					
						
							|  |  |  |       flex-direction: column; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     vizButton: css`
 | 
					
						
							|  |  |  |       text-align: left; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; |