11// Libraries
22import React , { FC , useContext , useState , useEffect } from 'react'
3- import { Link } from 'react-router-dom'
3+ import { useHistory , Link } from 'react-router-dom'
44import { useSelector } from 'react-redux'
55
66// Contexts
77import { FlowContext } from 'src/flows/context/flow.current'
8+ import { FlowListContext } from 'src/flows/context/flow.list'
89import { AppSettingProvider } from 'src/shared/contexts/app'
10+ import { deletePinnedItemByParam } from 'src/shared/contexts/pinneditems'
911
1012// Components
1113import {
@@ -14,9 +16,12 @@ import {
1416 IconFont ,
1517 ComponentColor ,
1618 ComponentStatus ,
19+ ConfirmationButton ,
20+ ButtonShape ,
1721 Dropdown ,
1822 ErrorTooltip ,
1923} from '@influxdata/clockface'
24+ import { PROJECT_NAME , PROJECT_NAME_PLURAL } from 'src/flows'
2025import TimeZoneDropdown from 'src/shared/components/TimeZoneDropdown'
2126import TimeRangeDropdown from 'src/flows/components/header/TimeRangeDropdown'
2227import Submit from 'src/flows/components/header/Submit'
@@ -49,7 +54,9 @@ interface Share {
4954}
5055
5156const FlowHeader : FC = ( ) => {
57+ const { remove, clone} = useContext ( FlowListContext )
5258 const { flow, updateOther} = useContext ( FlowContext )
59+ const history = useHistory ( )
5360 const { id : orgID } = useSelector ( getOrg )
5461 const [ sharing , setSharing ] = useState ( false )
5562 const [ token , setToken ] = useState < Token > ( )
@@ -145,6 +152,21 @@ const FlowHeader: FC = () => {
145152 /* eslint-enable no-console */
146153 }
147154
155+ const handleClone = async ( ) => {
156+ event ( 'clone_notebook' )
157+ const clonedId = await clone ( flow . id )
158+ history . push (
159+ `/orgs/${ orgID } /${ PROJECT_NAME_PLURAL . toLowerCase ( ) } /${ clonedId } `
160+ )
161+ }
162+
163+ const handleDelete = ( ) => {
164+ event ( 'delete_notebook' )
165+ deletePinnedItemByParam ( flow . id )
166+ remove ( flow . id )
167+ history . push ( `/orgs/${ orgID } /${ PROJECT_NAME_PLURAL . toLowerCase ( ) } ` )
168+ }
169+
148170 if ( ! flow ) {
149171 return null
150172 }
@@ -201,16 +223,33 @@ const FlowHeader: FC = () => {
201223 < TimeZoneDropdown />
202224 < TimeRangeDropdown />
203225 { flow ?. id && (
204- < FeatureFlag name = "shareNotebook" >
226+ < >
227+ < ConfirmationButton
228+ icon = { IconFont . Trash_New }
229+ shape = { ButtonShape . Square }
230+ confirmationLabel = { `Yes, delete this ${ PROJECT_NAME } ` }
231+ onConfirm = { handleDelete }
232+ confirmationButtonText = "Confirm"
233+ testID = "context-delete-menu"
234+ />
205235 < SquareButton
206- icon = { IconFont . Share }
207- onClick = { showShare }
208- color = {
209- ! ! share ? ComponentColor . Primary : ComponentColor . Secondary
210- }
211- titleText = "Share Notebook"
236+ icon = { IconFont . Duplicate_New }
237+ onClick = { handleClone }
238+ titleText = "Clone"
212239 />
213- </ FeatureFlag >
240+ < FeatureFlag name = "shareNotebook" >
241+ < SquareButton
242+ icon = { IconFont . Share }
243+ onClick = { showShare }
244+ color = {
245+ ! ! share
246+ ? ComponentColor . Primary
247+ : ComponentColor . Secondary
248+ }
249+ titleText = "Share Notebook"
250+ />
251+ </ FeatureFlag >
252+ </ >
214253 ) }
215254 < FeatureFlag name = "flow-snapshot" >
216255 < SquareButton
0 commit comments