Skip to content

Pivot to @wordpress/dataviews for the AI Orders table#25

Merged
pierorocca merged 1 commit into
mainfrom
feat/dataviews-ai-orders-table
Apr 18, 2026
Merged

Pivot to @wordpress/dataviews for the AI Orders table#25
pierorocca merged 1 commit into
mainfrom
feat/dataviews-ai-orders-table

Conversation

@pierorocca
Copy link
Copy Markdown
Collaborator

Summary

Replaces the @woocommerce/components TableCard adoption from PR #24 (which rendered DOM but never loaded its CSS on our submenu page) with @wordpress/dataviews in table-view mode. Also shifts the section from aggregate "Revenue by Agent" to per-order "Recent AI Orders" so merchants can click through to individual orders from the dashboard.

Why DataViews, not Woo TableCard

PR #24's enqueue dance didn't work. The wp_style_is('registered') guards for wc-components / wc-admin-layout / wc-experimental silently passed through because the handles aren't registered on non-wc-admin pages. Result: the table HTML rendered but looked broken ("1Total orders" with no spacing, unstyled column headers).

DataViews sidesteps the problem entirely — the WP dep-extraction plugin lists it in BUNDLED_PACKAGES, so webpack bundles the JS into our build. The CSS is copied to our build output by a postbuild script and flows through the plugin's existing CSS enqueue path. Zero dependency on the merchant's wc-admin asset registration.

Column set (matches WC Orders convention)

Order Date Status Agent Total
#123 → edit screen Apr 18 (relative) colored pill Gemini $55.36
  • Order links to the HPOS-aware order-edit URL
  • Date uses WC's own wc_format_datetime with the ISO date in a tooltip
  • Status is a colored pill using WC's own palette (inline styles — wc-admin's .order-status CSS isn't loaded on our page)
  • Agent is canonicalized through KNOWN_AGENT_HOSTS server-side, so legacy orders with raw hostnames (gemini.google.com) display as brand names (Gemini). DB meta is untouched — display-only.
  • Total uses Intl.NumberFormat for locale-aware currency

New REST endpoint

GET /wc/v3/ai-syndication/admin/recent-orders?per_page=10

Returns orders normalized for the DataViews row shape. wc_get_orders() with meta_key = AGENT_META_KEY bounds the scan to AI-attributed orders only.

Bundle size

Before After
JS bundle ~37 KB ~262 KB
CSS file none 74 KB (unminified)

DataViews is bundled into our build. This is a dashboard-only page loaded once per session, so the size is acceptable.

Files

Frontend: new ai-orders-table.js, deleted agent-revenue-table.js, data layer extended with fetchRecentOrders / SET_RECENT_ORDERS / getRecentOrders, colors.link token added.

Backend: new get_recent_orders method in admin controller; removed the wc-components / wc-admin-layout / wc-experimental enqueue loop (no longer needed).

Build/ops: new scripts/copy-dataviews-css.js + postbuild npm script, @wordpress/dataviews promoted to direct devDependency, release workflow excludes scripts/ from the zip.

Docs: AGENTS.md Styling section rewritten — the three-part Woo pattern is replaced with the DataViews recipe and an externalized-vs-bundled table explaining the runtime model difference.

Test plan

  • 42 Jest tests pass
  • 379 PHPUnit / 1075 assertions pass
  • PHPCS clean
  • PHPStan clean
  • ESLint clean
  • Webpack build + postbuild emits both ai-syndication-settings.js AND ai-syndication-settings.css
  • Manual (critical): on your staging store, Overview tab shows the Recent AI Orders table with proper DataViews styling — wc-admin-looking table, pagination controls, sortable columns
  • Manual: the legacy gemini.google.com test order now shows as Gemini (server-side canonicalization)
  • Manual: clicking #{order_number} navigates to the order edit screen

Ships as

Merged to main, not tagged. Queues with PRs #21, #22, #23 behind the next release signal. Should effectively replace PR #24's visible work.

🤖 Generated with Claude Code

Replace the @woocommerce/components TableCard adoption from PR #24
(which rendered DOM but never loaded its CSS on our submenu page)
with @wordpress/dataviews in table-view mode. Also shifts the
section's semantic from "Revenue by Agent" (aggregate, 1 row = 1
agent) to "Recent AI Orders" (per-order list, 1 row = 1 order) so
merchants can act on individual orders without leaving the
dashboard.

## Why DataViews, not Woo TableCard

PR #24 tried to make Woo's TableCard work. The CSS enqueue dance
(wp_style_is('registered') guards for wc-components / wc-admin-layout
/ wc-experimental) failed in practice — the handles aren't
registered on non-wc-admin pages, so the guards silently passed
through and the component rendered unstyled ("1Total orders" with
no spacing, unstyled column headers, etc.).

DataViews sidesteps this entirely. The WP dependency-extraction
plugin lists @wordpress/dataviews in BUNDLED_PACKAGES, so webpack
bundles the JS into our build — no runtime dependency on the
merchant's wc-admin asset registration. The CSS ships via a
postbuild copy step (scripts/copy-dataviews-css.js → build/...css)
and flows through the plugin's existing CSS enqueue path.

## Columns (matching WC Orders convention)

| Order | Date | Status | Agent | Total

- Order: #{number} linked to the order-edit screen (HPOS-aware)
- Date: WC-formatted relative string, ISO in title tooltip
- Status: colored pill using WC's own palette (inline styles because
  wc-admin's .order-status CSS isn't loaded on our page)
- Agent: canonicalized through KNOWN_AGENT_HOSTS server-side so
  legacy orders with raw hostnames (gemini.google.com) display as
  brand names (Gemini). Non-destructive — DB meta stays untouched.
- Total: Intl.NumberFormat currency formatting

## Files at a glance

Frontend:
- client/settings/ai-syndication/ai-orders-table.js (new)
- client/settings/ai-syndication/agent-revenue-table.js (removed)
- client/data/ai-syndication/{actions,reducer,selectors,action-types}.js
  (+fetchRecentOrders, +setRecentOrders, +getRecentOrders,
  +SET_RECENT_ORDERS)
- client/settings/ai-syndication/tokens.js (+colors.link)
- client/settings/ai-syndication/settings-page.js (swap component)

Backend:
- includes/admin/class-wc-ai-syndication-admin-controller.php
  (+get_recent_orders endpoint at /wc/v3/ai-syndication/admin/recent-orders,
  returns normalized shape including canonicalized agent names and
  HPOS-aware edit URLs)
- includes/class-wc-ai-syndication.php (remove wc-components /
  wc-admin-layout / wc-experimental enqueue loop — no longer needed)

Build / ops:
- scripts/copy-dataviews-css.js (new — copies DataViews' stylesheet
  into build/ai-syndication-settings.css; existing PHP enqueue
  picks it up)
- package.json (+postbuild, +@wordpress/dataviews direct dev dep)
- .github/workflows/release.yml (exclude scripts/ from zip)

Docs:
- AGENTS.md Styling section: replace "three-part Woo adoption
  pattern" with DataViews adoption recipe + externalized-vs-bundled
  table. Candidate-migrations list trimmed to what's realistically
  useful.

## Bundle size

Our JS bundle grows from ~37 KB to ~262 KB (DataViews is bundled).
CSS file is 74 KB unminified, served once per admin-page load. For
a dashboard-only surface this is acceptable — merchants don't live
on this page, they visit it once per session.

## Quality gates

42 Jest tests, 379 PHPUnit / 1075 assertions, PHPCS clean, PHPStan
clean, ESLint clean. Ships queued on main, no tag.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@pierorocca pierorocca merged commit 15fb471 into main Apr 18, 2026
7 checks passed
@pierorocca pierorocca deleted the feat/dataviews-ai-orders-table branch April 18, 2026 22:34
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