-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Submission Summary V2 with FetchContract #2350
Changes from 54 commits
f8fc4e2
b355084
ce369d7
3e45343
5836518
e2dd1b0
a36eb52
0cd849c
a42ea4b
1686aa9
8201ea0
0696cae
aa2e7c9
ec4cd34
609af02
ff4d5b9
24f8970
1b05f8d
c66526b
8dd9b62
c5a1653
8a5ca31
9cd0a58
ec9bbc0
c6ef2c9
cc74d8c
c342a11
5aee09a
c6516bf
b37f87f
5b28925
8d26735
7ebbba6
f589287
4fe6252
dc11a52
af49041
745da54
23eb6ff
9f83988
acc5249
1d96a2d
78dc953
c82d4dc
18043fc
c456132
3b6ac15
57e2b4a
37c9b04
2252971
e3ae827
7ee8429
8b09893
7784374
f555a3b
11d0268
5bc2584
d9c1df9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import React from 'react' | ||
import { dayjs } from '../../common-code/dateHelpers/dayjs' | ||
import { SectionHeader } from '../SectionHeader' | ||
import { Accordion, Link } from '@trussworks/react-uswds' | ||
import type { AccordionItemProps } from '@trussworks/react-uswds/lib/components/Accordion/Accordion' | ||
import { UpdateInformation, Contract } from '../../gen/gqlClient' | ||
import styles from './ChangeHistory.module.scss' | ||
type ChangeHistoryProps = { | ||
contract: Contract | ||
} | ||
|
||
type flatRevisions = UpdateInformation & { | ||
kind: 'submit' | 'unlock' | ||
revisionVersion: string | undefined | ||
} | ||
|
||
export const ChangeHistoryV2 = ({ | ||
contract, | ||
}: ChangeHistoryProps): React.ReactElement => { | ||
const flattenedRevisions = (): flatRevisions[] => { | ||
const result: flatRevisions[] = [] | ||
//Reverse revisions to order from earliest to latest revision. This is to correctly set version for each | ||
// contract & recontract. | ||
const reversedRevisions = [...contract.packageSubmissions].reverse() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Is this code working properly with linked rates? I am under the impression that we would only want contract related package submissions in our change right now. I think at this point we only seek parity with current I would think we need to filter only contract changes from Change history work with the full package submissions list is entirely different epic I believe @macrael can you weigh in? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that if you filtered out all packages that dont have reason: "CONTRACT_SUBMISSION" then you will have the same number of entries as before. That will also give us the correct unlock reasons, we should only ever show unlocks from CONTRACT_SUBMISSION, not from RATE* updates I definitely want this code to be using packageSubmissions and get off of the old revisions code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @haworku that makes sense to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pearl-truss sounds like @macrael agrees, we should be filtering only the contract_submission packages here - can you make that change and ignore rate stuff? Otherwise looks good. |
||
reversedRevisions.forEach((r, index) => { | ||
if (r.contractRevision.unlockInfo) { | ||
const newUnlock: flatRevisions = {} as flatRevisions | ||
newUnlock.updatedAt = r.contractRevision.unlockInfo.updatedAt | ||
newUnlock.updatedBy = r.contractRevision.unlockInfo.updatedBy | ||
newUnlock.updatedReason = | ||
r.contractRevision.unlockInfo.updatedReason | ||
newUnlock.kind = 'unlock' | ||
//Use unshift to push the latest revision unlock info to the beginning of the array | ||
result.unshift(newUnlock) | ||
} | ||
if (r.contractRevision.submitInfo) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is necessary b/c it is optional in the types, but just to reiterate every revision in packageSubmissions must have this set. |
||
const newSubmit: flatRevisions = {} as flatRevisions | ||
|
||
// Only set revisionVersion if not the latest revision and if not unlocked. This is not the same | ||
// as the order of change history. The version correlates with each submitted revision. | ||
const revisionVersion = | ||
index !== reversedRevisions.length - 1 | ||
? String(index + 1) //Offset version, we want to start at 1 | ||
: undefined | ||
|
||
newSubmit.updatedAt = r.contractRevision.submitInfo.updatedAt | ||
newSubmit.updatedBy = r.contractRevision.submitInfo.updatedBy | ||
newSubmit.updatedReason = | ||
r.contractRevision.submitInfo.updatedReason | ||
newSubmit.kind = 'submit' | ||
newSubmit.revisionVersion = revisionVersion | ||
//Use unshift to push the latest revision submit info to the beginning of the array | ||
result.unshift(newSubmit) | ||
} | ||
}) | ||
return result | ||
} | ||
|
||
const revisionHistory = flattenedRevisions() | ||
|
||
const revisedItems: AccordionItemProps[] = revisionHistory.map( | ||
(r, index) => { | ||
const isInitialSubmission = r.updatedReason === 'Initial contract' | ||
const isSubsequentSubmission = r.kind === 'submit' | ||
// We want to know if this contract has multiple submissions. To have multiple submissions, there must be minimum | ||
// more than the initial contract revision. | ||
const hasSubsequentSubmissions = revisionHistory.length > 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously this was set to >=3:
I thought it might make sense to change it to > 1 because each packageSubmission has an array of revs but the multiple submissions part might not be relevant anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code change you made looks good to me. I would delete the comment totally- I agree that it doesn't make sense for the new world where related rate changes can result in entries in that same package submission array |
||
return { | ||
title: ( | ||
<div> | ||
{dayjs | ||
.utc(r.updatedAt) | ||
.tz('America/New_York') | ||
.format('MM/DD/YY h:mma')}{' '} | ||
ET - {isSubsequentSubmission ? 'Submission' : 'Unlock'} | ||
</div> | ||
), | ||
// Display this code if this is the initial contract. We only want to display the link of the initial contract | ||
// only if there has been subsequent contracts. We do not want to display a link if the package initial | ||
// contract was unlocked, but has not been resubmitted yet. | ||
headingLevel: 'h4', | ||
content: isInitialSubmission ? ( | ||
<div data-testid={`change-history-record`}> | ||
<span className={styles.tag}>Submitted by:</span> | ||
<span> {r.updatedBy}</span> | ||
<br /> | ||
{r.revisionVersion && hasSubsequentSubmissions && ( | ||
<Link | ||
href={`/contracts/${contract.id}/revisions/${r.revisionVersion}`} | ||
data-testid={`revision-link-${r.revisionVersion}`} | ||
> | ||
View past contract version | ||
</Link> | ||
)} | ||
</div> | ||
) : ( | ||
<div data-testid={`change-history-record`}> | ||
<div> | ||
<span className={styles.tag}> | ||
{isSubsequentSubmission | ||
? 'Submitted by: ' | ||
: 'Unlocked by: '}{' '} | ||
</span> | ||
<span>{r.updatedBy}</span> | ||
</div> | ||
<div> | ||
<span className={styles.tag}> | ||
{isSubsequentSubmission | ||
? 'Changes made: ' | ||
: 'Reason for unlock: '} | ||
</span> | ||
<span>{r.updatedReason}</span> | ||
</div> | ||
{isSubsequentSubmission && r.revisionVersion && ( | ||
<Link | ||
href={`/contracts/${contract.id}/revisions/${r.revisionVersion}`} | ||
data-testid={`revision-link-${r.revisionVersion}`} | ||
> | ||
View past contract version | ||
</Link> | ||
)} | ||
</div> | ||
), | ||
expanded: false, | ||
id: r.updatedAt.toString(), | ||
} | ||
} | ||
) | ||
return ( | ||
<section id="changeHistory" className={styles.summarySection}> | ||
<SectionHeader header="Change history" hideBorder /> | ||
<Accordion items={revisedItems} multiselectable /> | ||
</section> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to put package submissions in time order? I was matching revisions b/c calling contract.packageSubmissions[0] feels like a nice way to always get the most recent submission but could be convinced otherwise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@macrael I think we do if we want to keep the order the same as what currently appears (unless I'm missing something?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. Multiple pages use that
contract.packageSubmissions[0]
logic already and its working well. This is edge case - I think it's literally just for that integer in the previous submission urls why we reverse in this order on this one page - everywhere else fine to keep current backend ordering and assume latest first.