Skip to content

Updated offers table to use Shade primitives#29534

Merged
9larsons merged 2 commits into
mainfrom
codex/admin-settings-shade-offers-table
Jul 22, 2026
Merged

Updated offers table to use Shade primitives#29534
9larsons merged 2 commits into
mainfrom
codex/admin-settings-shade-offers-table

Conversation

@9larsons

@9larsons 9larsons commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What changed

  • replaced the raw offers table markup with Shade Table primitives
  • replaced bespoke active, inactive and archived pills with Shade Badge
  • moved table surfaces, borders and secondary text onto semantic Shade tokens
  • changed click-only anchors into buttons while keeping redemption destinations as links
  • fixed sorting so Date added, Name, Redemptions and direction apply to every visible signup and retention row
  • derived retention-row dates from the latest underlying retention offer
  • added acceptance coverage for every sorting option and both directions

Why

The settings rip-out plan identified Offers as the dense table minefield in the lists/tables group. Splitting it into a focused PR keeps its interaction and visual review separate from the broader legacy List/Table component deletion that follows.

The existing sort implementation only sorted signup offers. Retention rows were permanently pinned, so on sites with one signup offer—such as the local fixture—every sorting option appeared to do nothing.

Impact

Signup and retention offers now form one sortable visible list. Archived filtering, editor navigation and redemption links are preserved. Retention rows use their aggregated redemption count and latest underlying creation date when sorting.

Validation

  • pnpm --filter @tryghost/admin-x-settings lint
  • pnpm --filter @tryghost/admin-x-settings test:unit — 206 tests
  • targeted offers acceptance suite — 19 tests
  • full Admin acceptance suite — 371 tests before the sorting follow-up
  • pnpm --filter @tryghost/admin build
  • local rendered verification of Name sorting and direction reversal with no browser console errors

Manual testing

  1. Open Settings → Growth → Offers → Manage offers.
  2. Check signup and retention row alignment.
  3. Select Name and confirm every visible row reorders; reverse the direction and confirm the order reverses.
  4. Repeat with Redemptions and Date added.
  5. Toggle Show archived and confirm archived signup offers join the same sorted list.
  6. Click ordinary cells in signup and retention rows and confirm the correct edit view opens.
  7. For an offer with redemptions, click the count and confirm Members opens with the offer filter.
  8. Check badges and sticky Name cells in light/dark mode and with horizontal scrolling.

no ref

Moves the dense offers minefield onto shared table, badge and layout primitives before the remaining legacy list and table components are removed.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The offers modal now uses design-system table components, renders retention and signup offers through dedicated row components, and sorts the combined list by name, redemptions, or creation date. Discount and retention-term formatting is updated, retention offers expose creation timestamps, and acceptance tests cover sorting and row selection.

Possibly related PRs

  • TryGhost/Ghost#29495: Updates the offers filter and archived-offers dropdown with related screen and test changes.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: migrating the offers table to Shade primitives.
Description check ✅ Passed The description accurately summarizes the table, badge, sorting, and retention-date changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/admin-settings-shade-offers-table

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Jul 22, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 1daae1a

Command Status Duration Result
nx run @tryghost/admin:test:acceptance ✅ Succeeded 6m 22s View ↗
nx run-many -t test:unit -p @tryghost/admin-x-s... ✅ Succeeded 2m 20s View ↗
nx run ghost-monorepo:lint:boundaries ✅ Succeeded 21s View ↗
nx run-many -t lint -p @tryghost/admin-x-settin... ✅ Succeeded 1m 5s View ↗
nx run @tryghost/admin:build ✅ Succeeded 17s View ↗
nx run-many --target=build --projects=tag:publi... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-07-22 16:10:34 UTC

no ref

Sorting previously applied only to signup offers, leaving the two retention rows permanently pinned and making every option appear ineffective on small offer lists.
@9larsons
9larsons marked this pull request as ready for review July 22, 2026 16:06
@9larsons
9larsons enabled auto-merge (squash) July 22, 2026 16:06

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
apps/admin-x-settings/src/components/settings/growth/offers/offers-index.tsx (1)

100-217: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated button-cell markup between RetentionOfferRow and SignupOfferRow.

Both row components repeat the same <TableCell className='p-0 whitespace-nowrap'><button className='block w-full cursor-pointer p-5 text-left' type='button' onClick={onClick}>... wrapper many times. Extracting a small ClickableCell helper would reduce this repetition and centralize the click-cell styling.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/admin-x-settings/src/components/settings/growth/offers/offers-index.tsx`
around lines 100 - 217, Extract the repeated clickable TableCell/button wrapper
from RetentionOfferRow and SignupOfferRow into a shared ClickableCell helper,
accepting onClick and rendering children. Replace the duplicated non-link cell
markup in both row components with this helper while preserving each cell’s
content, styling, and click behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/admin-x-settings/src/components/settings/growth/offers/offers-index.tsx`:
- Around line 227-259: Update sortOfferListItems so missing createdAt
comparisons assign their ordering to result instead of returning early, ensuring
those comparisons also pass through the sort-direction multiplier. Preserve the
existing placement rules for missing dates and the name/date sorting behavior
for populated dates.
- Around line 32-33: Update the formatPrice function to pass
minimumFractionDigits: 2 alongside maximumFractionDigits: 2 to formatNumber,
ensuring whole-dollar price and terms labels retain two decimal places.

---

Nitpick comments:
In
`@apps/admin-x-settings/src/components/settings/growth/offers/offers-index.tsx`:
- Around line 100-217: Extract the repeated clickable TableCell/button wrapper
from RetentionOfferRow and SignupOfferRow into a shared ClickableCell helper,
accepting onClick and rendering children. Replace the duplicated non-link cell
markup in both row components with this helper while preserving each cell’s
content, styling, and click behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2f688b4d-3520-4fed-b728-38144465e1d1

📥 Commits

Reviewing files that changed from the base of the PR and between aaab1b3 and 8bf54f7.

📒 Files selected for processing (5)
  • apps/admin-x-settings/src/components/settings/growth/offers/offers-index.tsx
  • apps/admin-x-settings/src/components/settings/growth/offers/offers-retention.tsx
  • apps/admin/src/settings/offers.acceptance.test.tsx
  • apps/admin/src/settings/offers.screen.ts
  • packages/testing/test-data/src/selectors/offers.ts

Comment on lines 32 to +33
const formatToTwoDecimals = (num: number): number => parseFloat(num.toFixed(2));
const formatPrice = (num: number): string => formatNumber(formatToTwoDecimals(currencyToDecimal(num)), {maximumFractionDigits: 2});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== offers-index.tsx ==\n'
sed -n '1,220p' apps/admin-x-settings/src/components/settings/growth/offers/offers-index.tsx

printf '\n== search formatNumber definitions/usages ==\n'
rg -n "function formatNumber|const formatNumber|formatNumber\(" apps/admin-x-settings src packages -g '!**/node_modules/**' | sed -n '1,200p'

Repository: TryGhost/Ghost

Length of output: 20328


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '1,120p' apps/admin-x-settings/src/components/settings/growth/offers/offers-index.tsx

Repository: TryGhost/Ghost

Length of output: 6205


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== locate shade formatNumber implementation ==\n'
rg -n "export .*formatNumber|function formatNumber|const formatNumber" . -g '!**/node_modules/**' | sed -n '1,200p'

printf '\n== currency price formatting call sites ==\n'
rg -n "maximumFractionDigits: 2|minimumFractionDigits: 2|formatNumber\(.*currencyToDecimal|currencyToDecimal\(.*formatNumber" apps/admin-x-settings packages apps -g '!**/node_modules/**' | sed -n '1,220p'

Repository: TryGhost/Ghost

Length of output: 2515


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '170,220p' apps/shade/src/lib/ds-utils.ts

Repository: TryGhost/Ghost

Length of output: 1798


Preserve two decimal places in price labels. formatNumber(..., {maximumFractionDigits: 2}) will render whole-dollar values like 10.00 as 10; add minimumFractionDigits: 2 so the Price and Terms columns stay consistent.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/admin-x-settings/src/components/settings/growth/offers/offers-index.tsx`
around lines 32 - 33, Update the formatPrice function to pass
minimumFractionDigits: 2 alongside maximumFractionDigits: 2 to formatNumber,
ensuring whole-dollar price and terms labels retain two decimal places.

Comment on lines +227 to +259
const sortOfferListItems = (items: OfferListItem[], sortOption: string, sortDirection: string): OfferListItem[] => {
const multiplier = sortDirection === 'desc' ? -1 : 1;

return [...items].sort((item1, item2) => {
let result: number;

switch (sortOption) {
case 'name':
result = getOfferListItemName(item1).localeCompare(getOfferListItemName(item2));
break;
case 'redemptions':
result = getOfferListItemRedemptions(item1) - getOfferListItemRedemptions(item2);
break;
default: {
const date1 = getOfferListItemCreatedAt(item1);
const date2 = getOfferListItemCreatedAt(item2);

if (!date1 && !date2) {
result = 0;
} else if (!date1) {
return 1;
} else if (!date2) {
return -1;
} else {
result = new Date(date1).getTime() - new Date(date2).getTime();
}
break;
}
}

return (result || getOfferListItemName(item1).localeCompare(getOfferListItemName(item2))) * multiplier;
});
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Sort direction is ignored for items with a missing createdAt.

The else if (!date1) { return 1; } / else if (!date2) { return -1; } branches return directly instead of assigning to result, so they never pass through * multiplier. Toggling ascending/descending has no effect on where null-date items land, while all other comparisons correctly flip. Since getRetentionOffers (offers-retention.tsx) can return createdAt: null for a cadence that has never had an offer, this is a realistic scenario, not just a theoretical edge case.

🐛 Proposed fix
             if (!date1 && !date2) {
                 result = 0;
             } else if (!date1) {
-                return 1;
+                result = 1;
             } else if (!date2) {
-                return -1;
+                result = -1;
             } else {
                 result = new Date(date1).getTime() - new Date(date2).getTime();
             }
             break;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const sortOfferListItems = (items: OfferListItem[], sortOption: string, sortDirection: string): OfferListItem[] => {
const multiplier = sortDirection === 'desc' ? -1 : 1;
return [...items].sort((item1, item2) => {
let result: number;
switch (sortOption) {
case 'name':
result = getOfferListItemName(item1).localeCompare(getOfferListItemName(item2));
break;
case 'redemptions':
result = getOfferListItemRedemptions(item1) - getOfferListItemRedemptions(item2);
break;
default: {
const date1 = getOfferListItemCreatedAt(item1);
const date2 = getOfferListItemCreatedAt(item2);
if (!date1 && !date2) {
result = 0;
} else if (!date1) {
return 1;
} else if (!date2) {
return -1;
} else {
result = new Date(date1).getTime() - new Date(date2).getTime();
}
break;
}
}
return (result || getOfferListItemName(item1).localeCompare(getOfferListItemName(item2))) * multiplier;
});
};
const sortOfferListItems = (items: OfferListItem[], sortOption: string, sortDirection: string): OfferListItem[] => {
const multiplier = sortDirection === 'desc' ? -1 : 1;
return [...items].sort((item1, item2) => {
let result: number;
switch (sortOption) {
case 'name':
result = getOfferListItemName(item1).localeCompare(getOfferListItemName(item2));
break;
case 'redemptions':
result = getOfferListItemRedemptions(item1) - getOfferListItemRedemptions(item2);
break;
default: {
const date1 = getOfferListItemCreatedAt(item1);
const date2 = getOfferListItemCreatedAt(item2);
if (!date1 && !date2) {
result = 0;
} else if (!date1) {
result = 1;
} else if (!date2) {
result = -1;
} else {
result = new Date(date1).getTime() - new Date(date2).getTime();
}
break;
}
}
return (result || getOfferListItemName(item1).localeCompare(getOfferListItemName(item2))) * multiplier;
});
};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/admin-x-settings/src/components/settings/growth/offers/offers-index.tsx`
around lines 227 - 259, Update sortOfferListItems so missing createdAt
comparisons assign their ordering to result instead of returning early, ensuring
those comparisons also pass through the sort-direction multiplier. Preserve the
existing placement rules for missing dates and the name/date sorting behavior
for populated dates.

@9larsons
9larsons merged commit 446d6dc into main Jul 22, 2026
44 checks passed
@9larsons
9larsons deleted the codex/admin-settings-shade-offers-table branch July 22, 2026 16:15
9larsons added a commit that referenced this pull request Jul 22, 2026
- main's offers table rework (#29534) fixed sorting to apply across signup
  and retention rows together and added acceptance coverage; ported the
  unified sort (name tiebreak, null dates last) and the offers-table-body
  testid into the native offers index dialog
- main's color picker migration (#29538/#29542) renamed the hex input's
  accessible name to "Hex color" and the design suite now targets it;
  matched the native color picker field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant