Skip to content

Commit

Permalink
add deleted tab in fms
Browse files Browse the repository at this point in the history
  • Loading branch information
eutopian committed Mar 3, 2023
1 parent ffd9ff4 commit c91c2a5
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 91 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-chefs-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@smartcontractkit/operator-ui': patch
---

Allow job deletion requests to be sent from FMS
4 changes: 2 additions & 2 deletions src/screens/FeedsManager/ApprovedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export const ApprovedTable = withStyles(tableStyles)(
</TableHead>

<TableBody>
{proposals?.map((proposal, idx) => (
<TableRow key={idx} className={classes.row} hover>
{proposals?.map((proposal) => (
<TableRow key={proposal.id} className={classes.row} hover>
<TableCell className={classes.cell} component="th" scope="row">
<Link
className={classes.link}
Expand Down
4 changes: 2 additions & 2 deletions src/screens/FeedsManager/InactiveTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const InactiveTable = withStyles(tableStyles)(
</TableHead>

<TableBody>
{proposals?.map((proposal, idx) => (
<TableRow key={idx} className={classes.row} hover>
{proposals?.map((proposal) => (
<TableRow key={proposal.id} className={classes.row} hover>
<TableCell className={classes.cell} component="th" scope="row">
<Link
className={classes.link}
Expand Down
19 changes: 17 additions & 2 deletions src/screens/FeedsManager/JobProposalsCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
buildApprovedJobProposal,
buildCancelledJobProposal,
buildRejectedJobProposal,
buildDeletedJobProposal,
} from 'support/factories/gql/fetchFeedsManagersWithProposals'
import { JobProposalsCard } from './JobProposalsCard'

Expand All @@ -30,19 +31,22 @@ describe('JobProposalsCard', () => {
buildApprovedJobProposal({ pendingUpdate: true }),
buildRejectedJobProposal({ pendingUpdate: true }),
buildCancelledJobProposal({ pendingUpdate: true }),
buildDeletedJobProposal({ pendingUpdate: true }),
buildDeletedJobProposal({ pendingUpdate: false }),
]

renderWithRouter(<JobProposalsCard proposals={proposals} />)

expect(getByTestId('updates-badge')).toHaveTextContent('3')
expect(getByTestId('updates-badge')).toHaveTextContent('4')
expect(getByTestId('approved-badge')).toHaveTextContent('1')
expect(getByTestId('rejected-badge')).toHaveTextContent('1')
expect(getByTestId('cancelled-badge')).toHaveTextContent('1')
expect(getByTestId('deleted-badge')).toHaveTextContent('1')

userEvent.click(getByRole('tab', { name: /updates/i }))

const rows = await findAllByRole('row')
expect(rows).toHaveLength(4)
expect(rows).toHaveLength(5)
})

it('renders the approved job proposals', async () => {
Expand Down Expand Up @@ -77,4 +81,15 @@ describe('JobProposalsCard', () => {
const rows = await findAllByRole('row')
expect(rows).toHaveLength(2)
})

it('renders the deleted job proposals', async () => {
const proposals = buildJobProposals()

renderWithRouter(<JobProposalsCard proposals={proposals} />)

userEvent.click(getByRole('tab', { name: /deleted/i }))

const rows = await findAllByRole('row')
expect(rows).toHaveLength(2)
})
})
21 changes: 21 additions & 0 deletions src/screens/FeedsManager/JobProposalsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const tabToStatus: { [key: number]: string } = {
2: 'APPROVED',
3: 'REJECTED',
4: 'CANCELLED',
5: 'DELETED',
}

const styles = (theme: Theme) => {
Expand Down Expand Up @@ -84,13 +85,15 @@ export const JobProposalsCard = withStyles(styles)(
APPROVED: number
REJECTED: number
CANCELLED: number
DELETED: number
} = React.useMemo(() => {
const tabBadgeCounts = {
PENDING: 0,
UPDATES: 0,
APPROVED: 0,
REJECTED: 0,
CANCELLED: 0,
DELETED: 0,
}

proposals.forEach((p) => {
Expand All @@ -111,6 +114,10 @@ export const JobProposalsCard = withStyles(styles)(
case 'REJECTED':
tabBadgeCounts['REJECTED']++

break
case 'DELETED':
tabBadgeCounts['DELETED']++

break
default:
break
Expand Down Expand Up @@ -158,6 +165,8 @@ export const JobProposalsCard = withStyles(styles)(
return <InactiveTable proposals={proposals} />
case 'APPROVED':
return <ApprovedTable proposals={proposals} />
case 'DELETED':
return <InactiveTable proposals={proposals} />
default:
return null
}
Expand Down Expand Up @@ -239,6 +248,18 @@ export const JobProposalsCard = withStyles(styles)(
</Badge>
}
/>
<Tab
label={
<Badge
color="primary"
badgeContent={tabBadgeCounts.DELETED}
className={classes.badge}
data-testid="deleted-badge"
>
Deleted
</Badge>
}
/>
</Tabs>

{renderTable(filteredProposals)}
Expand Down
4 changes: 2 additions & 2 deletions src/screens/FeedsManager/PendingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const PendingTable = withStyles(tableStyles)(
</TableHead>

<TableBody>
{proposals?.map((proposal, idx) => (
<TableRow key={idx} className={classes.row} hover>
{proposals?.map((proposal) => (
<TableRow key={proposal.id} className={classes.row} hover>
<TableCell className={classes.cell} component="th" scope="row">
<Link
className={classes.link}
Expand Down
76 changes: 32 additions & 44 deletions src/screens/FeedsManager/SupportedChainsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ export const SupportedChainsCard = withStyles(styles)(
}
/>

{cfgs.map((cfg, idx) => (
{cfgs.map((cfg) => (
<ExpansionPanel
key={idx}
key={cfg.id}
defaultExpanded={false}
classes={{
root: classes.panel,
Expand Down Expand Up @@ -463,26 +463,6 @@ const OCRJobTypeRow = withStyles(styles)(
return null
}

const renderBootstrap = () => (
<Grid item xs={12} sm={1} md={5}>
<DetailsCardItemTitle title="Multiaddr" />
<DetailsCardItemValue value={cfg.multiaddr} />
</Grid>
)

const renderOracle = () => (
<>
<Grid item xs={12} sm={1} md={5}>
<DetailsCardItemTitle title="P2P Peer ID" />
<DetailsCardItemValue value={cfg.p2pPeerID} />
</Grid>
<Grid item xs={12} sm={1} md={5}>
<DetailsCardItemTitle title="OCR Key ID" />
<DetailsCardItemValue value={cfg.keyBundleID} />
</Grid>
</>
)

return (
<>
<Grid item xs={12} sm={1} md={2}>
Expand All @@ -494,7 +474,7 @@ const OCRJobTypeRow = withStyles(styles)(
</div>
</Grid>

{cfg.isBootstrap ? renderBootstrap() : renderOracle()}
{cfg.isBootstrap ? renderBootstrap(cfg) : renderOracle(cfg)}
</>
)
},
Expand All @@ -510,26 +490,6 @@ const OCR2JobTypeRow = withStyles(styles)(
return null
}

const renderBootstrap = () => (
<Grid item xs={12} sm={1} md={5}>
<DetailsCardItemTitle title="Multiaddr" />
<DetailsCardItemValue value={cfg.multiaddr} />
</Grid>
)

const renderOracle = () => (
<>
<Grid item xs={12} sm={1} md={5}>
<DetailsCardItemTitle title="P2P Peer ID" />
<DetailsCardItemValue value={cfg.p2pPeerID} />
</Grid>
<Grid item xs={12} sm={1} md={5}>
<DetailsCardItemTitle title="OCR Key ID" />
<DetailsCardItemValue value={cfg.keyBundleID} />
</Grid>
</>
)

return (
<>
<Grid item xs={12} sm={1} md={2}>
Expand All @@ -541,8 +501,36 @@ const OCR2JobTypeRow = withStyles(styles)(
</div>
</Grid>

{cfg.isBootstrap ? renderBootstrap() : renderOracle()}
{cfg.isBootstrap ? renderBootstrap(cfg) : renderOracle(cfg)}
</>
)
},
)

const renderBootstrap = (
cfg:
| FeedsManager_ChainConfigFields['ocr2JobConfig']
| FeedsManager_ChainConfigFields['ocr1JobConfig'],
) => (
<Grid item xs={12} sm={1} md={5}>
<DetailsCardItemTitle title="Multiaddr" />
<DetailsCardItemValue value={cfg.multiaddr} />
</Grid>
)

const renderOracle = (
cfg:
| FeedsManager_ChainConfigFields['ocr2JobConfig']
| FeedsManager_ChainConfigFields['ocr1JobConfig'],
) => (
<>
<Grid item xs={12} sm={1} md={5}>
<DetailsCardItemTitle title="P2P Peer ID" />
<DetailsCardItemValue value={cfg.p2pPeerID} />
</Grid>
<Grid item xs={12} sm={1} md={5}>
<DetailsCardItemTitle title="OCR Key ID" />
<DetailsCardItemValue value={cfg.keyBundleID} />
</Grid>
</>
)
4 changes: 2 additions & 2 deletions src/screens/FeedsManager/UpdatesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const UpdatesTable = withStyles(tableStyles)(
</TableHead>

<TableBody>
{proposals?.map((proposal, idx) => (
<TableRow key={idx} className={classes.row} hover>
{proposals?.map((proposal) => (
<TableRow key={proposal.id} className={classes.row} hover>
<TableCell className={classes.cell} component="th" scope="row">
<Link
className={classes.link}
Expand Down
22 changes: 22 additions & 0 deletions src/screens/JobProposal/JobProposalView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,26 @@ describe('JobProposalView', () => {
expect(queryByText(/edit/i)).toBeNull()
})
})

describe('deleted proposal', () => {
let proposal: JobProposalPayloadFields

beforeEach(() => {
proposal = buildJobProposal({
status: 'DELETED',
specs: [buildJobProposalSpec({ status: 'APPROVED' })],
})
})

it('renders a rejected job proposal', async () => {
renderComponent(proposal)

expect(queryByText('Deleted')).toBeInTheDocument()

expect(getByTestId('codeblock')).toHaveTextContent(
proposal.specs[0].definition,
)
expect(queryByText(/edit/i)).toBeNull()
})
})
})
2 changes: 2 additions & 0 deletions src/screens/JobProposal/JobProposalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const JOB_PROPOSAL_PAYLOAD_FIELDS = gql`
...JobProposal_SpecsFields
}
status
pendingUpdate
}
`

Expand Down Expand Up @@ -59,6 +60,7 @@ export const JobProposalView: React.FC<Props> = ({
<Grid container spacing={32}>
<Grid item xs={12}>
<SpecsView
proposal={proposal}
specs={proposal.specs}
onReject={onReject}
onApprove={onApprove}
Expand Down
Loading

0 comments on commit c91c2a5

Please sign in to comment.