@aglyn/plugins-marketing 1.0.0-beta.232 → 1.0.0-beta.233

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/package.json +16 -16
  2. package/src/lib/components/campaign-conversions-card.js +58 -15
  3. package/src/lib/components/campaign-conversions-card.js.map +1 -1
  4. package/src/lib/components/campaign-detail-card.js +50 -5
  5. package/src/lib/components/campaign-detail-card.js.map +1 -1
  6. package/src/lib/components/campaign-members-section.js +36 -8
  7. package/src/lib/components/campaign-members-section.js.map +1 -1
  8. package/src/lib/components/campaigns-card.js +64 -10
  9. package/src/lib/components/campaigns-card.js.map +1 -1
  10. package/src/lib/components/email-recipients-card.js +37 -2
  11. package/src/lib/components/email-recipients-card.js.map +1 -1
  12. package/src/lib/components/emails-list-card.js +59 -6
  13. package/src/lib/components/emails-list-card.js.map +1 -1
  14. package/src/lib/components/host-experiments-card.component.js +32 -6
  15. package/src/lib/components/host-experiments-card.component.js.map +1 -1
  16. package/src/lib/components/staff-org-email-card.component.js +82 -6
  17. package/src/lib/components/staff-org-email-card.component.js.map +1 -1
  18. package/src/lib/model/campaign-conversions.d.ts +2 -0
  19. package/src/lib/model/campaign-conversions.js +32 -0
  20. package/src/lib/model/campaign-conversions.js.map +1 -1
  21. package/src/lib/model/campaign-list-query.d.ts +6 -2
  22. package/src/lib/model/campaign-list-query.js +64 -9
  23. package/src/lib/model/campaign-list-query.js.map +1 -1
  24. package/src/lib/model/campaign-members-query.d.ts +2 -1
  25. package/src/lib/model/campaign-members-query.js +23 -1
  26. package/src/lib/model/campaign-members-query.js.map +1 -1
  27. package/src/lib/model/experiment-list-query.js +30 -2
  28. package/src/lib/model/experiment-list-query.js.map +1 -1
  29. package/src/lib/model/native-vocabulary.d.ts +26 -0
  30. package/src/lib/model/native-vocabulary.js +31 -0
  31. package/src/lib/model/native-vocabulary.js.map +1 -0
  32. package/src/lib/server/campaign-manage.d.ts +1 -1
  33. package/src/lib/server/campaign-manage.js +1 -0
  34. package/src/lib/server/campaign-manage.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/components/campaign-members-section.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n pluginRecordHref,\n pluginRecordListHref,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-routes'\nimport { AppLink } from '@aglyn/shared-ui-jsx'\nimport {\n Figure,\n Section,\n} from '@aglyn/shared-ui-jsx/components/measured-figures.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport ListQueryNotices, {\n listQueryRefusals,\n} from '@aglyn/shared-ui-jsx/components/list-query-notices.component'\nimport { ListTable } from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport { useListGridFilter } from '@aglyn/shared-ui-jsx/hooks/use-list-grid-filter'\nimport { TABLE_ROW_HEIGHT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport { useListQuery } from '@aglyn/tenant-feature-instance/hooks/use-list-query'\nimport {\n buildRoute,\n readContainerIds,\n Route,\n type FormStats,\n type FormStatsTotals,\n} from '@aglyn/aglyn'\nimport { Alert, Stack, Typography } from '@mui/material'\nimport type { GridColDef } from '@mui/x-data-grid'\nimport {\n collection,\n documentId,\n limit,\n orderBy,\n query,\n where,\n} from 'firebase/firestore'\nimport { useCallback, useMemo } from 'react'\nimport {\n useConsoleHostRoute,\n useFirestore,\n useFirestoreCollection,\n} from '@aglyn/tenant-feature-instance'\nimport {\n campaignFormsRollup,\n campaignFormTotals,\n campaignPeriodRange,\n isWindowedRange,\n type CampaignFormsRollup,\n} from '../model/campaign-membership-figures'\nimport { CAMPAIGN_KIND, CAMPAIGN_MEMBERSHIP_FIELD } from '../model/campaign-kind'\nimport {\n CAMPAIGN_MEMBERS_QUERY,\n CAMPAIGN_MEMBERS_SEARCH_NOTICE,\n campaignMembersBase,\n campaignMembersSearchClause,\n type CampaignMemberCollection,\n} from '../model/campaign-members-query'\n\n/**\n * How many forms the holdings figures add up.\n *\n * The tables page through every member; the figures are a sum, read from a\n * window of their own. One document past it is asked for, so \"the figures\n * cover some of the forms\" is a fact rather than a guess — the same probe\n * the emails figures on this page make.\n */\nconst FIGURES_CEILING = 25\n\nexport interface CampaignMembersSectionProps {\n hostId: string\n /**\n * The site's name, when the section is one of several — the org hub draws\n * one per site the campaign is placed on, and each heading says whose\n * forms and screens it lists.\n */\n siteName?: string\n campaignId: string\n /** The campaign's first day, when it has one. */\n startAtMs?: number | null\n /** The campaign's last day, when it has one. */\n endAtMs?: number | null\n}\n\n/** One row, whatever collection it came out of. */\ninterface MemberRow {\n id: string\n name: string\n href: string | null\n /** Why there is no link, when there is none. */\n hrefReason?: string\n /** The member's own counters, for a kind that carries them. */\n totals?: FormStatsTotals\n /** Campaigns the member is filed under, this one included. */\n campaigns?: number\n}\n\n/**\n * WHAT ELSE IS IN THIS CAMPAIGN — the landing pages and forms assigned to it,\n * and what those forms have collected.\n *\n * ## Declared, and therefore different from every section above it\n *\n * The conversions, revenue and destinations sections are EVIDENCE: they join\n * on the campaign's send ids and report what visitors did BECAUSE of this\n * campaign's mail. This one is a statement the merchant made — a screen or a\n * form carries this campaign's id in {@link CAMPAIGN_MEMBERSHIP_FIELD} — plus\n * the counters those records carry on their own documents.\n *\n * The distinction survives into the wording, because the arithmetic will not\n * enforce it. A form's submissions are the form's; filing the form under a\n * campaign does not make them the campaign's, and a heading that said\n * \"this campaign produced 40 leads\" over a number meaning \"the forms filed\n * here have 40 leads\" would be a worse page than one showing nothing. So the\n * figures are labeled as what the forms HOLD, they sit in their own block\n * under their own disclaimer, and no total on this page adds them to an\n * attributed one.\n *\n * ## Three ways the forms' counters could mislead, each answered\n *\n * 1. **They are lifetime.** `stats.submissions` has counted since the form\n * existed, including every submission from before anybody filed it here.\n * Where the campaign carries dates, the figures are summed from the\n * monthly `stats.periods` series over those months instead, and the\n * caption says which of the two a reader is looking at. Months are whole,\n * so a campaign starting mid-month includes that month entire — stated,\n * not rounded away.\n * 2. **A form can be in twenty campaigns.** `campaignIds` is an array, so\n * the same submissions count toward every campaign the form is filed\n * under. Rows say so and the total refuses to present itself as\n * exclusive.\n * 3. **A counter nobody wrote is not a zero.** `stats.leads` is counted\n * only for a form whose `routing.lead` is set, and `stats.views` only by\n * the analytics beacon. Both reach the shared `Figure`, which draws an em\n * dash and the words \"not recorded\" rather than a confident 0.\n *\n * ## Screens carry no counter, and this section will not invent one\n *\n * A form's counters ride on the form document, so the query this section\n * already makes pays for them. A screen's traffic does not: it is one\n * document per screen per day in `hosts/{hostId}/screenAnalytics`, with no\n * lifetime total anywhere, so a views column here would cost a range read\n * across screens times days on every open of this page — and the display of\n * those figures is a paid entitlement this section does not resolve. The\n * screens block names the absence and links to the surface that does measure\n * it, which is a smaller lie than a number nobody can stand behind.\n *\n * ## The join is `array-contains`, on the member's own document\n *\n * A campaign holds no member list. Each record names the campaigns it is in,\n * which is what makes deleting one record leave nothing behind and what lets\n * a record's own page draw its campaigns without a query. The query here is\n * the other direction of the same field.\n *\n * ## Each kind is a table paged by its own query (AGL-3321)\n *\n * The screens and the forms are each a list a reader pages and searches, so\n * the membership, the soft delete and the search word are all on the\n * table's Firestore query (`campaign-members-query.ts`), and every member is\n * reachable a page at a time. Nothing is matched over rows already read: a\n * deleted screen is left out by `deletedAt == null`, which every screen\n * stores, and the search is a prefix range on the stored `nameLower`.\n *\n * Unsearched, a table walks the document name, which every record has — a\n * form carries `updatedAt` only if some writer stamped one, and ordering on a\n * field a writer may omit does not mis-sort the list, it drops rows from it.\n *\n * The forms' HOLDINGS are a sum, not a list, so they read a window of their\n * own — the first {@link FIGURES_CEILING} forms by document name — and say\n * when the campaign holds more, as the mail figures on this page do.\n *\n * ## Contacts are named here and NOT listed, and the reason is a query limit\n *\n * A contact is org-scoped and shared between the sites that captured it, so\n * every client read of the collection has to carry\n * `visibleTo array-contains-any` — that is what makes the read provable\n * per-document under the rules. Firestore permits ONE array clause per query,\n * and that is it: there is no client query that filters contacts by campaign\n * as well, so there is no pre-filtered address to link to either. The link\n * offered goes to the Contacts page and says it arrives unfiltered; the\n * assignment is real, is set from the contact's own drawer, and a count of it\n * would cost a scan of the collection the customer is billed on.\n */\nexport function CampaignMembersSection(props: CampaignMembersSectionProps) {\n const { hostId, siteName, campaignId, startAtMs, endAtMs } = props\n const firestore = useFirestore()\n const { orgSlug, subdomain: host } = useConsoleHostRoute(hostId)\n\n /*\n * The window the holdings figures add up: the forms filed here, by\n * document name, one past the ceiling as the probe. A form has no soft\n * delete — it is deleted outright — so every document this returns is a\n * form in use or a retired one, and both hold what they collected.\n */\n const { data: figureDocs } = useFirestoreCollection<Record<string, unknown>>(\n () =>\n query(\n collection(firestore, 'hosts', hostId, 'forms'),\n where(CAMPAIGN_MEMBERSHIP_FIELD, 'array-contains', campaignId),\n orderBy(documentId()),\n limit(FIGURES_CEILING + 1),\n ),\n [firestore, hostId, campaignId],\n { idField: '$id' },\n )\n\n /*\n * The months the campaign's dates cover, or nothing where it has neither.\n * Derived from props the detail card already holds, so asking what a\n * figure covers costs no read.\n */\n const range = useMemo(\n () => campaignPeriodRange({ startAtMs, endAtMs }),\n [startAtMs, endAtMs],\n )\n const windowed = isWindowedRange(range)\n\n const screenRow = useCallback(\n (row: Record<string, unknown>): MemberRow => {\n const id = String(row['$id'])\n const versionId = String(row['versionId'] ?? '')\n return {\n id,\n name: String(row['displayName'] ?? id),\n /*\n * A screen with no saved version has no detail address to build —\n * the route carries a version — so it stays plain text rather than\n * linking somewhere that 404s. The screens list applies the same\n * guard to its own name column.\n */\n href:\n versionId && orgSlug && host\n ? buildRoute(Route.SCREEN_DETAILS, {\n orgSlug,\n host,\n screenId: id,\n versionId,\n })\n : null,\n hrefReason: versionId\n ? 'This site’s console URL has not resolved yet'\n : 'This page has no saved version yet',\n campaigns: readContainerIds(row, CAMPAIGN_KIND).length,\n }\n },\n [orgSlug, host],\n )\n\n /*\n * The counters ride on the form documents, so each row's figures are paid\n * for by the read that lists it.\n */\n const formRow = useCallback(\n (row: Record<string, unknown>): MemberRow => {\n const id = String(row['$id'])\n return {\n id,\n name: String(row['displayName'] ?? id),\n href: orgSlug && host ? pluginRecordHref('form', { orgSlug, host }, id) : null,\n hrefReason: 'This site’s console URL has not resolved yet',\n totals: campaignFormTotals(row['stats'] as FormStats | undefined, range),\n campaigns: readContainerIds(row, CAMPAIGN_KIND).length,\n }\n },\n [orgSlug, host, range],\n )\n\n const figureForms = useMemo(\n () => (figureDocs ?? []).slice(0, FIGURES_CEILING).map(formRow),\n [figureDocs, formRow],\n )\n const figuresTruncated = (figureDocs ?? []).length > FIGURES_CEILING\n const rollup = useMemo(\n () =>\n campaignFormsRollup(\n figureForms.map((row) => ({\n totals: row.totals as FormStatsTotals,\n campaigns: row.campaigns ?? 1,\n })),\n ),\n [figureForms],\n )\n\n const analyticsHref =\n orgSlug && host\n ? buildRoute(Route.HOST_ANALYTICS, { orgSlug, host })\n : null\n const contactsHref =\n orgSlug && host ? pluginRecordListHref('contact', { orgSlug, host }) : null\n\n return (\n <Section\n title={\n siteName\n ? `Assigned to this campaign on ${siteName}`\n : 'Assigned to this campaign'\n }\n >\n <Stack spacing={2}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'The pages and forms somebody put in this campaign. Assignment is ' +\n 'a grouping — what the campaign was credited with is measured ' +\n 'above, from the links its emails carried.'}\n </Typography>\n <MemberTable\n heading=\"Pages\"\n noun=\"page\"\n collectionName=\"screens\"\n hostId={hostId}\n campaignId={campaignId}\n toRow={screenRow}\n />\n {/*\n The absence, named where a reader would look for the number.\n\n A screen's traffic is not on the screen document — it is a day doc\n per screen in `screenAnalytics` — so a views column here would be a\n read across screens times days on every open, for figures whose\n display is a paid entitlement this section does not resolve. The\n page that does both is linked instead.\n */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Page views are not shown here. A page keeps no running total ' +\n 'on its own record — traffic is stored a day at a time — so ' +\n 'counting it would be a fresh read of the site’s history every ' +\n 'time this view opens. '}\n {analyticsHref ? (\n <AppLink href={analyticsHref}>\n {'The site’s analytics measures it by page.'}\n </AppLink>\n ) : (\n 'The site’s analytics view measures it by page.'\n )}\n </Typography>\n <MemberTable\n heading=\"Forms\"\n noun=\"form\"\n collectionName=\"forms\"\n hostId={hostId}\n campaignId={campaignId}\n toRow={formRow}\n figures\n />\n {/*\n THE MEMBERSHIP TOTAL, fenced off from the attributed ones above.\n\n Same `Figure` primitive as the mail rollup, deliberately different\n words: it says what the forms HOLD, and the caption beneath refuses\n the reading a merchant will reach for first.\n */}\n {figureForms.length ? (\n <FormsHoldings\n rollup={rollup}\n windowed={windowed}\n from={range.from ?? null}\n to={range.to ?? null}\n truncated={figuresTruncated}\n />\n ) : null}\n {/*\n The people, named rather than omitted.\n\n A contact CAN be filed under a campaign and this page cannot list\n them — see the module comment for the query rule that decides it.\n Leaving the heading out entirely would read as \"contacts cannot be\n assigned\", which is the one thing it does not mean.\n */}\n <Stack spacing={0.5}>\n <Typography variant=\"overline\" color=\"text.secondary\">\n {'Contacts'}\n </Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Contacts are filed under a campaign from the contact’s own ' +\n 'panel on the Contacts page. They are not listed or counted ' +\n 'here: a contact belongs to the organization rather than to ' +\n 'this site, so the query that reads them is already spending ' +\n 'its one array filter on which sites may see the person. '}\n {contactsHref ? (\n <AppLink href={contactsHref}>{'Open Contacts'}</AppLink>\n ) : null}\n {contactsHref\n ? ' — it opens unfiltered, because that same rule leaves no ' +\n 'campaign filter for the address to carry.'\n : ''}\n </Typography>\n </Stack>\n </Stack>\n </Section>\n )\n}\n\n/**\n * What the campaign's forms have collected — and what that is NOT.\n *\n * Two sentences do the whole job of keeping this apart from the attributed\n * figures, and both are load-bearing:\n *\n * - The first refuses causation outright. A merchant reading a number under\n * a campaign's heading will assume the campaign caused it unless told\n * otherwise in the same breath.\n * - The second says which months the number covers. A lifetime total under a\n * campaign that ran for six weeks is the same lie one step quieter.\n *\n * `shared` is stated as a count rather than folded into the arithmetic. There\n * is no honest way to divide a submission between two campaigns a form is\n * filed under, so the total is left whole and the overlap is disclosed.\n */\nfunction FormsHoldings(props: {\n rollup: CampaignFormsRollup\n windowed: boolean\n from: string | null\n to: string | null\n /** The campaign holds more forms than the figures add up. */\n truncated: boolean\n}) {\n const { rollup, windowed, from, to, truncated } = props\n const note = (recorded: number) =>\n recorded < rollup.members\n ? `across ${recorded} of ${rollup.members} forms`\n : `across ${rollup.members} form${rollup.members === 1 ? '' : 's'}`\n const span = windowed\n ? `the campaign’s months (${from ?? 'the first month recorded'} to ${\n to ?? 'now'\n })`\n : 'each form’s whole history'\n return (\n <Stack spacing={1}>\n <Typography variant=\"overline\" color=\"text.secondary\">\n {'What these forms hold'}\n </Typography>\n <Stack useFlexGap direction=\"row\" spacing={3} sx={{ flexWrap: 'wrap' }}>\n <Figure\n label=\"Views\"\n value={rollup.views.value}\n note={note(rollup.views.recorded)}\n />\n <Figure\n label=\"Started\"\n value={rollup.starts.value}\n note={note(rollup.starts.recorded)}\n />\n <Figure\n label=\"Submissions\"\n value={rollup.submissions.value}\n note={note(rollup.submissions.recorded)}\n />\n <Figure\n label=\"Leads\"\n value={rollup.leads.value}\n note={note(rollup.leads.recorded)}\n />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'These are the forms’ own counters, not this campaign’s results. ' +\n 'A submission is counted here because somebody filed the form ' +\n 'under this campaign, whether or not this campaign’s mail sent ' +\n `the visitor. Counted over ${span}.`}\n </Typography>\n {windowed ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Whole calendar months: a campaign that started or ended mid-' +\n 'month takes that month entire, and a form counting nothing in ' +\n 'those months adds nothing here even where its lifetime total ' +\n 'is large.'}\n </Typography>\n ) : (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'This campaign has no dates, so nothing narrows the figures to ' +\n 'it. They are lifetime totals and include everything from ' +\n 'before the forms were put in this campaign. Give the campaign ' +\n 'a start and an end to count only its months.'}\n </Typography>\n )}\n {truncated ? (\n <Alert severity=\"info\">\n {`These figures add up the first ${FIGURES_CEILING} forms in this ` +\n 'campaign, in document order. It holds more; the table above ' +\n 'lists every one of them.'}\n </Alert>\n ) : null}\n {rollup.shared ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${rollup.shared} of these ${rollup.members} forms ${\n rollup.shared === 1 ? 'is' : 'are'\n } filed under another campaign too, so the same submissions are ` +\n 'counted there as well. This total is not exclusive to this ' +\n 'campaign.'}\n </Typography>\n ) : null}\n </Stack>\n )\n}\nFormsHoldings.displayName = 'FormsHoldings'\n\n/** A counter as a cell: an em dash where nothing was recorded, never a zero. */\nfunction statCell(value: number | null | undefined) {\n return value === null || value === undefined ? '—' : value.toLocaleString()\n}\n\n/** The counters a form carries on its own document, in the order they are read. */\nconst MEMBER_FIGURES = [\n ['views', 'Views'],\n ['starts', 'Started'],\n ['submissions', 'Submissions'],\n ['leads', 'Leads'],\n] as const\n\n/** How the search reads on a notice: the box, not a column. */\nconst MEMBER_SEARCH_HEADERS: Readonly<Record<string, string>> = {\n name: 'Search',\n}\n\n/**\n * One kind's members, as a record list in the shared grid, paged by its own\n * query (AGL-3321).\n *\n * The membership, the soft delete and the search word are predicates on the\n * query (`campaign-members-query.ts`); the grid neither filters nor sorts\n * the page it is handed. The search box is the grid's quick filter, turned\n * into \"name starts with\" because the membership holds the query's one\n * array clause; the Filters panel is not offered, because every column\n * beside it would need an index of its own for a list this size.\n *\n * `figures` adds the counter columns for a kind that carries them on its own\n * document. It is a prop rather than two lists because the row grammar — the\n * name cell, the reason a member has no link, the footer — is the part that\n * has to stay identical between screens and forms.\n */\nfunction MemberTable(props: {\n heading: string\n noun: string\n collectionName: CampaignMemberCollection\n hostId: string\n campaignId: string\n toRow: (row: Record<string, unknown>) => MemberRow\n figures?: boolean\n}) {\n const { heading, noun, collectionName, hostId, campaignId, toRow, figures } =\n props\n const firestore = useFirestore()\n const gridFilter = useListGridFilter({})\n const search = campaignMembersSearchClause(gridFilter.searchWords)\n const page = useListQuery<Record<string, unknown>>({\n collection: collection(firestore, 'hosts', hostId, collectionName),\n declaration: CAMPAIGN_MEMBERS_QUERY,\n request: {\n clauses: search ? [search] : [],\n base: campaignMembersBase(collectionName, campaignId),\n },\n deps: [firestore, hostId, collectionName, campaignId],\n idField: '$id',\n })\n const rows = useMemo(() => page.rows.map(toRow), [page.rows, toRow])\n // Nothing typed and nothing on the first page: the campaign holds none,\n // which is said in words rather than as an empty grid.\n const none = !search && page.page === 0 && rows.length === 0\n const columns = useMemo<GridColDef<MemberRow>[]>(\n () => [\n {\n field: 'name',\n headerName: 'Name',\n flex: 1,\n minWidth: 240,\n renderCell: ({ row }) => (\n <Stack sx={{ py: 1, minWidth: 0 }}>\n {row.href ? (\n <AppLink href={row.href}>{row.name}</AppLink>\n ) : (\n <>\n <Typography variant=\"body2\">{row.name}</Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {row.hrefReason}\n </Typography>\n </>\n )}\n {/*\n The overlap, on the row that causes it. A reader comparing two\n campaigns has to be able to see which rows they have in common\n without opening either.\n */}\n {(row.campaigns ?? 1) > 1 ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Also in ${(row.campaigns ?? 1) - 1} other campaign${\n (row.campaigns ?? 1) - 1 === 1 ? '' : 's'\n }`}\n </Typography>\n ) : null}\n </Stack>\n ),\n },\n ...(figures\n ? MEMBER_FIGURES.map(\n ([figure, headerName]): GridColDef<MemberRow> => ({\n field: figure,\n headerName,\n type: 'number',\n align: 'right',\n headerAlign: 'right',\n width: 120,\n valueGetter: (_value, row) => row.totals?.[figure] ?? null,\n renderCell: ({ row }) => statCell(row.totals?.[figure]),\n }),\n )\n : []),\n ],\n [figures],\n )\n return (\n <Stack spacing={0.5}>\n <Typography variant=\"overline\" color=\"text.secondary\">\n {heading}\n </Typography>\n {none ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {page.status === 'loading'\n ? `Reading this campaign’s ${noun}s…`\n : `No ${noun} is in this campaign. Open a ${noun} and pick this ` +\n 'campaign on its own page to put it in one.'}\n </Typography>\n ) : (\n <>\n <ListQueryNotices\n refused={listQueryRefusals(page.plan.refused, {\n fields: CAMPAIGN_MEMBERS_QUERY.fields,\n headers: MEMBER_SEARCH_HEADERS,\n })}\n notices={\n search\n ? [CAMPAIGN_MEMBERS_SEARCH_NOTICE, ...page.plan.notices]\n : page.plan.notices\n }\n />\n <ListTable\n aria-label={heading}\n rows={rows}\n columns={columns}\n getRowId={(row: MemberRow) => row.id}\n rowHeight={TABLE_ROW_HEIGHT}\n // A member's name carries why it has no link, and the other\n // campaigns it is in, beneath it.\n getRowHeight={() => 'auto'}\n loading={page.status === 'loading'}\n filterMode=\"server\"\n filterModel={gridFilter.filterModel}\n onFilterModelChange={gridFilter.onFilterModelChange}\n quickFilter\n disableColumnFilter\n disableColumnSorting\n hideFooter\n noRowsLabel={`No ${noun} in this campaign starts with that`}\n />\n <ListPagination\n page={page.page}\n pageSize={page.pageSize}\n rowCount={rows.length}\n hasMore={page.hasMore}\n onPageChange={page.setPage}\n onPageSizeChange={page.setPageSize}\n />\n </>\n )}\n </Stack>\n )\n}\n\nCampaignMembersSection.displayName = 'CampaignMembersSection'\n\nexport default CampaignMembersSection\n"],"names":["pluginRecordHref","pluginRecordListHref","AppLink","Figure","Section","ListPagination","ListQueryNotices","listQueryRefusals","ListTable","useListGridFilter","TABLE_ROW_HEIGHT","useListQuery","buildRoute","readContainerIds","Route","Alert","Stack","Typography","collection","documentId","limit","orderBy","query","where","useCallback","useMemo","useConsoleHostRoute","useFirestore","useFirestoreCollection","campaignFormsRollup","campaignFormTotals","campaignPeriodRange","isWindowedRange","CAMPAIGN_KIND","CAMPAIGN_MEMBERSHIP_FIELD","CAMPAIGN_MEMBERS_QUERY","CAMPAIGN_MEMBERS_SEARCH_NOTICE","campaignMembersBase","campaignMembersSearchClause","FIGURES_CEILING","CampaignMembersSection","props","range","hostId","siteName","campaignId","startAtMs","endAtMs","firestore","orgSlug","subdomain","host","data","figureDocs","idField","windowed","screenRow","row","id","String","versionId","name","href","SCREEN_DETAILS","screenId","hrefReason","campaigns","length","formRow","totals","figureForms","slice","map","figuresTruncated","rollup","analyticsHref","HOST_ANALYTICS","contactsHref","title","spacing","variant","color","MemberTable","heading","noun","collectionName","toRow","figures","FormsHoldings","from","to","truncated","note","recorded","members","span","useFlexGap","direction","sx","flexWrap","label","value","views","starts","submissions","leads","severity","shared","displayName","statCell","undefined","toLocaleString","MEMBER_FIGURES","MEMBER_SEARCH_HEADERS","gridFilter","search","searchWords","page","declaration","request","clauses","base","deps","rows","none","columns","field","headerName","flex","minWidth","renderCell","py","figure","type","align","headerAlign","width","valueGetter","_value","status","refused","plan","fields","headers","notices","aria-label","getRowId","rowHeight","getRowHeight","loading","filterMode","filterModel","onFilterModelChange","quickFilter","disableColumnFilter","disableColumnSorting","hideFooter","noRowsLabel","pageSize","rowCount","hasMore","onPageChange","setPage","onPageSizeChange","setPageSize"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SACEA,gBAAgB,EAChBC,oBAAoB,QACf,mDAAkD;AACzD,SAASC,OAAO,QAAQ,uBAAsB;AAC9C,SACEC,MAAM,EACNC,OAAO,QACF,6DAA4D;AACnE,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,OAAOC,oBACLC,iBAAiB,QACZ,+DAA8D;AACrE,SAASC,SAAS,QAAQ,uDAAsD;AAChF,SAASC,iBAAiB,QAAQ,kDAAiD;AACnF,SAASC,gBAAgB,QAAQ,8CAA6C;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C;wBAClC0I,cAAc,IAAM;wBACpBC,SAAShC,KAAKsB,MAAM,KAAK;wBACzBW,YAAW;wBACXC,aAAarC,WAAWqC,WAAW;wBACnCC,qBAAqBtC,WAAWsC,mBAAmB;wBACnDC,WAAW;wBACXC,mBAAmB;wBACnBC,oBAAoB;wBACpBC,UAAU;wBACVC,aAAa,CAAC,GAAG,EAAEzE,KAAK,kCAAkC,CAAC;;kCAE7D,KAAC/E;wBACCgH,MAAMA,KAAKA,IAAI;wBACfyC,UAAUzC,KAAKyC,QAAQ;wBACvBC,UAAUpC,KAAKxD,MAAM;wBACrB6F,SAAS3C,KAAK2C,OAAO;wBACrBC,cAAc5C,KAAK6C,OAAO;wBAC1BC,kBAAkB9C,KAAK+C,WAAW;;;;;;AAM9C;AAEA5H,uBAAuBoE,WAAW,GAAG;AAErC,eAAepE,uBAAsB"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/components/campaign-members-section.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n pluginRecordHref,\n pluginRecordListHref,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-routes'\nimport { AppLink } from '@aglyn/shared-ui-jsx'\nimport {\n Figure,\n Section,\n} from '@aglyn/shared-ui-jsx/components/measured-figures.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport ListQueryNotices, {\n listQueryRefusals,\n} from '@aglyn/shared-ui-jsx/components/list-query-notices.component'\nimport { ListTable } from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport { useListGridFilter } from '@aglyn/shared-ui-jsx/hooks/use-list-grid-filter'\nimport { useListColumnSort } from '@aglyn/shared-ui-jsx/hooks/use-list-column-sort'\nimport type { ListQuerySort } from '@aglyn/shared-ui-jsx/const/list-query-plan'\nimport { TABLE_ROW_HEIGHT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport { useListQuery } from '@aglyn/tenant-feature-instance/hooks/use-list-query'\nimport {\n buildRoute,\n readContainerIds,\n Route,\n type FormStats,\n type FormStatsTotals,\n} from '@aglyn/aglyn'\nimport { Alert, Stack, Typography } from '@mui/material'\nimport type { GridColDef } from '@mui/x-data-grid'\nimport {\n collection,\n documentId,\n limit,\n orderBy,\n query,\n where,\n} from 'firebase/firestore'\nimport { useCallback, useMemo, useState } from 'react'\nimport {\n useConsoleHostRoute,\n useFirestore,\n useFirestoreCollection,\n} from '@aglyn/tenant-feature-instance'\nimport {\n campaignFormsRollup,\n campaignFormTotals,\n campaignPeriodRange,\n isWindowedRange,\n type CampaignFormsRollup,\n} from '../model/campaign-membership-figures'\nimport { CAMPAIGN_KIND, CAMPAIGN_MEMBERSHIP_FIELD } from '../model/campaign-kind'\nimport {\n CAMPAIGN_MEMBERS_QUERY,\n CAMPAIGN_MEMBERS_SEARCH_NOTICE,\n campaignMembersBase,\n campaignMembersSearchClause,\n type CampaignMemberCollection,\n} from '../model/campaign-members-query'\n\n/**\n * How many forms the holdings figures add up.\n *\n * The tables page through every member; the figures are a sum, read from a\n * window of their own. One document past it is asked for, so \"the figures\n * cover some of the forms\" is a fact rather than a guess — the same probe\n * the emails figures on this page make.\n */\nconst FIGURES_CEILING = 25\n\nexport interface CampaignMembersSectionProps {\n hostId: string\n /**\n * The site's name, when the section is one of several — the org hub draws\n * one per site the campaign is placed on, and each heading says whose\n * forms and screens it lists.\n */\n siteName?: string\n campaignId: string\n /** The campaign's first day, when it has one. */\n startAtMs?: number | null\n /** The campaign's last day, when it has one. */\n endAtMs?: number | null\n}\n\n/** One row, whatever collection it came out of. */\ninterface MemberRow {\n id: string\n name: string\n href: string | null\n /** Why there is no link, when there is none. */\n hrefReason?: string\n /** The member's own counters, for a kind that carries them. */\n totals?: FormStatsTotals\n /** Campaigns the member is filed under, this one included. */\n campaigns?: number\n}\n\n/**\n * WHAT ELSE IS IN THIS CAMPAIGN — the landing pages and forms assigned to it,\n * and what those forms have collected.\n *\n * ## Declared, and therefore different from every section above it\n *\n * The conversions, revenue and destinations sections are EVIDENCE: they join\n * on the campaign's send ids and report what visitors did BECAUSE of this\n * campaign's mail. This one is a statement the merchant made — a screen or a\n * form carries this campaign's id in {@link CAMPAIGN_MEMBERSHIP_FIELD} — plus\n * the counters those records carry on their own documents.\n *\n * The distinction survives into the wording, because the arithmetic will not\n * enforce it. A form's submissions are the form's; filing the form under a\n * campaign does not make them the campaign's, and a heading that said\n * \"this campaign produced 40 leads\" over a number meaning \"the forms filed\n * here have 40 leads\" would be a worse page than one showing nothing. So the\n * figures are labeled as what the forms HOLD, they sit in their own block\n * under their own disclaimer, and no total on this page adds them to an\n * attributed one.\n *\n * ## Three ways the forms' counters could mislead, each answered\n *\n * 1. **They are lifetime.** `stats.submissions` has counted since the form\n * existed, including every submission from before anybody filed it here.\n * Where the campaign carries dates, the figures are summed from the\n * monthly `stats.periods` series over those months instead, and the\n * caption says which of the two a reader is looking at. Months are whole,\n * so a campaign starting mid-month includes that month entire — stated,\n * not rounded away.\n * 2. **A form can be in twenty campaigns.** `campaignIds` is an array, so\n * the same submissions count toward every campaign the form is filed\n * under. Rows say so and the total refuses to present itself as\n * exclusive.\n * 3. **A counter nobody wrote is not a zero.** `stats.leads` is counted\n * only for a form whose `routing.lead` is set, and `stats.views` only by\n * the analytics beacon. Both reach the shared `Figure`, which draws an em\n * dash and the words \"not recorded\" rather than a confident 0.\n *\n * ## Screens carry no counter, and this section will not invent one\n *\n * A form's counters ride on the form document, so the query this section\n * already makes pays for them. A screen's traffic does not: it is one\n * document per screen per day in `hosts/{hostId}/screenAnalytics`, with no\n * lifetime total anywhere, so a views column here would cost a range read\n * across screens times days on every open of this page — and the display of\n * those figures is a paid entitlement this section does not resolve. The\n * screens block names the absence and links to the surface that does measure\n * it, which is a smaller lie than a number nobody can stand behind.\n *\n * ## The join is `array-contains`, on the member's own document\n *\n * A campaign holds no member list. Each record names the campaigns it is in,\n * which is what makes deleting one record leave nothing behind and what lets\n * a record's own page draw its campaigns without a query. The query here is\n * the other direction of the same field.\n *\n * ## Each kind is a table paged by its own query (AGL-3321)\n *\n * The screens and the forms are each a list a reader pages and searches, so\n * the membership, the soft delete and the search word are all on the\n * table's Firestore query (`campaign-members-query.ts`), and every member is\n * reachable a page at a time. Nothing is matched over rows already read: a\n * deleted screen is left out by `deletedAt == null`, which every screen\n * stores, and the search is a prefix range on the stored `nameLower`.\n *\n * Unsearched, a table walks the document name, which every record has — a\n * form carries `updatedAt` only if some writer stamped one, and ordering on a\n * field a writer may omit does not mis-sort the list, it drops rows from it.\n *\n * The forms' HOLDINGS are a sum, not a list, so they read a window of their\n * own — the first {@link FIGURES_CEILING} forms by document name — and say\n * when the campaign holds more, as the mail figures on this page do.\n *\n * ## Contacts are named here and NOT listed, and the reason is a query limit\n *\n * A contact is org-scoped and shared between the sites that captured it, so\n * every client read of the collection has to carry\n * `visibleTo array-contains-any` — that is what makes the read provable\n * per-document under the rules. Firestore permits ONE array clause per query,\n * and that is it: there is no client query that filters contacts by campaign\n * as well, so there is no pre-filtered address to link to either. The link\n * offered goes to the Contacts page and says it arrives unfiltered; the\n * assignment is real, is set from the contact's own drawer, and a count of it\n * would cost a scan of the collection the customer is billed on.\n */\nexport function CampaignMembersSection(props: CampaignMembersSectionProps) {\n const { hostId, siteName, campaignId, startAtMs, endAtMs } = props\n const firestore = useFirestore()\n const { orgSlug, subdomain: host } = useConsoleHostRoute(hostId)\n\n /*\n * The window the holdings figures add up: the forms filed here, by\n * document name, one past the ceiling as the probe. A form has no soft\n * delete — it is deleted outright — so every document this returns is a\n * form in use or a retired one, and both hold what they collected.\n */\n const { data: figureDocs } = useFirestoreCollection<Record<string, unknown>>(\n () =>\n query(\n collection(firestore, 'hosts', hostId, 'forms'),\n where(CAMPAIGN_MEMBERSHIP_FIELD, 'array-contains', campaignId),\n orderBy(documentId()),\n limit(FIGURES_CEILING + 1),\n ),\n [firestore, hostId, campaignId],\n { idField: '$id' },\n )\n\n /*\n * The months the campaign's dates cover, or nothing where it has neither.\n * Derived from props the detail card already holds, so asking what a\n * figure covers costs no read.\n */\n const range = useMemo(\n () => campaignPeriodRange({ startAtMs, endAtMs }),\n [startAtMs, endAtMs],\n )\n const windowed = isWindowedRange(range)\n\n const screenRow = useCallback(\n (row: Record<string, unknown>): MemberRow => {\n const id = String(row['$id'])\n const versionId = String(row['versionId'] ?? '')\n return {\n id,\n name: String(row['displayName'] ?? id),\n /*\n * A screen with no saved version has no detail address to build —\n * the route carries a version — so it stays plain text rather than\n * linking somewhere that 404s. The screens list applies the same\n * guard to its own name column.\n */\n href:\n versionId && orgSlug && host\n ? buildRoute(Route.SCREEN_DETAILS, {\n orgSlug,\n host,\n screenId: id,\n versionId,\n })\n : null,\n hrefReason: versionId\n ? 'This site’s console URL has not resolved yet'\n : 'This page has no saved version yet',\n campaigns: readContainerIds(row, CAMPAIGN_KIND).length,\n }\n },\n [orgSlug, host],\n )\n\n /*\n * The counters ride on the form documents, so each row's figures are paid\n * for by the read that lists it.\n */\n const formRow = useCallback(\n (row: Record<string, unknown>): MemberRow => {\n const id = String(row['$id'])\n return {\n id,\n name: String(row['displayName'] ?? id),\n href: orgSlug && host ? pluginRecordHref('form', { orgSlug, host }, id) : null,\n hrefReason: 'This site’s console URL has not resolved yet',\n totals: campaignFormTotals(row['stats'] as FormStats | undefined, range),\n campaigns: readContainerIds(row, CAMPAIGN_KIND).length,\n }\n },\n [orgSlug, host, range],\n )\n\n const figureForms = useMemo(\n () => (figureDocs ?? []).slice(0, FIGURES_CEILING).map(formRow),\n [figureDocs, formRow],\n )\n const figuresTruncated = (figureDocs ?? []).length > FIGURES_CEILING\n const rollup = useMemo(\n () =>\n campaignFormsRollup(\n figureForms.map((row) => ({\n totals: row.totals as FormStatsTotals,\n campaigns: row.campaigns ?? 1,\n })),\n ),\n [figureForms],\n )\n\n const analyticsHref =\n orgSlug && host\n ? buildRoute(Route.HOST_ANALYTICS, { orgSlug, host })\n : null\n const contactsHref =\n orgSlug && host ? pluginRecordListHref('contact', { orgSlug, host }) : null\n\n return (\n <Section\n title={\n siteName\n ? `Assigned to this campaign on ${siteName}`\n : 'Assigned to this campaign'\n }\n >\n <Stack spacing={2}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'The pages and forms somebody put in this campaign. Assignment is ' +\n 'a grouping — what the campaign was credited with is measured ' +\n 'above, from the links its emails carried.'}\n </Typography>\n <MemberTable\n heading=\"Pages\"\n noun=\"page\"\n collectionName=\"screens\"\n hostId={hostId}\n campaignId={campaignId}\n toRow={screenRow}\n />\n {/*\n The absence, named where a reader would look for the number.\n\n A screen's traffic is not on the screen document — it is a day doc\n per screen in `screenAnalytics` — so a views column here would be a\n read across screens times days on every open, for figures whose\n display is a paid entitlement this section does not resolve. The\n page that does both is linked instead.\n */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Page views are not shown here. A page keeps no running total ' +\n 'on its own record — traffic is stored a day at a time — so ' +\n 'counting it would be a fresh read of the site’s history every ' +\n 'time this view opens. '}\n {analyticsHref ? (\n <AppLink href={analyticsHref}>\n {'The site’s analytics measures it by page.'}\n </AppLink>\n ) : (\n 'The site’s analytics view measures it by page.'\n )}\n </Typography>\n <MemberTable\n heading=\"Forms\"\n noun=\"form\"\n collectionName=\"forms\"\n hostId={hostId}\n campaignId={campaignId}\n toRow={formRow}\n figures\n />\n {/*\n THE MEMBERSHIP TOTAL, fenced off from the attributed ones above.\n\n Same `Figure` primitive as the mail rollup, deliberately different\n words: it says what the forms HOLD, and the caption beneath refuses\n the reading a merchant will reach for first.\n */}\n {figureForms.length ? (\n <FormsHoldings\n rollup={rollup}\n windowed={windowed}\n from={range.from ?? null}\n to={range.to ?? null}\n truncated={figuresTruncated}\n />\n ) : null}\n {/*\n The people, named rather than omitted.\n\n A contact CAN be filed under a campaign and this page cannot list\n them — see the module comment for the query rule that decides it.\n Leaving the heading out entirely would read as \"contacts cannot be\n assigned\", which is the one thing it does not mean.\n */}\n <Stack spacing={0.5}>\n <Typography variant=\"overline\" color=\"text.secondary\">\n {'Contacts'}\n </Typography>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Contacts are filed under a campaign from the contact’s own ' +\n 'panel on the Contacts page. They are not listed or counted ' +\n 'here: a contact belongs to the organization rather than to ' +\n 'this site, so the query that reads them is already spending ' +\n 'its one array filter on which sites may see the person. '}\n {contactsHref ? (\n <AppLink href={contactsHref}>{'Open Contacts'}</AppLink>\n ) : null}\n {contactsHref\n ? ' — it opens unfiltered, because that same rule leaves no ' +\n 'campaign filter for the address to carry.'\n : ''}\n </Typography>\n </Stack>\n </Stack>\n </Section>\n )\n}\n\n/**\n * What the campaign's forms have collected — and what that is NOT.\n *\n * Two sentences do the whole job of keeping this apart from the attributed\n * figures, and both are load-bearing:\n *\n * - The first refuses causation outright. A merchant reading a number under\n * a campaign's heading will assume the campaign caused it unless told\n * otherwise in the same breath.\n * - The second says which months the number covers. A lifetime total under a\n * campaign that ran for six weeks is the same lie one step quieter.\n *\n * `shared` is stated as a count rather than folded into the arithmetic. There\n * is no honest way to divide a submission between two campaigns a form is\n * filed under, so the total is left whole and the overlap is disclosed.\n */\nfunction FormsHoldings(props: {\n rollup: CampaignFormsRollup\n windowed: boolean\n from: string | null\n to: string | null\n /** The campaign holds more forms than the figures add up. */\n truncated: boolean\n}) {\n const { rollup, windowed, from, to, truncated } = props\n const note = (recorded: number) =>\n recorded < rollup.members\n ? `across ${recorded} of ${rollup.members} forms`\n : `across ${rollup.members} form${rollup.members === 1 ? '' : 's'}`\n const span = windowed\n ? `the campaign’s months (${from ?? 'the first month recorded'} to ${\n to ?? 'now'\n })`\n : 'each form’s whole history'\n return (\n <Stack spacing={1}>\n <Typography variant=\"overline\" color=\"text.secondary\">\n {'What these forms hold'}\n </Typography>\n <Stack useFlexGap direction=\"row\" spacing={3} sx={{ flexWrap: 'wrap' }}>\n <Figure\n label=\"Views\"\n value={rollup.views.value}\n note={note(rollup.views.recorded)}\n />\n <Figure\n label=\"Started\"\n value={rollup.starts.value}\n note={note(rollup.starts.recorded)}\n />\n <Figure\n label=\"Submissions\"\n value={rollup.submissions.value}\n note={note(rollup.submissions.recorded)}\n />\n <Figure\n label=\"Leads\"\n value={rollup.leads.value}\n note={note(rollup.leads.recorded)}\n />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'These are the forms’ own counters, not this campaign’s results. ' +\n 'A submission is counted here because somebody filed the form ' +\n 'under this campaign, whether or not this campaign’s mail sent ' +\n `the visitor. Counted over ${span}.`}\n </Typography>\n {windowed ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Whole calendar months: a campaign that started or ended mid-' +\n 'month takes that month entire, and a form counting nothing in ' +\n 'those months adds nothing here even where its lifetime total ' +\n 'is large.'}\n </Typography>\n ) : (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'This campaign has no dates, so nothing narrows the figures to ' +\n 'it. They are lifetime totals and include everything from ' +\n 'before the forms were put in this campaign. Give the campaign ' +\n 'a start and an end to count only its months.'}\n </Typography>\n )}\n {truncated ? (\n <Alert severity=\"info\">\n {`These figures add up the first ${FIGURES_CEILING} forms in this ` +\n 'campaign, in document order. It holds more; the table above ' +\n 'lists every one of them.'}\n </Alert>\n ) : null}\n {rollup.shared ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${rollup.shared} of these ${rollup.members} forms ${\n rollup.shared === 1 ? 'is' : 'are'\n } filed under another campaign too, so the same submissions are ` +\n 'counted there as well. This total is not exclusive to this ' +\n 'campaign.'}\n </Typography>\n ) : null}\n </Stack>\n )\n}\nFormsHoldings.displayName = 'FormsHoldings'\n\n/** A counter as a cell: an em dash where nothing was recorded, never a zero. */\nfunction statCell(value: number | null | undefined) {\n return value === null || value === undefined ? '—' : value.toLocaleString()\n}\n\n/** The counters a form carries on its own document, in the order they are read. */\nconst MEMBER_FIGURES = [\n ['views', 'Views'],\n ['starts', 'Started'],\n ['submissions', 'Submissions'],\n ['leads', 'Leads'],\n] as const\n\n/*\n * The figures are summed from the campaign's visits for the members on the\n * page, so they sort the page; Name orders the query (AGL-3680).\n */\nconst MEMBER_PAGE_SORTS = Object.fromEntries(\n MEMBER_FIGURES.map(([figure]) => [figure, (row: MemberRow) => row.totals?.[figure] ?? null]),\n)\nconst MEMBER_PAGE_SORT_HEADERS = Object.fromEntries(MEMBER_FIGURES)\n\n/** How the search reads on a notice: the box, not a column. */\nconst MEMBER_SEARCH_HEADERS: Readonly<Record<string, string>> = {\n name: 'Search',\n}\n\n/**\n * One kind's members, as a record list in the shared grid, paged by its own\n * query (AGL-3321).\n *\n * The membership, the soft delete and the search word are predicates on the\n * query (`campaign-members-query.ts`); the grid neither filters nor sorts\n * the page it is handed. The search box is the grid's quick filter, turned\n * into \"name starts with\" because the membership holds the query's one\n * array clause; the Filters panel is not offered, because every column\n * beside it would need an index of its own for a list this size.\n *\n * `figures` adds the counter columns for a kind that carries them on its own\n * document. It is a prop rather than two lists because the row grammar — the\n * name cell, the reason a member has no link, the footer — is the part that\n * has to stay identical between screens and forms.\n */\nfunction MemberTable(props: {\n heading: string\n noun: string\n collectionName: CampaignMemberCollection\n hostId: string\n campaignId: string\n toRow: (row: Record<string, unknown>) => MemberRow\n figures?: boolean\n}) {\n const { heading, noun, collectionName, hostId, campaignId, toRow, figures } =\n props\n const firestore = useFirestore()\n const gridFilter = useListGridFilter({})\n const search = campaignMembersSearchClause(gridFilter.searchWords)\n const [askedSort, setAskedSort] = useState<ListQuerySort | null>(null)\n const page = useListQuery<Record<string, unknown>>({\n collection: collection(firestore, 'hosts', hostId, collectionName),\n declaration: CAMPAIGN_MEMBERS_QUERY,\n request: {\n clauses: search ? [search] : [],\n base: campaignMembersBase(collectionName, campaignId),\n sort: askedSort,\n },\n deps: [firestore, hostId, collectionName, campaignId],\n idField: '$id',\n })\n const rows = useMemo(() => page.rows.map(toRow), [page.rows, toRow])\n const columnSort = useListColumnSort<MemberRow>({\n sorts: CAMPAIGN_MEMBERS_QUERY.sorts,\n sort: askedSort,\n onSortChange: setAskedSort,\n orderBy: page.plan.orderBy,\n rows,\n pageSorts: figures ? MEMBER_PAGE_SORTS : undefined,\n headers: MEMBER_PAGE_SORT_HEADERS,\n })\n // Nothing typed and nothing on the first page: the campaign holds none,\n // which is said in words rather than as an empty grid.\n const none = !search && page.page === 0 && rows.length === 0\n const columns = useMemo<GridColDef<MemberRow>[]>(\n () => [\n {\n field: 'name',\n headerName: 'Name',\n flex: 1,\n minWidth: 240,\n renderCell: ({ row }) => (\n <Stack sx={{ py: 1, minWidth: 0 }}>\n {row.href ? (\n <AppLink href={row.href}>{row.name}</AppLink>\n ) : (\n <>\n <Typography variant=\"body2\">{row.name}</Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {row.hrefReason}\n </Typography>\n </>\n )}\n {/*\n The overlap, on the row that causes it. A reader comparing two\n campaigns has to be able to see which rows they have in common\n without opening either.\n */}\n {(row.campaigns ?? 1) > 1 ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Also in ${(row.campaigns ?? 1) - 1} other campaign${\n (row.campaigns ?? 1) - 1 === 1 ? '' : 's'\n }`}\n </Typography>\n ) : null}\n </Stack>\n ),\n },\n ...(figures\n ? MEMBER_FIGURES.map(\n ([figure, headerName]): GridColDef<MemberRow> => ({\n field: figure,\n headerName,\n type: 'number',\n align: 'right',\n headerAlign: 'right',\n width: 120,\n valueGetter: (_value, row) => row.totals?.[figure] ?? null,\n renderCell: ({ row }) => statCell(row.totals?.[figure]),\n }),\n )\n : []),\n ],\n [figures],\n )\n return (\n <Stack spacing={0.5}>\n <Typography variant=\"overline\" color=\"text.secondary\">\n {heading}\n </Typography>\n {none ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {page.status === 'loading'\n ? `Reading this campaign’s ${noun}s…`\n : `No ${noun} is in this campaign. Open a ${noun} and pick this ` +\n 'campaign on its own page to put it in one.'}\n </Typography>\n ) : (\n <>\n <ListQueryNotices\n refused={listQueryRefusals(page.plan.refused, {\n fields: CAMPAIGN_MEMBERS_QUERY.fields,\n headers: MEMBER_SEARCH_HEADERS,\n })}\n notices={[\n ...(search ? [CAMPAIGN_MEMBERS_SEARCH_NOTICE] : []),\n ...page.plan.notices,\n ...columnSort.notices,\n ]}\n />\n <ListTable\n aria-label={heading}\n rows={columnSort.rows}\n columns={columns}\n getRowId={(row: MemberRow) => row.id}\n rowHeight={TABLE_ROW_HEIGHT}\n // A member's name carries why it has no link, and the other\n // campaigns it is in, beneath it.\n getRowHeight={() => 'auto'}\n loading={page.status === 'loading'}\n filterMode=\"server\"\n filterModel={gridFilter.filterModel}\n onFilterModelChange={gridFilter.onFilterModelChange}\n quickFilter\n disableColumnFilter\n // Name orders the query, the figures the page (AGL-3680).\n columnSort={columnSort}\n hideFooter\n noRowsLabel={`No ${noun} in this campaign starts with that`}\n />\n <ListPagination\n page={page.page}\n pageSize={page.pageSize}\n rowCount={rows.length}\n hasMore={page.hasMore}\n onPageChange={page.setPage}\n onPageSizeChange={page.setPageSize}\n />\n </>\n )}\n </Stack>\n )\n}\n\nCampaignMembersSection.displayName = 'CampaignMembersSection'\n\nexport default CampaignMembersSection\n"],"names":["pluginRecordHref","pluginRecordListHref","AppLink","Figure","Section","ListPagination","ListQueryNotices","listQueryRefusals","ListTable","useListGridFilter","useListColumnSort","TABLE_ROW_HEIGHT","useListQuery","buildRoute","readContainerIds","Route","Alert","Stack","Typography","collection","documentId","limit","orderBy","query","where","useCallback","useMemo","useState","useConsoleHostRoute","useFirestore","useFirestoreCollection","campaignFormsRollup","campaignFormTotals","campaignPeriodRange","isWindowedRange","CAMPAIGN_KIND","CAMPAIGN_MEMBERSHIP_FIELD","CAMPAIGN_MEMBERS_QUERY","CAMPAIGN_MEMBERS_SEARCH_NOTICE","campaignMembersBase","campaignMembersSearchClause","FIGURES_CEILING","CampaignMembersSection","props","range","hostId","siteName","campaignId","startAtMs","endAtMs","firestore","orgSlug","subdomain","host","data","figureDocs","idField","windowed","screenRow","row","id","String","versionId","name","href","SCREEN_DETAILS","screenId","hrefReason","campaigns","length","formRow","totals","figureForms","slice","map","figuresTruncated","rollup","analyticsHref","HOST_ANALYTICS","contactsHref","title","spacing","variant","color","MemberTable","heading","noun","collectionName","toRow","figures","FormsHoldings","from","to","truncated","note","recorded","members","span","useFlexGap","direction","sx","flexWrap","label","value","views","starts","submissions","leads","severity","shared","displayName","statCell","undefined","toLocaleString","MEMBER_FIGURES","MEMBER_PAGE_SORTS","Object","fromEntries","figure","MEMBER_PAGE_SORT_HEADERS","MEMBER_SEARCH_HEADERS","gridFilter","search","searchWords","askedSort","setAskedSort","page","declaration","request","clauses","base","sort","deps","rows","columnSort","sorts","onSortChange","plan","pageSorts","headers","none","columns","field","headerName","flex","minWidth","renderCell","py","type","align","headerAlign","width","valueGetter","_value","status","refused","fields","notices","aria-label","getRowId","rowHeight","getRowHeight","loading","filterMode","filterModel","onFilterModelChange","quickFilter","disableColumnFilter","hideFooter","noRowsLabel","pageSize","rowCount","hasMore","onPageChange","setPage","onPageSizeChange","setPageSize"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SACEA,gBAAgB,EAChBC,oBAAoB,QACf,mDAAkD;AACzD,SAASC,OAAO,QAAQ,uBAAsB;AAC9C,SACEC,MAAM,EACNC,OAAO,QACF,6DAA4D;AACnE,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,OAAOC,oBACLC,iBAAiB,QACZ,+DAA8D;AACrE,SAASC,SAAS,QAAQ,uDAAsD;AAChF,SAASC,iBAAiB,QAAQ,kDAAiD;AACnF,SAASC,iBAAiB,QAAQ,kDAAiD;AAEnF,SAASC,gBAAgB,QAAQ,8CAA6C;AAC9E,S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AM,KAAK,YACb,CAAC,wBAAwB,EAAEpE,KAAK,EAAE,CAAC,GACnC,CAAC,GAAG,EAAEA,KAAK,6BAA6B,EAAEA,KAAK,eAAe,CAAC,GAC/D;+BAGN;;kCACE,KAAChF;wBACCqJ,SAASpJ,kBAAkBuH,KAAKW,IAAI,CAACkB,OAAO,EAAE;4BAC5CC,QAAQvH,uBAAuBuH,MAAM;4BACrCjB,SAASnB;wBACX;wBACAqC,SAAS;+BACHnC,SAAS;gCAACpF;6BAA+B,GAAG,EAAE;+BAC/CwF,KAAKW,IAAI,CAACoB,OAAO;+BACjBvB,WAAWuB,OAAO;yBACtB;;kCAEH,KAACrJ;wBACCsJ,cAAYzE;wBACZgD,MAAMC,WAAWD,IAAI;wBACrBQ,SAASA;wBACTkB,UAAU,CAACpG,MAAmBA,IAAIC,EAAE;wBACpCoG,WAAWrJ;wBACX,4DAA4D;wBAC5D,kCAAkC;wBAClCsJ,cAAc,IAAM;wBACpBC,SAASpC,KAAK4B,MAAM,KAAK;wBACzBS,YAAW;wBACXC,aAAa3C,WAAW2C,WAAW;wBACnCC,qBAAqB5C,WAAW4C,mBAAmB;wBACnDC,WAAW;wBACXC,mBAAmB;wBACnB,0DAA0D;wBAC1DjC,YAAYA;wBACZkC,UAAU;wBACVC,aAAa,CAAC,GAAG,EAAEnF,KAAK,kCAAkC,CAAC;;kCAE7D,KAACjF;wBACCyH,MAAMA,KAAKA,IAAI;wBACf4C,UAAU5C,KAAK4C,QAAQ;wBACvBC,UAAUtC,KAAKhE,MAAM;wBACrBuG,SAAS9C,KAAK8C,OAAO;wBACrBC,cAAc/C,KAAKgD,OAAO;wBAC1BC,kBAAkBjD,KAAKkD,WAAW;;;;;;AAM9C;AAEAtI,uBAAuBoE,WAAW,GAAG;AAErC,eAAepE,uBAAsB"}
@@ -32,6 +32,7 @@ import { ListRowActions, ListTable, listActionsColumn } from "@aglyn/shared-ui-j
32
32
  import { hiddenFilterVisibility } from "@aglyn/shared-ui-jsx/const/list-filter";
33
33
  import { listFilterGridColumns } from "@aglyn/shared-ui-jsx/const/list-grid-filter";
34
34
  import { useListGridFilter } from "@aglyn/shared-ui-jsx/hooks/use-list-grid-filter";
35
+ import { useListColumnSort } from "@aglyn/shared-ui-jsx/hooks/use-list-column-sort";
35
36
  import { useSnackbar } from "@aglyn/shared-ui-snackstack";
36
37
  import { Alert, Button, Chip, Stack, ToggleButton, ToggleButtonGroup, Typography } from "@mui/material";
37
38
  import { collection, limit, query, setDoc, where } from "firebase/firestore";
@@ -57,6 +58,21 @@ import { useCampaignTopicOptions } from "./use-campaign-topic-options.js";
57
58
  /** Firestore's cap on an `in` clause's values. */ const IN_LIMIT = 30;
58
59
  const formatDay = (ms)=>ms === null ? '' : new Date(ms).toLocaleDateString();
59
60
  /** A rolled-up figure, or an em dash where nothing recorded one. */ const figure = (value)=>value.value === null ? '—' : value.value.toLocaleString();
61
+ /*
62
+ * EVERY HEADER SORTS (AGL-3680). A campaign's name and a single send's
63
+ * subject order the kind's query (`declaration.sorts`); what a row is drawn
64
+ * from — its sites, its window, its lists, and its figures (a campaign's
65
+ * summed from its emails for the page, a send's counters absent until
66
+ * something is counted) — sorts the page.
67
+ */ const CAMPAIGN_PAGE_SORT_HEADERS = {
68
+ sitesLabel: 'Sites',
69
+ windowState: 'Window',
70
+ listIds: 'Lists',
71
+ emails: 'Emails',
72
+ sent: 'Mail sent',
73
+ opens: 'Mail opens',
74
+ clicks: 'Mail clicks'
75
+ };
60
76
  const WINDOW_LABEL = {
61
77
  undated: 'No dates',
62
78
  upcoming: 'Upcoming',
@@ -146,6 +162,8 @@ const NO_CLAUSES = {
146
162
  * is asked by scope token, a send by the site it was sent as); the search
147
163
  * words are the reader's and carry across.
148
164
  *=========================================*/ const [kind, setKind] = useState('campaign');
165
+ // The header order asked of the kind on screen; a new kind starts unsorted.
166
+ const [askedSort, setAskedSort] = useState(null);
149
167
  const [clausesByKind, setClausesByKind] = useState(NO_CLAUSES);
150
168
  const [searchWords, setSearchWords] = useState([]);
151
169
  const setKindClauses = useCallback((next)=>setClausesByKind((current)=>_extends({}, current, {
@@ -184,7 +202,8 @@ const NO_CLAUSES = {
184
202
  ...gridFilter.clauses
185
203
  ] : gridFilter.clauses : [],
186
204
  search: hostId ? [] : gridFilter.searchWords,
187
- base: campaignContainersScope(hostId)
205
+ base: campaignContainersScope(hostId),
206
+ sort: kind === 'campaign' ? askedSort : null
188
207
  },
189
208
  deps: [
190
209
  firestore,
@@ -203,7 +222,8 @@ const NO_CLAUSES = {
203
222
  base: [
204
223
  SINGLE_SENDS_BASE,
205
224
  ...campaignSendsScope(hostId)
206
- ]
225
+ ],
226
+ sort: kind === 'single' ? askedSort : null
207
227
  },
208
228
  deps: [
209
229
  firestore,
@@ -335,6 +355,32 @@ const NO_CLAUSES = {
335
355
  restSends.rows,
336
356
  orgMount
337
357
  ]);
358
+ const pageSorts = useMemo(()=>({
359
+ sitesLabel: (row)=>row.sitesLabel || null,
360
+ windowState: (row)=>{
361
+ var _ref, _row_startAtMs;
362
+ return (_ref = (_row_startAtMs = row.startAtMs) != null ? _row_startAtMs : row.endAtMs) != null ? _ref : null;
363
+ },
364
+ listIds: (row)=>row.listIds.map((id)=>{
365
+ var _listNames_get;
366
+ return (_listNames_get = listNames.get(id)) != null ? _listNames_get : id;
367
+ }).join(', ') || null,
368
+ emails: (row)=>row.rollup.sends,
369
+ sent: (row)=>row.rollup.sent.value,
370
+ opens: (row)=>row.rollup.opens.value,
371
+ clicks: (row)=>row.rollup.clicks.value
372
+ }), [
373
+ listNames
374
+ ]);
375
+ const columnSort = useListColumnSort({
376
+ sorts: declaration.sorts,
377
+ sort: askedSort,
378
+ onSortChange: setAskedSort,
379
+ orderBy: page.plan.orderBy,
380
+ rows,
381
+ pageSorts,
382
+ headers: CAMPAIGN_PAGE_SORT_HEADERS
383
+ });
338
384
  /*
339
385
  * The choices the picked fields offer. A campaign's Sites are asked by
340
386
  * scope token — `org` is placed on every site — and a single send's by
@@ -827,7 +873,10 @@ const NO_CLAUSES = {
827
873
  size: "small",
828
874
  value: kind,
829
875
  onChange: (_event, next)=>{
830
- if (next) setKind(next);
876
+ if (next) {
877
+ setKind(next);
878
+ setAskedSort(null);
879
+ }
831
880
  },
832
881
  "aria-label": "Which rows the table lists",
833
882
  sx: {
@@ -857,25 +906,30 @@ const NO_CLAUSES = {
857
906
  headers: filterHeaders,
858
907
  options: filterOptions
859
908
  }),
860
- notices: siteSearch ? [
861
- CAMPAIGN_SITE_SEARCH_NOTICE,
862
- ...page.plan.notices
863
- ] : page.plan.notices
909
+ notices: [
910
+ ...siteSearch ? [
911
+ CAMPAIGN_SITE_SEARCH_NOTICE
912
+ ] : [],
913
+ ...page.plan.notices,
914
+ ...columnSort.notices
915
+ ]
864
916
  }),
865
917
  /*#__PURE__*/ _jsx(ListTable, {
866
- rows: rows,
918
+ rows: columnSort.rows,
867
919
  columns: listFilterGridColumns(columns, declaration.fields, filterOptions, filterHeaders),
868
920
  onOpen: (id)=>openCampaign(id),
869
921
  loading: page.status === 'loading',
870
922
  /*
871
923
  * The panel and the search are the grid's; every clause and the
872
924
  * search word are on the list's query (AGL-3321), and the grid
873
- * neither filters nor sorts the page it is handed.
925
+ * neither filters nor sorts the page it is handed: a stored
926
+ * column's header orders the query, a drawn one the page
927
+ * (AGL-3680).
874
928
  */ filterMode: "server",
875
929
  filterModel: gridFilter.filterModel,
876
930
  onFilterModelChange: gridFilter.onFilterModelChange,
877
931
  quickFilter: true,
878
- disableColumnSorting: true,
932
+ columnSort: columnSort,
879
933
  hideFooter: true,
880
934
  initialState: {
881
935
  columns: {