Skip to content

feat: add "Import as template" to File Tree context menu#602

Open
Adityakk9031 wants to merge 2 commits into
inkeep:mainfrom
Adityakk9031:#590
Open

feat: add "Import as template" to File Tree context menu#602
Adityakk9031 wants to merge 2 commits into
inkeep:mainfrom
Adityakk9031:#590

Conversation

@Adityakk9031

Copy link
Copy Markdown

Resolves #590

Description

This PR addresses the feature request to easily convert existing documents into templates. It adds an Import as template option directly to the right-click context menu of standard markdown files in the File Tree.

Users can now choose to:

  • Keep original file: Copies the content and its frontmatter directly into a new template within .ok/templates/.
  • Convert (delete original): Copies the file to the templates directory and safely removes the source document, updating the UI automatically.

Changes Made

  • API (Core & Server): Added a secure POST /api/template/import endpoint (handleTemplateImport) which atomically extracts the source file's frontmatter, manages potential disk/sync conflicts, and persists the new template.
  • Frontend (FileTree.tsx & Client API): Added the nested context menu items using the Lucide FileKey icon, bound them to a new importTemplate client wrapper, and handled immediate UI state cleanups (closing open tabs and removing deleted source files from the view).
  • Changeset: Added a patch changeset for the release notes.

@CLAassistant

CLAassistant commented Jul 10, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Adityakk9031
❌ tim-inkeep
You have signed the CLA already but the status is still pending? Let us recheck it.

@tim-inkeep tim-inkeep self-assigned this Jul 15, 2026
@itsmistermoon

itsmistermoon commented Jul 17, 2026

Copy link
Copy Markdown

Why is this being ignored 😭 it's the one thing I've been waiting to use OK

@tim-inkeep

Copy link
Copy Markdown
Contributor

Hey @itsmistermoon, not ignoring it! This one's on me to review. @Adityakk9031 put together a real implementation here, so we want to give it a proper look rather than rush it. Will follow up on the PR shortly.

@tim-inkeep
tim-inkeep self-requested a review July 17, 2026 20:54
Adityakk9031 and others added 2 commits July 17, 2026 17:17
Fixups on top of the "Import as template" feature so it compiles and clears CI:

- Restore handleTemplateMove's closing: the new handler splice dropped its
  `},` plus `{ handler: 'template-move', method: 'POST' }` options argument,
  which broke the parse of api-extension.ts (whole server failed to build).
- Add 'template-import' to checkTemplateConflictGate's handler union (typecheck).
- Register handleTemplateImport in the route meta-tests: REQUIRED in
  conflict-gate-coverage (it calls respondDocInConflict), EXEMPT in
  attribution-sweep-coverage (single-file-mode guard emits before identity).
- Extract Lingui catalogs for the new UI strings (en + pseudo).
- Add a changeset; tidy the empty catch and name fallback for lint.

Co-authored-by: Aditya kumar singh <143548997+Adityakk9031@users.noreply.github.com>
@tim-inkeep

Copy link
Copy Markdown
Contributor

Thanks for this @Adityakk9031 — really useful feature and it maps cleanly onto how folder templates already work. I pushed a few commits to the branch to get it building and through our CI gates (the handler insertion had accidentally dropped the tail of handleTemplateMove, so the server package wasn't compiling; also added the i18n catalog extraction, route meta-test registrations, and a changeset, then rebased on main).

Two design questions before we merge:

1. The source title bakes into every instance. The import copies the source doc's frontmatter into the template's instantiated body, so title gets carried in — every new doc created from this template inherits the original file's exact title (make a template from "Q3 Planning" and every doc created from it is titled "Q3 Planning"). For a reusable template that's usually not what you want. Could we drop title from the instantiated frontmatter (keep it only in the template identity block) or make it a placeholder? Carrying description/tags over is fine.

@tim-inkeep

Copy link
Copy Markdown
Contributor

2. "Convert (delete original)" deletes the source with no confirmation. It's one click inside a submenu and irreversible from the UI. Could we gate it behind a confirm step (reusing the existing delete-confirmation dialog)? "Keep original" is safe as-is; it's just the convert path that needs the guard.

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.

[Feature]: Allow drag-and-drop or import existing files as templates

4 participants