From 5e3f719af088899728ce789072acb27b3a98653f Mon Sep 17 00:00:00 2001 From: Shreyag02 Date: Sun, 15 Nov 2026 17:19:24 +0530 Subject: [PATCH 1/5] feat(sdk): feature info popover on plans table - Show an info icon with a popover for features that have metadata.info - Parse [label](url) links in info; only http, https and mailto become links - Fix crash when a feature cell value is a number or boolean - Move feature row building into a pure helper with tests --- .../views/plans/components/feature-info.tsx | 61 ++++++++ .../plans/components/feature-table.module.css | 17 +++ .../views/plans/components/feature-table.tsx | 20 +-- .../views/plans/helpers/feature-rows.test.ts | 135 ++++++++++++++++++ .../views/plans/helpers/feature-rows.ts | 82 +++++++++++ web/sdk/client/views/plans/plans-view.tsx | 22 +-- 6 files changed, 310 insertions(+), 27 deletions(-) create mode 100644 web/sdk/client/views/plans/components/feature-info.tsx create mode 100644 web/sdk/client/views/plans/helpers/feature-rows.test.ts create mode 100644 web/sdk/client/views/plans/helpers/feature-rows.ts diff --git a/web/sdk/client/views/plans/components/feature-info.tsx b/web/sdk/client/views/plans/components/feature-info.tsx new file mode 100644 index 0000000000..dc406bde73 --- /dev/null +++ b/web/sdk/client/views/plans/components/feature-info.tsx @@ -0,0 +1,61 @@ +'use client'; + +import { Fragment } from 'react'; +import { Link, Popover, Text } from '@raystack/apsara'; +import { InfoCircledIcon } from '@radix-ui/react-icons'; +import { parseFeatureInfo } from '~/client/views/plans/helpers/feature-rows'; +import styles from './feature-table.module.css'; + +interface FeatureInfoProps { + info: string; +} + +export function FeatureInfo({ info }: FeatureInfoProps) { + return ( + + {parseFeatureInfo(info).map((part, index) => + part.type === 'link' ? ( + + {part.label} + + ) : ( + {part.text} + ) + )} + + ); +} + +interface FeatureInfoPopoverProps { + title: string; + info: string; +} + +export function FeatureInfoPopover({ title, info }: FeatureInfoPopoverProps) { + return ( + + + + + } + > + + + + ); +} diff --git a/web/sdk/client/views/plans/components/feature-table.module.css b/web/sdk/client/views/plans/components/feature-table.module.css index a394fc182b..0a31956a3e 100644 --- a/web/sdk/client/views/plans/components/feature-table.module.css +++ b/web/sdk/client/views/plans/components/feature-table.module.css @@ -43,3 +43,20 @@ height: 16px; flex-shrink: 0; } + +.infoTrigger { + display: inline-flex; + align-items: center; + flex-shrink: 0; + padding: 0; + border: none; + background: none; + cursor: pointer; + color: var(--rs-color-foreground-base-tertiary); +} + +.infoContent { + max-width: 360px; + white-space: normal; + overflow-wrap: break-word; +} diff --git a/web/sdk/client/views/plans/components/feature-table.tsx b/web/sdk/client/views/plans/components/feature-table.tsx index 71d7e7563d..e20de3f59f 100644 --- a/web/sdk/client/views/plans/components/feature-table.tsx +++ b/web/sdk/client/views/plans/components/feature-table.tsx @@ -1,7 +1,6 @@ 'use client'; import { Flex, Image, Skeleton, Text } from '@raystack/apsara'; -import { InfoCircledIcon } from '@radix-ui/react-icons'; import { get } from 'lodash'; import { IntervalKeys, @@ -9,6 +8,8 @@ import { PlanIntervalPricing } from '~/src/types'; import checkCircle from '~/client/assets/check-circle.svg'; +import { FeatureRow, normalizeFeatureValue } from '~/client/views/plans/helpers/feature-rows'; +import { FeatureInfoPopover } from '~/client/views/plans/components/feature-info'; import styles from './feature-table.module.css'; interface FeatureValueCellProps { @@ -21,8 +22,8 @@ function FeatureValueCell({ feature, plan }: FeatureValueCellProps) { const productMetaDataFeatureValues = plan?.productNames .map(name => get(planFeature.metadata, name)) .filter(value => value !== undefined); - const value = productMetaDataFeatureValues?.[0] || '-'; - const isAvailable = value?.toLowerCase() === 'true'; + const value = normalizeFeatureValue(productMetaDataFeatureValues?.[0]); + const isAvailable = value.toLowerCase() === 'true'; return ( @@ -42,7 +43,7 @@ function FeatureValueCell({ feature, plan }: FeatureValueCellProps) { } export interface FeatureTableProps { - features: string[]; + features: FeatureRow[]; plans: PlanIntervalPricing[]; selectedIntervals: Record; isLoading?: boolean; @@ -92,10 +93,13 @@ export function FeatureTable({ {features.map(feature => ( - + - {feature} + {feature.title} + {feature.info && ( + + )} ))} @@ -111,8 +115,8 @@ export function FeatureTable({ > {features.map(feature => ( ))} diff --git a/web/sdk/client/views/plans/helpers/feature-rows.test.ts b/web/sdk/client/views/plans/helpers/feature-rows.test.ts new file mode 100644 index 0000000000..050d8fc6dc --- /dev/null +++ b/web/sdk/client/views/plans/helpers/feature-rows.test.ts @@ -0,0 +1,135 @@ +import { + buildFeatureRows, + normalizeFeatureValue, + parseFeatureInfo +} from '~/client/views/plans/helpers/feature-rows'; + +describe('buildFeatureRows', () => { + it('sorts by weightage', () => { + const rows = buildFeatureRows([ + { title: 'C', metadata: { weightage: 3 } }, + { title: 'A', metadata: { weightage: 1 } }, + { title: 'B', metadata: { weightage: 2 } } + ]); + expect(rows.map(r => r.title)).toEqual(['A', 'B', 'C']); + }); + + it('falls back to the feature count when weightage is missing', () => { + const rows = buildFeatureRows([ + { title: 'NoWeight', metadata: {} }, + { title: 'NoMeta' }, + { title: 'Last', metadata: { weightage: 5 } }, + { title: 'First', metadata: { weightage: 1 } } + ]); + expect(rows.map(r => r.title)).toEqual([ + 'First', + 'NoWeight', + 'NoMeta', + 'Last' + ]); + }); + + it('drops empty titles', () => { + const rows = buildFeatureRows([ + { title: '', metadata: { weightage: 1 } }, + { metadata: { weightage: 1 } }, + { title: 'A', metadata: { weightage: 2 } } + ]); + expect(rows).toEqual([{ title: 'A' }]); + }); + + it('collapses duplicate titles and keeps the first non-empty info', () => { + const rows = buildFeatureRows([ + { title: 'A', metadata: { weightage: 1, info: ' ' } }, + { title: 'B', metadata: { weightage: 2 } }, + { title: 'A', metadata: { weightage: 3, info: 'first' } }, + { title: 'A', metadata: { weightage: 3, info: 'second' } } + ]); + expect(rows).toEqual([{ title: 'B' }, { title: 'A', info: 'first' }]); + }); + + it('ignores missing, blank and non-string info', () => { + const rows = buildFeatureRows([ + { title: 'A', metadata: { weightage: 1 } }, + { title: 'B', metadata: { weightage: 2, info: '' } }, + { title: 'C', metadata: { weightage: 3, info: ' ' } }, + { title: 'D', metadata: { weightage: 4, info: 42 } }, + { title: 'E', metadata: { weightage: 5, info: { text: 'x' } } }, + { title: 'F', metadata: { weightage: 6, info: 'Help' } } + ]); + expect(rows).toEqual([ + { title: 'A' }, + { title: 'B' }, + { title: 'C' }, + { title: 'D' }, + { title: 'E' }, + { title: 'F', info: 'Help' } + ]); + }); +}); + +describe('parseFeatureInfo', () => { + it('returns plain text as one part', () => { + expect(parseFeatureInfo('Just text.')).toEqual([ + { type: 'text', text: 'Just text.' } + ]); + }); + + it('parses one link', () => { + expect(parseFeatureInfo('See [Details](https://example.com).')).toEqual([ + { type: 'text', text: 'See ' }, + { type: 'link', label: 'Details', url: 'https://example.com' }, + { type: 'text', text: '.' } + ]); + }); + + it('parses two links', () => { + expect( + parseFeatureInfo( + '[Docs](http://example.com/docs) or [support@example.com](mailto:support@example.com)' + ) + ).toEqual([ + { type: 'link', label: 'Docs', url: 'http://example.com/docs' }, + { type: 'text', text: ' or ' }, + { + type: 'link', + label: 'support@example.com', + url: 'mailto:support@example.com' + } + ]); + }); + + it('keeps links with a disallowed scheme as plain text', () => { + const input = 'Click [here](javascript:alert(1)) now'; + expect(parseFeatureInfo(input)).toEqual([{ type: 'text', text: input }]); + }); + + it('keeps malformed markdown as plain text', () => { + const inputs = [ + '[Details](https://example.com', + '[Details] (https://example.com)', + '[](https://example.com)', + 'Details](https://example.com)' + ]; + inputs.forEach(input => { + expect(parseFeatureInfo(input)).toEqual([{ type: 'text', text: input }]); + }); + }); +}); + +describe('normalizeFeatureValue', () => { + it('returns strings unchanged', () => { + expect(normalizeFeatureValue('10 GB')).toBe('10 GB'); + }); + + it('converts true and non-zero numbers to strings', () => { + expect(normalizeFeatureValue(true)).toBe('true'); + expect(normalizeFeatureValue(5)).toBe('5'); + }); + + it('returns "-" for falsy values', () => { + [undefined, null, '', false, 0].forEach(value => { + expect(normalizeFeatureValue(value)).toBe('-'); + }); + }); +}); diff --git a/web/sdk/client/views/plans/helpers/feature-rows.ts b/web/sdk/client/views/plans/helpers/feature-rows.ts new file mode 100644 index 0000000000..ae715b9fc9 --- /dev/null +++ b/web/sdk/client/views/plans/helpers/feature-rows.ts @@ -0,0 +1,82 @@ +export interface FeatureRow { + title: string; + info?: string; +} + +interface FeatureLike { + title?: string; + metadata?: unknown; +} + +export type FeatureInfoPart = + | { type: 'text'; text: string } + | { type: 'link'; label: string; url: string }; + +/* + * Builds the feature table rows. + * - Sorted by metadata.weightage; missing/falsy weightage falls back to the feature count. + * - Duplicate titles collapse into one row: last weightage wins, first non-empty info wins. + * - Empty titles are dropped. + */ +export function buildFeatureRows(features: FeatureLike[]): FeatureRow[] { + const totalFeatures = features.length; + const rows = new Map(); + + features.forEach(feature => { + const metadata = (feature.metadata || {}) as Record; + const title = feature.title || ''; + const weightage = metadata.weightage || totalFeatures; + const info = + typeof metadata.info === 'string' && metadata.info.trim() + ? metadata.info + : undefined; + + const existing = rows.get(title); + rows.set(title, { weightage, info: existing?.info ?? info }); + }); + + return Array.from(rows.entries()) + .sort((a, b) => Number(a[1].weightage) - Number(b[1].weightage)) + .filter(([title]) => Boolean(title)) + .map(([title, { info }]) => (info ? { title, info } : { title })); +} + +const LINK_PATTERN = /\[([^\]]+)\]\(([^)\s]+)\)/g; +const ALLOWED_URL_PATTERN = /^(https?|mailto):/i; + +/* + * Splits info text into text and link parts. + * - Only [label](url) is parsed; the url must start with http:, https: or mailto:. + * - Everything else is kept as plain text exactly as written. + */ +export function parseFeatureInfo(info: string): FeatureInfoPart[] { + const parts: FeatureInfoPart[] = []; + const pushText = (text: string) => { + if (!text) return; + const last = parts[parts.length - 1]; + if (last?.type === 'text') last.text += text; + else parts.push({ type: 'text', text }); + }; + + let cursor = 0; + for (const match of Array.from(info.matchAll(LINK_PATTERN))) { + const [raw, label, url] = match; + const start = match.index ?? 0; + pushText(info.slice(cursor, start)); + if (ALLOWED_URL_PATTERN.test(url)) parts.push({ type: 'link', label, url }); + else pushText(raw); + cursor = start + raw.length; + } + pushText(info.slice(cursor)); + + return parts; +} + +/* + * Normalises a feature cell value to a string. + * - Falsy values (missing, '', false, 0) become '-'. + * - Everything else goes through String(), so lowercasing never throws. + */ +export function normalizeFeatureValue(value: unknown): string { + return value ? String(value) : '-'; +} diff --git a/web/sdk/client/views/plans/plans-view.tsx b/web/sdk/client/views/plans/plans-view.tsx index a9a8a694eb..e413a7434a 100644 --- a/web/sdk/client/views/plans/plans-view.tsx +++ b/web/sdk/client/views/plans/plans-view.tsx @@ -21,6 +21,7 @@ import { ViewContainer } from '~/client/components/view-container'; import { ViewHeader } from '~/client/components/view-header'; import { UpcomingPlanChangeBanner } from '~/client/views/billing/components/upcoming-plan-change-banner'; import { groupPlansPricingByInterval } from './helpers'; +import { buildFeatureRows } from '~/client/views/plans/helpers/feature-rows'; import { IntervalKeys, IntervalPricingWithPlan } from '~/src/types'; import { PlanCard } from './components/plan-card'; import { FeatureTable } from './components/feature-table'; @@ -77,24 +78,7 @@ export function PlansView() { isActiveSubscriptionLoading || isActiveOrganizationLoading; - const totalFeatures = features.length; - - const sortedFeatures = useMemo(() => { - const featureTitleMap = features.reduce( - (acc, f) => { - const weightage = - (f.metadata as Record)?.weightage || totalFeatures; - acc[f.title || ''] = weightage; - return acc; - }, - {} as Record - ); - - return Object.entries(featureTitleMap) - .sort((f1, f2) => f1[1] - f2[1]) - .map(f => f[0]) - .filter(Boolean); - }, [features, totalFeatures]); + const featureRows = useMemo(() => buildFeatureRows(features), [features]); const [intervalOverrides, setIntervalOverrides] = useState< Record @@ -192,7 +176,7 @@ export function PlansView() { Date: Mon, 16 Nov 2026 01:51:01 +0530 Subject: [PATCH 2/5] fix(sdk): harden plans feature info popover - Make max-width and scrolling win over Apsara's popover styles - Keep row ordering identical to the previous inline sort - Describe the popover with its text for screen readers - Underline links, keep line breaks, cap height, ignore blank link labels - Simplify the info parser and test what it shows --- .../views/plans/components/feature-info.tsx | 22 +++--- .../plans/components/feature-table.module.css | 11 ++- .../views/plans/helpers/feature-rows.test.ts | 79 ++++++++++++------- .../views/plans/helpers/feature-rows.ts | 49 +++++------- 4 files changed, 91 insertions(+), 70 deletions(-) diff --git a/web/sdk/client/views/plans/components/feature-info.tsx b/web/sdk/client/views/plans/components/feature-info.tsx index dc406bde73..eabfe058d4 100644 --- a/web/sdk/client/views/plans/components/feature-info.tsx +++ b/web/sdk/client/views/plans/components/feature-info.tsx @@ -1,25 +1,26 @@ 'use client'; -import { Fragment } from 'react'; -import { Link, Popover, Text } from '@raystack/apsara'; +import { Fragment, useId } from 'react'; +import { Link, Popover } from '@raystack/apsara'; import { InfoCircledIcon } from '@radix-ui/react-icons'; import { parseFeatureInfo } from '~/client/views/plans/helpers/feature-rows'; import styles from './feature-table.module.css'; interface FeatureInfoProps { + id: string; info: string; } -export function FeatureInfo({ info }: FeatureInfoProps) { +function FeatureInfo({ id, info }: FeatureInfoProps) { return ( - + {parseFeatureInfo(info).map((part, index) => part.type === 'link' ? ( {part.label} @@ -28,7 +29,7 @@ export function FeatureInfo({ info }: FeatureInfoProps) { {part.text} ) )} - + ); } @@ -38,6 +39,7 @@ interface FeatureInfoPopoverProps { } export function FeatureInfoPopover({ title, info }: FeatureInfoPopoverProps) { + const descriptionId = useId(); return ( } + render={ +
+ } > - + ); diff --git a/web/sdk/client/views/plans/components/feature-table.module.css b/web/sdk/client/views/plans/components/feature-table.module.css index 0a31956a3e..e0f85dceb3 100644 --- a/web/sdk/client/views/plans/components/feature-table.module.css +++ b/web/sdk/client/views/plans/components/feature-table.module.css @@ -47,7 +47,6 @@ .infoTrigger { display: inline-flex; align-items: center; - flex-shrink: 0; padding: 0; border: none; background: none; @@ -55,8 +54,14 @@ color: var(--rs-color-foreground-base-tertiary); } +/* + * - Host apps load Apsara's CSS after the SDK's, so its .popover wins ties. + * - !important keeps our max-width and overflow over Apsara's. + */ .infoContent { - max-width: 360px; - white-space: normal; + max-width: 360px !important; + max-height: min(60vh, 400px); + overflow-y: auto !important; + white-space: pre-line; overflow-wrap: break-word; } diff --git a/web/sdk/client/views/plans/helpers/feature-rows.test.ts b/web/sdk/client/views/plans/helpers/feature-rows.test.ts index 050d8fc6dc..b311e04465 100644 --- a/web/sdk/client/views/plans/helpers/feature-rows.test.ts +++ b/web/sdk/client/views/plans/helpers/feature-rows.test.ts @@ -66,55 +66,80 @@ describe('buildFeatureRows', () => { { title: 'F', info: 'Help' } ]); }); -}); -describe('parseFeatureInfo', () => { - it('returns plain text as one part', () => { - expect(parseFeatureInfo('Just text.')).toEqual([ - { type: 'text', text: 'Just text.' } + it('trims surrounding whitespace from info', () => { + const rows = buildFeatureRows([ + { title: 'A', metadata: { weightage: 1, info: '\n Help text\n' } } ]); + expect(rows[0].info).toBe('Help text'); }); - it('parses one link', () => { - expect(parseFeatureInfo('See [Details](https://example.com).')).toEqual([ - { type: 'text', text: 'See ' }, - { type: 'link', label: 'Details', url: 'https://example.com' }, - { type: 'text', text: '.' } + it('keeps the old ordering for tied integer-like titles', () => { + const rows = buildFeatureRows([ + { title: 'Storage', metadata: {} }, + { title: '2', metadata: {} }, + { title: '1', metadata: {} } ]); + expect(rows.map(r => r.title)).toEqual(['1', '2', 'Storage']); }); +}); + +/* + * - Renders parts the way the popover shows them: links as . + * - Asserts on visible output, not on how text is split into parts. + */ +const show = (info: string) => + parseFeatureInfo(info) + .map(p => (p.type === 'text' ? p.text : `<${p.url}|${p.label}>`)) + .join(''); - it('parses two links', () => { +describe('parseFeatureInfo', () => { + it('shows plain text unchanged', () => { + expect(show('Just text.')).toBe('Just text.'); + }); + + it('turns one link into a link', () => { + expect(show('See [Details](https://example.com).')).toBe( + 'See .' + ); + }); + + it('turns two links into links', () => { expect( - parseFeatureInfo( + show( '[Docs](http://example.com/docs) or [support@example.com](mailto:support@example.com)' ) - ).toEqual([ - { type: 'link', label: 'Docs', url: 'http://example.com/docs' }, - { type: 'text', text: ' or ' }, - { - type: 'link', - label: 'support@example.com', - url: 'mailto:support@example.com' - } - ]); + ).toBe( + ' or ' + ); }); it('keeps links with a disallowed scheme as plain text', () => { - const input = 'Click [here](javascript:alert(1)) now'; - expect(parseFeatureInfo(input)).toEqual([{ type: 'text', text: input }]); + [ + 'Click [here](javascript:alert(1)) now', + 'Go [there](/settings/billing)', + 'Get [file](ftp://example.com/file)', + 'Shout [docs](HTTPS://example.com)' + ].forEach(input => { + expect(show(input)).toBe(input); + }); }); it('keeps malformed markdown as plain text', () => { - const inputs = [ + [ '[Details](https://example.com', '[Details] (https://example.com)', '[](https://example.com)', 'Details](https://example.com)' - ]; - inputs.forEach(input => { - expect(parseFeatureInfo(input)).toEqual([{ type: 'text', text: input }]); + ].forEach(input => { + expect(show(input)).toBe(input); }); }); + + it('keeps a blank label as plain text', () => { + const input = 'Hidden [ ](https://example.com) link'; + expect(show(input)).toBe(input); + }); }); describe('normalizeFeatureValue', () => { diff --git a/web/sdk/client/views/plans/helpers/feature-rows.ts b/web/sdk/client/views/plans/helpers/feature-rows.ts index ae715b9fc9..4472a06208 100644 --- a/web/sdk/client/views/plans/helpers/feature-rows.ts +++ b/web/sdk/client/views/plans/helpers/feature-rows.ts @@ -14,61 +14,48 @@ export type FeatureInfoPart = /* * Builds the feature table rows. - * - Sorted by metadata.weightage; missing/falsy weightage falls back to the feature count. - * - Duplicate titles collapse into one row: last weightage wins, first non-empty info wins. - * - Empty titles are dropped. + * - Plain object keyed by title, so ordering matches the old inline sort exactly. + * - Missing/falsy weightage falls back to the feature count; last weightage wins. + * - First non-blank info wins; empty titles are dropped. */ export function buildFeatureRows(features: FeatureLike[]): FeatureRow[] { - const totalFeatures = features.length; - const rows = new Map(); + const weightages: Record = {}; + const infos = new Map(); features.forEach(feature => { const metadata = (feature.metadata || {}) as Record; const title = feature.title || ''; - const weightage = metadata.weightage || totalFeatures; - const info = - typeof metadata.info === 'string' && metadata.info.trim() - ? metadata.info - : undefined; - - const existing = rows.get(title); - rows.set(title, { weightage, info: existing?.info ?? info }); + weightages[title] = metadata.weightage || features.length; + const info = typeof metadata.info === 'string' ? metadata.info.trim() : ''; + if (info && !infos.has(title)) infos.set(title, info); }); - return Array.from(rows.entries()) - .sort((a, b) => Number(a[1].weightage) - Number(b[1].weightage)) + return Object.entries(weightages) + .sort((a, b) => Number(a[1]) - Number(b[1])) .filter(([title]) => Boolean(title)) - .map(([title, { info }]) => (info ? { title, info } : { title })); + .map(([title]) => ({ title, info: infos.get(title) })); } const LINK_PATTERN = /\[([^\]]+)\]\(([^)\s]+)\)/g; -const ALLOWED_URL_PATTERN = /^(https?|mailto):/i; +const ALLOWED_URL_PATTERN = /^(https?|mailto):/; /* * Splits info text into text and link parts. - * - Only [label](url) is parsed; the url must start with http:, https: or mailto:. + * - [label](url) becomes a link only with a non-blank label and an http:, https: or mailto: url. * - Everything else is kept as plain text exactly as written. */ export function parseFeatureInfo(info: string): FeatureInfoPart[] { const parts: FeatureInfoPart[] = []; - const pushText = (text: string) => { - if (!text) return; - const last = parts[parts.length - 1]; - if (last?.type === 'text') last.text += text; - else parts.push({ type: 'text', text }); - }; - let cursor = 0; - for (const match of Array.from(info.matchAll(LINK_PATTERN))) { + for (const match of info.matchAll(LINK_PATTERN)) { const [raw, label, url] = match; const start = match.index ?? 0; - pushText(info.slice(cursor, start)); - if (ALLOWED_URL_PATTERN.test(url)) parts.push({ type: 'link', label, url }); - else pushText(raw); + const isLink = label.trim() !== '' && ALLOWED_URL_PATTERN.test(url); + parts.push({ type: 'text', text: info.slice(cursor, start) }); + parts.push(isLink ? { type: 'link', label, url } : { type: 'text', text: raw }); cursor = start + raw.length; } - pushText(info.slice(cursor)); - + parts.push({ type: 'text', text: info.slice(cursor) }); return parts; } From c6076cde0eebe866843c542746dd9e4d3c8ead90 Mon Sep 17 00:00:00 2001 From: Shreyag02 Date: Wed, 18 Nov 2026 15:50:55 +0530 Subject: [PATCH 3/5] refactor(sdk): simplify plans feature info per review - Drop the feature-rows helper and tests; keep main's sort, returning whole features - Use the proto Feature type; keep normalizeFeatureValue in the table - Render info links inline with split; allow parentheses in urls, skip blank or bracketed labels - Use IconButton for the trigger, sized and coloured to match Figma - Open the popover on top; use Apsara defaults for the rest --- .../views/plans/components/feature-info.tsx | 81 ++++----- .../plans/components/feature-table.module.css | 24 +-- .../views/plans/components/feature-table.tsx | 45 +++-- .../views/plans/helpers/feature-rows.test.ts | 160 ------------------ .../views/plans/helpers/feature-rows.ts | 69 -------- web/sdk/client/views/plans/plans-view.tsx | 21 ++- 6 files changed, 93 insertions(+), 307 deletions(-) delete mode 100644 web/sdk/client/views/plans/helpers/feature-rows.test.ts delete mode 100644 web/sdk/client/views/plans/helpers/feature-rows.ts diff --git a/web/sdk/client/views/plans/components/feature-info.tsx b/web/sdk/client/views/plans/components/feature-info.tsx index eabfe058d4..89ba23c847 100644 --- a/web/sdk/client/views/plans/components/feature-info.tsx +++ b/web/sdk/client/views/plans/components/feature-info.tsx @@ -1,64 +1,57 @@ 'use client'; -import { Fragment, useId } from 'react'; -import { Link, Popover } from '@raystack/apsara'; +import { IconButton, Link, Popover } from '@raystack/apsara'; import { InfoCircledIcon } from '@radix-ui/react-icons'; -import { parseFeatureInfo } from '~/client/views/plans/helpers/feature-rows'; import styles from './feature-table.module.css'; -interface FeatureInfoProps { - id: string; - info: string; -} +/* + * Matches [label](url) for http, https and mailto urls only. + * - Label needs a non-space character, so [ ](url) stays text. + * - Label can't hold brackets, so [[a](url) links only "a". + * - Url may hold balanced parentheses one level deep, e.g. .../Foo_(bar). + */ +const LINK_PATTERN = + /\[(\s*[^[\]\s][^[\]]*)\]\(((?:https?|mailto):(?:[^()\s]|\([^()\s]*\))+)\)/; -function FeatureInfo({ id, info }: FeatureInfoProps) { - return ( - - {parseFeatureInfo(info).map((part, index) => - part.type === 'link' ? ( - - {part.label} - - ) : ( - {part.text} - ) - )} - - ); -} - -interface FeatureInfoPopoverProps { +interface FeatureInfoProps { title: string; info: string; } -export function FeatureInfoPopover({ title, info }: FeatureInfoPopoverProps) { - const descriptionId = useId(); +export function FeatureInfo({ title, info }: FeatureInfoProps) { return ( - - - + } > - + + + + {/* split() returns [text, label, url, text, label, url, ..., text] */} + {info.split(LINK_PATTERN).map((part, i, parts) => { + if (i % 3 === 0) return part; + if (i % 3 === 2) return null; + const url = parts[i + 1]; + return ( + + {part} + + ); + })} ); diff --git a/web/sdk/client/views/plans/components/feature-table.module.css b/web/sdk/client/views/plans/components/feature-table.module.css index e0f85dceb3..5ed0e0c72a 100644 --- a/web/sdk/client/views/plans/components/feature-table.module.css +++ b/web/sdk/client/views/plans/components/feature-table.module.css @@ -44,24 +44,12 @@ flex-shrink: 0; } -.infoTrigger { - display: inline-flex; - align-items: center; - padding: 0; - border: none; - background: none; - cursor: pointer; - color: var(--rs-color-foreground-base-tertiary); -} - /* - * - Host apps load Apsara's CSS after the SDK's, so its .popover wins ties. - * - !important keeps our max-width and overflow over Apsara's. + * Figma: 16px icon in fg/Subtle. + * - IconButton adds 2px padding and a darker colour. + * - .cell raises specificity so this wins over Apsara's class in any load order. */ -.infoContent { - max-width: 360px !important; - max-height: min(60vh, 400px); - overflow-y: auto !important; - white-space: pre-line; - overflow-wrap: break-word; +.cell .infoTrigger { + padding: 0; + color: var(--rs-color-foreground-base-tertiary); } diff --git a/web/sdk/client/views/plans/components/feature-table.tsx b/web/sdk/client/views/plans/components/feature-table.tsx index e20de3f59f..646406bdd7 100644 --- a/web/sdk/client/views/plans/components/feature-table.tsx +++ b/web/sdk/client/views/plans/components/feature-table.tsx @@ -2,16 +2,34 @@ import { Flex, Image, Skeleton, Text } from '@raystack/apsara'; import { get } from 'lodash'; +import { Feature } from '@raystack/proton/frontier'; import { IntervalKeys, IntervalPricingWithPlan, PlanIntervalPricing } from '~/src/types'; import checkCircle from '~/client/assets/check-circle.svg'; -import { FeatureRow, normalizeFeatureValue } from '~/client/views/plans/helpers/feature-rows'; -import { FeatureInfoPopover } from '~/client/views/plans/components/feature-info'; +import { FeatureInfo } from '~/client/views/plans/components/feature-info'; import styles from './feature-table.module.css'; +/* + * Normalises a feature cell value to a string. + * - Falsy values (missing, '', false, 0) become '-'. + * - Everything else goes through String(), so lowercasing never throws. + */ +function normalizeFeatureValue(value: unknown): string { + return value ? String(value) : '-'; +} + +/* + * Reads the feature's info text. + * - Only a non-blank string shows the info icon. + */ +function getFeatureInfo(feature: Feature): string { + const info = feature.metadata?.info; + return typeof info === 'string' ? info.trim() : ''; +} + interface FeatureValueCellProps { feature: string; plan?: IntervalPricingWithPlan; @@ -43,7 +61,7 @@ function FeatureValueCell({ feature, plan }: FeatureValueCellProps) { } export interface FeatureTableProps { - features: FeatureRow[]; + features: Feature[]; plans: PlanIntervalPricing[]; selectedIntervals: Record; isLoading?: boolean; @@ -92,16 +110,17 @@ export function FeatureTable({ return ( - {features.map(feature => ( - - - {feature.title} - - {feature.info && ( - - )} - - ))} + {features.map(feature => { + const info = getFeatureInfo(feature); + return ( + + + {feature.title} + + {info && } + + ); + })} {plans.map(plan => { diff --git a/web/sdk/client/views/plans/helpers/feature-rows.test.ts b/web/sdk/client/views/plans/helpers/feature-rows.test.ts deleted file mode 100644 index b311e04465..0000000000 --- a/web/sdk/client/views/plans/helpers/feature-rows.test.ts +++ /dev/null @@ -1,160 +0,0 @@ -import { - buildFeatureRows, - normalizeFeatureValue, - parseFeatureInfo -} from '~/client/views/plans/helpers/feature-rows'; - -describe('buildFeatureRows', () => { - it('sorts by weightage', () => { - const rows = buildFeatureRows([ - { title: 'C', metadata: { weightage: 3 } }, - { title: 'A', metadata: { weightage: 1 } }, - { title: 'B', metadata: { weightage: 2 } } - ]); - expect(rows.map(r => r.title)).toEqual(['A', 'B', 'C']); - }); - - it('falls back to the feature count when weightage is missing', () => { - const rows = buildFeatureRows([ - { title: 'NoWeight', metadata: {} }, - { title: 'NoMeta' }, - { title: 'Last', metadata: { weightage: 5 } }, - { title: 'First', metadata: { weightage: 1 } } - ]); - expect(rows.map(r => r.title)).toEqual([ - 'First', - 'NoWeight', - 'NoMeta', - 'Last' - ]); - }); - - it('drops empty titles', () => { - const rows = buildFeatureRows([ - { title: '', metadata: { weightage: 1 } }, - { metadata: { weightage: 1 } }, - { title: 'A', metadata: { weightage: 2 } } - ]); - expect(rows).toEqual([{ title: 'A' }]); - }); - - it('collapses duplicate titles and keeps the first non-empty info', () => { - const rows = buildFeatureRows([ - { title: 'A', metadata: { weightage: 1, info: ' ' } }, - { title: 'B', metadata: { weightage: 2 } }, - { title: 'A', metadata: { weightage: 3, info: 'first' } }, - { title: 'A', metadata: { weightage: 3, info: 'second' } } - ]); - expect(rows).toEqual([{ title: 'B' }, { title: 'A', info: 'first' }]); - }); - - it('ignores missing, blank and non-string info', () => { - const rows = buildFeatureRows([ - { title: 'A', metadata: { weightage: 1 } }, - { title: 'B', metadata: { weightage: 2, info: '' } }, - { title: 'C', metadata: { weightage: 3, info: ' ' } }, - { title: 'D', metadata: { weightage: 4, info: 42 } }, - { title: 'E', metadata: { weightage: 5, info: { text: 'x' } } }, - { title: 'F', metadata: { weightage: 6, info: 'Help' } } - ]); - expect(rows).toEqual([ - { title: 'A' }, - { title: 'B' }, - { title: 'C' }, - { title: 'D' }, - { title: 'E' }, - { title: 'F', info: 'Help' } - ]); - }); - - it('trims surrounding whitespace from info', () => { - const rows = buildFeatureRows([ - { title: 'A', metadata: { weightage: 1, info: '\n Help text\n' } } - ]); - expect(rows[0].info).toBe('Help text'); - }); - - it('keeps the old ordering for tied integer-like titles', () => { - const rows = buildFeatureRows([ - { title: 'Storage', metadata: {} }, - { title: '2', metadata: {} }, - { title: '1', metadata: {} } - ]); - expect(rows.map(r => r.title)).toEqual(['1', '2', 'Storage']); - }); -}); - -/* - * - Renders parts the way the popover shows them: links as . - * - Asserts on visible output, not on how text is split into parts. - */ -const show = (info: string) => - parseFeatureInfo(info) - .map(p => (p.type === 'text' ? p.text : `<${p.url}|${p.label}>`)) - .join(''); - -describe('parseFeatureInfo', () => { - it('shows plain text unchanged', () => { - expect(show('Just text.')).toBe('Just text.'); - }); - - it('turns one link into a link', () => { - expect(show('See [Details](https://example.com).')).toBe( - 'See .' - ); - }); - - it('turns two links into links', () => { - expect( - show( - '[Docs](http://example.com/docs) or [support@example.com](mailto:support@example.com)' - ) - ).toBe( - ' or ' - ); - }); - - it('keeps links with a disallowed scheme as plain text', () => { - [ - 'Click [here](javascript:alert(1)) now', - 'Go [there](/settings/billing)', - 'Get [file](ftp://example.com/file)', - 'Shout [docs](HTTPS://example.com)' - ].forEach(input => { - expect(show(input)).toBe(input); - }); - }); - - it('keeps malformed markdown as plain text', () => { - [ - '[Details](https://example.com', - '[Details] (https://example.com)', - '[](https://example.com)', - 'Details](https://example.com)' - ].forEach(input => { - expect(show(input)).toBe(input); - }); - }); - - it('keeps a blank label as plain text', () => { - const input = 'Hidden [ ](https://example.com) link'; - expect(show(input)).toBe(input); - }); -}); - -describe('normalizeFeatureValue', () => { - it('returns strings unchanged', () => { - expect(normalizeFeatureValue('10 GB')).toBe('10 GB'); - }); - - it('converts true and non-zero numbers to strings', () => { - expect(normalizeFeatureValue(true)).toBe('true'); - expect(normalizeFeatureValue(5)).toBe('5'); - }); - - it('returns "-" for falsy values', () => { - [undefined, null, '', false, 0].forEach(value => { - expect(normalizeFeatureValue(value)).toBe('-'); - }); - }); -}); diff --git a/web/sdk/client/views/plans/helpers/feature-rows.ts b/web/sdk/client/views/plans/helpers/feature-rows.ts deleted file mode 100644 index 4472a06208..0000000000 --- a/web/sdk/client/views/plans/helpers/feature-rows.ts +++ /dev/null @@ -1,69 +0,0 @@ -export interface FeatureRow { - title: string; - info?: string; -} - -interface FeatureLike { - title?: string; - metadata?: unknown; -} - -export type FeatureInfoPart = - | { type: 'text'; text: string } - | { type: 'link'; label: string; url: string }; - -/* - * Builds the feature table rows. - * - Plain object keyed by title, so ordering matches the old inline sort exactly. - * - Missing/falsy weightage falls back to the feature count; last weightage wins. - * - First non-blank info wins; empty titles are dropped. - */ -export function buildFeatureRows(features: FeatureLike[]): FeatureRow[] { - const weightages: Record = {}; - const infos = new Map(); - - features.forEach(feature => { - const metadata = (feature.metadata || {}) as Record; - const title = feature.title || ''; - weightages[title] = metadata.weightage || features.length; - const info = typeof metadata.info === 'string' ? metadata.info.trim() : ''; - if (info && !infos.has(title)) infos.set(title, info); - }); - - return Object.entries(weightages) - .sort((a, b) => Number(a[1]) - Number(b[1])) - .filter(([title]) => Boolean(title)) - .map(([title]) => ({ title, info: infos.get(title) })); -} - -const LINK_PATTERN = /\[([^\]]+)\]\(([^)\s]+)\)/g; -const ALLOWED_URL_PATTERN = /^(https?|mailto):/; - -/* - * Splits info text into text and link parts. - * - [label](url) becomes a link only with a non-blank label and an http:, https: or mailto: url. - * - Everything else is kept as plain text exactly as written. - */ -export function parseFeatureInfo(info: string): FeatureInfoPart[] { - const parts: FeatureInfoPart[] = []; - let cursor = 0; - for (const match of info.matchAll(LINK_PATTERN)) { - const [raw, label, url] = match; - const start = match.index ?? 0; - const isLink = label.trim() !== '' && ALLOWED_URL_PATTERN.test(url); - parts.push({ type: 'text', text: info.slice(cursor, start) }); - parts.push(isLink ? { type: 'link', label, url } : { type: 'text', text: raw }); - cursor = start + raw.length; - } - parts.push({ type: 'text', text: info.slice(cursor) }); - return parts; -} - -/* - * Normalises a feature cell value to a string. - * - Falsy values (missing, '', false, 0) become '-'. - * - Everything else goes through String(), so lowercasing never throws. - */ -export function normalizeFeatureValue(value: unknown): string { - return value ? String(value) : '-'; -} diff --git a/web/sdk/client/views/plans/plans-view.tsx b/web/sdk/client/views/plans/plans-view.tsx index e413a7434a..89b8b353ea 100644 --- a/web/sdk/client/views/plans/plans-view.tsx +++ b/web/sdk/client/views/plans/plans-view.tsx @@ -21,7 +21,6 @@ import { ViewContainer } from '~/client/components/view-container'; import { ViewHeader } from '~/client/components/view-header'; import { UpcomingPlanChangeBanner } from '~/client/views/billing/components/upcoming-plan-change-banner'; import { groupPlansPricingByInterval } from './helpers'; -import { buildFeatureRows } from '~/client/views/plans/helpers/feature-rows'; import { IntervalKeys, IntervalPricingWithPlan } from '~/src/types'; import { PlanCard } from './components/plan-card'; import { FeatureTable } from './components/feature-table'; @@ -78,7 +77,23 @@ export function PlansView() { isActiveSubscriptionLoading || isActiveOrganizationLoading; - const featureRows = useMemo(() => buildFeatureRows(features), [features]); + const totalFeatures = features.length; + + const sortedFeatures = useMemo(() => { + const featureTitleMap = features.reduce( + (acc, f) => { + acc[f.title || ''] = f; + return acc; + }, + {} as Record + ); + const weightage = (f: Feature) => + (f.metadata as Record)?.weightage || totalFeatures; + + return Object.values(featureTitleMap) + .sort((f1, f2) => weightage(f1) - weightage(f2)) + .filter(f => Boolean(f.title)); + }, [features, totalFeatures]); const [intervalOverrides, setIntervalOverrides] = useState< Record @@ -176,7 +191,7 @@ export function PlansView() { Date: Thu, 19 Nov 2026 09:57:04 +0530 Subject: [PATCH 4/5] fix(sdk): name feature info popover and require a host in info links --- web/sdk/client/views/plans/components/feature-info.tsx | 8 ++++++-- web/sdk/client/views/plans/components/feature-table.tsx | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/web/sdk/client/views/plans/components/feature-info.tsx b/web/sdk/client/views/plans/components/feature-info.tsx index 89ba23c847..f84514d276 100644 --- a/web/sdk/client/views/plans/components/feature-info.tsx +++ b/web/sdk/client/views/plans/components/feature-info.tsx @@ -8,10 +8,11 @@ import styles from './feature-table.module.css'; * Matches [label](url) for http, https and mailto urls only. * - Label needs a non-space character, so [ ](url) stays text. * - Label can't hold brackets, so [[a](url) links only "a". + * - http(s) needs // and a host, so https:x and https://#a stay text. * - Url may hold balanced parentheses one level deep, e.g. .../Foo_(bar). */ const LINK_PATTERN = - /\[(\s*[^[\]\s][^[\]]*)\]\(((?:https?|mailto):(?:[^()\s]|\([^()\s]*\))+)\)/; + /\[(\s*[^[\]\s][^[\]]*)\]\(((?:https?:\/\/(?=[^\s()/?#])|mailto:)(?:[^()\s]|\([^()\s]*\))+)\)/; interface FeatureInfoProps { title: string; @@ -34,7 +35,10 @@ export function FeatureInfo({ title, info }: FeatureInfoProps) { > - + } + > {/* split() returns [text, label, url, text, label, url, ..., text] */} {info.split(LINK_PATTERN).map((part, i, parts) => { if (i % 3 === 0) return part; diff --git a/web/sdk/client/views/plans/components/feature-table.tsx b/web/sdk/client/views/plans/components/feature-table.tsx index 646406bdd7..ea72adf5fe 100644 --- a/web/sdk/client/views/plans/components/feature-table.tsx +++ b/web/sdk/client/views/plans/components/feature-table.tsx @@ -15,7 +15,7 @@ import styles from './feature-table.module.css'; /* * Normalises a feature cell value to a string. * - Falsy values (missing, '', false, 0) become '-'. - * - Everything else goes through String(), so lowercasing never throws. + * - Plain values go through String(), so lowercasing a number or boolean doesn't throw. */ function normalizeFeatureValue(value: unknown): string { return value ? String(value) : '-'; From 0eceabcced9a8bc199f7ab91d0fe01363f40d14e Mon Sep 17 00:00:00 2001 From: Shreyag02 Date: Thu, 19 Nov 2026 10:01:47 +0530 Subject: [PATCH 5/5] chore(admin): align @raystack/proton pin with the sdk --- web/apps/admin/package.json | 2 +- web/pnpm-lock.yaml | 26 ++------------------------ 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/web/apps/admin/package.json b/web/apps/admin/package.json index f90c4e5272..006dd736c1 100644 --- a/web/apps/admin/package.json +++ b/web/apps/admin/package.json @@ -20,7 +20,7 @@ "@radix-ui/react-icons": "^1.3.0", "@raystack/apsara": "^1.1.0", "@raystack/frontier": "workspace:^", - "@raystack/proton": "0.1.0-859ba765e6cfd44736ddcf42664b742fe7fd916e", + "@raystack/proton": "0.1.0-94668c362cad03165629c14c7b1abf753e885496", "@stitches/react": "^1.2.8", "@tanstack/react-query": "^5.90.2", "@tanstack/react-query-devtools": "^5.90.2", diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml index 2ee7dc093c..ae3192bcbe 100644 --- a/web/pnpm-lock.yaml +++ b/web/pnpm-lock.yaml @@ -61,8 +61,8 @@ importers: specifier: workspace:^ version: link:../../sdk '@raystack/proton': - specifier: 0.1.0-859ba765e6cfd44736ddcf42664b742fe7fd916e - version: 0.1.0-859ba765e6cfd44736ddcf42664b742fe7fd916e(@tanstack/query-core@5.90.20)(@tanstack/react-query@5.90.21(react@19.2.4))(react-dom@19.2.4(react@19.2.4))(react@19.2.4) + specifier: 0.1.0-94668c362cad03165629c14c7b1abf753e885496 + version: 0.1.0-94668c362cad03165629c14c7b1abf753e885496(@tanstack/query-core@5.90.20)(@tanstack/react-query@5.90.21(react@19.2.4))(react-dom@19.2.4(react@19.2.4))(react@19.2.4) '@stitches/react': specifier: ^1.2.8 version: 1.2.8(react@19.2.4) @@ -1587,14 +1587,6 @@ packages: '@types/react': optional: true - '@raystack/proton@0.1.0-859ba765e6cfd44736ddcf42664b742fe7fd916e': - resolution: {integrity: sha512-82QvGoJjcp5zGt/QIkdSJEn2iX8vn/g2H4jm8O3QH3YIZuZp0bXFXo+ddD5S49tSUtWiegi7qWJargHgBceLPg==} - peerDependencies: - '@tanstack/react-query': ^5.0.0 - peerDependenciesMeta: - '@tanstack/react-query': - optional: true - '@raystack/proton@0.1.0-94668c362cad03165629c14c7b1abf753e885496': resolution: {integrity: sha512-C1dqPzOnF0Pb1Pyx5kKUPFtclNFravCNVM1kpfvgk2dUgkNlYd7kDCQpma0LOhs/gkddt2usu+U4qRjhykgyQQ==} peerDependencies: @@ -8076,20 +8068,6 @@ snapshots: - '@date-fns/tz' - date-fns - '@raystack/proton@0.1.0-859ba765e6cfd44736ddcf42664b742fe7fd916e(@tanstack/query-core@5.90.20)(@tanstack/react-query@5.90.21(react@19.2.4))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)': - dependencies: - '@bufbuild/protobuf': 2.11.0 - '@connectrpc/connect': 2.1.1(@bufbuild/protobuf@2.11.0) - '@connectrpc/connect-query': 2.1.1(@bufbuild/protobuf@2.11.0)(@connectrpc/connect@2.1.1(@bufbuild/protobuf@2.11.0))(@tanstack/query-core@5.90.20)(@tanstack/react-query@5.90.21(react@19.2.4))(react-dom@19.2.4(react@19.2.4))(react@19.2.4) - '@protobuf-ts/runtime': 2.11.1 - '@protobuf-ts/runtime-rpc': 2.11.1 - optionalDependencies: - '@tanstack/react-query': 5.90.21(react@19.2.4) - transitivePeerDependencies: - - '@tanstack/query-core' - - react - - react-dom - '@raystack/proton@0.1.0-94668c362cad03165629c14c7b1abf753e885496(@tanstack/query-core@5.90.20)(@tanstack/react-query@5.90.21(react@19.2.4))(react-dom@19.2.4(react@19.2.4))(react@19.2.4)': dependencies: '@bufbuild/protobuf': 2.11.0