Skip to content

Commit f5dd62f

Browse files
cursoragentarmenzg
andcommitted
Fix billing plan anchor IDs and disabled category code logic
Co-authored-by: Armen Zambrano G. <armenzg@users.noreply.github.com>
1 parent 7c05e3c commit f5dd62f

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

static/gsAdmin/views/billingPlans.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,15 @@ function TableOfContents({plans}: {plans: Plans}) {
278278
<td>{planTierIdFormatted}</td>
279279
{planColumnOrder.map(planName => {
280280
const planDetails = planTier[planName];
281-
const planNameFormattedForId = formatPlanName(planName);
281+
const fallbackPlanId = getPlanAnchorId(
282+
planTierIdFormatted,
283+
planName
284+
);
282285
return (
283286
<td key={planName}>
284287
{planDetails ? (
285288
<span style={{display: 'block'}}>
286-
<a
287-
href={`#${planDetails.id ?? `${planTierIdFormatted}-${planNameFormattedForId}`}`}
288-
>
289+
<a href={`#${planDetails.id ?? fallbackPlanId}`}>
289290
{formatPlanName(planName, true)}
290291
</a>
291292
{planDetails.id && (
@@ -369,16 +370,14 @@ function PlanDetailsSection({
369370
}) {
370371
const theme = useTheme();
371372
const planNameFormatted = formatPlanName(planName);
373+
const fallbackPlanId = getPlanAnchorId(planTierIdFormatted, planName);
372374

373375
return (
374376
<div>
375377
<div
376378
style={{display: 'flex', alignItems: 'center', marginBottom: theme.space['2xl']}}
377379
>
378-
<h3
379-
id={planDetails.id ?? `${planTierIdFormatted}-${planNameFormatted}`}
380-
style={{margin: '20px 0 5px'}}
381-
>
380+
<h3 id={planDetails.id ?? fallbackPlanId} style={{margin: '20px 0 5px'}}>
382381
{planTierIdFormatted} {planNameFormatted} Plan
383382
{planDetails.id ? ` (${planDetails.id})` : null}
384383
</h3>
@@ -535,7 +534,10 @@ function getCategoryInfo(
535534

536535
function shouldShowCategoryCode(categoryLabel: string, categoryCode?: string): boolean {
537536
if (!categoryCode) return false;
538-
const labelWithoutPlural = categoryLabel.toLowerCase().replace(/s$/, '');
537+
const labelWithoutStatusSuffix = categoryLabel
538+
.toLowerCase()
539+
.replace(/\s+\(disabled\)$/, '');
540+
const labelWithoutPlural = labelWithoutStatusSuffix.replace(/s$/, '');
539541
return labelWithoutPlural !== categoryCode;
540542
}
541543

@@ -551,6 +553,7 @@ function MergedPriceTiersTable({
551553
categories?: Record<string, CategoryInfo | string>;
552554
}) {
553555
const [expandedKeys, setExpandedKeys] = useState<Set<string>>(new Set());
556+
const planNameIdPart = formatIdToken(planNameFormatted);
554557

555558
const entries = (
556559
Object.entries(planDetails.price_tiers) as Array<[DataCategory, PriceTier[]]>
@@ -560,7 +563,7 @@ function MergedPriceTiersTable({
560563

561564
const groups: TierGroup[] = entries.flatMap(([dataCategory, tiers]) => {
562565
const dataCategoryFormatted = formatDataCategory(dataCategory);
563-
const dataCategoryId = `${planTierIdFormatted}-${planNameFormatted}-${dataCategoryFormatted}`;
566+
const dataCategoryId = `${planTierIdFormatted}-${planNameIdPart}-${formatIdToken(dataCategoryFormatted)}`;
564567
const disabled = planDetails.data_categories_disabled.includes(dataCategory);
565568
const categoryLabel = disabled
566569
? `${dataCategoryFormatted} (DISABLED)`
@@ -1253,6 +1256,14 @@ function formatPlanName(planType: string, shortenEnterprise = false): string {
12531256
return planType.charAt(0).toUpperCase() + planType.slice(1);
12541257
}
12551258

1259+
function formatIdToken(value: string): string {
1260+
return value.trim().replace(/\s+/g, '_');
1261+
}
1262+
1263+
function getPlanAnchorId(planTierIdFormatted: string, planName: string): string {
1264+
return `${planTierIdFormatted}-${formatIdToken(formatPlanName(planName))}`;
1265+
}
1266+
12561267
function formatDataCategory(dataCategory: DataCategory): string {
12571268
// Capitalize the first letter of each word
12581269
return capitalizeWords(dataCategory);

0 commit comments

Comments
 (0)