teqo/src/utilities/municipalityPortfolioIndex.ts
Francisco Ignácio Fontoura Solla 812e3a0bee B34: editable município chips on the leaderships list.
The "Municípios" column was dead text; it is now chips that navigate to the
município, with a territory chip when a leadership covers a whole TI, and it is
editable in place. What picks inline vs. Drawer is the `pointer:` media query,
not viewport width: on a fine pointer the editor is always mounted (the "×" sits
at the chip's corner, revealed on hover/focus) and on a coarse pointer a tap
anywhere in the cell opens a Drawer with 44 px targets.

`AdvisorMunicipalityCell` is promoted to `shared/MunicipalityPortfolioCell` and
/campanha/assessores migrates onto it in the same change, so the second call site
is born with the first. One batch action only; the single-id advisor twin is
deleted with its int tests migrated. The anti-goal on always-mounted list inputs
is amended for chip-based relations on fine pointers, not reopened.

Also fixes a latent bug: `CampaignTableHead`'s `description` seam broke any RSC
caller, because its two helpers lived in a 'use client' module.
2026-07-27 22:35:19 -03:00

40 lines
1.5 KiB
TypeScript

import 'server-only'
import type { Payload } from 'payload'
import type { BahiaIdentityTerritory } from '@/lib/bahiaTerritories'
import type { MunicipalityPortfolioIndexEntry } from '@/lib/municipalityPortfolio'
/**
* Full municipality index for client-side portfolio search (município / TI / ZE),
* shared by every surface that edits a municipality relation by chips
* (`/campanha/assessores`, `/campanha/liderancas`).
*
* Intentional admin bypass: read-only reference data (name/slug/geography) whose
* grouping into territory chips is only correct against the complete catalog —
* scoping it would break the "covers the whole TI" collapse for advisors. The
* route gate has already asserted staff; what an actor may *add* is restricted
* separately by the caller.
*/
export const loadMunicipalityPortfolioIndex = async (
payload: Payload,
): Promise<MunicipalityPortfolioIndexEntry[]> => {
const result = await payload.find({
collection: 'municipality',
depth: 0,
limit: 0,
pagination: false,
// User-visible: `searchMunicipalityPortfolio` walks this array in order and
// stops at `limit`, so the suggestion list is alphabetical only because this is.
sort: 'name',
select: { name: true, slug: true, region: true },
overrideAccess: true,
})
return result.docs.map((municipality) => ({
id: municipality.id,
name: municipality.name,
slug: municipality.slug,
region: municipality.region as BahiaIdentityTerritory,
}))
}