Skip to content

Frontend: Render the DataView block on public pages#73

Merged
mcsf merged 8 commits into
mainfrom
cortext-frontend-collection-rendering
May 15, 2026
Merged

Frontend: Render the DataView block on public pages#73
mcsf merged 8 commits into
mainfrom
cortext-frontend-collection-rendering

Conversation

@mcsf

@mcsf mcsf commented May 7, 2026

Copy link
Copy Markdown
Member

Summary

Part of #154

  • Add server-side block registration (includes/Block/DataView.php) with a render callback that outputs a hydration container for the DataView block on public pages
  • Open the /cortext/v1/rows REST endpoint to anonymous reads via context=view when the parent collection is published; field definitions now include options for select/multiselect chip rendering
  • Hydrate interactive read-only DataViews on the frontend (PublicDataView, usePublicRows, publicFieldMapping) — no editor dependencies (core-data, dnd-kit, block-editor)
  • Auto-publish referenced collections when a page is published via PublishToggle
  • Add tech-debt items: align classes for public layout; split frontend bundle from page chrome.

Test plan

  • Publish a crtxt_page containing a cortext/data-view block — verify the collection status transitions to publish
  • Visit the public page logged out — DataViews table renders with collection rows
  • Change sort, filter, pagination, and search on the public DataViews — REST calls succeed with context=view
  • Hide/show and reorder fields in View Settings — changes persist within the session
  • Visit a page referencing an unpublished collection — block renders nothing
  • Verify existing editor functionality is unaffected
  • npm run build produces no errors; frontend bundle excludes core-data and dnd-kit
  • All PHP and JS tests pass

🤖 Generated with Claude Code

mcsf and others added 8 commits May 7, 2026 13:50
Whenever a page is published in the Cortext editor, any collections
rendered within will also be marked as published. The Rows REST endpoint
now allows unauthenticated requests to read such collections.

Adds a `render_callback` to Cortext's DataView block that renders a
mount site for a DataViews React island. The island then fetches rows
and fields data via the REST API. Rendering and fetching is mediated by
new helpers like PublicDataView, usePublicRows, etc. Supports
interactions such as filtering data and reordering fields.

Tech debt: CSS, which ignores WP conventions around alignwide, etc.
Right now, Cortext pages have their content's width fixed to 650px,
except for DataView blocks, which take up the full width.

Likely tech debt: duplication of field configurations around
`publicFieldMapping`, etc.
The DataViews view-settings popover needs the wp-components stylesheet
for its background. Add wp-components as a style dependency in both
Assets.php and the render callback.

Also document tech-debt.md#43: the DataView block should provision its
own script/style handles instead of sharing cortext-frontend with page
chrome.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Resolve two conflicts:

- includes/Plugin.php: page-cover/page-icon blocks were renamed to
  document-cover/document-icon on main. Keep the renames and add the
  new Block\DataView import + registration from this branch.

- docs/tech-debt.md: both sides added entries starting at 42. Keep
  main's 42–47 in place; renumber this branch's two entries to 48 and
  49.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PHPCS disallows short ternaries. Use the full form so the meta options
default falls back to null when get_post_meta returns an empty value.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- PublicDataView.js, frontend.js: prettier reformatting to match the
  repo style.
- publicFieldMapping.js: align the @param block by padding type and
  name columns to the widest entry.
- PublishToggle.js: add the missing @param doc for getCollectionIds.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mcsf mcsf force-pushed the cortext-frontend-collection-rendering branch from dc05bc7 to 860209f Compare May 15, 2026 13:08
@mcsf

mcsf commented May 15, 2026

Copy link
Copy Markdown
Member Author

@priethor: I refreshed this PR. It's a mouthful and it has a bunch of imperfections, but I think we should just iterate. Feel free to revert, but I'm going to merge :)

@mcsf mcsf merged commit c8c9a24 into main May 15, 2026
9 checks passed
@mcsf mcsf deleted the cortext-frontend-collection-rendering branch May 15, 2026 13:30
@priethor

Copy link
Copy Markdown
Collaborator

Nice, let's go and iterate! I'll give it a spin 🙂

@priethor priethor added this to the 0.1.0 milestone May 28, 2026
@priethor priethor added type: enhancement Improvement to existing behavior. area: publishing Public rendering through WordPress, templates, frontend block output, and theme-facing views. labels May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: publishing Public rendering through WordPress, templates, frontend block output, and theme-facing views. type: enhancement Improvement to existing behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants