@baack-software/baack-ts-crm 0.0.2 → 0.0.3

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 (112) hide show
  1. package/dist/backend.d.ts +29 -1
  2. package/dist/backend.d.ts.map +1 -1
  3. package/dist/backend.js +95 -0
  4. package/dist/backend.js.map +1 -1
  5. package/dist/crm-client.d.ts +55 -13
  6. package/dist/crm-client.d.ts.map +1 -1
  7. package/dist/crm-client.js +99 -15
  8. package/dist/crm-client.js.map +1 -1
  9. package/dist/deal-order.d.ts +42 -0
  10. package/dist/deal-order.d.ts.map +1 -0
  11. package/dist/deal-order.js +80 -0
  12. package/dist/deal-order.js.map +1 -0
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/invoices.d.ts +7 -0
  18. package/dist/invoices.d.ts.map +1 -1
  19. package/dist/invoices.js +20 -2
  20. package/dist/invoices.js.map +1 -1
  21. package/dist/period.d.ts +15 -2
  22. package/dist/period.d.ts.map +1 -1
  23. package/dist/period.js +27 -1
  24. package/dist/period.js.map +1 -1
  25. package/dist/pipeline.d.ts +6 -0
  26. package/dist/pipeline.d.ts.map +1 -1
  27. package/dist/pipeline.js +18 -0
  28. package/dist/pipeline.js.map +1 -1
  29. package/dist/react/ChoiceCombobox.d.ts +36 -0
  30. package/dist/react/ChoiceCombobox.d.ts.map +1 -0
  31. package/dist/react/ChoiceCombobox.js +105 -0
  32. package/dist/react/ChoiceCombobox.js.map +1 -0
  33. package/dist/react/DealsBoard.d.ts +22 -3
  34. package/dist/react/DealsBoard.d.ts.map +1 -1
  35. package/dist/react/DealsBoard.js +53 -4
  36. package/dist/react/DealsBoard.js.map +1 -1
  37. package/dist/react/Details.d.ts +40 -7
  38. package/dist/react/Details.d.ts.map +1 -1
  39. package/dist/react/Details.js +180 -23
  40. package/dist/react/Details.js.map +1 -1
  41. package/dist/react/Forms.d.ts +148 -17
  42. package/dist/react/Forms.d.ts.map +1 -1
  43. package/dist/react/Forms.js +365 -75
  44. package/dist/react/Forms.js.map +1 -1
  45. package/dist/react/Sales.d.ts +25 -6
  46. package/dist/react/Sales.d.ts.map +1 -1
  47. package/dist/react/Sales.js +114 -30
  48. package/dist/react/Sales.js.map +1 -1
  49. package/dist/react/SidePanel.d.ts +10 -0
  50. package/dist/react/SidePanel.d.ts.map +1 -1
  51. package/dist/react/SidePanel.js +14 -2
  52. package/dist/react/SidePanel.js.map +1 -1
  53. package/dist/react/index.d.ts +1 -0
  54. package/dist/react/index.d.ts.map +1 -1
  55. package/dist/react/index.js +1 -0
  56. package/dist/react/index.js.map +1 -1
  57. package/dist/react/parts.d.ts +12 -2
  58. package/dist/react/parts.d.ts.map +1 -1
  59. package/dist/react/parts.js +25 -2
  60. package/dist/react/parts.js.map +1 -1
  61. package/dist/react/pipeline-choice.d.ts +19 -0
  62. package/dist/react/pipeline-choice.d.ts.map +1 -0
  63. package/dist/react/pipeline-choice.js +39 -0
  64. package/dist/react/pipeline-choice.js.map +1 -0
  65. package/dist/react/text.d.ts +89 -2
  66. package/dist/react/text.d.ts.map +1 -1
  67. package/dist/react/text.js +89 -2
  68. package/dist/react/text.js.map +1 -1
  69. package/dist/react/ui/badge.d.ts +1 -1
  70. package/dist/react/ui/button.d.ts +2 -2
  71. package/dist/react/views.d.ts +33 -11
  72. package/dist/react/views.d.ts.map +1 -1
  73. package/dist/react/views.js +96 -27
  74. package/dist/react/views.js.map +1 -1
  75. package/dist/sales.d.ts +28 -3
  76. package/dist/sales.d.ts.map +1 -1
  77. package/dist/sales.js +33 -10
  78. package/dist/sales.js.map +1 -1
  79. package/dist/store.d.ts +31 -12
  80. package/dist/store.d.ts.map +1 -1
  81. package/dist/store.js +82 -21
  82. package/dist/store.js.map +1 -1
  83. package/dist/target.d.ts +2 -1
  84. package/dist/target.d.ts.map +1 -1
  85. package/dist/target.js +6 -2
  86. package/dist/target.js.map +1 -1
  87. package/dist/types.d.ts +24 -0
  88. package/dist/types.d.ts.map +1 -1
  89. package/dist/types.js.map +1 -1
  90. package/package.json +1 -1
  91. package/src/backend.ts +131 -1
  92. package/src/crm-client.ts +162 -19
  93. package/src/deal-order.ts +116 -0
  94. package/src/index.ts +1 -0
  95. package/src/invoices.ts +22 -2
  96. package/src/period.ts +41 -2
  97. package/src/pipeline.ts +21 -0
  98. package/src/react/ChoiceCombobox.tsx +227 -0
  99. package/src/react/DealsBoard.tsx +171 -4
  100. package/src/react/Details.tsx +608 -31
  101. package/src/react/Forms.tsx +1006 -139
  102. package/src/react/Sales.tsx +332 -44
  103. package/src/react/SidePanel.tsx +19 -10
  104. package/src/react/index.ts +1 -0
  105. package/src/react/parts.tsx +56 -4
  106. package/src/react/pipeline-choice.ts +54 -0
  107. package/src/react/text.ts +90 -2
  108. package/src/react/views.tsx +222 -32
  109. package/src/sales.ts +57 -10
  110. package/src/store.ts +136 -27
  111. package/src/target.ts +5 -2
  112. package/src/types.ts +28 -0
package/src/pipeline.ts CHANGED
@@ -13,6 +13,27 @@ export const stageOf = (deal: Deal, pipeline: Pipeline): PipelineStage | undefin
13
13
  export const pipelineOf = (deal: Deal, pipelines: readonly Pipeline[]): Pipeline | undefined =>
14
14
  pipelines.find((pipeline) => stageOf(deal, pipeline));
15
15
 
16
+ /**
17
+ * The pipeline to show and to start new deals in: `chosen` while it's still one of them (the one the user last picked,
18
+ * as their team may work in a different workflow), else the one holding the most deals, so a company's sales workflow
19
+ * wins over its other workflows, else the first.
20
+ */
21
+ export function defaultPipeline(
22
+ pipelines: readonly Pipeline[],
23
+ deals: readonly Deal[],
24
+ chosen?: string,
25
+ ): Pipeline | undefined {
26
+ const picked = chosen === undefined ? undefined : pipelines.find((pipeline) => pipeline.urn === chosen);
27
+ if (picked) return picked;
28
+ let busiest: Pipeline | undefined;
29
+ let most = 0;
30
+ for (const pipeline of pipelines) {
31
+ const count = deals.filter((deal) => stageOf(deal, pipeline)).length;
32
+ if (count > most) [busiest, most] = [pipeline, count];
33
+ }
34
+ return busiest ?? pipelines[0];
35
+ }
36
+
16
37
  /** How a deal stands: its own outcome, open when it has none. */
17
38
  export const dealOutcome = (deal: Deal): DealOutcome => deal.outcome ?? 'OPEN';
18
39
 
@@ -0,0 +1,227 @@
1
+ import { cn } from 'cn';
2
+ import { Check, Plus, X } from 'lucide-react';
3
+ import { useId, useState, type KeyboardEvent } from 'react';
4
+ import type { CrmChoice } from './Forms.tsx';
5
+ import { withText, type CrmText } from './text.ts';
6
+ import { Input } from './ui/input.tsx';
7
+
8
+ /** At most this many matches are listed; typing more narrows them. */
9
+ const MAX_SHOWN = 50;
10
+
11
+ /** Whether a choice matches every word typed, in its name, its detail (such as an email) or its keywords. */
12
+ export function choiceMatches(choice: CrmChoice, query: string): boolean {
13
+ const words = query.toLocaleLowerCase('en-GB').split(/\s+/).filter(Boolean);
14
+ if (words.length === 0) return true;
15
+ const haystack = [choice.name, choice.detail ?? '', ...(choice.keywords ?? [])].join(' ').toLocaleLowerCase('en-GB');
16
+ // Numbers are also found by their digits alone, so "07700" finds "+44 7700 900123" (its leading 0 dropped).
17
+ const digits = haystack.replace(/\D/g, '');
18
+ const byDigits = (word: string) =>
19
+ /^\+?[\d()-]+$/.test(word) && digits.includes(word.replace(/\D/g, '').replace(/^0/, ''));
20
+ return words.every((word) => haystack.includes(word) || byDigits(word));
21
+ }
22
+
23
+ /**
24
+ * Records chosen by searching: the chosen ones as removable chips, then a search box (an ARIA combobox) that lists the
25
+ * matching choices by name, detail and keywords. Arrow keys move through the matches, Enter picks or drops one,
26
+ * Escape closes the list and Backspace in an empty box drops the last chip. With `single`, picking one replaces the
27
+ * one chosen. With `add`, the list ends with a way to make a new record; one waiting to be made (`pending`) shows as a
28
+ * chip marked new. The box has `id`, so a field's label names it. Chosen records missing from `choices` are named by
29
+ * `named`, or by the end of their URN.
30
+ */
31
+ export function ChoiceCombobox({
32
+ id,
33
+ value,
34
+ onChange,
35
+ choices,
36
+ named,
37
+ single = false,
38
+ add,
39
+ pending,
40
+ placeholder,
41
+ disabled,
42
+ describedBy,
43
+ text,
44
+ }: {
45
+ id: string;
46
+ /** The chosen URNs, in order. */
47
+ value: readonly string[];
48
+ onChange: (urns: string[]) => void;
49
+ choices: readonly CrmChoice[];
50
+ named?: ((urn: string) => string | undefined) | undefined;
51
+ /** At most one record. */
52
+ single?: boolean | undefined;
53
+ add?: { label: string; onAdd: () => void } | undefined;
54
+ /** A new record to be made when the form is saved, and how to drop it. */
55
+ pending?: { name: string; onClear: () => void } | undefined;
56
+ placeholder?: string | undefined;
57
+ disabled?: boolean | undefined;
58
+ describedBy?: string | undefined;
59
+ text?: Partial<CrmText> | undefined;
60
+ }) {
61
+ const words = withText(text);
62
+ const ids = useId();
63
+ const [query, setQuery] = useState('');
64
+ const [open, setOpen] = useState(false);
65
+ const [active, setActive] = useState(0);
66
+ const matches = choices.filter((choice) => choiceMatches(choice, query)).slice(0, MAX_SHOWN);
67
+ // The add option, when there is one, comes after the matches.
68
+ const count = matches.length + (add ? 1 : 0);
69
+ const nameOf = (urn: string) =>
70
+ choices.find((choice) => choice.urn === urn)?.name ?? named?.(urn) ?? `...${urn.slice(-6)}`;
71
+ const pick = (index: number) => {
72
+ const choice = matches[index];
73
+ if (!choice) {
74
+ setOpen(false);
75
+ add?.onAdd();
76
+ return;
77
+ }
78
+ const urn = choice.urn;
79
+ if (single) {
80
+ pending?.onClear();
81
+ onChange(value.includes(urn) ? [] : [urn]);
82
+ setOpen(false);
83
+ } else onChange(value.includes(urn) ? value.filter((other) => other !== urn) : [...value, urn]);
84
+ setQuery('');
85
+ };
86
+ const listId = `${ids}-list`;
87
+ const optionId = (index: number) => `${ids}-option-${index}`;
88
+ const shown = open && !disabled;
89
+
90
+ const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
91
+ switch (event.key) {
92
+ case 'ArrowDown':
93
+ event.preventDefault();
94
+ if (!shown) setOpen(true);
95
+ else setActive((at) => Math.min(at + 1, count - 1));
96
+ break;
97
+ case 'ArrowUp':
98
+ event.preventDefault();
99
+ setActive((at) => Math.max(at - 1, 0));
100
+ break;
101
+ case 'Enter':
102
+ if (shown && active < count) {
103
+ event.preventDefault();
104
+ pick(active);
105
+ }
106
+ break;
107
+ case 'Escape':
108
+ if (shown) {
109
+ event.preventDefault();
110
+ setOpen(false);
111
+ }
112
+ break;
113
+ case 'Backspace':
114
+ if (query) break;
115
+ if (pending) pending.onClear();
116
+ else if (value.length > 0) onChange(value.slice(0, -1));
117
+ break;
118
+ }
119
+ };
120
+
121
+ const chip = (key: string, label: string, onRemove: () => void) => (
122
+ <li
123
+ key={key}
124
+ className="bg-secondary text-secondary-foreground inline-flex items-center gap-1 rounded-md py-0.5 ps-2 pe-0.5 text-sm"
125
+ >
126
+ {label}
127
+ <button
128
+ type="button"
129
+ disabled={disabled}
130
+ aria-label={`${words.remove}: ${label}`}
131
+ className="hover:bg-background/60 focus-visible:ring-ring rounded p-0.5 outline-none focus-visible:ring-2"
132
+ onClick={onRemove}
133
+ >
134
+ <X aria-hidden="true" className="size-3.5" />
135
+ </button>
136
+ </li>
137
+ );
138
+
139
+ return (
140
+ <div className="grid gap-2">
141
+ {(value.length > 0 || pending) && (
142
+ <ul aria-label={words.chosen} className="flex flex-wrap gap-1.5">
143
+ {value.map((urn) => chip(urn, nameOf(urn), () => onChange(value.filter((other) => other !== urn))))}
144
+ {pending && chip('pending', `${pending.name} (${words.toBeCreated})`, pending.onClear)}
145
+ </ul>
146
+ )}
147
+ <div className="relative">
148
+ <Input
149
+ id={id}
150
+ role="combobox"
151
+ type="text"
152
+ autoComplete="off"
153
+ aria-autocomplete="list"
154
+ aria-expanded={shown}
155
+ aria-controls={listId}
156
+ aria-activedescendant={shown && active < count ? optionId(active) : undefined}
157
+ aria-describedby={describedBy}
158
+ placeholder={placeholder}
159
+ disabled={disabled}
160
+ value={query}
161
+ onChange={(event) => {
162
+ setQuery(event.target.value);
163
+ setActive(0);
164
+ setOpen(true);
165
+ }}
166
+ onFocus={() => setOpen(true)}
167
+ onClick={() => setOpen(true)}
168
+ onBlur={() => setOpen(false)}
169
+ onKeyDown={onKeyDown}
170
+ />
171
+ <ul
172
+ id={listId}
173
+ role="listbox"
174
+ aria-multiselectable={single ? undefined : 'true'}
175
+ aria-label={placeholder ?? words.chosen}
176
+ hidden={!shown}
177
+ className="bg-popover text-popover-foreground absolute z-50 mt-1 max-h-60 w-full overflow-y-auto rounded-md border p-1 shadow-md"
178
+ >
179
+ {matches.length === 0 && (
180
+ <li role="presentation" className="text-muted-foreground px-2 py-1.5 text-sm">
181
+ {words.noMatches}
182
+ </li>
183
+ )}
184
+ {[...matches, ...(add ? [undefined] : [])].map((choice, index) => {
185
+ const selected = choice ? value.includes(choice.urn) : false;
186
+ return (
187
+ <li
188
+ key={choice?.urn ?? 'add'}
189
+ id={optionId(index)}
190
+ role="option"
191
+ aria-selected={selected}
192
+ className={cn(
193
+ 'flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm',
194
+ index === active && 'bg-accent text-accent-foreground',
195
+ )}
196
+ // Keeps focus in the box, so the list stays open for more picks.
197
+ onMouseDown={(event) => event.preventDefault()}
198
+ onMouseMove={() => setActive(index)}
199
+ onClick={() => pick(index)}
200
+ >
201
+ {choice ? (
202
+ <>
203
+ <Check aria-hidden="true" className={cn('size-4 shrink-0', !selected && 'invisible')} />
204
+ <span>
205
+ {choice.name}
206
+ {choice.detail && (
207
+ <>
208
+ {' '}
209
+ <span className="text-muted-foreground">{choice.detail}</span>
210
+ </>
211
+ )}
212
+ </span>
213
+ </>
214
+ ) : (
215
+ <>
216
+ <Plus aria-hidden="true" className="size-4 shrink-0" />
217
+ {add!.label}
218
+ </>
219
+ )}
220
+ </li>
221
+ );
222
+ })}
223
+ </ul>
224
+ </div>
225
+ </div>
226
+ );
227
+ }
@@ -1,12 +1,19 @@
1
1
  import { cn } from 'cn';
2
+ import { Search, X } from 'lucide-react';
3
+ import { useId } from 'react';
4
+ import { DEAL_ORDERS, sortDeals, type DealFilter, type DealOrder } from '../deal-order.ts';
2
5
  import { addMoney, type MoneyTotals } from '../money.ts';
3
6
  import { dealCompany, dealOutcome, orderedStages } from '../pipeline.ts';
4
- import type { Deal, Pipeline, PipelineStage } from '../types.ts';
7
+ import type { Deal, DealOutcome, Pipeline, PipelineStage } from '../types.ts';
8
+ import type { CrmChoice } from './Forms.tsx';
5
9
  import { companyNameOf, formatDate, formatMaybeMoney, formatTotals, type CrmNames } from './format.ts';
6
10
  import { OutcomeBadge, SampleDataBadge } from './parts.tsx';
7
11
  import { recordItemId } from './SidePanel.tsx';
8
12
  import { withText, type CrmText } from './text.ts';
13
+ import { Button } from './ui/button.tsx';
9
14
  import { Card, CardContent, CardHeader, CardTitle } from './ui/card.tsx';
15
+ import { Input } from './ui/input.tsx';
16
+ import { Label } from './ui/label.tsx';
10
17
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select.tsx';
11
18
 
12
19
  /** Picks the stage a deal is at; moving it is one choice, so it works from the keyboard as well as by pointer. */
@@ -50,9 +57,163 @@ export function StageSelect({
50
57
  );
51
58
  }
52
59
 
60
+ const ANY = '__any__';
61
+ const NONE = '__none__';
62
+
63
+ const ORDER_WORDS: Record<DealOrder, keyof CrmText> = {
64
+ weighted: 'orderWeighted',
65
+ size: 'orderSize',
66
+ urgency: 'orderUrgency',
67
+ };
68
+
69
+ const OUTCOMES: readonly { outcome: DealOutcome; label: keyof CrmText }[] = [
70
+ { outcome: 'OPEN', label: 'outcomeOpen' },
71
+ { outcome: 'WON', label: 'outcomeWon' },
72
+ { outcome: 'LOST', label: 'outcomeLost' },
73
+ ];
74
+
75
+ /** A labelled select of a filter or order, with "any" as `ANY` and "none" as `NONE`. */
76
+ function ToolbarSelect({
77
+ label,
78
+ value,
79
+ onChange,
80
+ options,
81
+ className,
82
+ }: {
83
+ label: string;
84
+ value: string;
85
+ onChange: (value: string) => void;
86
+ options: readonly { value: string; label: string }[];
87
+ className?: string;
88
+ }) {
89
+ const id = useId();
90
+ return (
91
+ <div className="grid gap-1.5">
92
+ <Label htmlFor={id}>{label}</Label>
93
+ <Select value={value} onValueChange={onChange}>
94
+ <SelectTrigger id={id} className={className}>
95
+ <SelectValue />
96
+ </SelectTrigger>
97
+ <SelectContent>
98
+ {options.map((option) => (
99
+ <SelectItem key={option.value} value={option.value}>
100
+ {option.label}
101
+ </SelectItem>
102
+ ))}
103
+ </SelectContent>
104
+ </Select>
105
+ </div>
106
+ );
107
+ }
108
+
109
+ /**
110
+ * Filters for the deals board, as the tasks view has (words, outcome, assignee and company), and the order of each
111
+ * column's deals: weighted, by size or by urgency (see `sortDeals`). Controlled; apply them with `filterDeals`.
112
+ */
113
+ export function DealFilters({
114
+ value,
115
+ onChange,
116
+ order,
117
+ onOrder,
118
+ team = [],
119
+ companies = [],
120
+ shown,
121
+ text,
122
+ }: {
123
+ value: DealFilter;
124
+ onChange: (filter: DealFilter) => void;
125
+ order: DealOrder;
126
+ onOrder: (order: DealOrder) => void;
127
+ team?: readonly CrmChoice[] | undefined;
128
+ companies?: readonly CrmChoice[] | undefined;
129
+ /** How many deals the filters leave, announced as they change. */
130
+ shown?: number | undefined;
131
+ text?: Partial<CrmText> | undefined;
132
+ }) {
133
+ const words = withText(text);
134
+ const set = <K extends keyof DealFilter>(key: K, next: DealFilter[K]) => {
135
+ const { [key]: _removed, ...rest } = value;
136
+ onChange(next === undefined ? rest : { ...rest, [key]: next });
137
+ };
138
+ const pick = (selected: string) => (selected === ANY ? undefined : selected === NONE ? null : selected);
139
+ const current = (selected: string | null | undefined) =>
140
+ selected === undefined ? ANY : selected === null ? NONE : selected;
141
+ const active = Object.values(value).some((field) => field !== undefined && field !== '');
142
+ return (
143
+ <div role="search" aria-label={words.filterDeals} className="flex flex-wrap items-end gap-3">
144
+ <div className="relative min-w-48 flex-1">
145
+ <Search
146
+ aria-hidden="true"
147
+ className="text-muted-foreground absolute top-1/2 left-2.5 size-4 -translate-y-1/2"
148
+ />
149
+ <Input
150
+ type="search"
151
+ aria-label={words.filterDeals}
152
+ placeholder={words.filterDeals}
153
+ value={value.text ?? ''}
154
+ onChange={(event) => set('text', event.target.value || undefined)}
155
+ className="pl-8"
156
+ />
157
+ </div>
158
+ <ToolbarSelect
159
+ label={words.outcome}
160
+ value={value.outcome ?? ANY}
161
+ onChange={(selected) => set('outcome', selected === ANY ? undefined : (selected as DealOutcome))}
162
+ options={[
163
+ { value: ANY, label: words.allOutcomes },
164
+ ...OUTCOMES.map(({ outcome, label }) => ({ value: outcome, label: words[label] })),
165
+ ]}
166
+ className="w-36"
167
+ />
168
+ <ToolbarSelect
169
+ label={words.assignee}
170
+ value={current(value.assignee)}
171
+ onChange={(selected) => set('assignee', pick(selected))}
172
+ options={[
173
+ { value: ANY, label: words.anyone },
174
+ { value: NONE, label: words.unassigned },
175
+ ...team.map((person) => ({ value: person.urn, label: person.name })),
176
+ ]}
177
+ className="w-44"
178
+ />
179
+ {companies.length > 0 && (
180
+ <ToolbarSelect
181
+ label={words.company}
182
+ value={current(value.company)}
183
+ onChange={(selected) => set('company', pick(selected))}
184
+ options={[
185
+ { value: ANY, label: words.allCompanies },
186
+ { value: NONE, label: words.noCompany },
187
+ ...companies.map((company) => ({ value: company.urn, label: company.name })),
188
+ ]}
189
+ className="w-44"
190
+ />
191
+ )}
192
+ <ToolbarSelect
193
+ label={words.sortBy}
194
+ value={order}
195
+ onChange={(selected) => onOrder(selected as DealOrder)}
196
+ options={DEAL_ORDERS.map((option) => ({ value: option, label: words[ORDER_WORDS[option]] }))}
197
+ className="w-36"
198
+ />
199
+ {active && (
200
+ <Button variant="ghost" size="sm" onClick={() => onChange({})}>
201
+ <X aria-hidden="true" />
202
+ {words.clearFilters}
203
+ </Button>
204
+ )}
205
+ {shown !== undefined && (
206
+ <p aria-live="polite" className="sr-only">
207
+ {shown} {words.dealsShown}
208
+ </p>
209
+ )}
210
+ </div>
211
+ );
212
+ }
213
+
53
214
  /**
54
- * Deals as a board, one column per pipeline stage with its count and value. Each deal can be opened, and moved with
55
- * its stage picker.
215
+ * Deals as a board, one column per pipeline stage with its count and value, each column in `order` (weighted to start
216
+ * with). Each deal can be opened, and moved with its stage picker.
56
217
  */
57
218
  export function DealsBoard({
58
219
  deals,
@@ -63,10 +224,13 @@ export function DealsBoard({
63
224
  selected,
64
225
  saving,
65
226
  sample,
227
+ order = 'weighted',
66
228
  text,
67
229
  }: {
68
230
  deals: readonly Deal[];
69
231
  pipeline: Pipeline;
232
+ /** How each column's deals are ordered. */
233
+ order?: DealOrder | undefined;
70
234
  names?: CrmNames | undefined;
71
235
  onOpen?: ((deal: Deal) => void) | undefined;
72
236
  onMove?: ((deal: Deal, stage: PipelineStage) => void) | undefined;
@@ -88,7 +252,10 @@ export function DealsBoard({
88
252
  {/* Focusable, so the columns past the edge can be scrolled to from the keyboard. */}
89
253
  <div tabIndex={0} aria-label={pipeline.name} className="flex gap-3 overflow-x-auto rounded-xl pb-2">
90
254
  {orderedStages(pipeline).map((stage) => {
91
- const here = deals.filter((deal) => deal.workflowStage?.urn === stage.urn);
255
+ const here = sortDeals(
256
+ deals.filter((deal) => deal.workflowStage?.urn === stage.urn),
257
+ order,
258
+ );
92
259
  const value = here.reduce<MoneyTotals>((totals, deal) => addMoney(totals, deal.targetValue), {});
93
260
  return (
94
261
  <section