Skip to content

Commit 1f66cfc

Browse files
authored
feat: keep track of multiple tasks (#3330)
1 parent b25aa3a commit 1f66cfc

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed

cypress/e2e/shared/dashboardsView.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ describe('Dashboard', () => {
105105

106106
cy.getByTestID('add-note--button').click()
107107
cy.getByTestID('note-editor--overlay').within(() => {
108-
cy.getByTestID('markdown-editor').within(() => {
109-
cy.get('textarea').type(`${headerPrefix} ${noteText}`, {force: true})
110-
})
108+
cy.get('.monaco-editor .view-line:last')
109+
.click({force: true})
110+
.focused()
111+
.type(`${headerPrefix} ${noteText}`, {force: true, delay: 1})
111112

112113
cy.getByTestID('note-editor--preview').contains(noteText)
113114
cy.getByTestID('note-editor--preview').should('not.contain', headerPrefix)
@@ -169,11 +170,10 @@ describe('Dashboard', () => {
169170
const headerPrefix2 = '-'
170171

171172
cy.getByTestID('note-editor--overlay').within(() => {
172-
cy.getByTestID('markdown-editor').within(() => {
173-
cy.get('textarea')
174-
.clear({force: true})
175-
.type(`${headerPrefix2} ${noteText2}`)
176-
})
173+
cy.get('.monaco-editor .view-line:last')
174+
.click({force: true})
175+
.focused()
176+
.type(`${headerPrefix2} ${noteText2}`, {force: true, delay: 1})
177177
cy.getByTestID('note-editor--preview').contains(noteText2)
178178
cy.getByTestID('note-editor--preview').should(
179179
'not.contain',

cypress/e2e/shared/tasks.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ http.post(url: "https://foo.bar/baz", data: bytes(v: "body"))`
7777
cy.getByTestID('task-card-cron-btn').click()
7878
cy.getByTestID('task-form-schedule-input')
7979
.click()
80+
.clear()
8081
.type('0 4 8-14 * *')
8182
cy.getByTestID('task-form-offset-input')
8283
.click()
84+
.clear()
8385
.type('10m')
8486

8587
cy.getByTestID('task-save-btn').click()
@@ -124,9 +126,11 @@ http.post(url: "https://foo.bar/baz", data: bytes(v: "body"))`
124126
.then(() => {
125127
cy.getByTestID('task-form-schedule-input')
126128
.click()
129+
.clear()
127130
.type('24h')
128131
cy.getByTestID('task-form-offset-input')
129132
.click()
133+
.clear()
130134
.type('20m')
131135
})
132136

src/flows/pipes/Schedule/ExportTaskButton.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ const ExportTaskButton: FC<Props> = ({
6464
status: 'inactive',
6565
},
6666
})
67+
} else if ((data?.task ?? []).length) {
68+
patchTask({
69+
taskID: data.task[0].id,
70+
data: {
71+
status: 'inactive',
72+
},
73+
})
6774
}
6875

6976
postTask({data: {orgID: org.id, flux: query}})

src/flows/pipes/Schedule/History.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import {PopupContext} from 'src/flows/context/popup'
2525

2626
import {event} from 'src/cloud/utils/reporting'
2727

28+
interface ListProps {
29+
tasks: Task[]
30+
}
31+
2832
interface Props {
2933
task: Task
3034
}
@@ -292,9 +296,11 @@ const History: FC<Props> = ({task}) => {
292296
)
293297
}
294298

295-
const WrappedHistory: FC<Props> = ({task}) => (
299+
const WrappedHistory: FC<ListProps> = ({tasks}) => (
296300
<ErrorBoundary>
297-
<History task={task} />
301+
{tasks.map(task => (
302+
<History key={task.id} task={task} />
303+
))}
298304
</ErrorBoundary>
299305
)
300306
export default WrappedHistory

src/flows/pipes/Schedule/view.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,13 @@ const Schedule: FC<PipeProp> = ({Context}) => {
229229
return format_from_js_file(ast)
230230
}, [queryText, data.interval, data.offset])
231231
const hasChanges = useMemo(() => {
232-
return taskText !== data?.task?.flux
232+
if (data.task?.id) {
233+
return taskText !== data.task.flux
234+
}
235+
if (data.task.length) {
236+
return taskText !== data.task[0].flux
237+
}
238+
return false
233239
}, [taskText, data?.task?.flux])
234240

235241
const updateInterval = evt => {
@@ -274,12 +280,14 @@ const Schedule: FC<PipeProp> = ({Context}) => {
274280
}, [taskText])
275281

276282
const storeTask = (task: any) => {
283+
const list = ((data.task.id ? [data.task] : data.task) || []).slice(0)
284+
list.unshift({
285+
id: task.id,
286+
name: task.name,
287+
flux: task.flux,
288+
})
277289
update({
278-
task: {
279-
id: task.id,
280-
name: task.name,
281-
flux: task.flux,
282-
},
290+
task: list,
283291
})
284292
}
285293

@@ -294,7 +302,7 @@ const Schedule: FC<PipeProp> = ({Context}) => {
294302
actions: [
295303
{
296304
title: 'View Run History',
297-
menu: <History task={data.task} />,
305+
menu: <History tasks={data.task.id ? data.task : data.task} />,
298306
},
299307
],
300308
},

0 commit comments

Comments
 (0)