Skip to content

Collections: Add inline collection creation to the DataView block#27

Merged
priethor merged 4 commits into
mainfrom
priethor/add/dataview-create
Apr 28, 2026
Merged

Collections: Add inline collection creation to the DataView block#27
priethor merged 4 commits into
mainfrom
priethor/add/dataview-create

Conversation

@priethor

@priethor priethor commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

What

Closes #97

Adds an inline way to create a collection from the DataView block placeholder, backed by a new cortext/v1/collections REST endpoint that creates the collection from just a title.

Why

Today, inserting a Collection view means leaving the editor to create the collection first, then coming back to pick it. This makes it a single step.

How

  • Adding a CollectionsController that turns the title into a unique, CPT-safe slug, inserts the crtxt_collection post, and registers the row CPT during the same request so the response can return a working restBase. Slug derivation reads existing slugs once and falls back to numeric suffixes when the desired slug is reserved, already taken, or would push past the 20-character post-type limit.

  • Reworking the block placeholder so the picker and a "Create collection" form sit together, and adding a toolbar dropdown to swap the active collection without removing the block. Splitting out invalid and error states in CollectionDataViews so a deleted collection or a failed row fetch shows a notice instead of an empty table. Pulling the collection list query into a shared constant so the sidebar and the block share a cache entry.

Testing Instructions

  1. Insert a Collection view block on a page that has no collections yet.
  2. Type a name, click "Create collection", and check that a data view renders for the new (empty) collection and that it shows up in the sidebar.
  3. Reload the page and check the saved collectionId resolves.
  4. From the block toolbar, open "Change collection" and pick a different one.
  5. Delete a collection that a saved block references, reopen the page, and check for the "no longer available" notice.
  6. Try titles that collide with reserved slugs ("Page", "Fields") or run longer than 14 characters. The slug should be auto-suffixed and stay inside the CPT length limit.
  7. Run composer test -- --filter=Test_Rest_Collections_Controller and the data-view-block.spec.js Playwright spec.
Grabacion.de.pantalla.2026-04-28.a.las.0.24.02.mov

@priethor priethor self-assigned this Apr 28, 2026
@priethor priethor merged commit fb5e6e3 into main Apr 28, 2026
6 checks passed
@mcsf mcsf deleted the priethor/add/dataview-create branch April 29, 2026 12:53
@priethor priethor added this to the 0.1.0 milestone May 28, 2026
@priethor priethor added type: enhancement Improvement to existing behavior. area: collections Fields, rows, views, DataViews, relations, rollups, formulas, and row properties. labels May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: collections Fields, rows, views, DataViews, relations, rollups, formulas, and row properties. type: enhancement Improvement to existing behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create collections from the DataViews block

1 participant