@aglyn/plugins-crm 1.0.0-beta.293 → 1.0.0-beta.296

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/plugins-crm",
3
- "version": "1.0.0-beta.293",
3
+ "version": "1.0.0-beta.296",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,19 +25,19 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.0.0-beta.293",
29
- "@aglyn/shared-data-enums": "1.0.0-beta.293",
30
- "@aglyn/shared-data-mdi": "1.0.0-beta.293",
31
- "@aglyn/shared-ui-jsx": "1.0.0-beta.293",
32
- "@aglyn/shared-ui-next": "1.0.0-beta.293",
33
- "@aglyn/shared-ui-snackstack": "1.0.0-beta.293",
34
- "@aglyn/shared-util-email": "1.0.0-beta.293",
35
- "@aglyn/shared-util-http": "1.0.0-beta.293",
36
- "@aglyn/shared-util-timestamp": "1.0.0-beta.293",
37
- "@aglyn/shared-util-tools": "1.0.0-beta.293",
38
- "@aglyn/tenant-data-admin": "1.0.0-beta.293",
39
- "@aglyn/tenant-feature-instance": "1.0.0-beta.293",
40
- "@aglyn/tenant-runtime": "1.0.0-beta.293",
28
+ "@aglyn/aglyn": "1.0.0-beta.296",
29
+ "@aglyn/shared-data-enums": "1.0.0-beta.296",
30
+ "@aglyn/shared-data-mdi": "1.0.0-beta.296",
31
+ "@aglyn/shared-ui-jsx": "1.0.0-beta.296",
32
+ "@aglyn/shared-ui-next": "1.0.0-beta.296",
33
+ "@aglyn/shared-ui-snackstack": "1.0.0-beta.296",
34
+ "@aglyn/shared-util-email": "1.0.0-beta.296",
35
+ "@aglyn/shared-util-http": "1.0.0-beta.296",
36
+ "@aglyn/shared-util-timestamp": "1.0.0-beta.296",
37
+ "@aglyn/shared-util-tools": "1.0.0-beta.296",
38
+ "@aglyn/tenant-data-admin": "1.0.0-beta.296",
39
+ "@aglyn/tenant-feature-instance": "1.0.0-beta.296",
40
+ "@aglyn/tenant-runtime": "1.0.0-beta.296",
41
41
  "@dnd-kit/core": "^6.3.1",
42
42
  "@dnd-kit/utilities": "^3.2.2",
43
43
  "@swc/helpers": "0.5.23",
@@ -17,7 +17,7 @@
17
17
  import { _ as _extends } from "@swc/helpers/_/_extends";
18
18
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
19
19
  import * as Aglyn from "@aglyn/aglyn";
20
- import { mdiAccountGroupOutline, mdiDeleteOutline, mdiDotsHorizontalCircleOutline, mdiEmailOutline, mdiEmailReceiveOutline, mdiNoteTextOutline, mdiPencilOutline, mdiPhoneOutline } from "@aglyn/shared-data-mdi";
20
+ import { mdiAccountGroupOutline, mdiDeleteOutline, mdiDotsHorizontalCircleOutline, mdiEmailOutline, mdiEmailReceiveOutline, mdiFacebookMessenger, mdiInstagram, mdiLinkedin, mdiMessageTextOutline, mdiNoteTextOutline, mdiPencilOutline, mdiPhoneOutline, mdiWhatsapp } from "@aglyn/shared-data-mdi";
21
21
  import { MdiIcon, useConfirmationContext } from "@aglyn/shared-ui-jsx";
22
22
  import EmptyStateComponent from "@aglyn/shared-ui-jsx/components/empty-state.component";
23
23
  import { ListPagination } from "@aglyn/shared-ui-jsx/components/list-pagination.component";
@@ -36,6 +36,11 @@ import { TimelineEntry, useTimelineExpansion, useTimelinePages } from "./activit
36
36
  */ const KIND_ICONS = {
37
37
  call: mdiPhoneOutline,
38
38
  email: mdiEmailOutline,
39
+ text: mdiMessageTextOutline,
40
+ whatsapp: mdiWhatsapp,
41
+ messenger: mdiFacebookMessenger,
42
+ instagram: mdiInstagram,
43
+ linkedin: mdiLinkedin,
39
44
  meeting: mdiAccountGroupOutline,
40
45
  note: mdiNoteTextOutline,
41
46
  other: mdiDotsHorizontalCircleOutline
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/activity-list.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 * as Aglyn from '@aglyn/aglyn'\nimport type { CrmActivityKind, CrmActivityRow } from '@aglyn/aglyn'\nimport {\n mdiAccountGroupOutline,\n mdiDeleteOutline,\n mdiDotsHorizontalCircleOutline,\n mdiEmailOutline,\n mdiEmailReceiveOutline,\n mdiNoteTextOutline,\n mdiPencilOutline,\n mdiPhoneOutline,\n} from '@aglyn/shared-data-mdi'\nimport { MdiIcon, useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport EmptyStateComponent from '@aglyn/shared-ui-jsx/components/empty-state.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { useUser, useUserName } from '@aglyn/tenant-feature-instance'\nimport { Chip, IconButton, Stack, Tooltip, Typography } from '@mui/material'\nimport { deleteDoc, doc } from 'firebase/firestore'\nimport { type ReactNode, useCallback, useState } from 'react'\nimport { type ActivityScope, useCanEditActivity } from './activity-queries'\nimport {\n TimelineEntry,\n type TimelineExpansion,\n useTimelineExpansion,\n useTimelinePages,\n} from './activity-timeline'\n\n/**\n * One glyph per kind. Typed against the union so a kind added to the list\n * cannot render with no icon — `MdiIcon` would fall back to its default\n * glyph silently, and a log where every note looks like a placeholder is\n * worse than a build error.\n */\nconst KIND_ICONS: Record<CrmActivityKind, { path: string }> = {\n call: mdiPhoneOutline,\n email: mdiEmailOutline,\n meeting: mdiAccountGroupOutline,\n note: mdiNoteTextOutline,\n other: mdiDotsHorizontalCircleOutline,\n}\n\n/** The icon for a kind — a stored kind outside the union draws as `other`. */\nexport function ActivityKindIcon(props: { kind: string; size?: number }) {\n const { kind, size = 1 } = props\n const icon = Aglyn.isCrmActivityKind(kind) ? KIND_ICONS[kind] : KIND_ICONS.other\n return <MdiIcon path={icon.path} size={size} />\n}\nActivityKindIcon.displayName = 'ActivityKindIcon'\n\n/**\n * The author's name for a row (AGL-2600).\n *\n * The denormalized `byName` leads: it is the only name a scoped colleague\n * can read, since a member document is readable by its subject and by\n * org-wide members alone. The signed-in user's OWN rows fall back to their\n * live name — the one case where a lookup is possible — and a row that\n * carries neither (written by a door that did not stamp one) reads as a\n * team member rather than as a uid.\n */\nexport function useActivityAuthorName(): (\n activity: Pick<CrmActivityRow, 'byUid' | 'byName'>,\n) => string {\n const { data: user } = useUser()\n const ownName = useUserName()\n const uid = user?.uid\n return useCallback(\n (activity) => {\n if (activity.byName) return activity.byName\n if (uid && activity.byUid === uid && ownName) return ownName\n return 'A team member'\n },\n [uid, ownName],\n )\n}\n\n/**\n * How long a note's own words may run on a collapsed row before it opens to\n * the rest; a single line under this reads whole, with nothing to open.\n */\nconst ACTIVITY_HEADING_MAX = 80\n\n/**\n * What a collapsed activity reads as, and whether opening it shows more.\n *\n * A subject is the heading and the body is what the row opens to. With no\n * subject the body's first line is the heading, and a body that runs past\n * that line, or past what one line holds, opens to the whole text.\n */\nexport function activityHeading(activity: Pick<CrmActivityRow, 'subject' | 'body'>): {\n heading: string\n opens: boolean\n} {\n const body = typeof activity.body === 'string' ? activity.body.trim() : ''\n const subject = typeof activity.subject === 'string' ? activity.subject.trim() : ''\n if (subject) return { heading: subject, opens: body !== '' }\n const firstLine = body.split('\\n').find((line) => line.trim() !== '')?.trim() ?? ''\n return {\n heading: firstLine,\n opens: body !== firstLine || firstLine.length > ACTIVITY_HEADING_MAX,\n }\n}\n\n/** \"45 min\" or \"2 h 05 min\" — a duration a manager reads at a glance. */\nfunction durationLabel(minutes: number): string {\n if (minutes < 60) return `${minutes} min`\n const hours = Math.floor(minutes / 60)\n const rest = minutes % 60\n return rest ? `${hours} h ${String(rest).padStart(2, '0')} min` : `${hours} h`\n}\n\nexport interface ActivityRowProps {\n activity: CrmActivityRow\n /** Where the delete is written, from `useActivityScope`. */\n scope: ActivityScope\n /** Opens the dialog on this activity. Absent, the row offers no edit. */\n onEdit?: (activity: CrmActivityRow) => void\n /**\n * What sits after the kind, before the body — a feed puts the record the\n * activity is about here, a record page needs nothing.\n */\n subject?: ReactNode\n /** The clock the relative time is read against; `Date.now()` when absent. */\n nowMs?: number\n /**\n * Whether THIS reader may edit and delete the row — the author, or an\n * org-wide member. Decided by whoever draws the rows, through\n * `useCanEditActivity`, once for the whole list: a row that asked for\n * itself would read the member document once per row.\n */\n editable?: boolean\n /**\n * Whether the row is open to its body. The list holds it so the card's\n * \"Expand all\" reaches every row; a row drawn alone holds its own.\n */\n expanded?: boolean\n onToggle?: () => void\n}\n\n/**\n * One logged activity: the kind's icon and label, what was said, how it\n * went, who logged it and how long ago — with edit and delete for whoever\n * may (AGL-2600).\n *\n * Collapsed, the row is its chips, its heading and its caption: the kind,\n * the direction and delivery state, how a call went, the subject or the\n * note's first line, and who, to or from whom, and when. Opened, it shows\n * the body — an email's whole text, a note's every line.\n *\n * Edit and delete appear only when `editable` says this reader may — the\n * author or an org-wide member. That is the console's verdict and not the\n * rules' — see `useCanEditActivity` for why the rules admit more — so the\n * controls are hidden rather than disabled: a disabled button asks \"why\n * not?\", and the honest answer would be \"you could, through the API\".\n */\nexport function ActivityRow(props: ActivityRowProps) {\n const { activity, scope, onEdit, subject, nowMs, editable } = props\n const [ownExpanded, setOwnExpanded] = useState(false)\n const expanded = props.expanded ?? ownExpanded\n const onToggle = props.onToggle ?? (() => setOwnExpanded((open) => !open))\n const { firestore, dataScope } = scope\n const authorName = useActivityAuthorName()\n const { confirm } = useConfirmationContext()\n const { enqueueSnackbar } = useSnackbar()\n\n const handleDelete = useCallback(async () => {\n if (!dataScope) return\n const confirmed = await confirm({\n title: 'Delete this activity?',\n description:\n `This ${Aglyn.CRM_ACTIVITY_KIND_LABELS[\n Aglyn.isCrmActivityKind(activity.kind) ? activity.kind : 'other'\n ].toLowerCase()} is removed from the record it was logged against. ` +\n 'Nothing the platform captured — a form, an order, a booking — is ' +\n 'affected.',\n confirmationText: 'Delete activity',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n try {\n await deleteDoc(\n doc(\n firestore,\n dataScope[0],\n dataScope[1],\n Aglyn.CRM_COLLECTIONS.activities,\n activity.$id,\n ),\n )\n enqueueSnackbar('Activity deleted', { variant: 'success', persist: false })\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n }, [dataScope, confirm, activity, firestore, enqueueSnackbar])\n\n const label =\n Aglyn.CRM_ACTIVITY_KIND_LABELS[\n Aglyn.isCrmActivityKind(activity.kind) ? activity.kind : 'other'\n ]\n /*\n * A message the platform SENT (AGL-2615) carries a subject, an address\n * and a delivery state the webhook advances; the state is the chip beside\n * the kind, red once the message did not land. What was sent is a record\n * of a fact and offers no edit — a rewritten body would misstate what\n * left — though whoever may delete a row may still delete this one.\n */\n const captured = typeof activity.messageId === 'string' && activity.messageId !== ''\n const deliveryState = Aglyn.isCrmEmailDeliveryState(activity.deliveryState)\n ? activity.deliveryState\n : null\n // A hand-logged email or call carries a direction too (AGL-3517); only a\n // message the platform carried or captured is \"sent\" or \"received\" here.\n const sent = activity.direction === 'outbound' && (deliveryState !== null || captured)\n /*\n * A message CAPTURED from a mailbox (AGL-2657) carries the provider's\n * Message-ID and, when a correspondent wrote it, the `inbound` direction.\n * It is drawn as its own thing — \"Received\" beside the kind, the sender\n * where a sent row shows the recipient, no author because nobody on the\n * team logged it — and a member's copied send reads \"Sent\" without a\n * delivery chip, since the platform did not carry it. Neither takes the\n * caller's \"Logged\" chip: nobody logged them.\n */\n const received = activity.direction === 'inbound' && captured\n /*\n * A hand-logged call or email names its direction in the kind's own chip\n * — \"Inbound call\", \"Outbound email\" (AGL-3517); a sent or captured\n * message says it with the chips below instead.\n */\n const kindChip =\n sent || received || captured\n ? label\n : Aglyn.crmActivityKindTitle(\n Aglyn.isCrmActivityKind(activity.kind) ? activity.kind : 'other',\n activity.direction,\n )\n const when = new Date(activity.atMs)\n const detail = [\n activity.outcome ? activity.outcome : null,\n typeof activity.durationMinutes === 'number' && activity.durationMinutes > 0\n ? durationLabel(activity.durationMinutes)\n : null,\n ].filter(Boolean)\n\n const { heading, opens } = activityHeading(activity)\n const hasSubject = typeof activity.subject === 'string' && activity.subject.trim() !== ''\n\n return (\n <TimelineEntry\n icon={\n received ? (\n <MdiIcon path={mdiEmailReceiveOutline.path} />\n ) : (\n <ActivityKindIcon kind={activity.kind} />\n )\n }\n label={heading || label.toLowerCase()}\n expanded={expanded}\n onToggle={onToggle}\n chips={\n <>\n <Chip label={kindChip} size=\"small\" />\n {received ? (\n <Chip\n label=\"Received\"\n size=\"small\"\n variant=\"outlined\"\n color=\"info\"\n data-testid=\"activity-direction\"\n />\n ) : captured ? (\n <Chip\n label=\"Sent\"\n size=\"small\"\n variant=\"outlined\"\n data-testid=\"activity-direction\"\n />\n ) : null}\n {deliveryState ? (\n <Tooltip\n title={\n typeof activity.deliveryAtMs === 'number'\n ? new Date(activity.deliveryAtMs).toLocaleString()\n : ''\n }\n >\n <Chip\n label={Aglyn.CRM_EMAIL_DELIVERY_STATE_LABELS[deliveryState]}\n size=\"small\"\n variant=\"outlined\"\n color={Aglyn.isCrmEmailDeliveryFailure(deliveryState) ? 'error' : 'default'}\n data-testid=\"activity-delivery-state\"\n />\n </Tooltip>\n ) : null}\n {captured ? null : subject}\n {detail.length ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {detail.join(' · ')}\n </Typography>\n ) : null}\n </>\n }\n // With no subject the heading IS the body's first line, so an open\n // row shows the body alone rather than its first line twice.\n title={hasSubject || !opens || !expanded ? heading : null}\n titleVariant={hasSubject ? 'subtitle2' : 'body2'}\n meta={\n <Tooltip title={when.toLocaleString()}>\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n sx={{ alignSelf: 'flex-start' }}\n >\n {[\n received ? null : authorName(activity),\n received && activity.from ? `from ${activity.from}` : null,\n sent && activity.to ? `to ${activity.to}` : null,\n Aglyn.activityTimeLabel(activity.atMs, nowMs ?? Date.now()),\n ]\n .filter(Boolean)\n .join(' · ')}\n </Typography>\n </Tooltip>\n }\n body={\n opens ? (\n <Typography variant=\"body2\" sx={{ whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' }}>\n {activity.body}\n </Typography>\n ) : undefined\n }\n actions={\n editable ? (\n <>\n {onEdit && !sent && !received ? (\n <IconButton\n size=\"small\"\n aria-label=\"Edit activity\"\n onClick={() => onEdit(activity)}\n >\n <MdiIcon path={mdiPencilOutline.path} size={0.8} />\n </IconButton>\n ) : null}\n <IconButton\n size=\"small\"\n aria-label=\"Delete activity\"\n onClick={handleDelete}\n >\n <MdiIcon path={mdiDeleteOutline.path} size={0.8} />\n </IconButton>\n </>\n ) : null\n }\n />\n )\n}\nActivityRow.displayName = 'ActivityRow'\n\nexport interface ActivityListProps {\n /** Newest-first, as the listener hands them back. */\n rows: readonly CrmActivityRow[]\n scope: ActivityScope\n onEdit?: (activity: CrmActivityRow) => void\n /** What the list says when there is nothing in it. */\n emptyText?: string\n /** The way out of an empty list — the record's \"Log activity\" button. */\n emptyAction?: ReactNode\n /** The listener holds less than exists; `onShowMore` widens it. */\n hasMore?: boolean\n onShowMore?: () => void\n /** The listener is reading, so an empty window is not yet an empty log. */\n loading?: boolean\n /** The record each row is about, for a list that spans records. */\n subjectFor?: (activity: CrmActivityRow) => ReactNode\n /**\n * No controls on any row, whoever is reading — and no member read to\n * decide them. A feed that spans records is a place to see what happened,\n * not to rewrite it; the record's own page is where an activity is\n * corrected, beside everything else about it.\n */\n readOnly?: boolean\n /**\n * Which rows are open, held by the card so its header's \"Expand all\"\n * reaches them. A list with no header control holds its own.\n */\n expansion?: TimelineExpansion\n}\n\n/**\n * A newest-first list of logged activities, collapsed to one entry each and\n * paged by the console's shared footer (AGL-2600).\n *\n * The rows arrive ordered — the query is `orderBy('atMs', 'desc')` — and the\n * list does not sort them again; a second sort here is a second place for\n * the order to be defined. The footer pages the window the listener holds,\n * and a page turned past it widens the listener while the probe row says\n * more exists (`useTimelinePages`).\n *\n * Who may edit is decided here, once, and handed to every row: the verdict\n * reads the member document, and the list is the one place that can ask\n * for it a single time however many rows it draws.\n */\nexport function ActivityList(props: ActivityListProps) {\n const {\n rows,\n scope,\n onEdit,\n emptyText = 'Nothing logged yet.',\n emptyAction,\n hasMore,\n onShowMore,\n loading,\n subjectFor,\n readOnly,\n } = props\n const canEdit = useCanEditActivity(scope.orgId, !readOnly)\n const ownExpansion = useTimelineExpansion()\n const expansion = props.expansion ?? ownExpansion\n const pages = useTimelinePages(rows.length, { hasMore, showMore: onShowMore, loading })\n // One clock for every row of one paint.\n const nowMs = Date.now()\n if (!rows.length) {\n return loading ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Loading…'}\n </Typography>\n ) : (\n <EmptyStateComponent\n compact\n label={'Nothing logged yet'}\n description={emptyText}\n action={emptyAction}\n />\n )\n }\n return (\n <Stack spacing={2}>\n {pages.slice(rows).map((activity) => (\n <ActivityRow\n key={activity.$id}\n activity={activity}\n scope={scope}\n onEdit={onEdit}\n subject={subjectFor?.(activity)}\n nowMs={nowMs}\n editable={canEdit(activity)}\n expanded={expansion.isExpanded(activity.$id)}\n onToggle={() => expansion.toggle(activity.$id)}\n />\n ))}\n <ListPagination {...pages.footer} />\n </Stack>\n )\n}\nActivityList.displayName = 'ActivityList'\n\nexport default ActivityList\n"],"names":["Aglyn","mdiAccountGroupOutline","mdiDeleteOutline","mdiDotsHorizontalCircleOutline","mdiEmailOutline","mdiEmailReceiveOutline","mdiNoteTextOutline","mdiPencilOutline","mdiPhoneOutline","MdiIcon","useConfirmationContext","EmptyStateComponent","ListPagination","useSnackbar","useUser","useUserName","Chip","IconButton","Stack","Tooltip","Typography","deleteDoc","doc","useCallback","useState","useCanEditActivity","TimelineEntry","useTimelineExpansion","useTimelinePages","KIND_ICONS","call","email","meeting","note","other","ActivityKindIcon","props","kind","size","icon","isCrmActivityKind","path","displayName","useActivityAuthorName","data","user","ownName","uid","activity","byName","byUid","ACTIVITY_HEADING_MAX","activityHeading","body","trim","subject","heading","opens","firstLine","split","find","line","length","durationLabel","minutes","hours","Math","floor","rest","String","padStart","ActivityRow","scope","onEdit","nowMs","editable","ownExpanded","setOwnExpanded","expanded","onToggle","open","firestore","dataScope","authorName","confirm","enqueueSnackbar","handleDelete","confirmed","title","description","CRM_ACTIVITY_KIND_LABELS","toLowerCase","confirmationText","confirmationButtonProps","color","then","catch","CRM_COLLECTIONS","activities","$id","variant","persist","error","console","allowDuplicate","label","captured","messageId","deliveryState","isCrmEmailDeliveryState","sent","direction","received","kindChip","crmActivityKindTitle","when","Date","atMs","detail","outcome","durationMinutes","filter","Boolean","hasSubject","chips","data-testid","deliveryAtMs","toLocaleString","CRM_EMAIL_DELIVERY_STATE_LABELS","isCrmEmailDeliveryFailure","join","titleVariant","meta","sx","alignSelf","from","to","activityTimeLabel","now","whiteSpace","overflowWrap","undefined","actions","aria-label","onClick","ActivityList","rows","emptyText","emptyAction","hasMore","onShowMore","loading","subjectFor","readOnly","canEdit","orgId","ownExpansion","expansion","pages","showMore","compact","action","spacing","slice","map","isExpanded","toggle","footer"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,YAAYA,WAAW,eAAc;AAErC,SACEC,sBAAsB,EACtBC,gBAAgB,EAChBC,8BAA8B,EAC9BC,eAAe,EACfC,sBAAsB,EACtBC,kBAAkB,EAClBC,gBAAgB,EAChBC,eAAe,QACV,yBAAwB;AAC/B,SAASC,OAAO,EAAEC,sBAAsB,QAAQ,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UAAU,IAAM8E,UAAUS,MAAM,CAACtH,SAASmD,GAAG;mBARxCnD,SAASmD,GAAG;0BAWrB,KAACvF,6BAAmBkJ,MAAMS,MAAM;;;AAGtC;AACAtB,aAAavG,WAAW,GAAG;AAE3B,eAAeuG,aAAY"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/components/activity-list.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 * as Aglyn from '@aglyn/aglyn'\nimport type { CrmActivityKind, CrmActivityRow } from '@aglyn/aglyn'\nimport {\n mdiAccountGroupOutline,\n mdiDeleteOutline,\n mdiDotsHorizontalCircleOutline,\n mdiEmailOutline,\n mdiEmailReceiveOutline,\n mdiFacebookMessenger,\n mdiInstagram,\n mdiLinkedin,\n mdiMessageTextOutline,\n mdiNoteTextOutline,\n mdiPencilOutline,\n mdiPhoneOutline,\n mdiWhatsapp,\n} from '@aglyn/shared-data-mdi'\nimport { MdiIcon, useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport EmptyStateComponent from '@aglyn/shared-ui-jsx/components/empty-state.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { useUser, useUserName } from '@aglyn/tenant-feature-instance'\nimport { Chip, IconButton, Stack, Tooltip, Typography } from '@mui/material'\nimport { deleteDoc, doc } from 'firebase/firestore'\nimport { type ReactNode, useCallback, useState } from 'react'\nimport { type ActivityScope, useCanEditActivity } from './activity-queries'\nimport {\n TimelineEntry,\n type TimelineExpansion,\n useTimelineExpansion,\n useTimelinePages,\n} from './activity-timeline'\n\n/**\n * One glyph per kind. Typed against the union so a kind added to the list\n * cannot render with no icon — `MdiIcon` would fall back to its default\n * glyph silently, and a log where every note looks like a placeholder is\n * worse than a build error.\n */\nconst KIND_ICONS: Record<CrmActivityKind, { path: string }> = {\n call: mdiPhoneOutline,\n email: mdiEmailOutline,\n text: mdiMessageTextOutline,\n whatsapp: mdiWhatsapp,\n messenger: mdiFacebookMessenger,\n instagram: mdiInstagram,\n linkedin: mdiLinkedin,\n meeting: mdiAccountGroupOutline,\n note: mdiNoteTextOutline,\n other: mdiDotsHorizontalCircleOutline,\n}\n\n/** The icon for a kind — a stored kind outside the union draws as `other`. */\nexport function ActivityKindIcon(props: { kind: string; size?: number }) {\n const { kind, size = 1 } = props\n const icon = Aglyn.isCrmActivityKind(kind) ? KIND_ICONS[kind] : KIND_ICONS.other\n return <MdiIcon path={icon.path} size={size} />\n}\nActivityKindIcon.displayName = 'ActivityKindIcon'\n\n/**\n * The author's name for a row (AGL-2600).\n *\n * The denormalized `byName` leads: it is the only name a scoped colleague\n * can read, since a member document is readable by its subject and by\n * org-wide members alone. The signed-in user's OWN rows fall back to their\n * live name — the one case where a lookup is possible — and a row that\n * carries neither (written by a door that did not stamp one) reads as a\n * team member rather than as a uid.\n */\nexport function useActivityAuthorName(): (\n activity: Pick<CrmActivityRow, 'byUid' | 'byName'>,\n) => string {\n const { data: user } = useUser()\n const ownName = useUserName()\n const uid = user?.uid\n return useCallback(\n (activity) => {\n if (activity.byName) return activity.byName\n if (uid && activity.byUid === uid && ownName) return ownName\n return 'A team member'\n },\n [uid, ownName],\n )\n}\n\n/**\n * How long a note's own words may run on a collapsed row before it opens to\n * the rest; a single line under this reads whole, with nothing to open.\n */\nconst ACTIVITY_HEADING_MAX = 80\n\n/**\n * What a collapsed activity reads as, and whether opening it shows more.\n *\n * A subject is the heading and the body is what the row opens to. With no\n * subject the body's first line is the heading, and a body that runs past\n * that line, or past what one line holds, opens to the whole text.\n */\nexport function activityHeading(activity: Pick<CrmActivityRow, 'subject' | 'body'>): {\n heading: string\n opens: boolean\n} {\n const body = typeof activity.body === 'string' ? activity.body.trim() : ''\n const subject = typeof activity.subject === 'string' ? activity.subject.trim() : ''\n if (subject) return { heading: subject, opens: body !== '' }\n const firstLine = body.split('\\n').find((line) => line.trim() !== '')?.trim() ?? ''\n return {\n heading: firstLine,\n opens: body !== firstLine || firstLine.length > ACTIVITY_HEADING_MAX,\n }\n}\n\n/** \"45 min\" or \"2 h 05 min\" — a duration a manager reads at a glance. */\nfunction durationLabel(minutes: number): string {\n if (minutes < 60) return `${minutes} min`\n const hours = Math.floor(minutes / 60)\n const rest = minutes % 60\n return rest ? `${hours} h ${String(rest).padStart(2, '0')} min` : `${hours} h`\n}\n\nexport interface ActivityRowProps {\n activity: CrmActivityRow\n /** Where the delete is written, from `useActivityScope`. */\n scope: ActivityScope\n /** Opens the dialog on this activity. Absent, the row offers no edit. */\n onEdit?: (activity: CrmActivityRow) => void\n /**\n * What sits after the kind, before the body — a feed puts the record the\n * activity is about here, a record page needs nothing.\n */\n subject?: ReactNode\n /** The clock the relative time is read against; `Date.now()` when absent. */\n nowMs?: number\n /**\n * Whether THIS reader may edit and delete the row — the author, or an\n * org-wide member. Decided by whoever draws the rows, through\n * `useCanEditActivity`, once for the whole list: a row that asked for\n * itself would read the member document once per row.\n */\n editable?: boolean\n /**\n * Whether the row is open to its body. The list holds it so the card's\n * \"Expand all\" reaches every row; a row drawn alone holds its own.\n */\n expanded?: boolean\n onToggle?: () => void\n}\n\n/**\n * One logged activity: the kind's icon and label, what was said, how it\n * went, who logged it and how long ago — with edit and delete for whoever\n * may (AGL-2600).\n *\n * Collapsed, the row is its chips, its heading and its caption: the kind,\n * the direction and delivery state, how a call went, the subject or the\n * note's first line, and who, to or from whom, and when. Opened, it shows\n * the body — an email's whole text, a note's every line.\n *\n * Edit and delete appear only when `editable` says this reader may — the\n * author or an org-wide member. That is the console's verdict and not the\n * rules' — see `useCanEditActivity` for why the rules admit more — so the\n * controls are hidden rather than disabled: a disabled button asks \"why\n * not?\", and the honest answer would be \"you could, through the API\".\n */\nexport function ActivityRow(props: ActivityRowProps) {\n const { activity, scope, onEdit, subject, nowMs, editable } = props\n const [ownExpanded, setOwnExpanded] = useState(false)\n const expanded = props.expanded ?? ownExpanded\n const onToggle = props.onToggle ?? (() => setOwnExpanded((open) => !open))\n const { firestore, dataScope } = scope\n const authorName = useActivityAuthorName()\n const { confirm } = useConfirmationContext()\n const { enqueueSnackbar } = useSnackbar()\n\n const handleDelete = useCallback(async () => {\n if (!dataScope) return\n const confirmed = await confirm({\n title: 'Delete this activity?',\n description:\n `This ${Aglyn.CRM_ACTIVITY_KIND_LABELS[\n Aglyn.isCrmActivityKind(activity.kind) ? activity.kind : 'other'\n ].toLowerCase()} is removed from the record it was logged against. ` +\n 'Nothing the platform captured — a form, an order, a booking — is ' +\n 'affected.',\n confirmationText: 'Delete activity',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n try {\n await deleteDoc(\n doc(\n firestore,\n dataScope[0],\n dataScope[1],\n Aglyn.CRM_COLLECTIONS.activities,\n activity.$id,\n ),\n )\n enqueueSnackbar('Activity deleted', { variant: 'success', persist: false })\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n }, [dataScope, confirm, activity, firestore, enqueueSnackbar])\n\n const label =\n Aglyn.CRM_ACTIVITY_KIND_LABELS[\n Aglyn.isCrmActivityKind(activity.kind) ? activity.kind : 'other'\n ]\n /*\n * A message the platform SENT (AGL-2615) carries a subject, an address\n * and a delivery state the webhook advances; the state is the chip beside\n * the kind, red once the message did not land. What was sent is a record\n * of a fact and offers no edit — a rewritten body would misstate what\n * left — though whoever may delete a row may still delete this one.\n */\n const captured = typeof activity.messageId === 'string' && activity.messageId !== ''\n const deliveryState = Aglyn.isCrmEmailDeliveryState(activity.deliveryState)\n ? activity.deliveryState\n : null\n // A hand-logged email or call carries a direction too (AGL-3517); only a\n // message the platform carried or captured is \"sent\" or \"received\" here.\n const sent = activity.direction === 'outbound' && (deliveryState !== null || captured)\n /*\n * A message CAPTURED from a mailbox (AGL-2657) carries the provider's\n * Message-ID and, when a correspondent wrote it, the `inbound` direction.\n * It is drawn as its own thing — \"Received\" beside the kind, the sender\n * where a sent row shows the recipient, no author because nobody on the\n * team logged it — and a member's copied send reads \"Sent\" without a\n * delivery chip, since the platform did not carry it. Neither takes the\n * caller's \"Logged\" chip: nobody logged them.\n */\n const received = activity.direction === 'inbound' && captured\n /*\n * A hand-logged call or email names its direction in the kind's own chip\n * — \"Inbound call\", \"Outbound email\" (AGL-3517); a sent or captured\n * message says it with the chips below instead.\n */\n const kindChip =\n sent || received || captured\n ? label\n : Aglyn.crmActivityKindTitle(\n Aglyn.isCrmActivityKind(activity.kind) ? activity.kind : 'other',\n activity.direction,\n )\n const when = new Date(activity.atMs)\n const detail = [\n activity.outcome ? activity.outcome : null,\n typeof activity.durationMinutes === 'number' && activity.durationMinutes > 0\n ? durationLabel(activity.durationMinutes)\n : null,\n ].filter(Boolean)\n\n const { heading, opens } = activityHeading(activity)\n const hasSubject = typeof activity.subject === 'string' && activity.subject.trim() !== ''\n\n return (\n <TimelineEntry\n icon={\n received ? (\n <MdiIcon path={mdiEmailReceiveOutline.path} />\n ) : (\n <ActivityKindIcon kind={activity.kind} />\n )\n }\n label={heading || label.toLowerCase()}\n expanded={expanded}\n onToggle={onToggle}\n chips={\n <>\n <Chip label={kindChip} size=\"small\" />\n {received ? (\n <Chip\n label=\"Received\"\n size=\"small\"\n variant=\"outlined\"\n color=\"info\"\n data-testid=\"activity-direction\"\n />\n ) : captured ? (\n <Chip\n label=\"Sent\"\n size=\"small\"\n variant=\"outlined\"\n data-testid=\"activity-direction\"\n />\n ) : null}\n {deliveryState ? (\n <Tooltip\n title={\n typeof activity.deliveryAtMs === 'number'\n ? new Date(activity.deliveryAtMs).toLocaleString()\n : ''\n }\n >\n <Chip\n label={Aglyn.CRM_EMAIL_DELIVERY_STATE_LABELS[deliveryState]}\n size=\"small\"\n variant=\"outlined\"\n color={Aglyn.isCrmEmailDeliveryFailure(deliveryState) ? 'error' : 'default'}\n data-testid=\"activity-delivery-state\"\n />\n </Tooltip>\n ) : null}\n {captured ? null : subject}\n {detail.length ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {detail.join(' · ')}\n </Typography>\n ) : null}\n </>\n }\n // With no subject the heading IS the body's first line, so an open\n // row shows the body alone rather than its first line twice.\n title={hasSubject || !opens || !expanded ? heading : null}\n titleVariant={hasSubject ? 'subtitle2' : 'body2'}\n meta={\n <Tooltip title={when.toLocaleString()}>\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n sx={{ alignSelf: 'flex-start' }}\n >\n {[\n received ? null : authorName(activity),\n received && activity.from ? `from ${activity.from}` : null,\n sent && activity.to ? `to ${activity.to}` : null,\n Aglyn.activityTimeLabel(activity.atMs, nowMs ?? Date.now()),\n ]\n .filter(Boolean)\n .join(' · ')}\n </Typography>\n </Tooltip>\n }\n body={\n opens ? (\n <Typography variant=\"body2\" sx={{ whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' }}>\n {activity.body}\n </Typography>\n ) : undefined\n }\n actions={\n editable ? (\n <>\n {onEdit && !sent && !received ? (\n <IconButton\n size=\"small\"\n aria-label=\"Edit activity\"\n onClick={() => onEdit(activity)}\n >\n <MdiIcon path={mdiPencilOutline.path} size={0.8} />\n </IconButton>\n ) : null}\n <IconButton\n size=\"small\"\n aria-label=\"Delete activity\"\n onClick={handleDelete}\n >\n <MdiIcon path={mdiDeleteOutline.path} size={0.8} />\n </IconButton>\n </>\n ) : null\n }\n />\n )\n}\nActivityRow.displayName = 'ActivityRow'\n\nexport interface ActivityListProps {\n /** Newest-first, as the listener hands them back. */\n rows: readonly CrmActivityRow[]\n scope: ActivityScope\n onEdit?: (activity: CrmActivityRow) => void\n /** What the list says when there is nothing in it. */\n emptyText?: string\n /** The way out of an empty list — the record's \"Log activity\" button. */\n emptyAction?: ReactNode\n /** The listener holds less than exists; `onShowMore` widens it. */\n hasMore?: boolean\n onShowMore?: () => void\n /** The listener is reading, so an empty window is not yet an empty log. */\n loading?: boolean\n /** The record each row is about, for a list that spans records. */\n subjectFor?: (activity: CrmActivityRow) => ReactNode\n /**\n * No controls on any row, whoever is reading — and no member read to\n * decide them. A feed that spans records is a place to see what happened,\n * not to rewrite it; the record's own page is where an activity is\n * corrected, beside everything else about it.\n */\n readOnly?: boolean\n /**\n * Which rows are open, held by the card so its header's \"Expand all\"\n * reaches them. A list with no header control holds its own.\n */\n expansion?: TimelineExpansion\n}\n\n/**\n * A newest-first list of logged activities, collapsed to one entry each and\n * paged by the console's shared footer (AGL-2600).\n *\n * The rows arrive ordered — the query is `orderBy('atMs', 'desc')` — and the\n * list does not sort them again; a second sort here is a second place for\n * the order to be defined. The footer pages the window the listener holds,\n * and a page turned past it widens the listener while the probe row says\n * more exists (`useTimelinePages`).\n *\n * Who may edit is decided here, once, and handed to every row: the verdict\n * reads the member document, and the list is the one place that can ask\n * for it a single time however many rows it draws.\n */\nexport function ActivityList(props: ActivityListProps) {\n const {\n rows,\n scope,\n onEdit,\n emptyText = 'Nothing logged yet.',\n emptyAction,\n hasMore,\n onShowMore,\n loading,\n subjectFor,\n readOnly,\n } = props\n const canEdit = useCanEditActivity(scope.orgId, !readOnly)\n const ownExpansion = useTimelineExpansion()\n const expansion = props.expansion ?? ownExpansion\n const pages = useTimelinePages(rows.length, { hasMore, showMore: onShowMore, loading })\n // One clock for every row of one paint.\n const nowMs = Date.now()\n if (!rows.length) {\n return loading ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Loading…'}\n </Typography>\n ) : (\n <EmptyStateComponent\n compact\n label={'Nothing logged yet'}\n description={emptyText}\n action={emptyAction}\n />\n )\n }\n return (\n <Stack spacing={2}>\n {pages.slice(rows).map((activity) => (\n <ActivityRow\n key={activity.$id}\n activity={activity}\n scope={scope}\n onEdit={onEdit}\n subject={subjectFor?.(activity)}\n nowMs={nowMs}\n editable={canEdit(activity)}\n expanded={expansion.isExpanded(activity.$id)}\n onToggle={() => expansion.toggle(activity.$id)}\n />\n ))}\n <ListPagination {...pages.footer} />\n </Stack>\n )\n}\nActivityList.displayName = 'ActivityList'\n\nexport default ActivityList\n"],"names":["Aglyn","mdiAccountGroupOutline","mdiDeleteOutline","mdiDotsHorizontalCircleOutline","mdiEmailOutline","mdiEmailReceiveOutline","mdiFacebookMessenger","mdiInstagram","mdiLinkedin","mdiMessageTextOutline","mdiNoteTextOutline","mdiPencilOutline","mdiPhoneOutline","mdiWhatsapp","MdiIcon","useConfirmationContext","EmptyStateComponent","ListPagination","useSnackbar","useUser","useUserName","Chip","IconButton","Stack","Tooltip","Typography","deleteDoc","doc","useCallback","useState","useCanEditActivity","TimelineEntry","useTimelineExpansion","useTimelinePages","KIND_ICONS","call","email","text","whatsapp","messenger","instagram","linkedin","meeting","note","other","ActivityKindIcon","props","kind","size","icon","isCrmActivityKind","path","displayName","useActivityAuthorName","data","user","ownName","uid","activity","byName","byUid","ACTIVITY_HEADING_MAX","activityHeading","body","trim","subject","heading","opens","firstLine","split","find","line","length","durationLabel","minutes","hours","Math","floor","rest","String","padStart","ActivityRow","scope","onEdit","nowMs","editable","ownExpanded","setOwnExpanded","expanded","onToggle","open","firestore","dataScope","authorName","confirm","enqueueSnackbar","handleDelete","confirmed","title","description","CRM_ACTIVITY_KIND_LABELS","toLowerCase","confirmationText","confirmationButtonProps","color","then","catch","CRM_COLLECTIONS","activities","$id","variant","persist","error","console","allowDuplicate","label","captured","messageId","deliveryState","isCrmEmailDeliveryState","sent","direction","received","kindChip","crmActivityKindTitle","when","Date","atMs","detail","outcome","durationMinutes","filter","Boolean","hasSubject","chips","data-testid","deliveryAtMs","toLocaleString","CRM_EMAIL_DELIVERY_STATE_LABELS","isCrmEmailDeliveryFailure","join","titleVariant","meta","sx","alignSelf","from","to","activityTimeLabel","now","whiteSpace","overflowWrap","undefined","actions","aria-label","onClick","ActivityList","rows","emptyText","emptyAction","hasMore","onShowMore","loading","subjectFor","readOnly","canEdit","orgId","ownExpansion","expansion","pages","showMore","compact","action","spacing","slice","map","isExpanded","toggle","footer"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,YAAYA,WAAW,eAAc;AAErC,SACEC,sBAAsB,EACtBC,gBAAgB,EAChBC,8BAA8B,EAC9BC,eAAe,EACfC,sBAAsB,EACtBC,oBAAoB,EACpBC,YAAY,EACZC,WAAW,EACXC,qBAAqB,EACrBC,kBAAkB,EAClBC,gBAAgB,EAChBC,eAAe,EACfC,WAAW,QACN,yBAAwB;AAC/B,SAASC,OAAO,EAAEC,sBAAsB,QAAQ,uBAAsB;AACtE,OAAOC,yBAAyB,wDAAuD;AACvF,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,OAAO,EAAEC,WAAW,QAAQ,iCAAgC;AACrE,SAASC,IAAI,EAAEC,UAAU,EAAEC,KAAK,EAAEC,OAAO,EAAEC,UAAU,QAAQ,gBAAe;AAC5E,SAASC,SAAS,EAAEC,GAAG,QAAQ,qBAAoB;AACnD,SAAyBC,WAAW,EAAEC,QAAQ,QAAQ,QAAO;AAC7D,SAA6BC,kBAAkB,QAAQ,wBAAoB;AAC3E,SACEC,aAAa,EAEbC,oBAAoB,EACpBC,gBAAgB,QACX,yBAAqB;AAE5B;;;;;CAKC,GACD,MAAMC,aAAwD;IAC5DC,MAAMvB;IACNwB,OAAOhC;IACPiC,MAAM5B;IACN6B,UAAUzB;IACV0B,WAAWjC;IACXkC,WAAWjC;IACXkC,UAAUjC;IACVkC,SAASzC;IACT0C,MAAMjC;IACNkC,OAAOzC;AACT;AAEA,4EAA4E,GAC5E,OAAO,SAAS0C,iBAAiBC,KAAsC;IACrE,MAAM,EAAEC,IAAI,EAAEC,OA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KAAKpF,MAAM,EAAE;QAAEuF;QAASU,UAAUT;QAAYC;IAAQ;IACrF,wCAAwC;IACxC,MAAM7E,QAAQ0C,KAAKsB,GAAG;IACtB,IAAI,CAACQ,KAAKpF,MAAM,EAAE;QAChB,OAAOyF,wBACL,KAACxI;YAAWqF,SAAQ;YAAQN,OAAM;sBAC/B;2BAGH,KAACxF;YACC0J,OAAO;YACPvD,OAAO;YACPhB,aAAa0D;YACbc,QAAQb;;IAGd;IACA,qBACE,MAACvI;QAAMqJ,SAAS;;YACbJ,MAAMK,KAAK,CAACjB,MAAMkB,GAAG,CAAC,CAACpH,yBACtB,KAACuB;oBAECvB,UAAUA;oBACVwB,OAAOA;oBACPC,QAAQA;oBACRlB,OAAO,EAAEiG,8BAAAA,WAAaxG;oBACtB0B,OAAOA;oBACPC,UAAU+E,QAAQ1G;oBAClB8B,UAAU+E,UAAUQ,UAAU,CAACrH,SAASmD,GAAG;oBAC3CpB,UAAU,IAAM8E,UAAUS,MAAM,CAACtH,SAASmD,GAAG;mBARxCnD,SAASmD,GAAG;0BAWrB,KAAC5F,6BAAmBuJ,MAAMS,MAAM;;;AAGtC;AACAtB,aAAavG,WAAW,GAAG;AAE3B,eAAeuG,aAAY"}
@@ -45,6 +45,16 @@ export interface DealBoardProps {
45
45
  * two closed columns start collapsed to a count-free stub and expand on
46
46
  * request, which is also when their rows are read — a collapsed column
47
47
  * costs no listener.
48
+ *
49
+ * ## Empty stages fold too, and the board says when there is more
50
+ *
51
+ * A pipeline with Salesforce's ten stages is wider than the card, and the
52
+ * stages with deals in them were off the edge with nothing to say so. An
53
+ * open stage with no deals folds to the same narrow stub, labelled and still
54
+ * a drop target, so the stages that hold work get the room. When the row is
55
+ * still wider than the card, chevrons at either end page it sideways the way
56
+ * MUI's scrollable Tabs do — the scrollbar alone stays hidden on a trackpad
57
+ * until the reader already knows to scroll.
48
58
  */
49
59
  export declare function DealBoard(props: DealBoardProps): import("react").JSX.Element;
50
60
  export declare namespace DealBoard {
@@ -21,8 +21,9 @@ import { MdiIcon } from "@aglyn/shared-ui-jsx";
21
21
  import RowActionsMenu from "@aglyn/shared-ui-jsx/components/row-actions-menu.component";
22
22
  import { closestCorners, DndContext, DragOverlay, KeyboardSensor, PointerSensor, useDraggable, useDroppable, useSensor, useSensors } from "@dnd-kit/core";
23
23
  import { CSS } from "@dnd-kit/utilities";
24
- import { Box, Button, Chip, CircularProgress, Paper, Stack, Typography } from "@mui/material";
24
+ import { Box, Button, Chip, CircularProgress, Paper, Stack, TabScrollButton, Tooltip, Typography } from "@mui/material";
25
25
  import { useCallback, useMemo, useState } from "react";
26
+ import { useScrollEdges } from "../hooks/use-scroll-edges.js";
26
27
  import { daysInStage, formatMoney, openStages } from "../model/deal-board-model.js";
27
28
  import { OwnerAvatar } from "./owner-avatar.js";
28
29
  /** The droppable id a stage column answers to. */ const columnId = (stageId)=>`stage:${stageId}`;
@@ -54,11 +55,23 @@ const stageOfColumn = (id)=>typeof id === 'string' && id.startsWith('stage:') ?
54
55
  * two closed columns start collapsed to a count-free stub and expand on
55
56
  * request, which is also when their rows are read — a collapsed column
56
57
  * costs no listener.
58
+ *
59
+ * ## Empty stages fold too, and the board says when there is more
60
+ *
61
+ * A pipeline with Salesforce's ten stages is wider than the card, and the
62
+ * stages with deals in them were off the edge with nothing to say so. An
63
+ * open stage with no deals folds to the same narrow stub, labelled and still
64
+ * a drop target, so the stages that hold work get the room. When the row is
65
+ * still wider than the card, chevrons at either end page it sideways the way
66
+ * MUI's scrollable Tabs do — the scrollbar alone stays hidden on a trackpad
67
+ * until the reader already knows to scroll.
57
68
  */ export function DealBoard(props) {
58
69
  const { pipeline, deals, won, lost, closedExpanded, onToggleClosed, labelFor, moving, onOpen, onMove, onWon, onLost, nowMs } = props;
59
70
  const stages = useMemo(()=>openStages(pipeline), [
60
71
  pipeline
61
72
  ]);
73
+ const edges = useScrollEdges();
74
+ const overflowing = edges.start || edges.end;
62
75
  const byStage = useMemo(()=>{
63
76
  const map = new Map();
64
77
  for (const stage of stages)map.set(stage.id, []);
@@ -165,70 +178,98 @@ const stageOfColumn = (id)=>typeof id === 'string' && id.startsWith('stage:') ?
165
178
  onDragEnd: handleDragEnd,
166
179
  onDragCancel: ()=>setDragging(null),
167
180
  children: [
168
- /*#__PURE__*/ _jsx(Box, {
181
+ /*#__PURE__*/ _jsxs(Stack, {
182
+ direction: "row",
169
183
  sx: {
170
- overflowX: 'auto',
171
- pb: 1,
184
+ alignItems: 'stretch',
172
185
  minWidth: 0,
173
186
  width: '100%'
174
187
  },
175
- children: /*#__PURE__*/ _jsxs(Stack, {
176
- direction: "row",
177
- spacing: 1.5,
178
- sx: {
179
- alignItems: 'stretch',
180
- minWidth: 'max-content'
181
- },
182
- children: [
183
- stages.map((stage)=>{
184
- var _ref, _byStage_map_get, _byStage_map_get1;
185
- var _byStage_map_get2, _byStage_map_get_, _byStage_map_get3;
186
- return /*#__PURE__*/ _jsx(StageColumn, {
187
- stage: stage,
188
- count: (_ref = (_byStage_map_get2 = byStage.map.get(stage.id)) == null ? void 0 : _byStage_map_get2.length) != null ? _ref : 0,
189
- total: ((_byStage_map_get = byStage.map.get(stage.id)) != null ? _byStage_map_get : []).reduce((sum, deal)=>sum + (Number(deal.amountCents) || 0), 0),
190
- currency: (_byStage_map_get3 = byStage.map.get(stage.id)) == null ? void 0 : (_byStage_map_get_ = _byStage_map_get3[0]) == null ? void 0 : _byStage_map_get_.currency,
191
- children: ((_byStage_map_get1 = byStage.map.get(stage.id)) != null ? _byStage_map_get1 : []).map(renderCard)
192
- }, stage.id);
193
- }),
194
- byStage.orphans.length ? /*#__PURE__*/ _jsx(StageColumn, {
195
- stage: {
196
- id: '__orphans',
197
- name: 'No stage',
198
- order: Number.MAX_SAFE_INTEGER,
199
- probability: 0,
200
- kind: 'open'
188
+ children: [
189
+ overflowing ? /*#__PURE__*/ _jsx(TabScrollButton, {
190
+ direction: "left",
191
+ orientation: "horizontal",
192
+ disabled: !edges.start,
193
+ onClick: ()=>edges.page(-1),
194
+ "aria-label": "Show earlier stages",
195
+ "data-testid": "deal-board-scroll-start"
196
+ }) : null,
197
+ /*#__PURE__*/ _jsx(Box, {
198
+ ref: edges.ref,
199
+ sx: {
200
+ overflowX: 'auto',
201
+ pb: 1,
202
+ minWidth: 0,
203
+ flex: 1
204
+ },
205
+ children: /*#__PURE__*/ _jsxs(Stack, {
206
+ direction: "row",
207
+ spacing: 1.5,
208
+ sx: {
209
+ alignItems: 'stretch',
210
+ minWidth: 'max-content'
201
211
  },
202
- count: byStage.orphans.length,
203
- total: 0,
204
- currency: undefined,
205
- droppable: false,
206
- caption: "These deals sit in a stage the pipeline no longer has. Move them.",
207
- children: byStage.orphans.map(renderCard)
208
- }) : null,
209
- closedStages.map((stage)=>{
210
- var _ref;
211
- const rows = stage.kind === 'won' ? won : lost;
212
- return /*#__PURE__*/ _jsx(StageColumn, {
213
- stage: stage,
214
- count: (_ref = rows == null ? void 0 : rows.length) != null ? _ref : null,
215
- total: null,
216
- currency: undefined,
217
- collapsed: !closedExpanded,
218
- onToggle: onToggleClosed,
219
- children: closedExpanded && rows === null ? /*#__PURE__*/ _jsx(Stack, {
220
- sx: {
221
- alignItems: 'center',
222
- py: 2
212
+ children: [
213
+ stages.map((stage)=>{
214
+ var _ref, _byStage_map_get, _byStage_map_get1;
215
+ var _byStage_map_get2, _byStage_map_get3, _byStage_map_get_, _byStage_map_get4;
216
+ return /*#__PURE__*/ _jsx(StageColumn, {
217
+ stage: stage,
218
+ folded: !((_byStage_map_get2 = byStage.map.get(stage.id)) == null ? void 0 : _byStage_map_get2.length),
219
+ count: (_ref = (_byStage_map_get3 = byStage.map.get(stage.id)) == null ? void 0 : _byStage_map_get3.length) != null ? _ref : 0,
220
+ total: ((_byStage_map_get = byStage.map.get(stage.id)) != null ? _byStage_map_get : []).reduce((sum, deal)=>sum + (Number(deal.amountCents) || 0), 0),
221
+ currency: (_byStage_map_get4 = byStage.map.get(stage.id)) == null ? void 0 : (_byStage_map_get_ = _byStage_map_get4[0]) == null ? void 0 : _byStage_map_get_.currency,
222
+ children: ((_byStage_map_get1 = byStage.map.get(stage.id)) != null ? _byStage_map_get1 : []).map(renderCard)
223
+ }, stage.id);
224
+ }),
225
+ byStage.orphans.length ? /*#__PURE__*/ _jsx(StageColumn, {
226
+ stage: {
227
+ id: '__orphans',
228
+ name: 'No stage',
229
+ order: Number.MAX_SAFE_INTEGER,
230
+ probability: 0,
231
+ kind: 'open'
223
232
  },
224
- children: /*#__PURE__*/ _jsx(CircularProgress, {
225
- size: 20
226
- })
227
- }) : (rows != null ? rows : []).map(renderCard)
228
- }, stage.id);
233
+ count: byStage.orphans.length,
234
+ total: 0,
235
+ currency: undefined,
236
+ droppable: false,
237
+ caption: "These deals sit in a stage the pipeline no longer has. Move them.",
238
+ children: byStage.orphans.map(renderCard)
239
+ }) : null,
240
+ closedStages.map((stage)=>{
241
+ var _ref;
242
+ const rows = stage.kind === 'won' ? won : lost;
243
+ return /*#__PURE__*/ _jsx(StageColumn, {
244
+ stage: stage,
245
+ count: (_ref = rows == null ? void 0 : rows.length) != null ? _ref : null,
246
+ total: null,
247
+ currency: undefined,
248
+ collapsed: !closedExpanded,
249
+ onToggle: onToggleClosed,
250
+ children: closedExpanded && rows === null ? /*#__PURE__*/ _jsx(Stack, {
251
+ sx: {
252
+ alignItems: 'center',
253
+ py: 2
254
+ },
255
+ children: /*#__PURE__*/ _jsx(CircularProgress, {
256
+ size: 20
257
+ })
258
+ }) : (rows != null ? rows : []).map(renderCard)
259
+ }, stage.id);
260
+ })
261
+ ]
229
262
  })
230
- ]
231
- })
263
+ }),
264
+ overflowing ? /*#__PURE__*/ _jsx(TabScrollButton, {
265
+ direction: "right",
266
+ orientation: "horizontal",
267
+ disabled: !edges.end,
268
+ onClick: ()=>edges.page(1),
269
+ "aria-label": "Show later stages",
270
+ "data-testid": "deal-board-scroll-end"
271
+ }) : null
272
+ ]
232
273
  }),
233
274
  /*#__PURE__*/ _jsx(DragOverlay, {
234
275
  dropAnimation: null,
@@ -244,7 +285,7 @@ const stageOfColumn = (id)=>typeof id === 'string' && id.startsWith('stage:') ?
244
285
  }
245
286
  DealBoard.displayName = 'DealBoard';
246
287
  function StageColumn(props) {
247
- const { stage, count, total, currency, droppable = true, collapsed = false, onToggle, caption, children } = props;
288
+ const { stage, count, total, currency, droppable = true, collapsed = false, folded = false, onToggle, caption, children } = props;
248
289
  const { setNodeRef, isOver } = useDroppable({
249
290
  id: columnId(stage.id),
250
291
  disabled: !droppable || collapsed
@@ -254,7 +295,7 @@ function StageColumn(props) {
254
295
  ref: setNodeRef,
255
296
  variant: "outlined",
256
297
  sx: {
257
- width: collapsed ? 56 : 260,
298
+ width: collapsed || folded ? 56 : 260,
258
299
  flexShrink: 0,
259
300
  display: 'flex',
260
301
  flexDirection: 'column',
@@ -267,7 +308,24 @@ function StageColumn(props) {
267
308
  ]),
268
309
  minHeight: 240
269
310
  },
270
- children: collapsed ? /*#__PURE__*/ _jsx(Button, {
311
+ children: folded && !collapsed ? /*#__PURE__*/ _jsx(Tooltip, {
312
+ title: `${stage.name}: no deals · ${stage.probability}% likely to close`,
313
+ placement: "top",
314
+ children: /*#__PURE__*/ _jsx(Typography, {
315
+ variant: "subtitle2",
316
+ color: "text.secondary",
317
+ "data-testid": "deal-board-folded-stage",
318
+ sx: {
319
+ flex: 1,
320
+ writingMode: 'vertical-rl',
321
+ textOrientation: 'mixed',
322
+ textAlign: 'center',
323
+ py: 2,
324
+ alignSelf: 'center'
325
+ },
326
+ children: stage.name
327
+ })
328
+ }) : collapsed ? /*#__PURE__*/ _jsx(Button, {
271
329
  onClick: onToggle,
272
330
  sx: {
273
331
  flex: 1,