Skip to content

Commit ccb623e

Browse files
authored
Ballot summaries (#2080)
* Add constant for Ballot Initiative Committee code, add more spacing for ballot initiative summaries * Use white-space: pre-wrap for ballot initiative summaries - these are long and preserving whitespace is important for legibility * Don't write DocumentText for bills if it is not present in the API - we are going to start manually (for now) overwriting DocumentText for bills with PDFs but not DocumentText, and we don't want the next scraper run to overwrite that data with null. * Adding type assertion to test for type change
1 parent 1c2edbe commit ccb623e

6 files changed

Lines changed: 36 additions & 6 deletions

File tree

components/bill/BillDetails.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { Back } from "components/shared/CommonComponents"
1515
import { useFlags } from "components/featureFlags"
1616
import { FollowBillButton } from "components/shared/FollowButton"
1717
import { PendingUpgradeBanner } from "components/PendingUpgradeBanner"
18-
import { isCurrentCourt } from "functions/src/shared"
18+
import {
19+
currentBallotInitiativeCommittee,
20+
isCurrentCourt
21+
} from "functions/src/shared"
1922

2023
export const BillDetails = ({ bill }: BillProps) => {
2124
const { t } = useTranslation("common")
@@ -27,7 +30,7 @@ export const BillDetails = ({ bill }: BillProps) => {
2730
let isBallotMeasure = false
2831
const curComm = bill?.currentCommittee?.id
2932

30-
if (curComm == "SJ42") {
33+
if (curComm === currentBallotInitiativeCommittee) {
3134
isBallotMeasure = true
3235
}
3336

components/bill/Summary.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import { SmartIcon } from "./SmartIcon"
1717
import { TestimonyCounts } from "./TestimonyCounts"
1818
import { BillProps } from "./types"
1919
import { BillTopic } from "functions/src/bills/types"
20-
import { currentGeneralCourt } from "functions/src/shared"
20+
import {
21+
currentBallotInitiativeCommittee,
22+
currentGeneralCourt
23+
} from "functions/src/shared"
2124

2225
const Divider = styled(Col)`
2326
width: 2px;
@@ -30,6 +33,10 @@ const FormattedBillDetails = styled(Col)`
3033
white-space: pre-wrap;
3134
`
3235

36+
const BallotSummaryRow = styled(Row)`
37+
white-space: pre-wrap;
38+
`
39+
3340
const SmartTag = ({ topic }: { topic: BillTopic }) => {
3441
return (
3542
<links.Internal
@@ -106,6 +113,8 @@ export const Summary = ({
106113
const handleHideBillDetails = () => setShowBillDetails(false)
107114
const billText = bill?.content?.DocumentText
108115
const hearingIds = bill?.hearingIds
116+
const isBallotMeasure =
117+
bill?.currentCommittee?.id === currentBallotInitiativeCommittee
109118

110119
const { showLLMFeatures } = useFlags()
111120

@@ -203,10 +212,20 @@ export const Summary = ({
203212
<hr className={`m-0 border-bottom border-2`} />
204213
<SmartDisclaimer />
205214
</>
215+
) : bill.summary !== undefined && isBallotMeasure ? (
216+
<>
217+
<hr className={`m-0 mb-3 border-bottom border-2`} />
218+
</>
206219
) : (
207220
<></>
208221
)}
209-
<Row className="mx-1 mb-3">{bill.summary}</Row>
222+
{bill.summary !== undefined && isBallotMeasure ? (
223+
<BallotSummaryRow className={`mx-1 mb-3`}>
224+
{bill.summary}
225+
</BallotSummaryRow>
226+
) : (
227+
<Row className="mx-1 mb-3">{bill.summary}</Row>
228+
)}
210229
<Row className={`d-flex mx-0 my-1`} xs="auto">
211230
{bill.topics?.map(t => (
212231
<SmartTag key={t.topic} topic={t} />

components/db/bills.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type BillContent = {
3333
Cosponsors: MemberReference[]
3434
LegislationTypeName: string
3535
Pinslip: string
36-
DocumentText: string
36+
DocumentText?: string
3737
}
3838

3939
export type BillTopic = {

functions/src/bills/bills.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const { fetchBatch: fetchBillBatch, startBatches: startBillBatches } =
2828
.getSimilarBills(court, id)
2929
.catch(logFetchError("similar bills", id))
3030
.then(bills => bills?.map(b => b.BillNumber).filter(isString) ?? [])
31+
if (content.DocumentText == null) {
32+
delete content.DocumentText
33+
}
34+
3135
const resource: Partial<Bill> = {
3236
content,
3337
history,

functions/src/shared/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ export const currentGeneralCourt = supportedGeneralCourts[0]
3535

3636
export const isCurrentCourt = (courtNumber: number) =>
3737
courtNumber === currentGeneralCourt
38+
39+
// Only applicable for court 193/194, but by the time we have another general court,
40+
// the full ballot initiative feature should be available and we can remove this check
41+
export const currentBallotInitiativeCommittee = "SJ42"

tests/unit/billdetail.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ describe("BillDetails", () => {
162162
const readMoreButton = screen.getByRole("button", { name: "Read more.." })
163163
expect(readMoreButton).toBeInTheDocument
164164
fireEvent.click(readMoreButton)
165-
expect(screen.getByText(DocumentText)).toBeInTheDocument
165+
expect(screen.getByText(DocumentText!)).toBeInTheDocument
166166
})
167167

168168
// below test assumes mockBill contains a primary sponsor

0 commit comments

Comments
 (0)