Skip to content

Commit 6917e8a

Browse files
authored
Fix task list display of completed runs (#29)
1 parent 782ef0a commit 6917e8a

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

.changeset/sweet-queens-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@smartcontractkit/operator-ui': patch
3+
---
4+
5+
Fixed a bug where the Task List would not be displayed correctly if a run was successfully completed.

src/components/Cards/TaskListDAG.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ function createDag({
119119
.attr('stroke-width', 6)
120120
.attr('fill', (node) => {
121121
switch (node.data.attributes?.status) {
122-
case 'in_progress':
122+
case TaskRunStatus.PENDING:
123123
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
124124
// @ts-ignore because material UI doesn't update theme types with options
125125
return theme.palette.warning.main
126-
case 'completed':
126+
case TaskRunStatus.COMPLETE:
127127
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
128128
// @ts-ignore because material UI doesn't update theme types with options
129129
return theme.palette.success.main
130-
case 'errored':
130+
case TaskRunStatus.ERROR:
131131
return theme.palette.error.main
132132
default:
133133
return theme.palette.grey['500']

src/screens/JobRun/JobRunView.test.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { renderWithRouter, screen } from 'test-utils'
55

66
import { JobRunView } from './JobRunView'
77
import { buildRun, buildTaskRun } from 'support/factories/gql/fetchJobRun'
8+
import { theme } from 'theme'
89

910
const { queryByRole, queryByText } = screen
1011

@@ -54,4 +55,46 @@ describe('JobView', () => {
5455
// Task Runs Card
5556
expect(queryByText(/jsonparse/i)).toBeInTheDocument()
5657
})
58+
59+
it('renders the job run view with no errors ', async () => {
60+
const run = buildRun({
61+
status: 'COMPLETED',
62+
allErrors: [],
63+
job: {
64+
id: '10',
65+
name: 'job 1',
66+
observationSource: `ds1 [type=bridge name="bridge-api0"] ds2 [type=bridge name="bridge-api1"]`,
67+
},
68+
taskRuns: [
69+
buildTaskRun({ dotID: 'ds1' }),
70+
buildTaskRun({ dotID: 'ds2' }),
71+
],
72+
})
73+
74+
renderComponent(run)
75+
76+
// Heading
77+
expect(queryByText(`Job Run #${run.id}`)).toBeInTheDocument()
78+
79+
// Job Run Card
80+
expect(queryByText(run.id)).toBeInTheDocument()
81+
82+
// Tabs
83+
expect(queryByRole('tab', { name: 'Overview' })).toBeInTheDocument()
84+
expect(queryByRole('tab', { name: 'JSON' })).toBeInTheDocument()
85+
86+
// Task List Card
87+
expect(queryByText(/task list/i)).toBeInTheDocument()
88+
89+
// ds1 and ds2 are correctly displayed
90+
const ds1 = queryByText(/ds1/, { selector: 'text' })?.parentNode?.firstChild
91+
const ds2 = queryByText(/ds2/, { selector: 'text' })?.parentNode?.firstChild
92+
93+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
94+
// @ts-expect-error because material UI doesn't update theme types with options
95+
expect(ds1).toHaveAttribute('fill', theme.palette.success.main)
96+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
97+
// @ts-expect-error because material UI doesn't update theme types with options
98+
expect(ds2).toHaveAttribute('fill', theme.palette.success.main)
99+
})
57100
})

src/screens/JobRun/JobRunView.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { TaskListCard } from 'src/components/Cards/TaskListCard'
1515
import { TaskRunsCard } from './TaskRunsCard'
1616
import { JSONCard } from './JSONCard'
1717
import { TaskRunStatus } from 'src/utils/taskRunStatus'
18+
import { parseDot } from 'utils/parseDot'
1819

1920
export const JOB_RUN_PAYLOAD__TASK_RUNS_FIELDS = gql`
2021
fragment JobRunPayload_TaskRunsFields on TaskRun {
@@ -59,7 +60,8 @@ export const JobRunView = ({ run }: Props) => {
5960

6061
// Generate a list of attributes which will get added to the stratify array.
6162
// We do this so we can display the correct status icon in the TaskList DAG
62-
const attrs = run.taskRuns.reduce((acc, run) => {
63+
type Attributes = Record<string, { status: TaskRunStatus }>
64+
const attrs = run.taskRuns.reduce<Attributes>((acc, run) => {
6365
let status: TaskRunStatus
6466

6567
if (run.error) {
@@ -78,6 +80,18 @@ export const JobRunView = ({ run }: Props) => {
7880
}
7981
}, {})
8082

83+
//When there are no errors, taskRun is empty so attributes are not set, we
84+
//must insert attributes
85+
if (run.allErrors.length == 0) {
86+
const graph = parseDot(`digraph {${run.job.observationSource}}`)
87+
graph.forEach((node) => {
88+
attrs[node.id] = {
89+
...node.attributes,
90+
status: TaskRunStatus.COMPLETE,
91+
}
92+
})
93+
}
94+
8195
return (
8296
<Content>
8397
<Grid container spacing={16}>

0 commit comments

Comments
 (0)