1- import React , { FC , createRef , RefObject , useContext } from 'react'
1+ import React , { FC , createRef , RefObject , useContext , useState } from 'react'
22import {
33 IconFont ,
44 Icon ,
@@ -7,12 +7,14 @@ import {
77 PopoverInteraction ,
88 SquareButton ,
99 InfluxColors ,
10+ RemoteDataState ,
11+ SpinnerContainer ,
12+ TechnoSpinner ,
1013} from '@influxdata/clockface'
1114import { useSelector } from 'react-redux'
1215
1316// Contexts
1417import { FlowContext } from 'src/flows/context/flow.current'
15- import { FlowListContext } from 'src/flows/context/flow.list'
1618import { VersionPublishContext } from 'src/flows/context/version.publish'
1719import { useHistory } from 'react-router-dom'
1820
@@ -33,32 +35,44 @@ type Props = {
3335}
3436
3537const MenuButton : FC < Props > = ( { handleResetShare} ) => {
36- const { remove, clone} = useContext ( FlowListContext )
37- const { flow} = useContext ( FlowContext )
38+ const { flow, cloneNotebook, deleteNotebook} = useContext ( FlowContext )
3839 const { handlePublish, versions} = useContext ( VersionPublishContext )
3940 const { id : orgID } = useSelector ( getOrg )
41+ const [ loading , setLoading ] = useState ( RemoteDataState . Done )
4042
4143 const triggerRef : RefObject < HTMLButtonElement > = createRef ( )
4244 const history = useHistory ( )
4345
4446 const handleClone = async ( ) => {
45- event ( 'clone_notebook' , {
46- context : 'notebook' ,
47- } )
48- const clonedId = await clone ( flow . id )
49- handleResetShare ( )
50- history . push (
51- `/orgs/${ orgID } /${ PROJECT_NAME_PLURAL . toLowerCase ( ) } /${ clonedId } `
52- )
47+ try {
48+ setLoading ( RemoteDataState . Loading )
49+ event ( 'clone_notebook' , {
50+ context : 'notebook' ,
51+ } )
52+ const clonedId = await cloneNotebook ( )
53+ handleResetShare ( )
54+ setLoading ( RemoteDataState . Done )
55+ history . push (
56+ `/orgs/${ orgID } /${ PROJECT_NAME_PLURAL . toLowerCase ( ) } /${ clonedId } `
57+ )
58+ } catch {
59+ setLoading ( RemoteDataState . Done )
60+ }
5361 }
5462
55- const handleDelete = ( ) => {
56- event ( 'delete_notebook' , {
57- context : 'notebook' ,
58- } )
59- deletePinnedItemByParam ( flow . id )
60- remove ( flow . id )
61- history . push ( `/orgs/${ orgID } /${ PROJECT_NAME_PLURAL . toLowerCase ( ) } ` )
63+ const handleDelete = async ( ) => {
64+ try {
65+ setLoading ( RemoteDataState . Loading )
66+ event ( 'delete_notebook' , {
67+ context : 'notebook' ,
68+ } )
69+ deletePinnedItemByParam ( flow . id )
70+ await deleteNotebook ( )
71+ setLoading ( RemoteDataState . Done )
72+ history . push ( `/orgs/${ orgID } /${ PROJECT_NAME_PLURAL . toLowerCase ( ) } ` )
73+ } catch {
74+ setLoading ( RemoteDataState . Error )
75+ }
6276 }
6377
6478 const canvasOptions = {
@@ -216,51 +230,57 @@ const MenuButton: FC<Props> = ({handleResetShare}) => {
216230 }
217231
218232 return (
219- < >
220- < SquareButton
221- ref = { triggerRef }
222- icon = { IconFont . More }
223- testID = "flow-menu-button"
224- />
225- < Popover
226- triggerRef = { triggerRef }
227- enableDefaultStyles = { false }
228- style = { { minWidth : 209 } }
229- onShow = { ( ) => {
230- event ( 'Notebook main menu opened' )
231- } }
232- showEvent = { PopoverInteraction . Click }
233- hideEvent = { PopoverInteraction . Click }
234- contents = { onHide => (
235- < List >
236- { menuItems . map ( item => {
237- if ( item . type === 'divider' ) {
233+ < SpinnerContainer
234+ loading = { loading }
235+ spinnerComponent = { < TechnoSpinner style = { { width : 20 , height : 20 } } /> }
236+ style = { { width : 20 , height : 20 } }
237+ >
238+ < >
239+ < SquareButton
240+ ref = { triggerRef }
241+ icon = { IconFont . More }
242+ testID = "flow-menu-button"
243+ />
244+ < Popover
245+ triggerRef = { triggerRef }
246+ enableDefaultStyles = { false }
247+ style = { { minWidth : 209 } }
248+ onShow = { ( ) => {
249+ event ( 'Notebook main menu opened' )
250+ } }
251+ showEvent = { PopoverInteraction . Click }
252+ hideEvent = { PopoverInteraction . Click }
253+ contents = { onHide => (
254+ < List >
255+ { menuItems . map ( item => {
256+ if ( item . type === 'divider' ) {
257+ return (
258+ < List . Divider
259+ key = { item . title }
260+ style = { { backgroundColor : InfluxColors . Grey35 } }
261+ />
262+ )
263+ }
238264 return (
239- < List . Divider
265+ < List . Item
240266 key = { item . title }
241- style = { { backgroundColor : InfluxColors . Grey35 } }
242- />
267+ disabled = { item ?. disabled ? item . disabled ( ) : false }
268+ onClick = { ( ) => {
269+ item ?. onClick ( )
270+ onHide ( )
271+ } }
272+ testID = { item ?. testID || '' }
273+ >
274+ < Icon glyph = { item ?. icon } />
275+ < span style = { { paddingLeft : '10px' } } > { item . title } </ span >
276+ </ List . Item >
243277 )
244- }
245- return (
246- < List . Item
247- key = { item . title }
248- disabled = { item ?. disabled ? item . disabled ( ) : false }
249- onClick = { ( ) => {
250- item ?. onClick ( )
251- onHide ( )
252- } }
253- testID = { item ?. testID || '' }
254- >
255- < Icon glyph = { item ?. icon } />
256- < span style = { { paddingLeft : '10px' } } > { item . title } </ span >
257- </ List . Item >
258- )
259- } ) }
260- </ List >
261- ) }
262- />
263- </ >
278+ } ) }
279+ </ List >
280+ ) }
281+ />
282+ </ >
283+ </ SpinnerContainer >
264284 )
265285}
266286
0 commit comments