@@ -9,11 +9,15 @@ import React, {
99 RefObject ,
1010} from 'react'
1111import { useHistory } from 'react-router-dom'
12- import { useDispatch , useSelector } from 'react-redux'
12+ import { useSelector } from 'react-redux'
1313
1414// Contexts
1515import { FlowContext } from 'src/flows/context/flow.current'
1616import { FlowListContext } from 'src/flows/context/flow.list'
17+ import {
18+ VersionPublishContext ,
19+ VersionPublishProvider ,
20+ } from 'src/flows/context/version.publish'
1721import { AppSettingProvider } from 'src/shared/contexts/app'
1822import { deletePinnedItemByParam } from 'src/shared/contexts/pinneditems'
1923
@@ -31,6 +35,7 @@ import {
3135 List ,
3236} from '@influxdata/clockface'
3337
38+ import PublishedVersions from 'src/flows/components/header/PublishedVersions'
3439import AutoRefreshButton from 'src/flows/components/header/AutoRefreshButton'
3540import TimeZoneDropdown from 'src/shared/components/TimeZoneDropdown'
3641import TimeRangeDropdown from 'src/flows/components/header/TimeRangeDropdown'
@@ -46,18 +51,13 @@ import {
4651 getNotebooksShare ,
4752 deleteNotebooksShare ,
4853 postNotebooksShare ,
49- postNotebooksVersion ,
5054} from 'src/client/notebooksRoutes'
5155import { event } from 'src/cloud/utils/reporting'
5256import { downloadImage } from 'src/shared/utils/download'
5357import { serialize } from 'src/flows/context/flow.list'
5458import { updatePinnedItemByParam } from 'src/shared/contexts/pinneditems'
5559import { getOrg } from 'src/organizations/selectors'
56- import { notify } from 'src/shared/actions/notifications'
57- import {
58- publishNotebookFailed ,
59- publishNotebookSuccessful ,
60- } from 'src/shared/copy/notifications'
60+
6161// Types
6262import { RemoteDataState } from 'src/types'
6363
@@ -123,15 +123,12 @@ interface Share {
123123}
124124
125125const FlowHeader : FC = ( ) => {
126- const dispatch = useDispatch ( )
127126 const { remove, clone} = useContext ( FlowListContext )
128127 const { flow, updateOther} = useContext ( FlowContext )
128+ const { handlePublish, publishLoading} = useContext ( VersionPublishContext )
129129 const history = useHistory ( )
130130 const { id : orgID } = useSelector ( getOrg )
131131 const [ sharing , setSharing ] = useState ( false )
132- const [ publishLoading , setPublishLoading ] = useState < RemoteDataState > (
133- RemoteDataState . NotStarted
134- )
135132 const [ share , setShare ] = useState < Share > ( )
136133 const [ linkLoading , setLinkLoading ] = useState ( RemoteDataState . NotStarted )
137134 const [ linkDeleting , setLinkDeleting ] = useState ( RemoteDataState . NotStarted )
@@ -147,34 +144,12 @@ const FlowHeader: FC = () => {
147144 . catch ( err => console . error ( 'failed to get notebook share' , err ) )
148145 } , [ flow . id ] )
149146
150- const handlePublish = useCallback ( async ( ) => {
151- if ( isFlagEnabled ( 'flowPublishLifecycle' ) ) {
152- setPublishLoading ( RemoteDataState . Loading )
153- try {
154- const response = await postNotebooksVersion ( { id : flow . id } )
155-
156- if ( response . status !== 204 ) {
157- throw new Error ( response . data . message )
158- }
159-
160- dispatch ( notify ( publishNotebookSuccessful ( flow . name ) ) )
161- setPublishLoading ( RemoteDataState . Done )
162- } catch ( error ) {
163- console . error ( { error} )
164- dispatch ( notify ( publishNotebookFailed ( flow . name ) ) )
165- setPublishLoading ( RemoteDataState . Error )
166- }
167- }
168- } , [ dispatch , flow . id , flow . name ] )
169-
170147 const handleSave = useCallback (
171148 event => {
149+ event . preventDefault ( )
172150 if ( isFlagEnabled ( 'flowPublishLifecycle' ) ) {
173151 if ( ( event . ctrlKey || event . metaKey ) && event . key === 's' ) {
174- // Prevent the Save dialog to open
175- event . preventDefault ( )
176152 handlePublish ( )
177- // Place your code here
178153 }
179154 }
180155 } ,
@@ -453,6 +428,13 @@ const FlowHeader: FC = () => {
453428 </ Page . ControlBarRight >
454429 </ Page . ControlBar >
455430 ) }
431+ { isFlagEnabled ( 'flowPublishLifecycle' ) && (
432+ < Page . ControlBar fullWidth >
433+ < Page . ControlBarRight >
434+ < PublishedVersions />
435+ </ Page . ControlBarRight >
436+ </ Page . ControlBar >
437+ ) }
456438 { ! ! sharing && ! ! share && (
457439 < Page . ControlBar fullWidth >
458440 < Page . ControlBarRight >
@@ -496,6 +478,8 @@ const FlowHeader: FC = () => {
496478
497479export default ( ) => (
498480 < AppSettingProvider >
499- < FlowHeader />
481+ < VersionPublishProvider >
482+ < FlowHeader />
483+ </ VersionPublishProvider >
500484 </ AppSettingProvider >
501485)
0 commit comments