Skip to content

Commit f8e796f

Browse files
authored
add revoked jobs tab to feeds manager (#31)
1 parent 0ccfc20 commit f8e796f

File tree

6 files changed

+95
-11
lines changed

6 files changed

+95
-11
lines changed

.changeset/shiny-lobsters-check.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+
Add revoked jobs tab in feeds manager

src/screens/FeedsManager/JobProposalsCard.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
buildCancelledJobProposal,
1010
buildRejectedJobProposal,
1111
buildDeletedJobProposal,
12+
buildRevokedJobProposal,
1213
} from 'support/factories/gql/fetchFeedsManagersWithProposals'
1314
import { JobProposalsCard } from './JobProposalsCard'
1415

@@ -33,6 +34,7 @@ describe('JobProposalsCard', () => {
3334
buildCancelledJobProposal({ pendingUpdate: true }),
3435
buildDeletedJobProposal({ pendingUpdate: true }),
3536
buildDeletedJobProposal({ pendingUpdate: false }),
37+
buildRevokedJobProposal({ pendingUpdate: false }),
3638
]
3739

3840
renderWithRouter(<JobProposalsCard proposals={proposals} />)
@@ -92,4 +94,15 @@ describe('JobProposalsCard', () => {
9294
const rows = await findAllByRole('row')
9395
expect(rows).toHaveLength(2)
9496
})
97+
98+
it('renders the revoked job proposals', async () => {
99+
const proposals = buildJobProposals()
100+
101+
renderWithRouter(<JobProposalsCard proposals={proposals} />)
102+
103+
userEvent.click(getByRole('tab', { name: /revoked/i }))
104+
105+
const rows = await findAllByRole('row')
106+
expect(rows).toHaveLength(2)
107+
})
95108
})

src/screens/FeedsManager/JobProposalsCard.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const tabToStatus: { [key: number]: string } = {
2424
3: 'REJECTED',
2525
4: 'CANCELLED',
2626
5: 'DELETED',
27+
6: 'REVOKED',
2728
}
2829

2930
const styles = (theme: Theme) => {
@@ -86,6 +87,7 @@ export const JobProposalsCard = withStyles(styles)(
8687
REJECTED: number
8788
CANCELLED: number
8889
DELETED: number
90+
REVOKED: number
8991
} = React.useMemo(() => {
9092
const tabBadgeCounts = {
9193
PENDING: 0,
@@ -94,6 +96,7 @@ export const JobProposalsCard = withStyles(styles)(
9496
REJECTED: 0,
9597
CANCELLED: 0,
9698
DELETED: 0,
99+
REVOKED: 0,
97100
}
98101

99102
proposals.forEach((p) => {
@@ -118,6 +121,10 @@ export const JobProposalsCard = withStyles(styles)(
118121
case 'DELETED':
119122
tabBadgeCounts['DELETED']++
120123

124+
break
125+
case 'REVOKED':
126+
tabBadgeCounts['REVOKED']++
127+
121128
break
122129
default:
123130
break
@@ -167,6 +174,8 @@ export const JobProposalsCard = withStyles(styles)(
167174
return <ApprovedTable proposals={proposals} />
168175
case 'DELETED':
169176
return <InactiveTable proposals={proposals} />
177+
case 'REVOKED':
178+
return <InactiveTable proposals={proposals} />
170179
default:
171180
return null
172181
}
@@ -260,6 +269,18 @@ export const JobProposalsCard = withStyles(styles)(
260269
</Badge>
261270
}
262271
/>
272+
<Tab
273+
label={
274+
<Badge
275+
color="primary"
276+
badgeContent={tabBadgeCounts.REVOKED}
277+
className={classes.badge}
278+
data-testid="revoked-badge"
279+
>
280+
Revoked
281+
</Badge>
282+
}
283+
/>
263284
</Tabs>
264285

265286
{renderTable(filteredProposals)}

src/screens/JobProposal/SpecsView.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,22 @@ describe('SpecsView', () => {
242242
expect(queryByText('Cancel')).not.toBeInTheDocument()
243243
})
244244
})
245+
246+
describe('revoked proposal with pending spec', () => {
247+
let specs: ReadonlyArray<JobProposal_SpecsFields>
248+
let proposal: JobProposalPayloadFields
249+
250+
beforeEach(() => {
251+
proposal = buildJobProposal({ status: 'REVOKED' })
252+
specs = [buildJobProposalSpec({ status: 'PENDING' })]
253+
})
254+
255+
it('renders a revoked job proposal', async () => {
256+
renderComponent(specs, proposal)
257+
258+
expect(getByTestId('codeblock')).toHaveTextContent(specs[0].definition)
259+
expect(queryByText(/edit/i)).toBeNull()
260+
expect(queryByText('Cancel')).not.toBeInTheDocument()
261+
})
262+
})
245263
})

src/screens/JobProposal/SpecsView.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,17 @@ export const SpecsView = withStyles(styles)(
141141
Reject
142142
</Button>
143143

144-
{latestSpec.id === specID && proposal.status !== 'DELETED' && (
145-
<Button
146-
variant="contained"
147-
color="primary"
148-
onClick={() => openConfirmationDialog('approve', specID)}
149-
>
150-
Approve
151-
</Button>
152-
)}
144+
{latestSpec.id === specID &&
145+
proposal.status !== 'DELETED' &&
146+
proposal.status !== 'REVOKED' && (
147+
<Button
148+
variant="contained"
149+
color="primary"
150+
onClick={() => openConfirmationDialog('approve', specID)}
151+
>
152+
Approve
153+
</Button>
154+
)}
153155

154156
{latestSpec.id === specID &&
155157
proposal.status === 'DELETED' &&
@@ -190,7 +192,11 @@ export const SpecsView = withStyles(styles)(
190192
</>
191193
)
192194
case 'CANCELLED':
193-
if (latestSpec.id === specID && proposal.status !== 'DELETED') {
195+
if (
196+
latestSpec.id === specID &&
197+
proposal.status !== 'DELETED' &&
198+
proposal.status !== 'REVOKED'
199+
) {
194200
return (
195201
<Button
196202
variant="contained"
@@ -237,7 +243,8 @@ export const SpecsView = withStyles(styles)(
237243
{idx === 0 &&
238244
(spec.status === 'PENDING' ||
239245
spec.status === 'CANCELLED') &&
240-
proposal.status !== 'DELETED' && (
246+
proposal.status !== 'DELETED' &&
247+
proposal.status !== 'REVOKED' && (
241248
<Button
242249
variant="contained"
243250
onClick={() => setIsEditing(true)}

support/factories/gql/fetchFeedsManagersWithProposals.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,25 @@ export function buildDeletedJobProposal(
126126
}
127127
}
128128

129+
// buildRevokedJobProposal builds an cancelled job proposal.
130+
export function buildRevokedJobProposal(
131+
overrides?: Partial<FeedsManager_JobProposalsFields>,
132+
): FeedsManager_JobProposalsFields {
133+
const minuteAgo = isoDate(Date.now() - MINUTE_MS)
134+
135+
return {
136+
id: '400',
137+
remoteUUID: '00000000-0000-0000-0000-000000000004',
138+
status: 'REVOKED',
139+
pendingUpdate: false,
140+
latestSpec: {
141+
createdAt: minuteAgo,
142+
version: 1,
143+
},
144+
...overrides,
145+
}
146+
}
147+
129148
// buildJobProposals builds a list of job proposals each containing a different
130149
// status for a FetchFeedsManagersWithProposals query
131150
export function buildJobProposals(): FeedsManager_JobProposalsFields[] {
@@ -135,5 +154,6 @@ export function buildJobProposals(): FeedsManager_JobProposalsFields[] {
135154
buildRejectedJobProposal(),
136155
buildCancelledJobProposal(),
137156
buildDeletedJobProposal(),
157+
buildRevokedJobProposal(),
138158
]
139159
}

0 commit comments

Comments
 (0)