Skip to content

Commit 23ef0b2

Browse files
authored
feat: connect resources to notebook panel (#3537)
1 parent d6aac8f commit 23ef0b2

File tree

14 files changed

+245
-934
lines changed

14 files changed

+245
-934
lines changed

cypress/e2e/shared/flowsAlerts.test.ts

Lines changed: 39 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,9 @@ describe('flows alert panel', () => {
112112
'r._notebook_link'
113113
)
114114

115-
// make sure task export contains notebook link
116-
cy.getByTestID('task-form-save').click()
117-
cy.getByTestID('overlay--body').should('be.visible')
118-
cy.getByTestID('flux-editor').should('exist')
119-
cy.getByTestID('form--footer').scrollIntoView()
120-
cy.getByTestID('overlay--body').within(() => {
121-
cy.url().then(url => {
122-
cy.getByTestID('flux-editor').contains(
123-
`|> set(key: "_notebook_link", value: "${url}")`
124-
)
125-
})
126-
})
115+
// NOTE: we need to verify that the generated task flux contains
116+
// `|> set(key: "_notebook_link", value: "${url}")`
117+
// but we dont currently redirect to the task editor anymore
127118
})
128119

129120
it('should build alert for each endpoint', () => {
@@ -192,7 +183,6 @@ describe('flows alert panel', () => {
192183

193184
const fakeEmail = 'super@fake.com'
194185
const fakeUrl = 'super-fake.com'
195-
const fakeSecretFlux = 'secrets.get(key: "mySecret")'
196186
const fakeChannel = 'fake-channel'
197187

198188
// === AWS SES ===
@@ -213,19 +203,11 @@ describe('flows alert panel', () => {
213203
cy.getByTestID('dropdown-item--mySecret').click()
214204
cy.getByTestID('input--email').type(fakeEmail)
215205

216-
// make sure task export contains the fields
217206
cy.getByTestID('task-form-save').click()
218-
cy.getByTestID('export-as-overlay--header').should('be.visible')
219-
cy.getByTestID('flux-editor').should('exist')
220-
cy.getByTestID('form--footer').scrollIntoView()
221-
cy.getByTestID('overlay--body').within(() => {
222-
cy.getByTestID('flux-editor').contains(fakeUrl)
223-
cy.getByTestID('flux-editor').contains(fakeSecretFlux)
224-
cy.getByTestID('flux-editor').contains(fakeEmail)
225-
})
226-
227-
// close popup
228-
cy.get('.cf-overlay--dismiss').click()
207+
/* NOTE: we used to be able to test that the generated flux contained the the
208+
* selected values, but that mechanism has been removed from the product
209+
* we should add back that ability here
210+
*/
229211

230212
// === HTTP ===
231213

@@ -236,18 +218,11 @@ describe('flows alert panel', () => {
236218
cy.getByTestID('input--url').type(fakeUrl)
237219
cy.getByTestID('input--token').type('fake-token')
238220

239-
// make sure task export contains the fields
240221
cy.getByTestID('task-form-save').click()
241-
cy.getByTestID('export-as-overlay--header').should('be.visible')
242-
cy.getByTestID('flux-editor').should('exist')
243-
cy.getByTestID('form--footer').scrollIntoView()
244-
cy.getByTestID('overlay--body').within(() => {
245-
cy.getByTestID('flux-editor').contains(fakeUrl)
246-
cy.getByTestID('flux-editor').contains('fake-token')
247-
})
248-
249-
// close popup
250-
cy.get('.cf-overlay--dismiss').click()
222+
/* NOTE: we used to be able to test that the generated flux contained the the
223+
* selected values, but that mechanism has been removed from the product
224+
* we should add back that ability here
225+
*/
251226

252227
// === MAILGUN ===
253228
const mailgunDomain = 'fake.com'
@@ -259,19 +234,11 @@ describe('flows alert panel', () => {
259234
cy.getByTestID('dropdown-item--mySecret').click()
260235
cy.getByTestID('input--email').type(fakeEmail)
261236

262-
// make sure task export contains the fields
263237
cy.getByTestID('task-form-save').click()
264-
cy.getByTestID('export-as-overlay--header').should('be.visible')
265-
cy.getByTestID('flux-editor').should('exist')
266-
cy.getByTestID('form--footer').scrollIntoView()
267-
cy.getByTestID('overlay--body').within(() => {
268-
cy.getByTestID('flux-editor').contains(mailgunDomain)
269-
cy.getByTestID('flux-editor').contains(fakeSecretFlux)
270-
cy.getByTestID('flux-editor').contains(fakeEmail)
271-
})
272-
273-
// close popup
274-
cy.get('.cf-overlay--dismiss').click()
238+
/* NOTE: we used to be able to test that the generated flux contained the the
239+
* selected values, but that mechanism has been removed from the product
240+
* we should add back that ability here
241+
*/
275242

276243
// === MAILJET ===
277244

@@ -283,18 +250,11 @@ describe('flows alert panel', () => {
283250
cy.getByTestID('dropdown-item--mySecret').click()
284251
cy.getByTestID('input--email').type(fakeEmail)
285252

286-
// make sure task export contains the fields
287253
cy.getByTestID('task-form-save').click()
288-
cy.getByTestID('export-as-overlay--header').should('be.visible')
289-
cy.getByTestID('flux-editor').should('exist')
290-
cy.getByTestID('form--footer').scrollIntoView()
291-
cy.getByTestID('overlay--body').within(() => {
292-
cy.getByTestID('flux-editor').contains(fakeEmail)
293-
cy.getByTestID('flux-editor').contains(fakeSecretFlux)
294-
})
295-
296-
// close popup
297-
cy.get('.cf-overlay--dismiss').click()
254+
/* NOTE: we used to be able to test that the generated flux contained the the
255+
* selected values, but that mechanism has been removed from the product
256+
* we should add back that ability here
257+
*/
298258

299259
// === PAGERDUTY ===
300260
const pagerDutyRoutingKey = 'fake-key'
@@ -304,18 +264,11 @@ describe('flows alert panel', () => {
304264
cy.getByTestID('input--url').type(fakeUrl)
305265
cy.getByTestID('input--key').type(pagerDutyRoutingKey)
306266

307-
// make sure task export contains the fields
308267
cy.getByTestID('task-form-save').click()
309-
cy.getByTestID('export-as-overlay--header').should('be.visible')
310-
cy.getByTestID('flux-editor').should('exist')
311-
cy.getByTestID('form--footer').scrollIntoView()
312-
cy.getByTestID('overlay--body').within(() => {
313-
cy.getByTestID('flux-editor').contains(fakeUrl)
314-
cy.getByTestID('flux-editor').contains(pagerDutyRoutingKey)
315-
})
316-
317-
// close popup
318-
cy.get('.cf-overlay--dismiss').click()
268+
/* NOTE: we used to be able to test that the generated flux contained the the
269+
* selected values, but that mechanism has been removed from the product
270+
* we should add back that ability here
271+
*/
319272

320273
// === SENDGRID ===
321274

@@ -325,44 +278,26 @@ describe('flows alert panel', () => {
325278
cy.getByTestID('dropdown--apiKey').click()
326279
cy.getByTestID('dropdown-item--mySecret').click()
327280

328-
// make sure task export contains the fields
329281
cy.getByTestID('task-form-save').click()
330-
cy.getByTestID('export-as-overlay--header').should('be.visible')
331-
cy.getByTestID('flux-editor').should('exist')
332-
cy.getByTestID('form--footer').scrollIntoView()
333-
cy.getByTestID('overlay--body').within(() => {
334-
cy.getByTestID('flux-editor').contains(fakeEmail)
335-
cy.getByTestID('flux-editor').contains(fakeSecretFlux)
336-
})
337-
338-
// close popup
339-
cy.get('.cf-overlay--dismiss').click()
282+
/* NOTE: we used to be able to test that the generated flux contained the the
283+
* selected values, but that mechanism has been removed from the product
284+
* we should add back that ability here
285+
*/
340286

341287
// === SLACK ===
342-
const slackColor = '#34BB55'
343288

344289
// complete fields
345290
cy.getByTestID('dropdown-item--slack').click()
346291
cy.getByTestID('input--url').type(fakeUrl)
347292
cy.getByTestID('input--channel').type(fakeChannel)
348293

349-
// make sure task export contains the fields
350294
cy.getByTestID('task-form-save').click()
351-
cy.getByTestID('export-as-overlay--header').should('be.visible')
352-
cy.getByTestID('flux-editor').should('exist')
353-
cy.getByTestID('form--footer').scrollIntoView()
354-
cy.getByTestID('overlay--body').within(() => {
355-
cy.getByTestID('flux-editor').contains(fakeUrl)
356-
cy.getByTestID('flux-editor').contains(fakeChannel)
357-
cy.getByTestID('flux-editor').contains(slackColor)
358-
})
359-
360-
// close popup
361-
cy.get('.cf-overlay--dismiss').click()
295+
/* NOTE: we used to be able to test that the generated flux contained the the
296+
* selected values, but that mechanism has been removed from the product
297+
* we should add back that ability here
298+
*/
362299

363300
// === TELEGRAM ===
364-
const parseMode = 'MarkdownV2'
365-
const telegramURL = 'https://api.telegram.org/bot'
366301

367302
// complete fields
368303
cy.getByTestID('dropdown-item--telegram').click()
@@ -376,22 +311,11 @@ describe('flows alert panel', () => {
376311
cy.getByTestID('variable-form-save').click()
377312
cy.getByTestID('dropdown-button--token').contains('an apple a day')
378313

379-
// make sure task export contains the fields
380314
cy.getByTestID('task-form-save').click()
381-
cy.getByTestID('export-as-overlay--header').should('be.visible')
382-
cy.getByTestID('flux-editor').should('exist')
383-
cy.getByTestID('form--footer').scrollIntoView()
384-
cy.getByTestID('overlay--body').within(() => {
385-
cy.getByTestID('flux-editor').contains(telegramURL)
386-
cy.getByTestID('flux-editor').contains(fakeChannel)
387-
cy.getByTestID('flux-editor').contains(
388-
'secrets.get(key: "an apple a day")'
389-
)
390-
cy.getByTestID('flux-editor').contains(parseMode)
391-
})
392-
393-
// close popup
394-
cy.get('.cf-overlay--dismiss').click()
315+
/* NOTE: we used to be able to test that the generated flux contained the the
316+
* selected values, but that mechanism has been removed from the product
317+
* we should add back that ability here
318+
*/
395319

396320
// === ZENOSS ===
397321
const zenossAction = 'my-action'
@@ -409,20 +333,10 @@ describe('flows alert panel', () => {
409333
cy.getByTestID('input--action').type(zenossAction)
410334
cy.getByTestID('input--method').type(zenossMethod)
411335

412-
// make sure task export contains the fields
413336
cy.getByTestID('task-form-save').click()
414-
cy.getByTestID('export-as-overlay--header').should('be.visible')
415-
cy.getByTestID('flux-editor').should('exist')
416-
cy.getByTestID('form--footer').scrollIntoView()
417-
cy.getByTestID('overlay--body').within(() => {
418-
cy.getByTestID('flux-editor').contains(fakeUrl)
419-
cy.getByTestID('flux-editor').contains(fakeSecretFlux)
420-
cy.getByTestID('flux-editor').contains(zenossMethod)
421-
cy.getByTestID('flux-editor').contains(zenossAction)
422-
cy.getByTestID('flux-editor').contains('Critical')
423-
})
424-
425-
// close popup
426-
cy.get('.cf-overlay--dismiss').click()
337+
/* NOTE: we used to be able to test that the generated flux contained the the
338+
* selected values, but that mechanism has been removed from the product
339+
* we should add back that ability here
340+
*/
427341
})
428342
})

src/flows/pipes/Schedule/ExportTaskButton.tsx

Lines changed: 72 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import {checkTaskLimits} from 'src/cloud/actions/limits'
2121
// Components
2222
import {Button} from '@influxdata/clockface'
2323
import {PipeContext} from 'src/flows/context/pipe'
24-
import {PopupContext} from 'src/flows/context/popup'
25-
import ExportTaskOverlay from 'src/flows/pipes/Schedule/ExportTaskOverlay'
24+
import {FlowContext} from 'src/flows/context/flow.current'
2625

2726
// Utils
2827
import {event} from 'src/cloud/utils/reporting'
@@ -45,65 +44,90 @@ const ExportTaskButton: FC<Props> = ({
4544
onCreate,
4645
disabled,
4746
}) => {
48-
const {data, range} = useContext(PipeContext)
49-
const {launch} = useContext(PopupContext)
47+
const {flow} = useContext(FlowContext)
48+
const {data} = useContext(PipeContext)
5049
const dispatch = useDispatch()
5150
const org = useSelector(getOrg)
5251

5352
const onClick = () => {
5453
const query = generate ? generate() : data.query
5554

56-
if (isFlagEnabled('removeExportModal')) {
57-
event('Export Task Modal Skipped', {from: type})
58-
59-
// we can soft delete the previously connected task by marking the old one inactive
60-
if (data?.task?.id) {
61-
patchTask({
62-
taskID: data.task.id,
63-
data: {
64-
status: 'inactive',
65-
},
66-
})
67-
} else if ((data?.task ?? []).length) {
68-
patchTask({
69-
taskID: data.task[0].id,
70-
data: {
71-
status: 'inactive',
72-
},
73-
})
74-
}
55+
event('Export Task Modal Skipped', {from: type})
56+
let taskid
7557

76-
postTask({data: {orgID: org.id, flux: query}})
77-
.then(resp => {
78-
if (resp.status !== 201) {
79-
throw new Error(resp.data.message)
80-
}
58+
// we can soft delete the previously connected task by marking the old one inactive
59+
if (data?.task?.id) {
60+
taskid = data.task.id
61+
} else if ((data?.task ?? []).length) {
62+
taskid = data.task[0].id
63+
}
8164

82-
dispatch(notify(taskCreatedSuccess()))
83-
dispatch(checkTaskLimits())
65+
if (taskid) {
66+
patchTask({
67+
taskID: taskid,
68+
data: {
69+
status: 'inactive',
70+
},
71+
})
8472

85-
if (onCreate) {
86-
onCreate(resp.data)
87-
}
88-
})
89-
.catch(error => {
90-
if (error?.response?.status === ASSET_LIMIT_ERROR_STATUS) {
91-
dispatch(notify(resourceLimitReached('tasks')))
92-
} else {
93-
const message = getErrorMessage(error)
94-
dispatch(notify(taskNotCreated(message)))
73+
if (isFlagEnabled('createWithFlows')) {
74+
fetch(
75+
`/api/v2private/notebooks/${flow.id}/resources?type=tasks&resource=${taskid}`,
76+
{
77+
method: 'GET',
9578
}
96-
})
79+
)
80+
.then(resp => resp.json())
81+
.then(resp => {
82+
if (!resp.length) {
83+
return
84+
}
9785

98-
return
86+
fetch(
87+
`/api/v2private/notebooks/${flow.id}/resources/${resp[0].id}`,
88+
{
89+
method: 'DELETE',
90+
}
91+
)
92+
})
93+
}
9994
}
10095

101-
event('Export Task Clicked', {from: type})
102-
launch(<ExportTaskOverlay text={text} type={type} />, {
103-
bucket: data.bucket,
104-
query,
105-
range,
106-
})
96+
postTask({data: {orgID: org.id, flux: query}})
97+
.then(resp => {
98+
if (resp.status !== 201) {
99+
throw new Error(resp.data.message)
100+
}
101+
102+
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+
}
115+
116+
dispatch(notify(taskCreatedSuccess()))
117+
dispatch(checkTaskLimits())
118+
119+
if (onCreate) {
120+
onCreate(resp.data)
121+
}
122+
})
123+
.catch(error => {
124+
if (error?.response?.status === ASSET_LIMIT_ERROR_STATUS) {
125+
dispatch(notify(resourceLimitReached('tasks')))
126+
} else {
127+
const message = getErrorMessage(error)
128+
dispatch(notify(taskNotCreated(message)))
129+
}
130+
})
107131
}
108132

109133
return (

0 commit comments

Comments
 (0)