Skip to content

[trees] Add a labels option for localizing tree text - #1272

Merged
unknwon merged 1 commit into
pierrecomputer:mainfrom
unknwon:jc/trees-labels
Nov 7, 2026
Merged

unknwon merged 1 commit into
pierrecomputer:mainfrom
unknwon:jc/trees-labels

Conversation

@unknwon

@unknwon unknwon commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a labels tree option and a setLabels() model method for the user-visible text the tree renders:

interface FileTreeLabels {
  searchPlaceholder: string; // "Search…"
  contextMenuTrigger: string; // aria-label "Options"
  renameItem: (itemName: string) => string; // aria-label "Rename <name>"
  gitStatusTitles: Readonly<Record<GitStatus, string>>; // "Git status: added", …
  containsGitStatusTitle: string; // "Contains git status items"
}

labels?: FileTreeLabelsOption; // every label optional, including each git status title
  • Every label falls back to its English default from the new DEFAULT_FILE_TREE_LABELS export, one key (and one git status) at a time, so existing output is unchanged.
  • setLabels() follows setIcons() and setGitStatus(): it stores the resolved labels and re-renders the mounted tree in place. React callers use it through the model like the other runtime setters, since useFileTree reads options once.
  • preloadFileTree renders the labels into SSR markup. Both it and the constructor pull labels out before the remaining options reach the controller.
  • The English git status titles moved from gitStatusPresentation.ts into the defaults so the text lives in one place. The A/D/M/R/U badge letters stay as they are, since they follow git's own convention.
  • Rename validation errors from renameFileTreePaths are left as is. They are returned to callers rather than rendered by the tree, so error codes may serve callers better than more labels. Happy to follow up if you prefer otherwise.

Motivation & Context

These strings are hard-coded in English inside the shadow root, so apps that localize their UI cannot translate the search placeholder, accessible names, or git status tooltips. Gogs renders the tree beside localized UI and currently has no way to translate them.

Opening as a draft to discuss the API shape before it is considered for merge. A companion PR adds the same option to @pierre/diffs: #1271.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality). You must have
    first discussed with the dev team and they should be aware that this PR is
    being opened
  • Breaking change (fix or feature that would change existing functionality).
    You must have first discussed with the dev team and they should be aware
    that this PR is being opened
  • Documentation update

Checklist

  • I have read the
    contributing guidelines
  • My code follows the code style of the project (moon run root:lint)
  • My code is formatted properly (moon run root:format)
  • I have updated the documentation accordingly (if applicable)
  • I have added tests to cover my changes (if applicable)
  • All new and existing tests pass (moonx trees:test)

The local moon (2.6.5) is outside the pinned ~2.3.3, so I ran the underlying commands directly: oxfmt, oxlint --type-aware (0 warnings, 0 errors on changed files), tsc --noEmit for packages/trees (clean), and bun test (333 pass, 0 fail, including the four new tests in file-tree-labels.test.ts). The Playwright suite was not run.

How was AI used in generating this PR

Drafted with Claude Code (Claude Opus 5.5), including the code, tests, docs, and this description.

Related issues

None filed.

@vercel

vercel Bot commented Nov 7, 2026

Copy link
Copy Markdown

@unknwon is attempting to deploy a commit to the Pierre Computer Company Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
vercel Bot temporarily deployed to Preview – pierrejs-diff-demo November 7, 2026 18:21 Inactive
@vercel

vercel Bot commented Nov 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
pierrejs-diff-demo Skipped Skipped Nov 7, 2026 6:21pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T18:54:41.805950Z 1d8091a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1d8091a4b4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

FileTreeLabelsOption,
} from '../model/publicTypes';

export const DEFAULT_FILE_TREE_LABELS: FileTreeLabels = Object.freeze({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Expose the frozen label defaults as readonly

When a TypeScript consumer customizes the exported defaults in place (for example, by assigning DEFAULT_FILE_TREE_LABELS.searchPlaceholder before passing it as labels), the declared mutable FileTreeLabels type lets the assignment compile, but the top-level Object.freeze makes it throw at runtime in ESM. Expose this constant as Readonly<FileTreeLabels> (or stop freezing it) so its public type matches its runtime behavior.

Useful? React with 👍 / 👎.

@unknwon
unknwon merged commit c24c152 into pierrecomputer:main Nov 7, 2026
5 of 8 checks passed
kclejeune pushed a commit to kclejeune/pierre that referenced this pull request Nov 19, 2026

This branch was previously deployed

1 inactive deployment
Preview – pierrejs-diff-demo — 1d8091a4 Deployed Nov 7, 2026 by vercel[bot]
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