@@ -7,7 +7,7 @@ import React, {
77 createRef ,
88 RefObject ,
99} from 'react'
10- import { useHistory , Link } from 'react-router-dom'
10+ import { useHistory } from 'react-router-dom'
1111import { useSelector } from 'react-redux'
1212
1313// Contexts
@@ -24,7 +24,6 @@ import {
2424 IconFont ,
2525 ComponentColor ,
2626 ComponentStatus ,
27- Dropdown ,
2827 ErrorTooltip ,
2928 Popover ,
3029 PopoverInteraction ,
@@ -52,7 +51,6 @@ import {downloadImage} from 'src/shared/utils/download'
5251import { serialize } from 'src/flows/context/flow.list'
5352import { updatePinnedItemByParam } from 'src/shared/contexts/pinneditems'
5453import { getOrg } from 'src/organizations/selectors'
55- import { getAuthorizations } from 'src/client/generatedRoutes'
5654
5755// Types
5856import { RemoteDataState } from 'src/types'
@@ -108,10 +106,6 @@ const MenuButton: FC<ButtonProp> = ({menuItems}) => {
108106 </ >
109107 )
110108}
111- interface Token {
112- token : string
113- description : string
114- }
115109
116110interface Share {
117111 id : string
@@ -124,11 +118,9 @@ const FlowHeader: FC = () => {
124118 const history = useHistory ( )
125119 const { id : orgID } = useSelector ( getOrg )
126120 const [ sharing , setSharing ] = useState ( false )
127- const [ token , setToken ] = useState < Token > ( )
128- const [ loadingToken , setLoadingToken ] = useState ( RemoteDataState . NotStarted )
129- const [ tokens , setTokens ] = useState < Token [ ] > ( [ ] )
130121 const [ share , setShare ] = useState < Share > ( )
131122 const [ linkLoading , setLinkLoading ] = useState ( RemoteDataState . NotStarted )
123+ const [ linkDeleting , setLinkDeleting ] = useState ( RemoteDataState . NotStarted )
132124
133125 useEffect ( ( ) => {
134126 getNotebooksShare ( { query : { orgID : '' , notebookID : flow . id } } )
@@ -150,40 +142,23 @@ const FlowHeader: FC = () => {
150142 }
151143 }
152144
153- const showShare = ( ) => {
154- setSharing ( true )
155- setLoadingToken ( RemoteDataState . Loading )
156- getAuthorizations ( { query : { orgID} } ) . then ( resp => {
157- if ( resp . status !== 200 ) {
158- return
159- }
160-
161- setLoadingToken ( RemoteDataState . Done )
162- const _tokens = resp . data . authorizations . map ( a => ( {
163- token : a . token ,
164- description : a . description || 'Describe this token' ,
165- } ) )
166-
167- setTokens ( _tokens )
168- event ( 'Notebook share tokens' , { count : _tokens . length } )
169- } )
170- event ( 'Show Share Menu' , { share : ! ! share ? 'sharing' : 'not sharing' } )
171- }
172-
173145 const hideShare = ( ) => {
174146 setSharing ( false )
175- setToken ( null )
176- setLoadingToken ( RemoteDataState . NotStarted )
177147 }
178148
179149 const deleteShare = ( ) => {
150+ setLinkDeleting ( RemoteDataState . Loading )
180151 deleteNotebooksShare ( { id : share . id } )
181152 . then ( ( ) => {
153+ setLinkDeleting ( RemoteDataState . Done )
182154 hideShare ( )
183155 setShare ( null )
184156 event ( 'Delete Share Link' )
185157 } )
186- . catch ( err => console . error ( 'failed to delete share' , err ) )
158+ . catch ( err => {
159+ setLinkDeleting ( RemoteDataState . Error )
160+ console . error ( 'failed to delete share' , err )
161+ } )
187162 }
188163
189164 const canvasOptions = {
@@ -265,17 +240,24 @@ const FlowHeader: FC = () => {
265240 }
266241
267242 const generateLink = ( ) => {
243+ event ( 'Show Share Menu' , { share : ! ! share ? 'sharing' : 'not sharing' } )
244+
245+ if ( ! ! share ) {
246+ setSharing ( true )
247+ return
248+ }
249+
268250 setLinkLoading ( RemoteDataState . Loading )
269251 postNotebooksShare ( {
270252 data : {
271253 notebookID : flow . id ,
272254 orgID,
273- token : token . token ,
274255 region : window . location . hostname ,
275256 } ,
276257 } )
277258 . then ( res => {
278259 setLinkLoading ( RemoteDataState . Done )
260+ setSharing ( true )
279261 setShare ( {
280262 id : ( res . data as Share ) . id ,
281263 accessID : ( res . data as Share ) . accessID ,
@@ -344,37 +326,6 @@ const FlowHeader: FC = () => {
344326 return null
345327 }
346328
347- let tokenDropdownStatus = ComponentStatus . Disabled
348-
349- if ( loadingToken === RemoteDataState . Loading ) {
350- tokenDropdownStatus = ComponentStatus . Loading
351- }
352- if ( loadingToken === RemoteDataState . Done && tokens . length ) {
353- tokenDropdownStatus = ComponentStatus . Default
354- }
355-
356- let linkGenerationStatus = ComponentStatus . Disabled
357-
358- if ( linkLoading === RemoteDataState . Loading ) {
359- linkGenerationStatus = ComponentStatus . Loading
360- } else if ( ! ! token ) {
361- linkGenerationStatus = ComponentStatus . Default
362- }
363-
364- const tokenOptions = tokens . map ( t => (
365- < Dropdown . Item
366- key = { t . token }
367- value = { t . token }
368- selected = { t . token === token ?. token }
369- title = { t . description }
370- className = "share-token--option"
371- onClick = { ( ) => setToken ( t ) }
372- >
373- < h1 > { t . description } </ h1 >
374- < h3 > { t . token } </ h3 >
375- </ Dropdown . Item >
376- ) )
377-
378329 return (
379330 < >
380331 < Page . Header fullWidth >
@@ -400,10 +351,15 @@ const FlowHeader: FC = () => {
400351 < >
401352 < SquareButton
402353 icon = { IconFont . Share }
403- onClick = { showShare }
354+ onClick = { generateLink }
404355 color = {
405356 ! ! share ? ComponentColor . Primary : ComponentColor . Secondary
406357 }
358+ status = {
359+ linkLoading === RemoteDataState . Loading
360+ ? ComponentStatus . Loading
361+ : ComponentStatus . Default
362+ }
407363 titleText = "Share Notebook"
408364 />
409365 < MenuButton menuItems = { menuItems } />
@@ -420,52 +376,6 @@ const FlowHeader: FC = () => {
420376 </ Page . ControlBarRight >
421377 </ Page . ControlBar >
422378 ) }
423- { ! ! sharing && ! share && (
424- < Page . ControlBar fullWidth >
425- < Page . ControlBarRight >
426- < p className = "share-token--steps" >
427- Choose an{ ' ' }
428- < Link to = { `/orgs/${ orgID } /load-data/tokens` } > API Token</ Link > { ' ' }
429- scoped to the resources you want to share
430- </ p >
431- < Dropdown
432- button = { ( active , onClick ) => (
433- < Dropdown . Button
434- onClick = { onClick }
435- active = { active }
436- status = { tokenDropdownStatus }
437- >
438- { token ? token . description : 'Select an API Token' }
439- </ Dropdown . Button >
440- ) }
441- menu = { onCollapse => (
442- < Dropdown . Menu onCollapse = { onCollapse } >
443- { tokenOptions }
444- </ Dropdown . Menu >
445- ) }
446- style = { { width : '250px' , flex : '0 0 250px' } }
447- />
448- < ErrorTooltip
449- className = "warning-icon"
450- tooltipContents = "By sharing this link, your org may incur charges when a user visits the page and the query is run."
451- tooltipStyle = { { width : '250px' } }
452- />
453- < SquareButton
454- icon = { IconFont . Checkmark_New }
455- onClick = { generateLink }
456- color = { ComponentColor . Success }
457- status = { linkGenerationStatus }
458- titleText = "Set Token"
459- />
460- < SquareButton
461- icon = { IconFont . Remove_New }
462- onClick = { hideShare }
463- color = { ComponentColor . Danger }
464- titleText = "Cancel"
465- />
466- </ Page . ControlBarRight >
467- </ Page . ControlBar >
468- ) }
469379 { ! ! sharing && ! ! share && (
470380 < Page . ControlBar fullWidth >
471381 < Page . ControlBarRight >
@@ -478,11 +388,21 @@ const FlowHeader: FC = () => {
478388 { `${ window . location . origin } /share/${ share . accessID } ` }
479389 </ a >
480390 </ p >
391+ < ErrorTooltip
392+ className = "warning-icon"
393+ tooltipContents = "By sharing this link, your org may incur charges when a user visits the page and the query is run."
394+ tooltipStyle = { { width : '250px' } }
395+ />
481396 < SquareButton
482397 icon = { IconFont . Trash_New }
483398 onClick = { deleteShare }
484399 color = { ComponentColor . Danger }
485400 titleText = "Delete"
401+ status = {
402+ linkDeleting === RemoteDataState . Loading
403+ ? ComponentStatus . Loading
404+ : ComponentStatus . Default
405+ }
486406 />
487407 < SquareButton
488408 icon = { IconFont . Remove_New }
0 commit comments