Skip to content

feat(admin): add code export modal for collections (#825)#831

Merged
lane711 merged 2 commits into
mainfrom
lane711/sonicjs-pr-825
May 9, 2026
Merged

feat(admin): add code export modal for collections (#825)#831
lane711 merged 2 commits into
mainfrom
lane711/sonicjs-pr-825

Conversation

@lane711
Copy link
Copy Markdown
Collaborator

@lane711 lane711 commented May 8, 2026

Internal mirror of #825 by @furelid so CI can run without the fork-authorization gate. Once green and any review fixes are stacked on top, this can be merged in place of #825.

Summary

Adds an Export button to the admin collection edit form that opens a modal showing the collection's configuration as a CollectionConfig TypeScript snippet, with copy-to-clipboard.

Changes

  • packages/core/src/templates/pages/admin-collections-form.template.ts — Export button, modal markup, fetch + JSON-render + copy logic, snake→camel key normalization.

Provenance

Cherry-picked from furelid:feature/collection-export @ e4e2e48. Original PR: #825.

Review notes / known follow-ups

  • Button currently renders on Create as well as Edit — should be gated on data.isEdit || data.id.
  • SVG icon uses hardcoded stroke="#000000" on a black button — invisible in light mode; should use currentColor.
  • let collectionName = '${data.name || ''}' is unsafe interpolation into JS context; prefer JSON.stringify.
  • Uses deprecated document.execCommand('copy'); navigator.clipboard.writeText() is the modern path.
  • Strip-list in normalizeCollectionObject leaves fields (id, lastSyncedAt, etc.) that aren't on CollectionConfig, so satisfies CollectionConfig will TS-error when pasted.

🤖 Generated with Claude Code

Added a modal for exporting collection code, including a button to trigger the modal and functionality to copy export options to the clipboard.
- Render export button + modal only on edit (need a name to fetch)
- Use currentColor on export icon (was invisible on light-mode button)
- JSON-stringify the embedded collection name to avoid breaking the script on quotes
- Escape display_name in the modal HTML
- Prefer navigator.clipboard.writeText with execCommand fallback
- Drop id from the exported snake→camel result so it satisfies CollectionConfig
- encodeURIComponent the collection name in the fetch URL
- Wrap script in IIFE to avoid leaking helpers to window

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@lane711 lane711 merged commit f0d1c0b into main May 9, 2026
2 checks passed
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.

2 participants