mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(frontend): add mobile composer tools menu and base branch select
This commit is contained in:
1 parent
fac23b1f1a
commit
4a2e695ec2
21 files changed
+819
-158
No files matched your search
@@ -5,6 +5,7 @@ import {
|
||||
sanitizeForTTS,
|
||||
randomId,
|
||||
formatShortRelativeTime,
|
||||
getOriginOnlyBranchNames,
|
||||
} from './utils'
|
||||
|
||||
describe('sanitizeForTTS', () => {
|
||||
@@ -89,6 +90,59 @@ describe('sanitizeForTTS', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getOriginOnlyBranchNames', () => {
|
||||
it('returns short names for origin remote branches without a local branch', () => {
|
||||
expect(
|
||||
getOriginOnlyBranchNames([
|
||||
{ name: 'main', type: 'local' },
|
||||
{ name: 'remotes/origin/release', type: 'remote' },
|
||||
]),
|
||||
).toEqual(['release'])
|
||||
})
|
||||
|
||||
it('excludes remote branches shadowed by a local branch', () => {
|
||||
expect(
|
||||
getOriginOnlyBranchNames([
|
||||
{ name: 'release', type: 'local' },
|
||||
{ name: 'remotes/origin/release', type: 'remote' },
|
||||
]),
|
||||
).toEqual([])
|
||||
})
|
||||
|
||||
it('excludes non-origin remotes', () => {
|
||||
expect(
|
||||
getOriginOnlyBranchNames([
|
||||
{ name: 'remotes/upstream/release', type: 'remote' },
|
||||
{ name: 'remotes/origin/release', type: 'remote' },
|
||||
]),
|
||||
).toEqual(['release'])
|
||||
})
|
||||
|
||||
it('excludes HEAD', () => {
|
||||
expect(
|
||||
getOriginOnlyBranchNames([
|
||||
{ name: 'remotes/origin/HEAD', type: 'remote' },
|
||||
{ name: 'remotes/origin/main', type: 'remote' },
|
||||
]),
|
||||
).toEqual(['main'])
|
||||
})
|
||||
|
||||
it('excludes empty short names', () => {
|
||||
expect(getOriginOnlyBranchNames([{ name: 'remotes/origin/', type: 'remote' }])).toEqual([])
|
||||
})
|
||||
|
||||
it('dedupes while preserving input order', () => {
|
||||
expect(
|
||||
getOriginOnlyBranchNames([
|
||||
{ name: 'remotes/origin/zeta', type: 'remote' },
|
||||
{ name: 'remotes/origin/alpha', type: 'remote' },
|
||||
{ name: 'remotes/origin/zeta', type: 'remote' },
|
||||
{ name: 'remotes/origin/beta', type: 'remote' },
|
||||
]),
|
||||
).toEqual(['zeta', 'alpha', 'beta'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('randomId', () => {
|
||||
const originalRandomUUID = globalThis.crypto?.randomUUID
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
import type { CSSProperties } from "react"
|
||||
import type { Repo } from "@/api/types"
|
||||
import type { GitBranch } from "@/api/repos"
|
||||
|
||||
export { getRepoDisplayName } from '@opencode-manager/shared/utils'
|
||||
|
||||
@@ -9,6 +10,25 @@ export function getRepoBranchLabel(repo: Pick<Repo, 'currentBranch' | 'branch'>)
|
||||
return repo.currentBranch || repo.branch || null
|
||||
}
|
||||
|
||||
const ORIGIN_REMOTE_PREFIX = 'remotes/origin/'
|
||||
|
||||
export function getOriginOnlyBranchNames(branches: Pick<GitBranch, 'name' | 'type'>[]): string[] {
|
||||
const localNames = new Set(branches.filter((b) => b.type === 'local').map((b) => b.name))
|
||||
const seen = new Set<string>()
|
||||
const result: string[] = []
|
||||
|
||||
for (const branch of branches) {
|
||||
if (branch.type !== 'remote' || !branch.name.startsWith(ORIGIN_REMOTE_PREFIX)) continue
|
||||
const shortName = branch.name.slice(ORIGIN_REMOTE_PREFIX.length)
|
||||
if (shortName.length === 0 || shortName === 'HEAD') continue
|
||||
if (localNames.has(shortName) || seen.has(shortName)) continue
|
||||
seen.add(shortName)
|
||||
result.push(shortName)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user