Skip to content

Commit 43f4e70

Browse files
authored
fix: save a notebook if it is ephemeral before linking (#3806)
1 parent a63c5a1 commit 43f4e70

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

src/flows/pipes/Schedule/ExportTaskButton.tsx

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Libraries
22
import React, {FC, useContext} from 'react'
3+
import {useHistory} from 'react-router-dom'
34
import {useDispatch, useSelector} from 'react-redux'
45
import {
56
ButtonType,
@@ -22,6 +23,7 @@ import {checkTaskLimits} from 'src/cloud/actions/limits'
2223
import {Button} from '@influxdata/clockface'
2324
import {PipeContext} from 'src/flows/context/pipe'
2425
import {FlowContext} from 'src/flows/context/flow.current'
26+
import {FlowListContext} from 'src/flows/context/flow.list'
2527

2628
// Utils
2729
import {event} from 'src/cloud/utils/reporting'
@@ -45,8 +47,10 @@ const ExportTaskButton: FC<Props> = ({
4547
disabled,
4648
}) => {
4749
const {flow} = useContext(FlowContext)
50+
const {add} = useContext(FlowListContext)
4851
const {data} = useContext(PipeContext)
4952
const dispatch = useDispatch()
53+
const history = useHistory()
5054
const org = useSelector(getOrg)
5155

5256
const onClick = () => {
@@ -100,24 +104,41 @@ const ExportTaskButton: FC<Props> = ({
100104
}
101105

102106
if (isFlagEnabled('createWithFlows')) {
103-
fetch(`/api/v2private/notebooks/${flow.id}/resources`, {
104-
method: 'POST',
105-
headers: {
106-
'Content-Type': 'application/json',
107-
},
108-
body: JSON.stringify({
109-
panel: data.id,
110-
resource: resp.data.id,
111-
type: 'tasks',
112-
}),
113-
})
114-
}
107+
new Promise(resolve => {
108+
if (flow.id) {
109+
resolve(flow.id)
110+
return
111+
}
115112

116-
dispatch(notify(taskCreatedSuccess()))
117-
dispatch(checkTaskLimits())
113+
add(flow).then(id => resolve(id))
114+
})
115+
.then(id => {
116+
return fetch(`/api/v2private/notebooks/${id}/resources`, {
117+
method: 'POST',
118+
headers: {
119+
'Content-Type': 'application/json',
120+
},
121+
body: JSON.stringify({
122+
panel: data.id,
123+
resource: resp.data.id,
124+
type: 'tasks',
125+
}),
126+
}).then(() => {
127+
return id
128+
})
129+
})
130+
.then(id => {
131+
dispatch(notify(taskCreatedSuccess()))
132+
dispatch(checkTaskLimits())
133+
134+
if (onCreate) {
135+
onCreate(resp.data)
136+
}
118137

119-
if (onCreate) {
120-
onCreate(resp.data)
138+
if (id !== flow.id) {
139+
history.replace(`/orgs/${org.id}/notebooks/${id}`)
140+
}
141+
})
121142
}
122143
})
123144
.catch(error => {

0 commit comments

Comments
 (0)