Files
kandev/apps/web/components/task/editor-worktree-options.ts
T
João Salavisa 5257dfbaab fix(web): close the i18n coverage gaps in the non-JSX scanner and locale catalogs (#2727)
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 23:03:29 +00:00

33 lines
1023 B
TypeScript

import type { Worktree } from "@/lib/state/slices/session/types";
import type { Repository } from "@/lib/types/http";
import { t } from "@/lib/i18n";
export type WorktreeOption = {
worktreeId: string;
label: string;
branch?: string;
};
function worktreePathBasename(path: string | undefined): string | undefined {
if (!path) return undefined;
return path.split(/[\\/]/).filter(Boolean).pop();
}
/**
* Builds display options for a session's worktrees: labeled by repository name
* when known, otherwise by the worktree folder name.
*/
export function buildWorktreeOptions(
worktrees: Worktree[],
repositories: Repository[],
): WorktreeOption[] {
return worktrees.map((worktree, index) => {
const repository = repositories.find((repo) => repo.id === worktree.repositoryId);
const label =
repository?.name ??
worktreePathBasename(worktree.path) ??
t("task:worktreeNumbered", { index: index + 1 });
return { worktreeId: worktree.id, label, branch: worktree.branch };
});
}