Pivot to @wordpress/dataviews for the AI Orders table#25
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 forwc-components/wc-admin-layout/wc-experimentalsilently 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)
wc_format_datetimewith the ISO date in a tooltip.order-statusCSS isn't loaded on our page)KNOWN_AGENT_HOSTSserver-side, so legacy orders with raw hostnames (gemini.google.com) display as brand names (Gemini). DB meta is untouched — display-only.Intl.NumberFormatfor locale-aware currencyNew REST endpoint
GET /wc/v3/ai-syndication/admin/recent-orders?per_page=10Returns orders normalized for the DataViews row shape.
wc_get_orders()withmeta_key = AGENT_META_KEYbounds the scan to AI-attributed orders only.Bundle size
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, deletedagent-revenue-table.js, data layer extended withfetchRecentOrders/SET_RECENT_ORDERS/getRecentOrders,colors.linktoken added.Backend: new
get_recent_ordersmethod in admin controller; removed thewc-components/wc-admin-layout/wc-experimentalenqueue loop (no longer needed).Build/ops: new
scripts/copy-dataviews-css.js+postbuildnpm script,@wordpress/dataviewspromoted to direct devDependency, release workflow excludesscripts/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
ai-syndication-settings.jsANDai-syndication-settings.cssgemini.google.comtest order now shows asGemini(server-side canonicalization)#{order_number}navigates to the order edit screenShips 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