Skip to content

Refactor: cwd display label logic is duplicated in App.tsx and Terminal.tsx #36

Description

@KrisPowers

Summary

The logic that converts a full filesystem path into a short two-segment display label (e.g., /home/user/projects/myapp becomes projects/myapp) exists in two different places with the same implementation:

In app/frontend/src/App.tsx (lines 84-89):

functiontabNameFromCwd(cwd: string): string{constparts=cwd.replace(/\/g,'/').replace(/\/$/,'').split('/').filter(Boolean)if(parts.length===0)return'~'if(parts.length===1)returnparts[0]returnparts.slice(-2).join('/')}

In app/frontend/src/components/Terminal.tsx (lines 857-861):

constcwdLabel=React.useMemo(()=>{constparts=cwd.replace(/\/g,'/').split('/').filter(Boolean)if(parts.length===0)return'~'returnparts.length<=2 ? parts.join('/') : parts.slice(-2).join('/')},[cwd])

There are also subtle differences between the two (the App.tsx version strips trailing slashes; the Terminal.tsx version does not and handles 2-part paths differently). This means they can show different labels for the same path.

How to fix

Move the canonical implementation to app/frontend/src/lib/pathUtils.ts (create if it does not exist) and import it in both files:

exportfunctionshortCwd(cwd: string): string{constparts=cwd.replace(/\/g,'/').replace(/\/$/,'').split('/').filter(Boolean)if(parts.length===0)return'~'if(parts.length===1)returnparts[0]returnparts.slice(-2).join('/')}

Files

  • app/frontend/src/App.tsx (lines 84-89, tabNameFromCwd)
  • app/frontend/src/components/Terminal.tsx (lines 857-861, cwdLabel useMemo)
  • New file: app/frontend/src/lib/pathUtils.ts

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions