| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  | import { css, cx } from '@emotion/css'; | 
					
						
							|  |  |  | import React, { MouseEventHandler } from 'react'; | 
					
						
							| 
									
										
										
										
											2023-03-08 17:38:06 +08:00
										 |  |  | import { DraggableProvided } from 'react-beautiful-dnd'; | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { GrafanaTheme2 } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2022-08-24 21:38:16 +08:00
										 |  |  | import { Icon, IconButton, useStyles2 } from '@grafana/ui'; | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-17 02:14:00 +08:00
										 |  |  | export interface QueryOperationRowHeaderProps { | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  |   actionsElement?: React.ReactNode; | 
					
						
							|  |  |  |   disabled?: boolean; | 
					
						
							|  |  |  |   draggable: boolean; | 
					
						
							| 
									
										
										
										
											2023-06-17 02:14:00 +08:00
										 |  |  |   collapsable?: boolean; | 
					
						
							| 
									
										
										
										
											2023-03-08 17:38:06 +08:00
										 |  |  |   dragHandleProps?: DraggableProvided['dragHandleProps']; | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  |   headerElement?: React.ReactNode; | 
					
						
							|  |  |  |   isContentVisible: boolean; | 
					
						
							|  |  |  |   onRowToggle: () => void; | 
					
						
							|  |  |  |   reportDragMousePosition: MouseEventHandler<HTMLDivElement>; | 
					
						
							| 
									
										
										
										
											2023-01-30 21:32:16 +08:00
										 |  |  |   title?: string; | 
					
						
							| 
									
										
										
										
											2022-09-30 19:03:55 +08:00
										 |  |  |   id: string; | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-15 22:56:09 +08:00
										 |  |  | export const QueryOperationRowHeader = ({ | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  |   actionsElement, | 
					
						
							|  |  |  |   disabled, | 
					
						
							|  |  |  |   draggable, | 
					
						
							| 
									
										
										
										
											2023-06-17 02:14:00 +08:00
										 |  |  |   collapsable = true, | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  |   dragHandleProps, | 
					
						
							|  |  |  |   headerElement, | 
					
						
							|  |  |  |   isContentVisible, | 
					
						
							|  |  |  |   onRowToggle, | 
					
						
							|  |  |  |   reportDragMousePosition, | 
					
						
							| 
									
										
										
										
											2023-01-30 21:32:16 +08:00
										 |  |  |   title, | 
					
						
							| 
									
										
										
										
											2022-09-30 19:03:55 +08:00
										 |  |  |   id, | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  | }: QueryOperationRowHeaderProps) => { | 
					
						
							|  |  |  |   const styles = useStyles2(getStyles); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className={styles.header}> | 
					
						
							|  |  |  |       <div className={styles.column}> | 
					
						
							| 
									
										
										
										
											2023-06-17 02:14:00 +08:00
										 |  |  |         {collapsable && ( | 
					
						
							|  |  |  |           <IconButton | 
					
						
							|  |  |  |             name={isContentVisible ? 'angle-down' : 'angle-right'} | 
					
						
							|  |  |  |             aria-label="toggle collapse and expand query row" | 
					
						
							|  |  |  |             tooltip={isContentVisible ? 'Collapse query row' : 'Expand query row'} | 
					
						
							|  |  |  |             className={styles.collapseIcon} | 
					
						
							|  |  |  |             onClick={onRowToggle} | 
					
						
							|  |  |  |             aria-expanded={isContentVisible} | 
					
						
							|  |  |  |             aria-controls={id} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         )} | 
					
						
							| 
									
										
										
										
											2023-01-30 21:32:16 +08:00
										 |  |  |         {title && ( | 
					
						
							| 
									
										
										
										
											2023-02-08 22:17:15 +08:00
										 |  |  |           // disabling the a11y rules here as the IconButton above handles keyboard interactions
 | 
					
						
							|  |  |  |           // this is just to provide a better experience for mouse users
 | 
					
						
							|  |  |  |           // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
 | 
					
						
							|  |  |  |           <div className={styles.titleWrapper} onClick={onRowToggle} aria-label="Query operation row title"> | 
					
						
							|  |  |  |             <div className={cx(styles.title, disabled && styles.disabled)}>{title}</div> | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  |           </div> | 
					
						
							|  |  |  |         )} | 
					
						
							|  |  |  |         {headerElement} | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <div className={styles.column}> | 
					
						
							|  |  |  |         {actionsElement} | 
					
						
							|  |  |  |         {draggable && ( | 
					
						
							|  |  |  |           <Icon | 
					
						
							|  |  |  |             title="Drag and drop to reorder" | 
					
						
							|  |  |  |             name="draggabledots" | 
					
						
							|  |  |  |             size="lg" | 
					
						
							|  |  |  |             className={styles.dragIcon} | 
					
						
							|  |  |  |             onMouseMove={reportDragMousePosition} | 
					
						
							|  |  |  |             {...dragHandleProps} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         )} | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const getStyles = (theme: GrafanaTheme2) => ({ | 
					
						
							|  |  |  |   header: css`
 | 
					
						
							|  |  |  |     label: Header; | 
					
						
							|  |  |  |     padding: ${theme.spacing(0.5, 0.5)}; | 
					
						
							|  |  |  |     border-radius: ${theme.shape.borderRadius(1)}; | 
					
						
							|  |  |  |     background: ${theme.colors.background.secondary}; | 
					
						
							|  |  |  |     min-height: ${theme.spacing(4)}; | 
					
						
							|  |  |  |     display: grid; | 
					
						
							|  |  |  |     grid-template-columns: minmax(100px, max-content) min-content; | 
					
						
							|  |  |  |     align-items: center; | 
					
						
							|  |  |  |     justify-content: space-between; | 
					
						
							|  |  |  |     white-space: nowrap; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     &:focus { | 
					
						
							|  |  |  |       outline: none; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   `,
 | 
					
						
							|  |  |  |   column: css`
 | 
					
						
							|  |  |  |     label: Column; | 
					
						
							|  |  |  |     display: flex; | 
					
						
							|  |  |  |     align-items: center; | 
					
						
							|  |  |  |   `,
 | 
					
						
							|  |  |  |   dragIcon: css`
 | 
					
						
							|  |  |  |     cursor: grab; | 
					
						
							|  |  |  |     color: ${theme.colors.text.disabled}; | 
					
						
							|  |  |  |     margin: ${theme.spacing(0, 0.5)}; | 
					
						
							|  |  |  |     &:hover { | 
					
						
							|  |  |  |       color: ${theme.colors.text}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   `,
 | 
					
						
							|  |  |  |   collapseIcon: css`
 | 
					
						
							| 
									
										
										
										
											2022-08-24 21:38:16 +08:00
										 |  |  |     margin-left: ${theme.spacing(0.5)}; | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  |     color: ${theme.colors.text.disabled}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   `,
 | 
					
						
							|  |  |  |   titleWrapper: css`
 | 
					
						
							|  |  |  |     display: flex; | 
					
						
							|  |  |  |     align-items: center; | 
					
						
							|  |  |  |     flex-grow: 1; | 
					
						
							| 
									
										
										
										
											2023-02-08 22:17:15 +08:00
										 |  |  |     cursor: pointer; | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  |     overflow: hidden; | 
					
						
							|  |  |  |     margin-right: ${theme.spacing(0.5)}; | 
					
						
							|  |  |  |   `,
 | 
					
						
							|  |  |  |   title: css`
 | 
					
						
							|  |  |  |     font-weight: ${theme.typography.fontWeightBold}; | 
					
						
							| 
									
										
										
										
											2023-02-08 22:17:15 +08:00
										 |  |  |     color: ${theme.colors.text.link}; | 
					
						
							| 
									
										
										
										
											2022-06-02 19:34:05 +08:00
										 |  |  |     margin-left: ${theme.spacing(0.5)}; | 
					
						
							|  |  |  |     overflow: hidden; | 
					
						
							|  |  |  |     text-overflow: ellipsis; | 
					
						
							|  |  |  |   `,
 | 
					
						
							|  |  |  |   disabled: css`
 | 
					
						
							|  |  |  |     color: ${theme.colors.text.disabled}; | 
					
						
							|  |  |  |   `,
 | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QueryOperationRowHeader.displayName = 'QueryOperationRowHeader'; |