Skip to content
Merged
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
3 changes: 3 additions & 0 deletions docs/GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ The **last band's one press** (v2.9258, punch list #464 step 3, `permitBandPass.
A permit of the last band is **held back for a look** when its builder line or its size line reads *We want it*, and it stays on the deck with its reason, while **Undo** in the box puts every passed permit back as one more row each.
Our place among the plumbers the permits name has its working in a kernel no screen reads yet (v2.9235, punch list #466, `src/lib/scoreboard/scoreboard.ts` over `plumbersCounted` in `permitMarketShape.ts`).
A city on Permits is **quiet** (v2.7880, `permitQuiet.ts`) when its newest permit day is more than 7 days back, 10 for San Antonio, while our own pull ran clean inside two days: the city picker then reads *quiet since* that day, and never when the pull itself stopped.
A builder's **share of dollars** and **share of permits** (v2.9263, punch list #465, `builderShare.ts`) are its parts of the dollars declared and of the permits on the Builders list as it was read, drawn as a dark bar and a light bar, so every name's shares add up to the whole list.
A name on Builders is **ours** when we priced a job for it in two years or a person tied it to a customer, and **not ours yet** otherwise: its bars are green or grey, and the chips **Everyone**, **Ours** and **Not ours yet** narrow the list.
Builders reads **All five cities** at once unless a city is picked, one row a name, through `research_builders_v2` (`20261203033600`, `loadBuildersOf`), which adds the dollars a name's permits declare, how many declare some and the cities they are in.
**Market** (v2.7978, punch list #405, `permitMarket.ts`) is the Permits view beside Builders that says what the permits mean for us: every **company we bid** in two years beside the commercial permits its names pulled in twelve months, each row reading *Builds, and we win*, *Builds, we never win*, too early to say or *No permit on record*, and **the clock**, the middle wait between two dates on a city's permits.
A **company we bid** there is a bid's customer or the old builders list's name on it, keyed as permits are, with practice bids (a project name that starts with the word ZZ) and a bid platform's catch-all customer left out, in the last two years.
That is **the one rule for our bids**: in the client `src/lib/research/ourBids.ts` (`bidCounts`, `bidPartyKey`), on the database `research_bid_counts` and `research_bid_party_key`, and since v2.8138, v2.8147 and v2.8181 Builders' **Our bids**, the call list's *We bid N, won N* and *Never bid*, a tied customer's bids and the skim's *warm · cold · seen · new name* word all count by it.
Expand Down
2 changes: 1 addition & 1 deletion docs/PROJECT_DOCUMENTATION.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/migrations/20261203033600_research_builders_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ A function's return type cannot change with `CREATE OR REPLACE`, and the client

## Applied

Not yet. This section is written when the push is read back.
Pushed to prod on 2026-12-03 at 04:21 UTC with `supabase db push`, from a clean checkout of `origin/main`. The dry run named this migration alone. `npm run check:migration-drift` then read 1,548 local files and 1,548 remote versions, fully applied.
37 changes: 37 additions & 0 deletions docs/recent-features/v2.9263.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# v2.9263 — Builders: who holds the work, in all five cities at once (2026-12-02)

Punch list #465, step 1, the client. It stands on v2.9261, the migration, which must be merged and pushed first: the list reads `research_builders_v2`, and until the push it says the database change is not in yet. Client only. Nothing owed on prod of its own.

## What it does

- **Every city at once.** The Permits tab's city picker has a first choice on Builders, *All five cities*, and the list opens on it unless the address asked for a city. `PermitBuilders` takes the cities it reads (`cities`), and `loadBuildersOf` in `permitResearchIo.ts` reads `research_builders_v2` for them, one row a name. A city picked reads that city alone, through the same function.
- **Two shares a name.** `builderShares` in the new kernel `src/lib/research/builderShare.ts` gives each name its part of the dollars declared and its part of the permits, with a rank on each for step 2. Both are parts of the whole list as it was read, whatever is drawn, so every row's shares add up to the whole.
- **Two bars.** The dollars' bar is the dark one and the permits' the light one, cut to the longest share drawn (`longestShare`, `barWidth`). Green is a name that is ours, grey one that is not yet. A name whose permits declare nothing reads *none declared* and has the permits' bar alone. Under the dollars' share the row says the dollars themselves, through `Money`.
- **Ours.** `isOurs`: a bid from us in two years, which `bids` already counts by the one rule, or a name a person tied to a customer (the keys of `book.tied`). The chips **Everyone**, **Ours** and **Not ours yet** narrow the list, each with its count, and each row ends in its chip.
- **Sorting.** A press on a heading sorts (`pressSort`, `sortBuilders`). The lit heading carries a mark and turns round on a second press. A name and a plumber start A to Z, a number starts with the most. A name with nothing to sort by goes last either way. The list opens on the most dollars. A phone has a picker in place of headings.
- **The lines.** *10 drawn here of 212 companies* beside the chips (`drawnWords`). Under the list, over every city, the cities whose records start less than a year ago, each with its day (`recordsStartWords`, over the new `usePermitRecordsStarts`).

## Where it differs from the drawing

The card ties the step to section 2 of its mock-up and says to name each difference.

- The theme's colours and the app's own chips stand where the drawing has its own. The greys of a bar are `var(--text-faint)` and `var(--border-strong)`. The greens are literals, as every status colour is.
- **The Companies or People switch is not here.** It is step 4's.
- **Kept, though the drawing has neither:** the chips *All*, *3 or more permits and never bid*, *Good*, *Avoid* and *No mark*, and the search. They narrow by our mark, and the new three narrow by whether the name is ours, so both rows stand. Nothing the list could do is taken away.
- **Moved:** the drawing has no *Mark* column and no *Last permit* column. A mark is a pill beside the name, drawn only where there is one, and the last permit's day is in the line under the name.
- **Without a plumber** is now headed **Open now**, the drawing's words, with the old words on its tip.
- **Over every city, two things of one city are not drawn:** the *Looks like a customer* chip and the *Read back to* press. A city picked brings both back. The Dashboard's *Answer them* line names a city, so it still opens on the chip.

## What it does not settle

- **How long the read of every city takes.** `research_builders_v2` runs once for each 1,000 names, as the one-city read did. Only prod can say how long five cities take. A failed read shows its reason with Retry, and a city picked reads less.
- **An application and the permit issued from it are two rows.** Both add their dollars. The guide says the dollars are what each filer wrote, and that a share is a part of the permits we hold.

## Tested

- `builderShare.test.ts`: the shares add up, a name with no dollars, ranks, ours by a bid or by a tie, the words of a share, the bars' measure, every column's order both ways, the heading's mark, the count drawn and the records' line.
- `PermitBuilders.render.test.tsx` and `ProspectsResearchTab.render.test.tsx`: the list over the new read, the bars, the chips, a heading's press, and *All five cities* on the picker.

## Owes a look

After its deploy, and after v2.9261's push: Prospects → Permits → Builders. It reads only. Time the first draw on *All five cities*. Add three names' permits' declared values by hand from the Ledger and hold each to its row. Press each heading. Press the three chips.
108 changes: 105 additions & 3 deletions src/components/prospects/PermitBuilders.render.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { LookupCheckRow, LookupRow } from '../../lib/research/builderLookup
* is, takes it back, asks *Same company?* of a customer whose name begins this one, and ties
* any other through a search. Every name here is made up.
*/
const research = vi.hoisted(() => ({ loadBuilders: vi.fn(), loadPermitsOfBuilder: vi.fn(), markBuilder: vi.fn(), saveBuilder: vi.fn(), pullPermitsBack: vi.fn(), loadRecordsStart: vi.fn() }))
const research = vi.hoisted(() => ({ loadBuilders: vi.fn(), loadBuildersOf: vi.fn(), loadPermitsOfBuilder: vi.fn(), markBuilder: vi.fn(), saveBuilder: vi.fn(), pullPermitsBack: vi.fn(), loadRecordsStart: vi.fn() }))
const siteIo = vi.hoisted(() => ({ loadAllNameAnswers: vi.fn(), loadAllNameContactMatches: vi.fn(), loadCustomerNames: vi.fn(), loadRecentBidsWithCustomer: vi.fn(), loadPermitsByHouseNumber: vi.fn(), recordNameAnswer: vi.fn() }))
const answersIo = vi.hoisted(() => ({ loadBuilderAnswersGround: vi.fn() }))
const marketIo = vi.hoisted(() => ({ loadBuilderLookupOf: vi.fn(), recordLookupCheck: vi.fn() }))
Expand Down Expand Up @@ -56,6 +56,8 @@ async function openSheet(name: string) {

beforeEach(() => {
research.loadBuilders.mockReset().mockResolvedValue([builder(), copperline])
// The list reads `research_builders_v2` for the cities it is given. Each case sets what a city's read gives, as before.
research.loadBuildersOf.mockReset().mockImplementation((cities: string[]) => research.loadBuilders(cities[0]))
research.loadPermitsOfBuilder.mockReset().mockResolvedValue([])
research.markBuilder.mockReset().mockResolvedValue(undefined)
research.saveBuilder.mockReset().mockResolvedValue(undefined)
Expand Down Expand Up @@ -109,13 +111,13 @@ describe('Builders, Our bids', () => {
// Nobody named: no column on the desk, and the phone card and the sheet say nothing of a plumber.
draw()
await screen.findByText('Ridgeway Builders of Texas LLC')
expect(screen.queryByRole('columnheader', { name: 'Plumber they use' })).toBeNull()
expect(screen.queryByRole('columnheader', { name: 'Their plumber' })).toBeNull()
expect(screen.queryByText(/not named on the permits/)).toBeNull()
cleanup()
// One builder's permits name a plumber: the column is back, and the other builder reads not named.
research.loadBuilders.mockResolvedValue([builder(), builder({ key: 'tallpine', sample_contact: 'Tall Pine Development', plumber: 'Blue Heron Plumbing', plumber_jobs: 2 })])
draw()
expect(await screen.findByRole('columnheader', { name: 'Plumber they use' })).toBeTruthy()
expect(await screen.findByRole('columnheader', { name: 'Their plumber' })).toBeTruthy()
expect(screen.getByText('Blue Heron Plumbing on 2')).toBeTruthy()
expect(screen.getByText('not named on the permits')).toBeTruthy()
})
Expand All @@ -138,6 +140,106 @@ describe('Builders, Our bids', () => {
})
})

describe('Builders, who holds the work (punch list #465, step 1)', () => {
const halden = builder({ key: 'haldencommercial', sample_contact: 'Halden Commercial', permits: 6, open: 3, declared: 600_000, declared_permits: 5, bids: 4, won: 1, cities: ['Austin', 'San Antonio'] })
const sable = builder({ key: 'sablecreek', sample_contact: 'Sable Creek Construction', permits: 3, open: 2, declared: 300_000, declared_permits: 3, cities: ['Austin'] })
const bexley = builder({ key: 'bexleygroup', sample_contact: 'Bexley Group', permits: 1, open: 1, declared: null, declared_permits: 0, cities: ['Seguin'] })
const names = () => screen.getAllByRole('row').slice(1).map((r) => within(r).getAllByRole('button')[0]?.textContent)
const everyCity = (isMobile = false) => renderWithProviders(<PermitBuilders city="San Antonio" cities={['San Antonio', 'Austin', 'Seguin']} authUserId="u1" todayYmd="2026-11-11" isMobile={isMobile} onChanged={() => {}} />)

it('gives each name its share of the dollars and of the permits, each a bar, and says the dollars', async () => {
research.loadBuilders.mockResolvedValue([halden, sable, bexley])
draw()
const row = (await screen.findByRole('button', { name: 'Halden Commercial' })).closest('tr') as HTMLElement
expect(within(row).getByLabelText('Share of dollars: 66.7%')).toBeTruthy()
expect(within(row).getByLabelText('Share of permits: 60.0%')).toBeTruthy()
expect(row.querySelectorAll('[data-share-bar]')).toHaveLength(2)
expect(row.textContent).toContain('$600,000 declared')
expect(within(row).getByText('Ours')).toBeTruthy()
// A name whose permits declare nothing has the permits' bar alone, and is not ours yet.
const none = screen.getByRole('button', { name: 'Bexley Group' }).closest('tr') as HTMLElement
expect(within(none).getByLabelText('Share of dollars: none declared')).toBeTruthy()
expect(none.querySelectorAll('[data-share-bar]')).toHaveLength(1)
expect(within(none).getByText('Not ours yet')).toBeTruthy()
})

it('opens on the most dollars, and a press on a heading sorts and says which way', async () => {
research.loadBuilders.mockResolvedValue([sable, bexley, halden])
draw()
await screen.findByRole('button', { name: 'Halden Commercial' })
expect(names()).toEqual(['Halden Commercial', 'Sable Creek Construction', 'Bexley Group'])
expect(screen.getByRole('columnheader', { name: 'Share of dollars ▾' }).getAttribute('aria-sort')).toBe('descending')
fireEvent.click(screen.getByRole('button', { name: 'Builder' }))
expect(names()).toEqual(['Bexley Group', 'Halden Commercial', 'Sable Creek Construction'])
expect(screen.getByRole('columnheader', { name: 'Builder ▴' }).getAttribute('aria-sort')).toBe('ascending')
fireEvent.click(screen.getByRole('button', { name: 'Builder ▴' }))
expect(names()).toEqual(['Sable Creek Construction', 'Halden Commercial', 'Bexley Group'])
fireEvent.click(screen.getByRole('button', { name: 'Open now' }))
expect(names()).toEqual(['Halden Commercial', 'Sable Creek Construction', 'Bexley Group'])
})

it('narrows to ours or not ours yet, counts each, and says how many are drawn', async () => {
research.loadBuilders.mockResolvedValue([halden, sable, bexley])
draw()
await screen.findByRole('button', { name: 'Halden Commercial' })
const whose = screen.getByRole('group', { name: 'Whose work' })
expect(within(whose).getByRole('button', { name: 'Everyone 3' }).getAttribute('aria-pressed')).toBe('true')
expect(whose.parentElement?.textContent).toContain('3 drawn here of 3 companies')
fireEvent.click(within(whose).getByRole('button', { name: 'Not ours yet 2' }))
expect(names()).toEqual(['Sable Creek Construction', 'Bexley Group'])
expect(whose.parentElement?.textContent).toContain('2 drawn here of 3 companies')
fireEvent.click(within(whose).getByRole('button', { name: 'Ours 1' }))
expect(names()).toEqual(['Halden Commercial'])
})

it('counts a name a person tied to a customer as ours, with no bid of its own', async () => {
research.loadBuilders.mockResolvedValue([builder({ declared: 100, declared_permits: 1 }), sable])
answersIo.loadBuilderAnswersGround.mockResolvedValue(ground([tie()]))
draw()
const row = (await screen.findByRole('button', { name: 'Ridgeway Builders of Texas LLC' })).closest('tr') as HTMLElement
expect(within(row).getByText('Ours')).toBeTruthy()
expect(screen.getByRole('button', { name: 'Ours 1' })).toBeTruthy()
})

it('reads every city in one call, says a name’s cities, and leaves out what is one city’s', async () => {
research.loadBuildersOf.mockResolvedValue([halden, sable, bexley])
research.loadRecordsStart.mockImplementation(async (c: string) => (c === 'Austin' ? '2025-01-01' : c === 'Seguin' ? '2026-08-26' : null))
siteIo.loadAllNameAnswers.mockResolvedValue([])
everyCity()
const row = (await screen.findByRole('button', { name: 'Halden Commercial' })).closest('tr') as HTMLElement
expect(research.loadBuildersOf).toHaveBeenCalledWith(['San Antonio', 'Austin', 'Seguin'])
expect(research.loadBuildersOf).toHaveBeenCalledTimes(1)
expect(row.textContent).toContain('Austin, San Antonio')
// No one day is where every city's records start: the column says Permits, and the line under the list names the short city.
expect(screen.getByRole('columnheader', { name: 'Permits' })).toBeTruthy()
await waitFor(() => expect(document.body.textContent).toContain('The records here start in Seguin on Aug 26. A count covers a year at most, and less where the records start later.'))
expect(screen.queryByRole('button', { name: /Looks like a customer/ })).toBeNull()
expect(screen.queryByRole('button', { name: /Read back to/ })).toBeNull()
// The sheet reads the name's permits in every city it is in.
await openSheet('Halden Commercial')
expect(research.loadPermitsOfBuilder).toHaveBeenCalledWith(['Austin', 'San Antonio'], 'haldencommercial', '2026-11-11')
})

it('draws the two shares and the chip on a phone card, with a picker to sort', async () => {
research.loadBuilders.mockResolvedValue([sable, halden])
draw(true)
const first = await screen.findByRole('button', { name: /Halden Commercial/ })
expect(within(first).getByLabelText('Share of dollars: 66.7%')).toBeTruthy()
expect(within(first).getByText('Ours')).toBeTruthy()
fireEvent.change(screen.getByLabelText('Sort by'), { target: { value: 'name' } })
const cards = screen.getAllByRole('button', { name: /Halden Commercial|Sable Creek Construction/ })
expect(cards[0]?.textContent).toContain('Halden Commercial')
fireEvent.change(screen.getByLabelText('Sort by'), { target: { value: 'open' } })
expect(screen.getAllByRole('button', { name: /Halden Commercial|Sable Creek Construction/ })[0]?.textContent).toContain('Halden Commercial')
})

it('says the database change is not in yet when the read of every city is not on the database', async () => {
research.loadBuildersOf.mockResolvedValue(null)
draw()
expect(await screen.findByText(/Builders opens once tonight’s database change is in/)).toBeTruthy()
})
})

describe('Builders, the chips', () => {
it('draws the lit chip bold at the chip size from the first draw, and moves the weight with a press (v2.7907)', async () => {
draw()
Expand Down
Loading
Loading