@@ -7,6 +7,11 @@ import classnames from 'classnames'
77
88// Utils
99import { event } from 'src/cloud/utils/reporting'
10+ import { copy } from 'src/shared/components/CopyToClipboard'
11+ import {
12+ copyQuerySuccess ,
13+ copyQueryFailure ,
14+ } from 'src/shared/copy/notifications/categories/dashboard'
1015
1116// Components
1217import {
@@ -22,6 +27,7 @@ import CellContextDangerItem from 'src/shared/components/cells/CellContextDanger
2227// Actions
2328import { deleteCellAndView , createCellWithView } from 'src/cells/actions/thunks'
2429import { showOverlay , dismissOverlay } from 'src/overlays/actions/overlays'
30+ import { notify } from 'src/shared/actions/notifications'
2531
2632// Types
2733import { Cell , View } from 'src/types'
@@ -76,6 +82,20 @@ const CellContext: FC<Props> = ({
7682 event ( 'editCell button Click' )
7783 }
7884
85+ const handleCopyQuery = async ( ) => {
86+ let result = false
87+ // this 'in' check satisfies TypeScript saying `property queries does not exist in ViewProperties` (which is a lie)
88+ if ( 'queries' in view . properties ) {
89+ result = await copy ( view . properties . queries ?. [ 0 ] ?. text )
90+ }
91+
92+ if ( ! result ) {
93+ dispatch ( notify ( copyQueryFailure ( cell . name ) ) )
94+ return
95+ }
96+ dispatch ( notify ( copyQuerySuccess ( cell . name ) ) )
97+ }
98+
7999 const popoverContents = ( onHide ) : JSX . Element => {
80100 if ( view . properties . type === 'markdown' ) {
81101 return (
@@ -185,6 +205,15 @@ const CellContext: FC<Props> = ({
185205 onHide = { onHide }
186206 testID = "cell-context--copy"
187207 />
208+ { view . properties ?. queries ?. length && (
209+ < CellContextItem
210+ label = "Copy Query"
211+ onClick = { handleCopyQuery }
212+ icon = { IconFont . Clipboard_New }
213+ onHide = { onHide }
214+ testID = "cell-context--copy-query"
215+ />
216+ ) }
188217 </ div >
189218 )
190219 }
0 commit comments