mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-28 15:43:10 +00:00
Coluna "Dobradinhas" em /campanha/liderancas com chips clicáveis para /campanha/dobradinhas/<slug> e edição via Popover+Command (padrão B27, escrita via server action delta + lock, como B19). - LeadershipRowViewModel.stateDeputies (StateDeputySummary[]) via loadStateDeputySummaries, substituindo stateDeputyNames. - setLeadershipStateDeputyMembership(Record): delta com withPayloadTransaction + acquireTextAdvisoryLocks + revalidatePath. - nextStateDeputyIdsAfterMembership (lib/leadershipStateDeputyMembership.ts), espelha nextAdvisorIdsAfterMembership. - loadStateDeputyOptions estendido com plainName/party/slug. - Catálogo entregue uma vez por tabela via leadershipColumns(options) (columns factory, mesmo precedente de municipalityListColumns). /simplify (1ª rodada): corrige revert otimista por delta (não pelo snapshot inteiro), remove fallback silencioso na adição, extrai sameIdSet compartilhado com MunicipalityListAdvisorsControl (B27), e evita leitura+revalidação supérfluas no caminho no-op da action. /simplify (2ª rodada, pós-rebase): troca o StateDeputyOptionsProvider (Context) inicial pela columns factory acima — a 1ª rodada tinha validado o Context por falta da evidência de que MunicipalityList.tsx já resolve o mesmo problema sem Context; corrige revalidatePath para o id concreto em vez do template dinâmico '/campanha/liderancas/[id]' (que invalidava toda ficha a cada toggle); remove non-null assertion movendo a guarda para dentro do setCurrent updater. Gate verde: tsc, lint --max-warnings=0, format:check, unit 530/530, int 406/406 (incl. os 6 de campaignLeadershipStateDeputyMembership), build. Aikido: 0 achados nos arquivos novos/editados.
107 lines
3 KiB
TypeScript
107 lines
3 KiB
TypeScript
import 'server-only'
|
|
|
|
import type { Payload } from 'payload'
|
|
|
|
import type { RelationOption } from '@/components/campaign/shared/RelationMultiSelect'
|
|
import type { CampaignUser } from '@/payload-types'
|
|
import { relationshipId } from '@/utilities/relationship'
|
|
|
|
export type ActivityRelationOption = RelationOption & {
|
|
municipalityId: number
|
|
}
|
|
|
|
/** Municipalities the actor may operate on (coordinator: all 436; advisor: administered). */
|
|
export const loadMunicipalityOptions = async (
|
|
payload: Payload,
|
|
user: CampaignUser,
|
|
): Promise<RelationOption[]> => {
|
|
const result = await payload.find({
|
|
collection: 'municipality',
|
|
depth: 0,
|
|
limit: 0,
|
|
pagination: false,
|
|
sort: 'name',
|
|
select: { name: true },
|
|
where: {},
|
|
user,
|
|
overrideAccess: false,
|
|
})
|
|
return result.docs.map((municipality) => ({ id: municipality.id, name: municipality.name }))
|
|
}
|
|
|
|
export const loadOrganizationOptions = async (
|
|
payload: Payload,
|
|
user: CampaignUser,
|
|
): Promise<RelationOption[]> => {
|
|
const result = await payload.find({
|
|
collection: 'organization',
|
|
depth: 0,
|
|
limit: 0,
|
|
pagination: false,
|
|
sort: 'name',
|
|
select: { name: true },
|
|
where: {},
|
|
user,
|
|
overrideAccess: false,
|
|
})
|
|
return result.docs.map((organization) => ({ id: organization.id, name: organization.name }))
|
|
}
|
|
|
|
export const loadActivityOptions = async (
|
|
payload: Payload,
|
|
user: CampaignUser,
|
|
): Promise<ActivityRelationOption[]> => {
|
|
const result = await payload.find({
|
|
collection: 'activity',
|
|
depth: 0,
|
|
limit: 0,
|
|
pagination: false,
|
|
sort: 'title',
|
|
select: { title: true, municipality: true },
|
|
where: {},
|
|
user,
|
|
overrideAccess: false,
|
|
})
|
|
|
|
return result.docs.flatMap((activity) => {
|
|
const municipalityId = relationshipId(activity.municipality)
|
|
return municipalityId ? [{ id: activity.id, name: activity.title, municipalityId }] : []
|
|
})
|
|
}
|
|
|
|
/**
|
|
* `name` folds in the party for select/typeahead disambiguation (e.g.
|
|
* `RelationMultiSelect`); `plainName`/`party`/`slug` ride along so cell-level
|
|
* consumers (B31's "Dobradinhas" column) can build a `StateDeputySummary`
|
|
* chip for an optimistic add and link to `/campanha/dobradinhas/<slug>`
|
|
* without a second catalog fetch.
|
|
*/
|
|
export type StateDeputyRelationOption = RelationOption & {
|
|
plainName: string
|
|
party: string | null
|
|
slug: string
|
|
}
|
|
|
|
export const loadStateDeputyOptions = async (
|
|
payload: Payload,
|
|
user: CampaignUser,
|
|
): Promise<StateDeputyRelationOption[]> => {
|
|
const result = await payload.find({
|
|
collection: 'stateDeputy',
|
|
depth: 0,
|
|
limit: 0,
|
|
pagination: false,
|
|
sort: 'name',
|
|
select: { name: true, party: true, slug: true },
|
|
where: {},
|
|
user,
|
|
overrideAccess: false,
|
|
})
|
|
return result.docs.map((stateDeputy) => ({
|
|
id: stateDeputy.id,
|
|
name: stateDeputy.party ? `${stateDeputy.name} (${stateDeputy.party})` : stateDeputy.name,
|
|
plainName: stateDeputy.name,
|
|
party: stateDeputy.party ?? null,
|
|
slug: stateDeputy.slug,
|
|
}))
|
|
}
|