Skip to content

Commit 77df902

Browse files
authored
feat: copy clone and delete to the notebook (#3315)
1 parent 78c4c8f commit 77df902

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

src/flows/components/header/index.tsx

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Libraries
22
import React, {FC, useContext, useState, useEffect} from 'react'
3-
import {Link} from 'react-router-dom'
3+
import {useHistory, Link} from 'react-router-dom'
44
import {useSelector} from 'react-redux'
55

66
// Contexts
77
import {FlowContext} from 'src/flows/context/flow.current'
8+
import {FlowListContext} from 'src/flows/context/flow.list'
89
import {AppSettingProvider} from 'src/shared/contexts/app'
10+
import {deletePinnedItemByParam} from 'src/shared/contexts/pinneditems'
911

1012
// Components
1113
import {
@@ -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'
2025
import TimeZoneDropdown from 'src/shared/components/TimeZoneDropdown'
2126
import TimeRangeDropdown from 'src/flows/components/header/TimeRangeDropdown'
2227
import Submit from 'src/flows/components/header/Submit'
@@ -49,7 +54,9 @@ interface Share {
4954
}
5055

5156
const 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

Comments
 (0)