@burdenoff/microfe-subscriberbot 2026.1107.3 → 2026.1107.5
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/dist/subscriberbot/components/PageLayout.d.ts.map +1 -1
- package/dist/subscriberbot/components/PageLayout.js +1 -1
- package/dist/subscriberbot/components/PageLayout.js.map +1 -1
- package/dist/subscriberbot/components/viz.d.ts +5 -2
- package/dist/subscriberbot/components/viz.d.ts.map +1 -1
- package/dist/subscriberbot/components/viz.js +122 -126
- package/dist/subscriberbot/components/viz.js.map +1 -1
- package/dist/subscriberbot/pages/providers/ProviderInsights.d.ts.map +1 -1
- package/dist/subscriberbot/pages/providers/ProviderInsights.js +4 -1
- package/dist/subscriberbot/pages/providers/ProviderInsights.js.map +1 -1
- package/dist/subscriberbot/pages/relationships/RelationshipDetailPage.js +5 -5
- package/dist/subscriberbot/pages/relationships/RelationshipDetailPage.js.map +1 -1
- package/dist/subscriberbot/utils/chartScale.d.ts +32 -0
- package/dist/subscriberbot/utils/chartScale.d.ts.map +1 -0
- package/dist/subscriberbot/utils/chartScale.js +45 -0
- package/dist/subscriberbot/utils/chartScale.js.map +1 -0
- package/dist/subscriberbot/utils/portfolio.d.ts +7 -4
- package/dist/subscriberbot/utils/portfolio.d.ts.map +1 -1
- package/dist/subscriberbot/utils/portfolio.js +47 -38
- package/dist/subscriberbot/utils/portfolio.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viz.js","names":[],"sources":["../../../src/subscriberbot/components/viz.tsx"],"sourcesContent":["/**\n * Tokenized, responsive SVG visualization primitives.\n * @module subscriberbot/components/viz\n *\n * Every color is a fe-libs semantic CSS variable (never a raw hex), so charts\n * theme automatically in light/dark and per-product themes. All charts scale to\n * their container (SVG viewBox) and carry an accessible role/label.\n */\nimport type { FC, ReactNode } from 'react';\nimport { useTr } from '../hooks/useTr';\nimport { cn } from '../utils/cn';\n\n/** Categorical palette — fe-libs chart tokens. */\nexport const CHART_COLORS = [\n 'var(--color-chart-1)',\n 'var(--color-chart-2)',\n 'var(--color-chart-3)',\n 'var(--color-chart-4)',\n 'var(--color-chart-5)',\n 'var(--color-chart-6)',\n 'var(--color-chart-7)',\n 'var(--color-chart-8)',\n] as const;\n\nconst POSITIVE = 'var(--color-chart-positive)';\nconst NEGATIVE = 'var(--color-chart-negative)';\nconst GRID = 'var(--color-chart-grid)';\nconst WARN = 'var(--color-status-warning-text)';\nconst SUCCESS = 'var(--color-status-success-text)';\n\nexport interface Segment {\n label: string;\n value: number;\n color?: string;\n}\n\nconst colorAt = (i: number, override?: string) => override ?? CHART_COLORS[i % CHART_COLORS.length];\n\n// ---------------------------------------------------------------------------\n// Donut — proportional ring with an optional center label.\n// ---------------------------------------------------------------------------\nexport const Donut: FC<{\n data: Segment[];\n size?: number;\n thickness?: number;\n centerLabel?: string;\n centerSub?: string;\n className?: string;\n}> = ({ data, size = 160, thickness = 18, centerLabel, centerSub, className }) => {\n const total = data.reduce((s, d) => s + Math.max(0, d.value), 0);\n const r = (size - thickness) / 2;\n const c = 2 * Math.PI * r;\n const cx = size / 2;\n let offset = 0;\n const label = data.map((d) => `${d.label}: ${d.value}`).join(', ');\n\n return (\n <div className={cn('relative inline-flex items-center justify-center', className)}>\n <svg\n width={size}\n height={size}\n viewBox={`0 0 ${size} ${size}`}\n role=\"img\"\n aria-label={`Donut chart. ${label}`}\n className=\"max-w-full\"\n >\n <circle\n cx={cx}\n cy={cx}\n r={r}\n fill=\"none\"\n stroke={GRID}\n strokeWidth={thickness}\n opacity={0.4}\n />\n {total > 0 &&\n data.map((d, i) => {\n const frac = Math.max(0, d.value) / total;\n const len = frac * c;\n const seg = (\n <circle\n key={i}\n cx={cx}\n cy={cx}\n r={r}\n fill=\"none\"\n stroke={colorAt(i, d.color)}\n strokeWidth={thickness}\n strokeDasharray={`${len} ${c - len}`}\n strokeDashoffset={-offset}\n strokeLinecap=\"butt\"\n transform={`rotate(-90 ${cx} ${cx})`}\n />\n );\n offset += len;\n return seg;\n })}\n </svg>\n {(centerLabel || centerSub) && (\n <div className=\"absolute inset-0 flex flex-col items-center justify-center text-center\">\n {centerLabel && (\n <span className=\"text-xl font-bold text-text-primary tabular-nums leading-none\">\n {centerLabel}\n </span>\n )}\n {centerSub && <span className=\"mt-1 text-xs text-text-secondary\">{centerSub}</span>}\n </div>\n )}\n </div>\n );\n};\n\n// ---------------------------------------------------------------------------\n// Legend — pairs with Donut / charts.\n// ---------------------------------------------------------------------------\nexport const Legend: FC<{\n data: Segment[];\n valueFormat?: (n: number) => string;\n className?: string;\n}> = ({ data, valueFormat, className }) => (\n <ul className={cn('space-y-2', className)}>\n {data.map((d, i) => (\n <li key={i} className=\"flex items-center gap-2 text-sm\">\n <span\n className=\"h-2.5 w-2.5 shrink-0 rounded-full\"\n style={{ backgroundColor: colorAt(i, d.color) }}\n aria-hidden\n />\n <span className=\"flex-1 truncate text-text-secondary\">{d.label}</span>\n <span className=\"font-medium text-text-primary tabular-nums\">\n {valueFormat ? valueFormat(d.value) : d.value}\n </span>\n </li>\n ))}\n </ul>\n);\n\n// ---------------------------------------------------------------------------\n// BarList — horizontal labelled bars (e.g. spend by category).\n// ---------------------------------------------------------------------------\nexport const BarList: FC<{\n data: Segment[];\n valueFormat?: (n: number) => string;\n className?: string;\n}> = ({ data, valueFormat, className }) => {\n const tr = useTr();\n const max = Math.max(1, ...data.map((d) => d.value));\n return (\n <ul className={cn('space-y-3', className)} aria-label={tr('charts.barLabel', 'Bar chart')}>\n {data.map((d, i) => (\n <li key={i}>\n <div className=\"flex items-center justify-between text-sm\">\n <span className=\"truncate text-text-secondary\">{d.label}</span>\n <span className=\"font-medium text-text-primary tabular-nums\">\n {valueFormat ? valueFormat(d.value) : d.value}\n </span>\n </div>\n <div\n className=\"mt-1.5 h-2 w-full overflow-hidden rounded-full\"\n style={{ backgroundColor: GRID }}\n >\n <div\n className=\"h-full rounded-full transition-all\"\n style={{ width: `${(d.value / max) * 100}%`, backgroundColor: colorAt(i, d.color) }}\n />\n </div>\n </li>\n ))}\n </ul>\n );\n};\n\n// ---------------------------------------------------------------------------\n// Sparkline / area — small trend line.\n// ---------------------------------------------------------------------------\nexport const Sparkline: FC<{\n points: number[];\n width?: number;\n height?: number;\n positive?: boolean;\n className?: string;\n}> = ({ points, width = 220, height = 56, positive = true, className }) => {\n const tr = useTr();\n if (points.length < 2) return null;\n const max = Math.max(...points);\n const min = Math.min(...points);\n const span = max - min || 1;\n const stroke = positive ? POSITIVE : NEGATIVE;\n const step = width / (points.length - 1);\n const coords = points.map((p, i) => [i * step, height - ((p - min) / span) * (height - 8) - 4]);\n const line = coords\n .map(([x, y], i) => `${i === 0 ? 'M' : 'L'}${x.toFixed(1)},${y.toFixed(1)}`)\n .join(' ');\n const area = `${line} L${width},${height} L0,${height} Z`;\n return (\n <svg\n width={width}\n height={height}\n viewBox={`0 0 ${width} ${height}`}\n role=\"img\"\n aria-label={tr('charts.trendLabel', 'Trend sparkline')}\n className={cn('max-w-full', className)}\n preserveAspectRatio=\"none\"\n >\n <path d={area} fill={stroke} opacity={0.12} />\n <path\n d={line}\n fill=\"none\"\n stroke={stroke}\n strokeWidth={2}\n strokeLinejoin=\"round\"\n strokeLinecap=\"round\"\n />\n </svg>\n );\n};\n\n// ---------------------------------------------------------------------------\n// Gauge — 0..max semicircle (e.g. health score).\n// ---------------------------------------------------------------------------\nexport const Gauge: FC<{\n value: number;\n max?: number;\n size?: number;\n label?: string;\n className?: string;\n}> = ({ value, max = 100, size = 120, label, className }) => {\n const pct = Math.max(0, Math.min(1, value / max));\n const r = size / 2 - 10;\n const cy = size / 2;\n const circ = Math.PI * r; // half circle\n const tone = pct >= 0.66 ? SUCCESS : pct >= 0.33 ? WARN : NEGATIVE;\n return (\n <div className={cn('inline-flex flex-col items-center', className)}>\n <svg\n width={size}\n height={size / 2 + 8}\n viewBox={`0 0 ${size} ${size / 2 + 8}`}\n role=\"img\"\n aria-label={`Gauge: ${Math.round(pct * 100)} percent`}\n className=\"max-w-full\"\n >\n <path\n d={`M10 ${cy} A ${r} ${r} 0 0 1 ${size - 10} ${cy}`}\n fill=\"none\"\n stroke={GRID}\n strokeWidth={10}\n strokeLinecap=\"round\"\n />\n <path\n d={`M10 ${cy} A ${r} ${r} 0 0 1 ${size - 10} ${cy}`}\n fill=\"none\"\n stroke={tone}\n strokeWidth={10}\n strokeLinecap=\"round\"\n strokeDasharray={`${pct * circ} ${circ}`}\n />\n </svg>\n <div className=\"-mt-4 text-center\">\n <span className=\"text-lg font-bold text-text-primary tabular-nums\">\n {Math.round(value)}\n </span>\n {label && <p className=\"text-xs text-text-secondary\">{label}</p>}\n </div>\n </div>\n );\n};\n\n// ---------------------------------------------------------------------------\n// Timeline — vertical events with a connector rail (e.g. renewals).\n// ---------------------------------------------------------------------------\nexport interface TimelineItem {\n title: string;\n sub?: string;\n meta?: ReactNode;\n tone?: 'default' | 'positive' | 'warning' | 'muted';\n}\nconst dotTone: Record<NonNullable<TimelineItem['tone']>, string> = {\n default: 'var(--color-accent-indigo)',\n positive: SUCCESS,\n warning: WARN,\n muted: 'var(--color-text-secondary)',\n};\nexport const Timeline: FC<{ items: TimelineItem[]; className?: string }> = ({\n items,\n className,\n}) => (\n <ol\n className={cn(\n 'relative space-y-5 ps-6 before:absolute before:start-[7px] before:top-1 before:bottom-1 before:w-px before:bg-border-subtle',\n className\n )}\n >\n {items.map((it, i) => (\n <li key={i} className=\"relative\">\n <span\n className=\"absolute -start-[22px] top-1 h-3 w-3 rounded-full ring-4 ring-bg-surface\"\n style={{ backgroundColor: dotTone[it.tone ?? 'default'] }}\n aria-hidden\n />\n <div className=\"flex items-baseline justify-between gap-2\">\n <p className=\"text-sm font-medium text-text-primary\">{it.title}</p>\n {it.meta && <span className=\"text-sm tabular-nums text-text-primary\">{it.meta}</span>}\n </div>\n {it.sub && <p className=\"text-xs text-text-secondary\">{it.sub}</p>}\n </li>\n ))}\n </ol>\n);\n\n// ---------------------------------------------------------------------------\n// MiniProgress — inline utilization bar (e.g. seats used).\n// ---------------------------------------------------------------------------\nexport const MiniProgress: FC<{\n value: number;\n max?: number;\n label: string;\n tone?: 'accent' | 'positive' | 'warning' | 'negative';\n className?: string;\n}> = ({ value, max = 100, label, tone = 'accent', className }) => {\n const pct = Math.max(0, Math.min(1, max ? value / max : 0));\n const color =\n tone === 'positive'\n ? SUCCESS\n : tone === 'warning'\n ? WARN\n : tone === 'negative'\n ? NEGATIVE\n : 'var(--color-accent-indigo)';\n return (\n <div\n className={cn('h-2 w-full overflow-hidden rounded-full', className)}\n style={{ backgroundColor: GRID }}\n role=\"progressbar\"\n aria-label={label}\n aria-valuenow={Math.round(pct * 100)}\n aria-valuemin={0}\n aria-valuemax={100}\n >\n <div\n className=\"h-full rounded-full transition-all\"\n style={{ width: `${pct * 100}%`, backgroundColor: color }}\n />\n </div>\n );\n};\n\n// ---------------------------------------------------------------------------\n// PriceHistoryChart — prices over time on a real date axis (BOFF-4003).\n// ---------------------------------------------------------------------------\n// Recorded prices are drawn as step lines (a price holds until it changes, and\n// the last one holds until `now`). A point with a null value is a price with no\n// monthly equivalent (lifetime, usage-based): the line stops there and resumes\n// at the next recurring price. Invoice charges are drawn as dots only,\n// since each one is a separate charge rather than a continuing price. Every\n// series must share one currency: the caller filters before passing data in.\nexport interface PriceChartPoint {\n /** ISO timestamp. */\n at: string;\n /** Monthly value; null ends a step line here (no monthly equivalent). */\n value: number | null;\n /** Text for the point's native tooltip. */\n title?: string;\n}\n\nexport interface PriceChartSeries {\n key: string;\n label: string;\n points: PriceChartPoint[];\n /** `step` holds each value until the next point; `dots` draws points only. */\n mode: 'step' | 'dots';\n}\n\nconst CHART_W = 640;\nconst CHART_H = 220;\nconst PAD = { top: 12, right: 16, bottom: 28, left: 64 };\nconst DAY_MS = 86_400_000;\n\nexport const PriceHistoryChart: FC<{\n series: PriceChartSeries[];\n /** Formats a y-axis value (e.g. as currency). */\n valueFormat: (n: number) => string;\n /** Formats an x-axis date. */\n dateFormat: (d: Date) => string;\n /** Right edge of the time axis; defaults to the latest point. */\n now?: Date;\n ariaLabel: string;\n className?: string;\n}> = ({ series, valueFormat, dateFormat, now, ariaLabel, className }) => {\n const all = series.flatMap((s) => s.points);\n const values = all.flatMap((p) => (p.value === null ? [] : [p.value]));\n if (values.length === 0) return null;\n\n const times = all.map((p) => new Date(p.at).getTime());\n let t0 = Math.min(...times);\n let t1 = Math.max(...times, now ? now.getTime() : Number.NEGATIVE_INFINITY);\n if (t1 - t0 < DAY_MS) {\n t0 -= 15 * DAY_MS;\n t1 += 15 * DAY_MS;\n }\n const vMin = Math.min(...values);\n const vMax = Math.max(...values);\n const vPad = vMax === vMin ? Math.max(Math.abs(vMax) * 0.2, 1) : (vMax - vMin) * 0.15;\n const y0 = Math.max(0, vMin - vPad);\n const y1 = vMax + vPad;\n\n const plotW = CHART_W - PAD.left - PAD.right;\n const plotH = CHART_H - PAD.top - PAD.bottom;\n const x = (t: number) => PAD.left + ((t - t0) / (t1 - t0)) * plotW;\n const y = (v: number) => PAD.top + plotH - ((v - y0) / (y1 - y0)) * plotH;\n\n const yTicks = [0, 1, 2, 3].map((i) => y0 + ((y1 - y0) * i) / 3);\n const xTicks = [0, 0.5, 1].map((f) => new Date(t0 + (t1 - t0) * f));\n\n return (\n <div className={cn('w-full', className)}>\n <svg\n viewBox={`0 0 ${CHART_W} ${CHART_H}`}\n role=\"img\"\n aria-label={ariaLabel}\n className=\"h-auto w-full\"\n >\n {yTicks.map((v, i) => (\n <g key={`y${i}`}>\n <line\n x1={PAD.left}\n x2={CHART_W - PAD.right}\n y1={y(v)}\n y2={y(v)}\n stroke={GRID}\n strokeWidth={1}\n />\n <text\n x={PAD.left - 8}\n y={y(v) + 4}\n textAnchor=\"end\"\n fontSize={11}\n fill=\"var(--color-text-secondary)\"\n >\n {valueFormat(v)}\n </text>\n </g>\n ))}\n {xTicks.map((d, i) => (\n <text\n key={`x${i}`}\n x={x(d.getTime())}\n y={CHART_H - 8}\n textAnchor={i === 0 ? 'start' : i === 2 ? 'end' : 'middle'}\n fontSize={11}\n fill=\"var(--color-text-secondary)\"\n >\n {dateFormat(d)}\n </text>\n ))}\n {series.map((s, si) => {\n const color = colorAt(si);\n const pts = [...s.points].sort(\n (a, b) => new Date(a.at).getTime() - new Date(b.at).getTime()\n );\n let path = '';\n if (s.mode === 'step') {\n // A segment runs from a recurring price to the next point; a null\n // point ends it, and the next recurring price starts a new one.\n let open = false;\n for (const p of pts) {\n const px = x(new Date(p.at).getTime()).toFixed(1);\n if (p.value === null) {\n if (open) path += ` H${px}`;\n open = false;\n continue;\n }\n const py = y(p.value).toFixed(1);\n path += open ? ` H${px} V${py}` : ` M${px},${py}`;\n open = true;\n }\n if (open) path += ` H${x(t1).toFixed(1)}`;\n path = path.trim();\n }\n return (\n <g key={s.key} data-series={s.key}>\n {path && (\n <path d={path} fill=\"none\" stroke={color} strokeWidth={2} strokeLinejoin=\"round\" />\n )}\n {pts.map((p, i) =>\n p.value === null ? null : (\n <circle\n key={`${s.key}-${i}`}\n cx={x(new Date(p.at).getTime())}\n cy={y(p.value)}\n r={s.mode === 'dots' ? 3.5 : 4}\n fill={s.mode === 'dots' ? 'var(--color-bg-surface)' : color}\n stroke={color}\n strokeWidth={2}\n >\n {p.title && <title>{p.title}</title>}\n </circle>\n )\n )}\n </g>\n );\n })}\n </svg>\n <ul className=\"mt-2 flex flex-wrap gap-x-4 gap-y-1\">\n {series.map((s, si) => (\n <li key={s.key} className=\"flex items-center gap-1.5 text-xs text-text-secondary\">\n <span\n className={cn(\n 'h-2.5 w-2.5 shrink-0',\n s.mode === 'dots' ? 'rounded-full border-2' : 'rounded-sm'\n )}\n style={\n s.mode === 'dots' ? { borderColor: colorAt(si) } : { backgroundColor: colorAt(si) }\n }\n aria-hidden\n />\n {s.label}\n </li>\n ))}\n </ul>\n </div>\n );\n};\n"],"mappings":";;;;AAaA,IAAa,IAAe;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;A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,KAAK,GAAG,MACd,kBAAC,MAAD;IAAgB,WAAU;cAA1B,CACE,kBAAC,QAAD;KACE,WAAW,EACT,wBACA,EAAE,SAAS,SAAS,0BAA0B,YAChD;KACA,OACE,EAAE,SAAS,SAAS,EAAE,aAAa,EAAQ,CAAE,EAAE,IAAI,EAAE,iBAAiB,EAAQ,CAAE,EAAE;KAEpF,eAAA;IACD,CAAA,GACA,EAAE,KACD;MAZK,EAAE,GAYP,CACL;EACC,CAAA,CACD;;AAET"}
|
|
1
|
+
{"version":3,"file":"viz.js","names":[],"sources":["../../../src/subscriberbot/components/viz.tsx"],"sourcesContent":["/**\n * Tokenized, responsive SVG visualization primitives.\n * @module subscriberbot/components/viz\n *\n * Every color is a fe-libs semantic CSS variable (never a raw hex), so charts\n * theme automatically in light/dark and per-product themes. All charts scale to\n * their container (SVG viewBox) and carry an accessible role/label.\n */\nimport type { FC, ReactNode } from 'react';\nimport { useTr } from '../hooks/useTr';\nimport { cn } from '../utils/cn';\nimport { niceScale } from '../utils/chartScale';\n\n/** Categorical palette — fe-libs chart tokens. */\nexport const CHART_COLORS = [\n 'var(--color-chart-1)',\n 'var(--color-chart-2)',\n 'var(--color-chart-3)',\n 'var(--color-chart-4)',\n 'var(--color-chart-5)',\n 'var(--color-chart-6)',\n 'var(--color-chart-7)',\n 'var(--color-chart-8)',\n] as const;\n\nconst POSITIVE = 'var(--color-chart-positive)';\nconst NEGATIVE = 'var(--color-chart-negative)';\nconst GRID = 'var(--color-chart-grid)';\nconst WARN = 'var(--color-status-warning-text)';\nconst SUCCESS = 'var(--color-status-success-text)';\n\nexport interface Segment {\n label: string;\n value: number;\n color?: string;\n}\n\nconst colorAt = (i: number, override?: string) => override ?? CHART_COLORS[i % CHART_COLORS.length];\n\n// ---------------------------------------------------------------------------\n// Donut — proportional ring with an optional center label.\n// ---------------------------------------------------------------------------\nexport const Donut: FC<{\n data: Segment[];\n size?: number;\n thickness?: number;\n centerLabel?: string;\n centerSub?: string;\n className?: string;\n}> = ({ data, size = 160, thickness = 18, centerLabel, centerSub, className }) => {\n const total = data.reduce((s, d) => s + Math.max(0, d.value), 0);\n const r = (size - thickness) / 2;\n const c = 2 * Math.PI * r;\n const cx = size / 2;\n let offset = 0;\n const label = data.map((d) => `${d.label}: ${d.value}`).join(', ');\n\n return (\n <div className={cn('relative inline-flex items-center justify-center', className)}>\n <svg\n width={size}\n height={size}\n viewBox={`0 0 ${size} ${size}`}\n role=\"img\"\n aria-label={`Donut chart. ${label}`}\n className=\"max-w-full\"\n >\n <circle\n cx={cx}\n cy={cx}\n r={r}\n fill=\"none\"\n stroke={GRID}\n strokeWidth={thickness}\n opacity={0.4}\n />\n {total > 0 &&\n data.map((d, i) => {\n const frac = Math.max(0, d.value) / total;\n const len = frac * c;\n const seg = (\n <circle\n key={i}\n cx={cx}\n cy={cx}\n r={r}\n fill=\"none\"\n stroke={colorAt(i, d.color)}\n strokeWidth={thickness}\n strokeDasharray={`${len} ${c - len}`}\n strokeDashoffset={-offset}\n strokeLinecap=\"butt\"\n transform={`rotate(-90 ${cx} ${cx})`}\n />\n );\n offset += len;\n return seg;\n })}\n </svg>\n {(centerLabel || centerSub) && (\n <div className=\"absolute inset-0 flex flex-col items-center justify-center text-center\">\n {centerLabel && (\n <span className=\"text-xl font-bold text-text-primary tabular-nums leading-none\">\n {centerLabel}\n </span>\n )}\n {centerSub && <span className=\"mt-1 text-xs text-text-secondary\">{centerSub}</span>}\n </div>\n )}\n </div>\n );\n};\n\n// ---------------------------------------------------------------------------\n// Legend — pairs with Donut / charts.\n// ---------------------------------------------------------------------------\nexport const Legend: FC<{\n data: Segment[];\n valueFormat?: (n: number) => string;\n className?: string;\n}> = ({ data, valueFormat, className }) => (\n <ul className={cn('space-y-2', className)}>\n {data.map((d, i) => (\n <li key={i} className=\"flex items-center gap-2 text-sm\">\n <span\n className=\"h-2.5 w-2.5 shrink-0 rounded-full\"\n style={{ backgroundColor: colorAt(i, d.color) }}\n aria-hidden\n />\n <span className=\"flex-1 truncate text-text-secondary\">{d.label}</span>\n <span className=\"font-medium text-text-primary tabular-nums\">\n {valueFormat ? valueFormat(d.value) : d.value}\n </span>\n </li>\n ))}\n </ul>\n);\n\n// ---------------------------------------------------------------------------\n// BarList — horizontal labelled bars (e.g. spend by category).\n// ---------------------------------------------------------------------------\nexport const BarList: FC<{\n data: Segment[];\n valueFormat?: (n: number) => string;\n className?: string;\n}> = ({ data, valueFormat, className }) => {\n const tr = useTr();\n const max = Math.max(1, ...data.map((d) => d.value));\n return (\n <ul className={cn('space-y-3', className)} aria-label={tr('charts.barLabel', 'Bar chart')}>\n {data.map((d, i) => (\n <li key={i}>\n <div className=\"flex items-center justify-between text-sm\">\n <span className=\"truncate text-text-secondary\">{d.label}</span>\n <span className=\"font-medium text-text-primary tabular-nums\">\n {valueFormat ? valueFormat(d.value) : d.value}\n </span>\n </div>\n <div\n className=\"mt-1.5 h-2 w-full overflow-hidden rounded-full\"\n style={{ backgroundColor: GRID }}\n >\n <div\n className=\"h-full rounded-full transition-all\"\n style={{ width: `${(d.value / max) * 100}%`, backgroundColor: colorAt(i, d.color) }}\n />\n </div>\n </li>\n ))}\n </ul>\n );\n};\n\n// ---------------------------------------------------------------------------\n// Sparkline / area — small trend line.\n// ---------------------------------------------------------------------------\nexport const Sparkline: FC<{\n points: number[];\n width?: number;\n height?: number;\n positive?: boolean;\n className?: string;\n}> = ({ points, width = 220, height = 56, positive = true, className }) => {\n const tr = useTr();\n if (points.length < 2) return null;\n const max = Math.max(...points);\n const min = Math.min(...points);\n const span = max - min || 1;\n const stroke = positive ? POSITIVE : NEGATIVE;\n const step = width / (points.length - 1);\n const coords = points.map((p, i) => [i * step, height - ((p - min) / span) * (height - 8) - 4]);\n const line = coords\n .map(([x, y], i) => `${i === 0 ? 'M' : 'L'}${x.toFixed(1)},${y.toFixed(1)}`)\n .join(' ');\n const area = `${line} L${width},${height} L0,${height} Z`;\n return (\n <svg\n width={width}\n height={height}\n viewBox={`0 0 ${width} ${height}`}\n role=\"img\"\n aria-label={tr('charts.trendLabel', 'Trend sparkline')}\n className={cn('max-w-full', className)}\n preserveAspectRatio=\"none\"\n >\n <path d={area} fill={stroke} opacity={0.12} />\n <path\n d={line}\n fill=\"none\"\n stroke={stroke}\n strokeWidth={2}\n strokeLinejoin=\"round\"\n strokeLinecap=\"round\"\n />\n </svg>\n );\n};\n\n// ---------------------------------------------------------------------------\n// Gauge — 0..max semicircle (e.g. health score).\n// ---------------------------------------------------------------------------\nexport const Gauge: FC<{\n value: number;\n max?: number;\n size?: number;\n label?: string;\n className?: string;\n}> = ({ value, max = 100, size = 120, label, className }) => {\n const pct = Math.max(0, Math.min(1, value / max));\n const r = size / 2 - 10;\n const cy = size / 2;\n const circ = Math.PI * r; // half circle\n const tone = pct >= 0.66 ? SUCCESS : pct >= 0.33 ? WARN : NEGATIVE;\n return (\n <div className={cn('inline-flex flex-col items-center', className)}>\n <svg\n width={size}\n height={size / 2 + 8}\n viewBox={`0 0 ${size} ${size / 2 + 8}`}\n role=\"img\"\n aria-label={`Gauge: ${Math.round(pct * 100)} percent`}\n className=\"max-w-full\"\n >\n <path\n d={`M10 ${cy} A ${r} ${r} 0 0 1 ${size - 10} ${cy}`}\n fill=\"none\"\n stroke={GRID}\n strokeWidth={10}\n strokeLinecap=\"round\"\n />\n <path\n d={`M10 ${cy} A ${r} ${r} 0 0 1 ${size - 10} ${cy}`}\n fill=\"none\"\n stroke={tone}\n strokeWidth={10}\n strokeLinecap=\"round\"\n strokeDasharray={`${pct * circ} ${circ}`}\n />\n </svg>\n <div className=\"-mt-4 text-center\">\n <span className=\"text-lg font-bold text-text-primary tabular-nums\">\n {Math.round(value)}\n </span>\n {label && <p className=\"text-xs text-text-secondary\">{label}</p>}\n </div>\n </div>\n );\n};\n\n// ---------------------------------------------------------------------------\n// Timeline — vertical events with a connector rail (e.g. renewals).\n// ---------------------------------------------------------------------------\nexport interface TimelineItem {\n title: string;\n sub?: string;\n meta?: ReactNode;\n tone?: 'default' | 'positive' | 'warning' | 'muted';\n}\nconst dotTone: Record<NonNullable<TimelineItem['tone']>, string> = {\n default: 'var(--color-accent-indigo)',\n positive: SUCCESS,\n warning: WARN,\n muted: 'var(--color-text-secondary)',\n};\nexport const Timeline: FC<{ items: TimelineItem[]; className?: string }> = ({\n items,\n className,\n}) => (\n <ol\n className={cn(\n 'relative space-y-5 ps-6 before:absolute before:start-[7px] before:top-1 before:bottom-1 before:w-px before:bg-border-subtle',\n className\n )}\n >\n {items.map((it, i) => (\n <li key={i} className=\"relative\">\n <span\n className=\"absolute -start-[22px] top-1 h-3 w-3 rounded-full ring-4 ring-bg-surface\"\n style={{ backgroundColor: dotTone[it.tone ?? 'default'] }}\n aria-hidden\n />\n <div className=\"flex items-baseline justify-between gap-2\">\n <p className=\"text-sm font-medium text-text-primary\">{it.title}</p>\n {it.meta && <span className=\"text-sm tabular-nums text-text-primary\">{it.meta}</span>}\n </div>\n {it.sub && <p className=\"text-xs text-text-secondary\">{it.sub}</p>}\n </li>\n ))}\n </ol>\n);\n\n// ---------------------------------------------------------------------------\n// MiniProgress — inline utilization bar (e.g. seats used).\n// ---------------------------------------------------------------------------\nexport const MiniProgress: FC<{\n value: number;\n max?: number;\n label: string;\n tone?: 'accent' | 'positive' | 'warning' | 'negative';\n className?: string;\n}> = ({ value, max = 100, label, tone = 'accent', className }) => {\n const pct = Math.max(0, Math.min(1, max ? value / max : 0));\n const color =\n tone === 'positive'\n ? SUCCESS\n : tone === 'warning'\n ? WARN\n : tone === 'negative'\n ? NEGATIVE\n : 'var(--color-accent-indigo)';\n return (\n <div\n className={cn('h-2 w-full overflow-hidden rounded-full', className)}\n style={{ backgroundColor: GRID }}\n role=\"progressbar\"\n aria-label={label}\n aria-valuenow={Math.round(pct * 100)}\n aria-valuemin={0}\n aria-valuemax={100}\n >\n <div\n className=\"h-full rounded-full transition-all\"\n style={{ width: `${pct * 100}%`, backgroundColor: color }}\n />\n </div>\n );\n};\n\n// ---------------------------------------------------------------------------\n// PriceHistoryChart — prices over time on a real date axis (BOFF-4003).\n// ---------------------------------------------------------------------------\n// Recorded prices are drawn as step lines (a price holds until it changes, and\n// the last one holds until `now`). A point with a null value is a price with no\n// monthly equivalent (lifetime, usage-based): the line stops there and resumes\n// at the next recurring price. Invoice charges are drawn as dots only,\n// since each one is a separate charge rather than a continuing price. Every\n// series must share one currency: the caller filters before passing data in.\nexport interface PriceChartPoint {\n /** ISO timestamp. */\n at: string;\n /** Monthly value; null ends a step line here (no monthly equivalent). */\n value: number | null;\n /** Text for the point's native tooltip. */\n title?: string;\n}\n\nexport interface PriceChartSeries {\n key: string;\n label: string;\n points: PriceChartPoint[];\n /** `step` holds each value until the next point; `dots` draws points only. */\n mode: 'step' | 'dots';\n}\n\nconst CHART_W = 640;\nconst CHART_H = 220;\nconst PAD = { top: 12, right: 16, bottom: 28, left: 64 };\nconst DAY_MS = 86_400_000;\n\nexport const PriceHistoryChart: FC<{\n series: PriceChartSeries[];\n /**\n * Formats a y-axis value (e.g. as currency). `fractionDigits` is the\n * precision the axis step needs so neighbouring labels never repeat.\n */\n valueFormat: (n: number, fractionDigits: number) => string;\n /** Formats an x-axis date. */\n dateFormat: (d: Date) => string;\n /** Right edge of the time axis; defaults to the latest point. */\n now?: Date;\n ariaLabel: string;\n className?: string;\n}> = ({ series, valueFormat, dateFormat, now, ariaLabel, className }) => {\n const all = series.flatMap((s) => s.points);\n const values = all.flatMap((p) => (p.value === null ? [] : [p.value]));\n if (values.length === 0) return null;\n\n const times = all.map((p) => new Date(p.at).getTime());\n let t0 = Math.min(...times);\n let t1 = Math.max(...times, now ? now.getTime() : Number.NEGATIVE_INFINITY);\n if (t1 - t0 < DAY_MS) {\n t0 -= 15 * DAY_MS;\n t1 += 15 * DAY_MS;\n }\n const vMin = Math.min(...values);\n const vMax = Math.max(...values);\n const vPad = vMax === vMin ? Math.max(Math.abs(vMax) * 0.2, 1) : (vMax - vMin) * 0.15;\n // Round the padded range out to a nice step so each gridline label is the\n // exact value it marks (never 9.7 / 10.47 / ... shown as \"$10, $11, $11\").\n const scale = niceScale(vMin >= 0 ? Math.max(0, vMin - vPad) : vMin - vPad, vMax + vPad, 4);\n const y0 = scale.min;\n const y1 = scale.max;\n\n const plotW = CHART_W - PAD.left - PAD.right;\n const plotH = CHART_H - PAD.top - PAD.bottom;\n const x = (t: number) => PAD.left + ((t - t0) / (t1 - t0)) * plotW;\n const y = (v: number) => PAD.top + plotH - ((v - y0) / (y1 - y0)) * plotH;\n\n const yTicks = scale.ticks;\n const xTicks = [0, 0.5, 1].map((f) => new Date(t0 + (t1 - t0) * f));\n\n return (\n <div className={cn('w-full', className)}>\n <svg\n viewBox={`0 0 ${CHART_W} ${CHART_H}`}\n role=\"img\"\n aria-label={ariaLabel}\n className=\"h-auto w-full\"\n >\n {yTicks.map((v, i) => (\n <g key={`y${i}`}>\n <line\n x1={PAD.left}\n x2={CHART_W - PAD.right}\n y1={y(v)}\n y2={y(v)}\n stroke={GRID}\n strokeWidth={1}\n />\n <text\n x={PAD.left - 8}\n y={y(v) + 4}\n textAnchor=\"end\"\n fontSize={11}\n fill=\"var(--color-text-secondary)\"\n >\n {valueFormat(v, scale.fractionDigits)}\n </text>\n </g>\n ))}\n {xTicks.map((d, i) => (\n <text\n key={`x${i}`}\n x={x(d.getTime())}\n y={CHART_H - 8}\n textAnchor={i === 0 ? 'start' : i === 2 ? 'end' : 'middle'}\n fontSize={11}\n fill=\"var(--color-text-secondary)\"\n >\n {dateFormat(d)}\n </text>\n ))}\n {series.map((s, si) => {\n const color = colorAt(si);\n const pts = [...s.points].sort(\n (a, b) => new Date(a.at).getTime() - new Date(b.at).getTime()\n );\n let path = '';\n if (s.mode === 'step') {\n // A segment runs from a recurring price to the next point; a null\n // point ends it, and the next recurring price starts a new one.\n let open = false;\n for (const p of pts) {\n const px = x(new Date(p.at).getTime()).toFixed(1);\n if (p.value === null) {\n if (open) path += ` H${px}`;\n open = false;\n continue;\n }\n const py = y(p.value).toFixed(1);\n path += open ? ` H${px} V${py}` : ` M${px},${py}`;\n open = true;\n }\n if (open) path += ` H${x(t1).toFixed(1)}`;\n path = path.trim();\n }\n return (\n <g key={s.key} data-series={s.key}>\n {path && (\n <path d={path} fill=\"none\" stroke={color} strokeWidth={2} strokeLinejoin=\"round\" />\n )}\n {pts.map((p, i) =>\n p.value === null ? null : (\n <circle\n key={`${s.key}-${i}`}\n cx={x(new Date(p.at).getTime())}\n cy={y(p.value)}\n r={s.mode === 'dots' ? 3.5 : 4}\n fill={s.mode === 'dots' ? 'var(--color-bg-surface)' : color}\n stroke={color}\n strokeWidth={2}\n >\n {p.title && <title>{p.title}</title>}\n </circle>\n )\n )}\n </g>\n );\n })}\n </svg>\n <ul className=\"mt-2 flex flex-wrap gap-x-4 gap-y-1\">\n {series.map((s, si) => (\n <li key={s.key} className=\"flex items-center gap-1.5 text-xs text-text-secondary\">\n <span\n className={cn(\n 'h-2.5 w-2.5 shrink-0',\n s.mode === 'dots' ? 'rounded-full border-2' : 'rounded-sm'\n )}\n style={\n s.mode === 'dots' ? { borderColor: colorAt(si) } : { backgroundColor: colorAt(si) }\n }\n aria-hidden\n />\n {s.label}\n </li>\n ))}\n </ul>\n </div>\n );\n};\n"],"mappings":";;;;;AAcA,IAAa,IAAe;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEM,IAAW,+BACX,IAAW,+BACX,IAAO,2BACP,IAAO,oCACP,IAAU,oCAQV,KAAW,GAAW,MAAsB,KAAY,EAAa,IAAI,EAAa,SAK/E,KAOP,EAAE,SAAM,UAAO,KAAK,eAAY,IAAI,gBAAa,cAAW,mBAAgB;CAChF,IAAM,IAAQ,EAAK,QAAQ,GAAG,MAAM,IAAI,KAAK,IAAI,GAAG,EAAE,KAAK,GAAG,CAAC,GACzD,KAAK,IAAO,KAAa,GACzB,IAAI,IAAI,KAAK,KAAK,GAClB,IAAK,IAAO,GACd,IAAS,GACP,IAAQ,EAAK,KAAK,MAAM,GAAG,EAAE,MAAM,IAAI,EAAE,OA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derInsights.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA4FH,wBAAgB,wBAAwB,CAAC,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,+
|
|
1
|
+
{"version":3,"file":"ProviderInsights.d.ts","sourceRoot":"","sources":["../../../../src/subscriberbot/pages/providers/ProviderInsights.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA4FH,wBAAgB,wBAAwB,CAAC,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,+BAmM9E;AA2GD,wBAAgB,oBAAoB,CAAC,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,+BAgD1E"}
|
|
@@ -128,7 +128,10 @@ function E({ providerId: r }) {
|
|
|
128
128
|
series: O,
|
|
129
129
|
now: /* @__PURE__ */ new Date(),
|
|
130
130
|
ariaLabel: s("providers.insights.chartLabel", "Monthly price paid over time, in {{currency}}", { currency: j }),
|
|
131
|
-
valueFormat: (e) => t(e, j, {
|
|
131
|
+
valueFormat: (e, n) => t(e, j, {
|
|
132
|
+
minimumFractionDigits: n,
|
|
133
|
+
maximumFractionDigits: n
|
|
134
|
+
}),
|
|
132
135
|
dateFormat: (e) => n(e, {
|
|
133
136
|
day: void 0,
|
|
134
137
|
month: "short",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderInsights.js","names":[],"sources":["../../../../src/subscriberbot/pages/providers/ProviderInsights.tsx"],"sourcesContent":["/**\n * Provider insights for the provider detail page (BOFF-4003)\n * @module subscriberbot/pages/providers\n *\n * Two sections that turn the provider page into a renewal decision surface:\n *\n * - `ProviderPaidPriceHistory` charts what this workspace has paid the\n * provider over time (`subProviderPriceHistory`): every recorded price of a\n * relationship with it, plus the invoices charged against them.\n * - `ProviderAlternatives` lists registry providers that could replace it\n * (`subProviderAlternatives`), ranked by shared capability tags, then\n * category, with providers the workspace already uses first.\n *\n * Amounts in different currencies are never drawn on one chart: the chart\n * shows the currency the backend summary picked (the most observed one).\n */\n\nimport { useMemo } from 'react';\nimport { ArrowRight, Shuffle } from 'lucide-react';\nimport { GlassCard } from '@burdenoff/fe-libs/ui';\nimport { EmptyState } from '../../components/EmptyState';\nimport { LoadingView, ErrorView, Section } from '../../components/StateViews';\nimport { StatusBadge } from '../../components/StatusBadge';\nimport { PriceHistoryChart, type PriceChartSeries } from '../../components';\nimport { useSubscriberBot } from '../../context/SubscriberBotContext';\nimport { useProviderAlternatives, useProviderPriceHistory } from '../../hooks/useSubscriberBotApi';\nimport { useTr } from '../../hooks/useTr';\nimport {\n formatCurrency,\n formatDate,\n formatEnumLabel,\n formatIntervalSuffix,\n} from '../../utils/formatters';\nimport { cn } from '../../utils/cn';\nimport type {\n SubPriceRange,\n SubProviderAlternative,\n SubProviderPriceHistory,\n SubProviderPriceSeries,\n} from '../../types';\n\n/** Points listed under the chart, newest first. */\nconst RECENT_POINTS = 6;\n\nfunction changeTone(percent: number | null): string {\n if (percent === null || percent === 0) return 'bg-bg-sunken text-text-secondary';\n return percent > 0\n ? 'bg-status-error-bg-subtle text-status-error-text'\n : 'bg-status-success-bg-subtle text-status-success-text';\n}\n\nfunction formatPercent(percent: number): string {\n return `${percent > 0 ? '+' : ''}${percent}%`;\n}\n\nfunction chartSeries(\n history: SubProviderPriceHistory,\n tr: ReturnType<typeof useTr>\n): PriceChartSeries[] {\n const currency = history.summary?.currency;\n if (!currency) return [];\n // A relationship's recorded prices are split per currency. When it moved to\n // another currency, that later price ends the displayed segment, exactly\n // like a non-recurring price does: the old currency's line must not run on.\n const otherCurrencyTimes = new Map<string, string[]>();\n for (const s of history.series) {\n if (s.source !== 'RELATIONSHIP' || s.currency === currency || !s.relationshipId) continue;\n const list = otherCurrencyTimes.get(s.relationshipId) ?? [];\n list.push(...s.points.map((p) => p.observedAt));\n otherCurrencyTimes.set(s.relationshipId, list);\n }\n return history.series\n .filter((s) => s.currency === currency)\n .map((s) => {\n // Recorded prices keep their non-recurring points (null value) so the\n // step line ends where a lifetime or usage-based price took over;\n // invoice dots without a monthly equivalent are simply not drawn.\n const points: PriceChartSeries['points'] = s.points\n .filter((p) => s.source !== 'INVOICE' || p.monthlyAmount !== null)\n .map((p) => ({\n at: p.observedAt,\n value: p.monthlyAmount,\n title: `${formatDate(p.observedAt)} · ${formatCurrency(p.amount, p.currency)}${formatIntervalSuffix(p.interval)}`,\n }));\n if (s.source === 'RELATIONSHIP' && s.relationshipId) {\n for (const at of otherCurrencyTimes.get(s.relationshipId) ?? []) {\n points.push({ at, value: null });\n }\n }\n return {\n key: s.key,\n label:\n s.source === 'INVOICE'\n ? tr('providers.insights.invoiceSeries', '{{label}} (invoices)', {\n label: s.label.replace(/ \\(invoices\\)$/, ''),\n })\n : s.label,\n mode: s.source === 'INVOICE' ? ('dots' as const) : ('step' as const),\n points,\n };\n })\n .filter((s) => s.points.some((p) => p.value !== null));\n}\n\n// ---------------------------------------------------------------------------\n// Price history — what this workspace has paid the provider\n// ---------------------------------------------------------------------------\nexport function ProviderPaidPriceHistory({ providerId }: { providerId: string }) {\n const tr = useTr();\n const { navigateTo } = useSubscriberBot();\n const { data, isLoading, isError, refetch } = useProviderPriceHistory(providerId);\n\n const series = useMemo(() => (data ? chartSeries(data, tr) : []), [data, tr]);\n const recent = useMemo(\n () => (data ? [...data.points].reverse().slice(0, RECENT_POINTS) : []),\n [data]\n );\n const summary = data?.summary ?? null;\n const currency = summary?.currency ?? 'USD';\n // Every relationship tracked under this provider contributes its latest\n // recorded price, so the headline is the workspace's total per month rather\n // than whichever relationship happens to come first.\n const latestTotal = useMemo(() => {\n // Each relationship's current price is its latest recorded point across\n // every currency; only those now priced in the display currency count.\n const latestByRelationship = new Map<string, { at: string; series: SubProviderPriceSeries }>();\n for (const s of data?.series ?? []) {\n const last = s.points[s.points.length - 1];\n if (s.source !== 'RELATIONSHIP' || !last) continue;\n const key = s.relationshipId ?? s.key;\n const seen = latestByRelationship.get(key);\n if (!seen || Date.parse(last.observedAt) > Date.parse(seen.at))\n latestByRelationship.set(key, { at: last.observedAt, series: s });\n }\n const recorded = [...latestByRelationship.values()]\n .map((v) => v.series)\n .filter((s) => s.currency === currency && s.latestMonthlyAmount != null);\n if (recorded.length === 0) return null;\n const amount = recorded.reduce((sum, s) => sum + (s.latestMonthlyAmount ?? 0), 0);\n return { amount: Math.round(amount * 100) / 100, count: recorded.length };\n }, [data, currency]);\n\n return (\n <Section\n title={tr('providers.insights.priceHistoryTitle', 'Your price history')}\n description={tr(\n 'providers.insights.priceHistoryDescription',\n 'What this workspace has paid this provider over time, per month'\n )}\n >\n <GlassCard treatment=\"metric\" className=\"p-5\" data-testid=\"provider-price-history\">\n {isLoading ? (\n <LoadingView\n className=\"min-h-[10rem]\"\n label={tr('providers.insights.priceHistoryLoading', 'Loading price history…')}\n />\n ) : isError ? (\n <ErrorView\n className=\"min-h-[10rem]\"\n title={tr('providers.insights.priceHistoryErrorTitle', 'Price history unavailable')}\n message={tr(\n 'providers.insights.priceHistoryError',\n 'Could not load what this workspace has paid this provider.'\n )}\n onRetry={() => void refetch()}\n />\n ) : !data || !summary ? (\n <EmptyState\n illustration=\"empty-data\"\n title={tr('providers.insights.priceHistoryEmptyTitle', 'No prices recorded yet')}\n description={tr(\n 'providers.insights.priceHistoryEmpty',\n 'Link a relationship to this provider and its price, and every later change, will be charted here.'\n )}\n />\n ) : (\n <>\n <div className=\"flex flex-wrap items-start gap-x-8 gap-y-3\">\n <div>\n <p className=\"text-xs text-text-secondary\">\n {latestTotal && latestTotal.count > 1\n ? tr(\n 'providers.insights.latestMonthlyTotal',\n 'Latest monthly price across {{count}} relationships',\n { count: latestTotal.count }\n )\n : tr('providers.insights.latestMonthly', 'Latest monthly price')}\n </p>\n <p className=\"text-2xl font-bold tabular-nums text-text-primary\">\n {latestTotal ? formatCurrency(latestTotal.amount, currency) : '—'}\n <span className=\"text-sm font-normal text-text-secondary\">/mo</span>\n </p>\n </div>\n <div>\n <p className=\"text-xs text-text-secondary\">\n {tr('providers.insights.range', 'Range paid')}\n </p>\n <p className=\"text-sm font-medium tabular-nums text-text-primary\">\n {summary.minMonthlyAmount != null && summary.maxMonthlyAmount != null\n ? `${formatCurrency(summary.minMonthlyAmount, currency)} – ${formatCurrency(summary.maxMonthlyAmount, currency)}`\n : '—'}\n </p>\n </div>\n <div>\n <p className=\"text-xs text-text-secondary\">\n {tr('providers.insights.priceChanges', 'Price changes')}\n </p>\n <p className=\"text-sm font-medium tabular-nums text-text-primary\">\n {summary.priceChangeCount}\n </p>\n </div>\n {summary.latestChangePercent != null && (\n <div>\n <p className=\"text-xs text-text-secondary\">\n {tr('providers.insights.latestChange', 'Latest change')}\n </p>\n <span\n className={cn(\n 'mt-0.5 inline-block rounded-full px-2 py-0.5 text-xs font-medium tabular-nums',\n changeTone(summary.latestChangePercent)\n )}\n >\n {formatPercent(summary.latestChangePercent)}\n {summary.latestChangeAt && ` · ${formatDate(summary.latestChangeAt)}`}\n </span>\n </div>\n )}\n </div>\n\n {series.length > 0 ? (\n <PriceHistoryChart\n className=\"mt-4\"\n series={series}\n now={new Date()}\n ariaLabel={tr(\n 'providers.insights.chartLabel',\n 'Monthly price paid over time, in {{currency}}',\n { currency }\n )}\n valueFormat={(n) => formatCurrency(n, currency, { maximumFractionDigits: 0 })}\n dateFormat={(d) =>\n formatDate(d, { day: undefined, month: 'short', year: 'numeric' })\n }\n />\n ) : (\n <p className=\"mt-4 text-sm text-text-secondary\">\n {tr(\n 'providers.insights.noRecurring',\n 'These prices are not recurring, so there is no monthly trend to chart.'\n )}\n </p>\n )}\n\n <ul className=\"mt-4 divide-y divide-border-subtle border-t border-border-subtle\">\n {recent.map((point) => (\n <li\n key={point.id}\n className=\"flex flex-wrap items-center justify-between gap-2 py-2 text-sm\"\n >\n <span className=\"flex min-w-0 items-center gap-2\">\n <span className=\"w-24 shrink-0 tabular-nums text-text-secondary\">\n {formatDate(point.observedAt)}\n </span>\n {point.relationshipId ? (\n <button\n type=\"button\"\n onClick={() => navigateTo(`/relationships/${point.relationshipId}`)}\n className=\"truncate text-text-link hover:underline\"\n >\n {point.label ?? tr('providers.insights.untitled', 'Untitled')}\n </button>\n ) : (\n <span className=\"truncate text-text-primary\">\n {point.label ??\n tr('providers.insights.removedRelationship', 'Removed relationship')}\n </span>\n )}\n <span className=\"rounded-full bg-bg-sunken px-2 py-0.5 text-[11px] text-text-secondary\">\n {point.source === 'INVOICE'\n ? tr('providers.insights.sourceInvoice', 'Invoice')\n : tr('providers.insights.sourceRecorded', 'Recorded price')}\n </span>\n </span>\n <span className=\"font-medium tabular-nums text-text-primary\">\n {formatCurrency(point.amount, point.currency)}\n <span className=\"text-xs font-normal text-text-secondary\">\n {formatIntervalSuffix(point.interval)}\n </span>\n </span>\n </li>\n ))}\n </ul>\n </>\n )}\n </GlassCard>\n </Section>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Alternatives — registry providers that could replace this one\n// ---------------------------------------------------------------------------\nfunction PriceRangeText({ range }: { range: SubPriceRange }) {\n const tr = useTr();\n const value =\n range.minMonthlyAmount === range.maxMonthlyAmount\n ? formatCurrency(range.minMonthlyAmount, range.currency)\n : `${formatCurrency(range.minMonthlyAmount, range.currency)} – ${formatCurrency(range.maxMonthlyAmount, range.currency)}`;\n return (\n <span className=\"tabular-nums\">\n {value}\n <span className=\"text-xs text-text-secondary\">/mo</span>{' '}\n <span className=\"text-xs text-text-secondary\">\n {range.basis === 'PLANS'\n ? tr('providers.insights.basisPlans', '({{count}} plans)', { count: range.count })\n : tr('providers.insights.basisRelationships', '(what you pay)')}\n </span>\n </span>\n );\n}\n\nfunction AlternativeRow({ alt }: { alt: SubProviderAlternative }) {\n const tr = useTr();\n const { navigateTo } = useSubscriberBot();\n const range = alt.priceRanges[0];\n return (\n <li className=\"py-4 first:pt-0 last:pb-0\" data-testid=\"provider-alternative\">\n <div className=\"flex flex-wrap items-start justify-between gap-3\">\n <div className=\"min-w-0\">\n <button\n type=\"button\"\n onClick={() => navigateTo(`/providers/${alt.providerId}`)}\n className=\"inline-flex items-center gap-1 text-sm font-semibold text-text-link hover:underline\"\n >\n {alt.name} <ArrowRight className=\"h-3.5 w-3.5\" />\n </button>\n <div className=\"mt-1 flex flex-wrap items-center gap-1.5\">\n {alt.provider && <StatusBadge status={alt.provider.status} />}\n <span className=\"rounded-full border border-border-subtle px-2 py-0.5 text-[11px] font-medium text-text-secondary\">\n {alt.matchReason === 'CAPABILITY'\n ? tr('providers.insights.matchCapability', 'Same capability')\n : tr('providers.insights.matchCategory', 'Same category')}\n </span>\n {alt.capabilities.map((cap) => (\n <span\n key={cap}\n className={cn(\n 'rounded-full px-2 py-0.5 text-[11px]',\n alt.sharedCapabilities.includes(cap)\n ? 'bg-[var(--color-accent-soft)] font-medium text-text-primary'\n : 'bg-bg-sunken text-text-secondary'\n )}\n >\n {formatEnumLabel(cap.replace(/-/g, '_'))}\n </span>\n ))}\n </div>\n </div>\n <div className=\"text-right text-sm text-text-primary\">\n {range ? (\n <PriceRangeText range={range} />\n ) : (\n <span className=\"text-text-secondary\">\n {tr('providers.insights.noPrice', 'No price on record')}\n </span>\n )}\n <p className=\"mt-0.5 text-xs text-text-secondary\">\n {alt.activeRelationshipCount > 0\n ? tr('providers.insights.inUse', 'In use · {{active}} of {{tracked}} active', {\n active: alt.activeRelationshipCount,\n tracked: alt.trackedRelationshipCount,\n })\n : alt.trackedRelationshipCount > 0\n ? tr('providers.insights.trackedOnly', '{{tracked}} tracked, none active', {\n tracked: alt.trackedRelationshipCount,\n })\n : tr('providers.insights.notUsed', 'Not used in this workspace')}\n </p>\n </div>\n </div>\n {alt.relationships.length > 0 && (\n <ul className=\"mt-2 flex flex-wrap gap-2\">\n {alt.relationships.map((rel) => (\n <li key={rel.id}>\n <button\n type=\"button\"\n onClick={() => navigateTo(`/relationships/${rel.id}`)}\n className=\"inline-flex items-center gap-1.5 rounded-lg border border-border-subtle px-2 py-1 text-xs text-text-primary hover:bg-bg-sunken\"\n >\n <span className=\"truncate\">{rel.label}</span>\n <span className=\"tabular-nums text-text-secondary\">\n {formatCurrency(rel.amount, rel.currency)}\n {formatIntervalSuffix(rel.interval)}\n </span>\n <StatusBadge status={rel.status} />\n </button>\n </li>\n ))}\n </ul>\n )}\n </li>\n );\n}\n\nexport function ProviderAlternatives({ providerId }: { providerId: string }) {\n const tr = useTr();\n const { data, isLoading, isError, refetch } = useProviderAlternatives(providerId);\n\n return (\n <Section\n title={tr('providers.insights.alternativesTitle', 'Alternatives')}\n description={tr(\n 'providers.insights.alternativesDescription',\n 'Providers in your registry that cover the same need, the ones you already use first'\n )}\n >\n <GlassCard treatment=\"metric\" className=\"p-5\" data-testid=\"provider-alternatives\">\n {isLoading ? (\n <LoadingView\n className=\"min-h-[8rem]\"\n label={tr('providers.insights.alternativesLoading', 'Finding alternatives…')}\n />\n ) : isError ? (\n <ErrorView\n className=\"min-h-[8rem]\"\n title={tr('providers.insights.alternativesErrorTitle', 'Alternatives unavailable')}\n message={tr(\n 'providers.insights.alternativesError',\n 'Could not look up alternative providers.'\n )}\n onRetry={() => void refetch()}\n />\n ) : !data || data.length === 0 ? (\n <div className=\"flex items-start gap-3 text-sm text-text-secondary\">\n <Shuffle className=\"mt-0.5 h-4 w-4 shrink-0\" />\n <p>\n {tr(\n 'providers.insights.alternativesEmpty',\n 'No comparable providers yet. Tag providers with capabilities (for example capability:design) or give them a specific category to see alternatives here.'\n )}\n </p>\n </div>\n ) : (\n <ul className=\"divide-y divide-border-subtle\">\n {data.map((alt) => (\n <AlternativeRow key={alt.providerId} alt={alt} />\n ))}\n </ul>\n )}\n </GlassCard>\n </Section>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0CA,IAAM,IAAgB;AAEtB,SAAS,EAAW,GAAgC;CAElD,OADI,MAAY,QAAQ,MAAY,IAAU,qCACvC,IAAU,IACb,qDACA;AACN;AAEA,SAAS,EAAc,GAAyB;CAC9C,OAAO,GAAG,IAAU,IAAI,MAAM,K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,eAAY,EAAwB,CAAU;CAEhF,OACE,kBAAC,GAAD;EACE,OAAO,EAAG,wCAAwC,cAAc;EAChE,aAAa,EACX,8CACA,qFACF;YAEA,kBAAC,GAAD;GAAW,WAAU;GAAS,WAAU;GAAM,eAAY;aACvD,IACC,kBAAC,GAAD;IACE,WAAU;IACV,OAAO,EAAG,0CAA0C,uBAAuB;GAC5E,CAAA,IACC,IACF,kBAAC,GAAD;IACE,WAAU;IACV,OAAO,EAAG,6CAA6C,0BAA0B;IACjF,SAAS,EACP,wCACA,0CACF;IACA,eAAe,KAAK,EAAQ;GAC7B,CAAA,IACC,CAAC,KAAQ,EAAK,WAAW,IAC3B,kBAAC,OAAD;IAAK,WAAU;cAAf,CACE,kBAAC,GAAD,EAAS,WAAU,0BAA2B,CAAA,GAC9C,kBAAC,KAAD,EAAA,UACG,EACC,wCACA,yJACF,EACC,CAAA,CACA;QAEL,kBAAC,MAAD;IAAI,WAAU;cACX,EAAK,KAAK,MACT,kBAAC,GAAD,EAA0C,OAAM,GAA3B,EAAI,UAAuB,CACjD;GACC,CAAA;EAEG,CAAA;CACJ,CAAA;AAEb"}
|
|
1
|
+
{"version":3,"file":"ProviderInsights.js","names":[],"sources":["../../../../src/subscriberbot/pages/providers/ProviderInsights.tsx"],"sourcesContent":["/**\n * Provider insights for the provider detail page (BOFF-4003)\n * @module subscriberbot/pages/providers\n *\n * Two sections that turn the provider page into a renewal decision surface:\n *\n * - `ProviderPaidPriceHistory` charts what this workspace has paid the\n * provider over time (`subProviderPriceHistory`): every recorded price of a\n * relationship with it, plus the invoices charged against them.\n * - `ProviderAlternatives` lists registry providers that could replace it\n * (`subProviderAlternatives`), ranked by shared capability tags, then\n * category, with providers the workspace already uses first.\n *\n * Amounts in different currencies are never drawn on one chart: the chart\n * shows the currency the backend summary picked (the most observed one).\n */\n\nimport { useMemo } from 'react';\nimport { ArrowRight, Shuffle } from 'lucide-react';\nimport { GlassCard } from '@burdenoff/fe-libs/ui';\nimport { EmptyState } from '../../components/EmptyState';\nimport { LoadingView, ErrorView, Section } from '../../components/StateViews';\nimport { StatusBadge } from '../../components/StatusBadge';\nimport { PriceHistoryChart, type PriceChartSeries } from '../../components';\nimport { useSubscriberBot } from '../../context/SubscriberBotContext';\nimport { useProviderAlternatives, useProviderPriceHistory } from '../../hooks/useSubscriberBotApi';\nimport { useTr } from '../../hooks/useTr';\nimport {\n formatCurrency,\n formatDate,\n formatEnumLabel,\n formatIntervalSuffix,\n} from '../../utils/formatters';\nimport { cn } from '../../utils/cn';\nimport type {\n SubPriceRange,\n SubProviderAlternative,\n SubProviderPriceHistory,\n SubProviderPriceSeries,\n} from '../../types';\n\n/** Points listed under the chart, newest first. */\nconst RECENT_POINTS = 6;\n\nfunction changeTone(percent: number | null): string {\n if (percent === null || percent === 0) return 'bg-bg-sunken text-text-secondary';\n return percent > 0\n ? 'bg-status-error-bg-subtle text-status-error-text'\n : 'bg-status-success-bg-subtle text-status-success-text';\n}\n\nfunction formatPercent(percent: number): string {\n return `${percent > 0 ? '+' : ''}${percent}%`;\n}\n\nfunction chartSeries(\n history: SubProviderPriceHistory,\n tr: ReturnType<typeof useTr>\n): PriceChartSeries[] {\n const currency = history.summary?.currency;\n if (!currency) return [];\n // A relationship's recorded prices are split per currency. When it moved to\n // another currency, that later price ends the displayed segment, exactly\n // like a non-recurring price does: the old currency's line must not run on.\n const otherCurrencyTimes = new Map<string, string[]>();\n for (const s of history.series) {\n if (s.source !== 'RELATIONSHIP' || s.currency === currency || !s.relationshipId) continue;\n const list = otherCurrencyTimes.get(s.relationshipId) ?? [];\n list.push(...s.points.map((p) => p.observedAt));\n otherCurrencyTimes.set(s.relationshipId, list);\n }\n return history.series\n .filter((s) => s.currency === currency)\n .map((s) => {\n // Recorded prices keep their non-recurring points (null value) so the\n // step line ends where a lifetime or usage-based price took over;\n // invoice dots without a monthly equivalent are simply not drawn.\n const points: PriceChartSeries['points'] = s.points\n .filter((p) => s.source !== 'INVOICE' || p.monthlyAmount !== null)\n .map((p) => ({\n at: p.observedAt,\n value: p.monthlyAmount,\n title: `${formatDate(p.observedAt)} · ${formatCurrency(p.amount, p.currency)}${formatIntervalSuffix(p.interval)}`,\n }));\n if (s.source === 'RELATIONSHIP' && s.relationshipId) {\n for (const at of otherCurrencyTimes.get(s.relationshipId) ?? []) {\n points.push({ at, value: null });\n }\n }\n return {\n key: s.key,\n label:\n s.source === 'INVOICE'\n ? tr('providers.insights.invoiceSeries', '{{label}} (invoices)', {\n label: s.label.replace(/ \\(invoices\\)$/, ''),\n })\n : s.label,\n mode: s.source === 'INVOICE' ? ('dots' as const) : ('step' as const),\n points,\n };\n })\n .filter((s) => s.points.some((p) => p.value !== null));\n}\n\n// ---------------------------------------------------------------------------\n// Price history — what this workspace has paid the provider\n// ---------------------------------------------------------------------------\nexport function ProviderPaidPriceHistory({ providerId }: { providerId: string }) {\n const tr = useTr();\n const { navigateTo } = useSubscriberBot();\n const { data, isLoading, isError, refetch } = useProviderPriceHistory(providerId);\n\n const series = useMemo(() => (data ? chartSeries(data, tr) : []), [data, tr]);\n const recent = useMemo(\n () => (data ? [...data.points].reverse().slice(0, RECENT_POINTS) : []),\n [data]\n );\n const summary = data?.summary ?? null;\n const currency = summary?.currency ?? 'USD';\n // Every relationship tracked under this provider contributes its latest\n // recorded price, so the headline is the workspace's total per month rather\n // than whichever relationship happens to come first.\n const latestTotal = useMemo(() => {\n // Each relationship's current price is its latest recorded point across\n // every currency; only those now priced in the display currency count.\n const latestByRelationship = new Map<string, { at: string; series: SubProviderPriceSeries }>();\n for (const s of data?.series ?? []) {\n const last = s.points[s.points.length - 1];\n if (s.source !== 'RELATIONSHIP' || !last) continue;\n const key = s.relationshipId ?? s.key;\n const seen = latestByRelationship.get(key);\n if (!seen || Date.parse(last.observedAt) > Date.parse(seen.at))\n latestByRelationship.set(key, { at: last.observedAt, series: s });\n }\n const recorded = [...latestByRelationship.values()]\n .map((v) => v.series)\n .filter((s) => s.currency === currency && s.latestMonthlyAmount != null);\n if (recorded.length === 0) return null;\n const amount = recorded.reduce((sum, s) => sum + (s.latestMonthlyAmount ?? 0), 0);\n return { amount: Math.round(amount * 100) / 100, count: recorded.length };\n }, [data, currency]);\n\n return (\n <Section\n title={tr('providers.insights.priceHistoryTitle', 'Your price history')}\n description={tr(\n 'providers.insights.priceHistoryDescription',\n 'What this workspace has paid this provider over time, per month'\n )}\n >\n <GlassCard treatment=\"metric\" className=\"p-5\" data-testid=\"provider-price-history\">\n {isLoading ? (\n <LoadingView\n className=\"min-h-[10rem]\"\n label={tr('providers.insights.priceHistoryLoading', 'Loading price history…')}\n />\n ) : isError ? (\n <ErrorView\n className=\"min-h-[10rem]\"\n title={tr('providers.insights.priceHistoryErrorTitle', 'Price history unavailable')}\n message={tr(\n 'providers.insights.priceHistoryError',\n 'Could not load what this workspace has paid this provider.'\n )}\n onRetry={() => void refetch()}\n />\n ) : !data || !summary ? (\n <EmptyState\n illustration=\"empty-data\"\n title={tr('providers.insights.priceHistoryEmptyTitle', 'No prices recorded yet')}\n description={tr(\n 'providers.insights.priceHistoryEmpty',\n 'Link a relationship to this provider and its price, and every later change, will be charted here.'\n )}\n />\n ) : (\n <>\n <div className=\"flex flex-wrap items-start gap-x-8 gap-y-3\">\n <div>\n <p className=\"text-xs text-text-secondary\">\n {latestTotal && latestTotal.count > 1\n ? tr(\n 'providers.insights.latestMonthlyTotal',\n 'Latest monthly price across {{count}} relationships',\n { count: latestTotal.count }\n )\n : tr('providers.insights.latestMonthly', 'Latest monthly price')}\n </p>\n <p className=\"text-2xl font-bold tabular-nums text-text-primary\">\n {latestTotal ? formatCurrency(latestTotal.amount, currency) : '—'}\n <span className=\"text-sm font-normal text-text-secondary\">/mo</span>\n </p>\n </div>\n <div>\n <p className=\"text-xs text-text-secondary\">\n {tr('providers.insights.range', 'Range paid')}\n </p>\n <p className=\"text-sm font-medium tabular-nums text-text-primary\">\n {summary.minMonthlyAmount != null && summary.maxMonthlyAmount != null\n ? `${formatCurrency(summary.minMonthlyAmount, currency)} – ${formatCurrency(summary.maxMonthlyAmount, currency)}`\n : '—'}\n </p>\n </div>\n <div>\n <p className=\"text-xs text-text-secondary\">\n {tr('providers.insights.priceChanges', 'Price changes')}\n </p>\n <p className=\"text-sm font-medium tabular-nums text-text-primary\">\n {summary.priceChangeCount}\n </p>\n </div>\n {summary.latestChangePercent != null && (\n <div>\n <p className=\"text-xs text-text-secondary\">\n {tr('providers.insights.latestChange', 'Latest change')}\n </p>\n <span\n className={cn(\n 'mt-0.5 inline-block rounded-full px-2 py-0.5 text-xs font-medium tabular-nums',\n changeTone(summary.latestChangePercent)\n )}\n >\n {formatPercent(summary.latestChangePercent)}\n {summary.latestChangeAt && ` · ${formatDate(summary.latestChangeAt)}`}\n </span>\n </div>\n )}\n </div>\n\n {series.length > 0 ? (\n <PriceHistoryChart\n className=\"mt-4\"\n series={series}\n now={new Date()}\n ariaLabel={tr(\n 'providers.insights.chartLabel',\n 'Monthly price paid over time, in {{currency}}',\n { currency }\n )}\n valueFormat={(n, digits) =>\n formatCurrency(n, currency, {\n minimumFractionDigits: digits,\n maximumFractionDigits: digits,\n })\n }\n dateFormat={(d) =>\n formatDate(d, { day: undefined, month: 'short', year: 'numeric' })\n }\n />\n ) : (\n <p className=\"mt-4 text-sm text-text-secondary\">\n {tr(\n 'providers.insights.noRecurring',\n 'These prices are not recurring, so there is no monthly trend to chart.'\n )}\n </p>\n )}\n\n <ul className=\"mt-4 divide-y divide-border-subtle border-t border-border-subtle\">\n {recent.map((point) => (\n <li\n key={point.id}\n className=\"flex flex-wrap items-center justify-between gap-2 py-2 text-sm\"\n >\n <span className=\"flex min-w-0 items-center gap-2\">\n <span className=\"w-24 shrink-0 tabular-nums text-text-secondary\">\n {formatDate(point.observedAt)}\n </span>\n {point.relationshipId ? (\n <button\n type=\"button\"\n onClick={() => navigateTo(`/relationships/${point.relationshipId}`)}\n className=\"truncate text-text-link hover:underline\"\n >\n {point.label ?? tr('providers.insights.untitled', 'Untitled')}\n </button>\n ) : (\n <span className=\"truncate text-text-primary\">\n {point.label ??\n tr('providers.insights.removedRelationship', 'Removed relationship')}\n </span>\n )}\n <span className=\"rounded-full bg-bg-sunken px-2 py-0.5 text-[11px] text-text-secondary\">\n {point.source === 'INVOICE'\n ? tr('providers.insights.sourceInvoice', 'Invoice')\n : tr('providers.insights.sourceRecorded', 'Recorded price')}\n </span>\n </span>\n <span className=\"font-medium tabular-nums text-text-primary\">\n {formatCurrency(point.amount, point.currency)}\n <span className=\"text-xs font-normal text-text-secondary\">\n {formatIntervalSuffix(point.interval)}\n </span>\n </span>\n </li>\n ))}\n </ul>\n </>\n )}\n </GlassCard>\n </Section>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Alternatives — registry providers that could replace this one\n// ---------------------------------------------------------------------------\nfunction PriceRangeText({ range }: { range: SubPriceRange }) {\n const tr = useTr();\n const value =\n range.minMonthlyAmount === range.maxMonthlyAmount\n ? formatCurrency(range.minMonthlyAmount, range.currency)\n : `${formatCurrency(range.minMonthlyAmount, range.currency)} – ${formatCurrency(range.maxMonthlyAmount, range.currency)}`;\n return (\n <span className=\"tabular-nums\">\n {value}\n <span className=\"text-xs text-text-secondary\">/mo</span>{' '}\n <span className=\"text-xs text-text-secondary\">\n {range.basis === 'PLANS'\n ? tr('providers.insights.basisPlans', '({{count}} plans)', { count: range.count })\n : tr('providers.insights.basisRelationships', '(what you pay)')}\n </span>\n </span>\n );\n}\n\nfunction AlternativeRow({ alt }: { alt: SubProviderAlternative }) {\n const tr = useTr();\n const { navigateTo } = useSubscriberBot();\n const range = alt.priceRanges[0];\n return (\n <li className=\"py-4 first:pt-0 last:pb-0\" data-testid=\"provider-alternative\">\n <div className=\"flex flex-wrap items-start justify-between gap-3\">\n <div className=\"min-w-0\">\n <button\n type=\"button\"\n onClick={() => navigateTo(`/providers/${alt.providerId}`)}\n className=\"inline-flex items-center gap-1 text-sm font-semibold text-text-link hover:underline\"\n >\n {alt.name} <ArrowRight className=\"h-3.5 w-3.5\" />\n </button>\n <div className=\"mt-1 flex flex-wrap items-center gap-1.5\">\n {alt.provider && <StatusBadge status={alt.provider.status} />}\n <span className=\"rounded-full border border-border-subtle px-2 py-0.5 text-[11px] font-medium text-text-secondary\">\n {alt.matchReason === 'CAPABILITY'\n ? tr('providers.insights.matchCapability', 'Same capability')\n : tr('providers.insights.matchCategory', 'Same category')}\n </span>\n {alt.capabilities.map((cap) => (\n <span\n key={cap}\n className={cn(\n 'rounded-full px-2 py-0.5 text-[11px]',\n alt.sharedCapabilities.includes(cap)\n ? 'bg-[var(--color-accent-soft)] font-medium text-text-primary'\n : 'bg-bg-sunken text-text-secondary'\n )}\n >\n {formatEnumLabel(cap.replace(/-/g, '_'))}\n </span>\n ))}\n </div>\n </div>\n <div className=\"text-right text-sm text-text-primary\">\n {range ? (\n <PriceRangeText range={range} />\n ) : (\n <span className=\"text-text-secondary\">\n {tr('providers.insights.noPrice', 'No price on record')}\n </span>\n )}\n <p className=\"mt-0.5 text-xs text-text-secondary\">\n {alt.activeRelationshipCount > 0\n ? tr('providers.insights.inUse', 'In use · {{active}} of {{tracked}} active', {\n active: alt.activeRelationshipCount,\n tracked: alt.trackedRelationshipCount,\n })\n : alt.trackedRelationshipCount > 0\n ? tr('providers.insights.trackedOnly', '{{tracked}} tracked, none active', {\n tracked: alt.trackedRelationshipCount,\n })\n : tr('providers.insights.notUsed', 'Not used in this workspace')}\n </p>\n </div>\n </div>\n {alt.relationships.length > 0 && (\n <ul className=\"mt-2 flex flex-wrap gap-2\">\n {alt.relationships.map((rel) => (\n <li key={rel.id}>\n <button\n type=\"button\"\n onClick={() => navigateTo(`/relationships/${rel.id}`)}\n className=\"inline-flex items-center gap-1.5 rounded-lg border border-border-subtle px-2 py-1 text-xs text-text-primary hover:bg-bg-sunken\"\n >\n <span className=\"truncate\">{rel.label}</span>\n <span className=\"tabular-nums text-text-secondary\">\n {formatCurrency(rel.amount, rel.currency)}\n {formatIntervalSuffix(rel.interval)}\n </span>\n <StatusBadge status={rel.status} />\n </button>\n </li>\n ))}\n </ul>\n )}\n </li>\n );\n}\n\nexport function ProviderAlternatives({ providerId }: { providerId: string }) {\n const tr = useTr();\n const { data, isLoading, isError, refetch } = useProviderAlternatives(providerId);\n\n return (\n <Section\n title={tr('providers.insights.alternativesTitle', 'Alternatives')}\n description={tr(\n 'providers.insights.alternativesDescription',\n 'Providers in your registry that cover the same need, the ones you already use first'\n )}\n >\n <GlassCard treatment=\"metric\" className=\"p-5\" data-testid=\"provider-alternatives\">\n {isLoading ? (\n <LoadingView\n className=\"min-h-[8rem]\"\n label={tr('providers.insights.alternativesLoading', 'Finding alternatives…')}\n />\n ) : isError ? (\n <ErrorView\n className=\"min-h-[8rem]\"\n title={tr('providers.insights.alternativesErrorTitle', 'Alternatives unavailable')}\n message={tr(\n 'providers.insights.alternativesError',\n 'Could not look up alternative providers.'\n )}\n onRetry={() => void refetch()}\n />\n ) : !data || data.length === 0 ? (\n <div className=\"flex items-start gap-3 text-sm text-text-secondary\">\n <Shuffle className=\"mt-0.5 h-4 w-4 shrink-0\" />\n <p>\n {tr(\n 'providers.insights.alternativesEmpty',\n 'No comparable providers yet. Tag providers with capabilities (for example capability:design) or give them a specific category to see alternatives here.'\n )}\n </p>\n </div>\n ) : (\n <ul className=\"divide-y divide-border-subtle\">\n {data.map((alt) => (\n <AlternativeRow key={alt.providerId} alt={alt} />\n ))}\n </ul>\n )}\n </GlassCard>\n </Section>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0CA,IAAM,IAAgB;AAEtB,SAAS,EAAW,GAAgC;CAElD,OADI,MAAY,QAAQ,MAAY,IAAU,qCACvC,IAAU,IACb,qDACA;AACN;AAEA,SAAS,EAAc,GAAyB;CAC9C,OAAO,GAAG,IAAU,IAAI,MAAM,KAAK,EAAQ;AAC7C;AAEA,SAAS,EACP,GACA,GACoB;CACpB,IAAM,IAAW,EAAQ,SAAS;CAClC,IAAI,CAAC,GAAU,OAAO,CAAC;CAIvB,IAAM,oBAAqB,IAAI,IAAs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AW,WAAU;GAAS,WAAU;GAAM,eAAY;aACvD,IACC,kBAAC,GAAD;IACE,WAAU;IACV,OAAO,EAAG,0CAA0C,uBAAuB;GAC5E,CAAA,IACC,IACF,kBAAC,GAAD;IACE,WAAU;IACV,OAAO,EAAG,6CAA6C,0BAA0B;IACjF,SAAS,EACP,wCACA,0CACF;IACA,eAAe,KAAK,EAAQ;GAC7B,CAAA,IACC,CAAC,KAAQ,EAAK,WAAW,IAC3B,kBAAC,OAAD;IAAK,WAAU;cAAf,CACE,kBAAC,GAAD,EAAS,WAAU,0BAA2B,CAAA,GAC9C,kBAAC,KAAD,EAAA,UACG,EACC,wCACA,yJACF,EACC,CAAA,CACA;QAEL,kBAAC,MAAD;IAAI,WAAU;cACX,EAAK,KAAK,MACT,kBAAC,GAAD,EAA0C,OAAM,GAA3B,EAAI,UAAuB,CACjD;GACC,CAAA;EAEG,CAAA;CACJ,CAAA;AAEb"}
|
|
@@ -703,12 +703,12 @@ function me() {
|
|
|
703
703
|
title: $.label,
|
|
704
704
|
description: $.provider?.name ?? y(oe[$.kind], h($.kind)),
|
|
705
705
|
actions: /* @__PURE__ */ U("div", {
|
|
706
|
-
className: "flex items-center gap-2",
|
|
706
|
+
className: "flex flex-wrap items-center gap-2",
|
|
707
707
|
children: [
|
|
708
708
|
/* @__PURE__ */ U("button", {
|
|
709
709
|
type: "button",
|
|
710
710
|
onClick: () => J(!0),
|
|
711
|
-
className: "inline-flex items-center gap-2 rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken",
|
|
711
|
+
className: "inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken",
|
|
712
712
|
children: [
|
|
713
713
|
/* @__PURE__ */ H(ee, { className: "h-4 w-4" }),
|
|
714
714
|
" ",
|
|
@@ -719,7 +719,7 @@ function me() {
|
|
|
719
719
|
type: "button",
|
|
720
720
|
"data-testid": "negotiate-bill",
|
|
721
721
|
onClick: () => C(`/negotiations/new?relationshipId=${encodeURIComponent($.id)}`),
|
|
722
|
-
className: "inline-flex items-center gap-2 rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken",
|
|
722
|
+
className: "inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken",
|
|
723
723
|
children: [
|
|
724
724
|
/* @__PURE__ */ H(L, { className: "h-4 w-4" }),
|
|
725
725
|
" ",
|
|
@@ -730,7 +730,7 @@ function me() {
|
|
|
730
730
|
type: "button",
|
|
731
731
|
"data-testid": "request-procurement",
|
|
732
732
|
onClick: () => C(`/procurement/new?relationshipId=${encodeURIComponent($.id)}`),
|
|
733
|
-
className: "inline-flex items-center gap-2 rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken",
|
|
733
|
+
className: "inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken",
|
|
734
734
|
children: [
|
|
735
735
|
/* @__PURE__ */ H(N, { className: "h-4 w-4" }),
|
|
736
736
|
" ",
|
|
@@ -740,7 +740,7 @@ function me() {
|
|
|
740
740
|
/* @__PURE__ */ U("button", {
|
|
741
741
|
type: "button",
|
|
742
742
|
onClick: () => C("/relationships"),
|
|
743
|
-
className: "inline-flex items-center gap-2 rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken",
|
|
743
|
+
className: "inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken",
|
|
744
744
|
children: [
|
|
745
745
|
/* @__PURE__ */ H(j, { className: "rtl:rotate-180 h-4 w-4" }),
|
|
746
746
|
" ",
|