Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 85 additions & 6 deletions components/db/lobbying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,98 @@ export type BillRow = {
async function fetchLobbyingBillSummaries(
court: number
): Promise<Record<string, BillSummaryEntry>> {
const snap = await getDoc(
doc(firestore, LOBBYING_STATS_COLLECTION, `billSummaries_${court}`)
const snap = await getDocs(
collection(
firestore,
LOBBYING_STATS_COLLECTION,
`billSummaries_${court}`,
"bills"
)
)
if (!snap.exists()) return {}
const raw = snap.data() as { data?: string }
if (!raw.data) return {}
return JSON.parse(raw.data) as Record<string, BillSummaryEntry>
const result: Record<string, BillSummaryEntry> = {}
snap.docs.forEach(d => {
result[d.id] = d.data() as BillSummaryEntry
})
return result
}

export function useLobbyingBillSummaries(court: number) {
return useAsync(fetchLobbyingBillSummaries, [court])
}

// ── Client / firm summaries (precomputed server-side; see writer.py and
// seedLobbyingStats.ts). Replaces client-side derivation over
// useLobbyingAllRegistrants(), which only fetches the first 2,000 of
// 25,000+ registrant docs and was silently showing an incomplete list. ────

export type ClientSummaryFirm = {
entityName: string
entityNameNorm: string
compensation: number | null
}

export type ClientSummaryRow = {
clientName: string
clientNameNorm: string
totalCompensation: number | null
registrantCount: number
firms: ClientSummaryFirm[]
}

export type FirmSummaryRow = {
entityName: string
entityNameNorm: string
regType: string
years: number[]
clientCount: number
}

async function fetchClientSummaries(): Promise<ClientSummaryRow[]> {
const snap = await getDocs(
collection(
firestore,
LOBBYING_STATS_COLLECTION,
"clientSummaries",
"clients"
)
)
return snap.docs.map(d => d.data() as ClientSummaryRow)
}

async function fetchClientSummary(
clientNameNorm: string
): Promise<ClientSummaryRow | undefined> {
const snap = await getDoc(
doc(
firestore,
LOBBYING_STATS_COLLECTION,
"clientSummaries",
"clients",
encodeURIComponent(clientNameNorm)
)
)
return snap.exists() ? (snap.data() as ClientSummaryRow) : undefined
}

async function fetchFirmSummaries(): Promise<FirmSummaryRow[]> {
const snap = await getDocs(
collection(firestore, LOBBYING_STATS_COLLECTION, "firmSummaries", "firms")
)
return snap.docs.map(d => d.data() as FirmSummaryRow)
}

export function useLobbyingClientSummaries() {
return useAsync(fetchClientSummaries, [])
}

export function useLobbyingClientSummary(clientNameNorm: string) {
return useAsync(fetchClientSummary, [clientNameNorm])
}

export function useLobbyingFirmSummaries() {
return useAsync(fetchFirmSummaries, [])
}

export function useLobbyingBillRows(courts: number[]) {
const courtsKey = courts.join(",")
return useAsync(
Expand Down
18 changes: 16 additions & 2 deletions components/lobbying/LobbyingBillCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import React from "react"
import { useTranslation } from "next-i18next"
import { useLobbyingFilingsForBill } from "components/db/lobbying"
import { LobbyingFilingsTable } from "./LobbyingFilingsTable"
import { LobbyingPaginationBar } from "./LobbyingPaginationBar"
import { usePagination } from "./usePagination"
import { MAPLE_COLORS } from "./chartTheme"
import { normalizePosition } from "./LobbyingPositionChip"

const PAGE_SIZE = 10

interface LobbyingBillCardProps {
court: number
billId: string
Expand All @@ -22,6 +26,10 @@ export const LobbyingBillCard: React.FC<LobbyingBillCardProps> = ({
status,
error
} = useLobbyingFilingsForBill(court, billId)
const { page, setPage, pageItems, totalPages, totalItems } = usePagination(
filings ?? [],
PAGE_SIZE
)

if (status === "loading" || status === "not-requested") {
return (
Expand Down Expand Up @@ -87,12 +95,18 @@ export const LobbyingBillCard: React.FC<LobbyingBillCardProps> = ({
</div>

<LobbyingFilingsTable
filings={filings}
filings={pageItems}
showBill={false}
showClient
showFirm
showAmount={false}
maxRows={5}
/>
<LobbyingPaginationBar
page={page}
totalPages={totalPages}
totalItems={totalItems}
pageSize={PAGE_SIZE}
onPage={setPage}
/>

<a href={explorerHref} style={viewAllLinkStyle}>
Expand Down
26 changes: 24 additions & 2 deletions components/lobbying/LobbyingFilingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,30 @@ export const LobbyingFilingsTable: React.FC<LobbyingFilingsTableProps> = ({
)}
</td>
)}
{showClient && <td style={cellStyle}>{f.clientName}</td>}
{showFirm && <td style={cellStyle}>{f.entityName}</td>}
{showClient && (
<td style={cellStyle}>
<a
href={`/lobbying/clients/${encodeURIComponent(
f.clientNameNorm
)}`}
style={{ color: MAPLE_COLORS.primary }}
>
{f.clientName}
</a>
</td>
)}
{showFirm && (
<td style={cellStyle}>
<a
href={`/lobbying/firms/${encodeURIComponent(
f.entityNameNorm
)}`}
style={{ color: MAPLE_COLORS.primary }}
>
{f.entityName}
</a>
</td>
)}
{showActivity && (
<td style={{ ...cellStyle, color: MAPLE_COLORS.textMuted }}>
{f.activityTitle || "—"}
Expand Down
21 changes: 21 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ service cloud.firestore {
match /lobbyingMeta/{id} {
allow read: if true;
allow write: if false;

// billSummaries_{court} docs store per-bill counts as small docs in
// this subcollection (not as a single JSON blob) to avoid Firestore's
// 1MB per-document/field size limit as a session's filings accumulate.
match /bills/{billId} {
allow read: if true;
allow write: if false;
}

// clientSummaries/firmSummaries store one small doc per client/firm
// (same reasoning as billSummaries above) so the clients and firms
// browse pages can read a precomputed rollup instead of scanning the
// full, capped-at-2000 lobbyingRegistrants query client-side.
match /clients/{clientId} {
allow read: if true;
allow write: if false;
}
match /firms/{firmId} {
allow read: if true;
allow write: if false;
}
}
match /transcriptions/{tid} {
// public, read-only
Expand Down
Loading
Loading