Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/apps/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 2 additions & 24 deletions web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions web/sdk/client/views/plans/components/feature-info.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use client';

import { IconButton, Link, Popover } from '@raystack/apsara';
import { InfoCircledIcon } from '@radix-ui/react-icons';
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?:\/\/(?=[^\s()/?#])|mailto:)(?:[^()\s]|\([^()\s]*\))+)\)/;

interface FeatureInfoProps {
title: string;
info: string;
}

export function FeatureInfo({ title, info }: FeatureInfoProps) {
return (
<Popover>
<Popover.Trigger
openOnHover
render={
<IconButton
size={2}
aria-label={`About ${title}`}
className={styles.infoTrigger}
data-test-id="frontier-sdk-plans-feature-info-btn"
/>
}
>
<InfoCircledIcon />
</Popover.Trigger>
<Popover.Content
side="top"
render={<div aria-label={`About ${title}`} />}
>
{/* 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 (
<Link
key={i}
href={url}
Comment thread
Shreyag02 marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
external={url.startsWith('http')}
underline
data-test-id="frontier-sdk-plans-feature-info-link"
>
{part}
</Link>
);
})}
</Popover.Content>
</Popover>
);
}
10 changes: 10 additions & 0 deletions web/sdk/client/views/plans/components/feature-table.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@
height: 16px;
flex-shrink: 0;
}

/*
* 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.
*/
.cell .infoTrigger {
padding: 0;
color: var(--rs-color-foreground-base-tertiary);
}
49 changes: 36 additions & 13 deletions web/sdk/client/views/plans/components/feature-table.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
'use client';

import { Flex, Image, Skeleton, Text } from '@raystack/apsara';
import { InfoCircledIcon } from '@radix-ui/react-icons';
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 { 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 '-'.
* - Plain values go through String(), so lowercasing a number or boolean doesn't throw.
*/
function normalizeFeatureValue(value: unknown): string {
return value ? String(value) : '-';
Comment thread
Shreyag02 marked this conversation as resolved.
Resolved
}

/*
* 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;
Expand All @@ -21,8 +40,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 (
<Flex className={`${styles.cell} ${styles.valueCell}`}>
Expand All @@ -42,7 +61,7 @@ function FeatureValueCell({ feature, plan }: FeatureValueCellProps) {
}

export interface FeatureTableProps {
features: string[];
features: Feature[];
plans: PlanIntervalPricing[];
selectedIntervals: Record<string, IntervalKeys>;
isLoading?: boolean;
Expand Down Expand Up @@ -91,13 +110,17 @@ export function FeatureTable({
return (
<Flex className={styles.table}>
<Flex direction="column" className={styles.featureColumn}>
{features.map(feature => (
<Flex key={feature} className={styles.cell}>
<Text size="regular" className={styles.featureLabel}>
{feature}
</Text>
</Flex>
))}
{features.map(feature => {
const info = getFeatureInfo(feature);
return (
<Flex key={feature.title} className={styles.cell}>
<Text size="regular" className={styles.featureLabel}>
{feature.title}
</Text>
{info && <FeatureInfo title={feature.title} info={info} />}
</Flex>
);
})}
</Flex>

{plans.map(plan => {
Expand All @@ -111,8 +134,8 @@ export function FeatureTable({
>
{features.map(feature => (
<FeatureValueCell
key={`${plan.slug}-${feature}`}
feature={feature}
key={`${plan.slug}-${feature.title}`}
feature={feature.title}
plan={planPricing}
/>
))}
Expand Down
15 changes: 7 additions & 8 deletions web/sdk/client/views/plans/plans-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,17 @@ export function PlansView() {
const sortedFeatures = useMemo(() => {
const featureTitleMap = features.reduce(
(acc, f) => {
const weightage =
(f.metadata as Record<string, number>)?.weightage || totalFeatures;
acc[f.title || ''] = weightage;
acc[f.title || ''] = f;
return acc;
},
{} as Record<string, number>
{} as Record<string, Feature>
);
const weightage = (f: Feature) =>
(f.metadata as Record<string, number>)?.weightage || totalFeatures;

return Object.entries(featureTitleMap)
.sort((f1, f2) => f1[1] - f2[1])
.map(f => f[0])
.filter(Boolean);
return Object.values(featureTitleMap)
.sort((f1, f2) => weightage(f1) - weightage(f2))
.filter(f => Boolean(f.title));
}, [features, totalFeatures]);

const [intervalOverrides, setIntervalOverrides] = useState<
Expand Down
Loading