Skip to content

Commit 0173774

Browse files
committed
minor refactoring and adding changelog.
1 parent 785a077 commit 0173774

File tree

3 files changed

+40
-43
lines changed

3 files changed

+40
-43
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
<!-- @NOTE: On next release, please bump the MCP pacakge as there are breaking changes in this! -->
1111

12+
### Added
13+
- Implement dynamic tab titles for files and folders in browse tab. [#560](https://github.com/sourcebot-dev/sourcebot/pull/560)
14+
1215
### Fixed
1316
- Fixed "dubious ownership" errors when cloning / fetching repos. [#553](https://github.com/sourcebot-dev/sourcebot/pull/553)
1417

packages/web/src/app/[domain]/browse/[...path]/page.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,43 @@ import { CodePreviewPanel } from "./components/codePreviewPanel";
44
import { Loader2 } from "lucide-react";
55
import { TreePreviewPanel } from "./components/treePreviewPanel";
66
import { Metadata } from "next";
7-
import { parsePathForTitle} from "@/lib/utils";
7+
8+
/**
9+
* Parses the URL path to generate a descriptive title.
10+
* It handles three cases:
11+
* 1. File view (`blob`): "filename.ts - owner/repo"
12+
* 2. Directory view (`tree`): "directory/ - owner/repo"
13+
* 3. Repository root: "owner/repo"
14+
*
15+
* @param path The array of path segments from Next.js params.
16+
* @returns A formatted title string.
17+
*/
18+
export const parsePathForTitle = (path: string[]): string => {
19+
const pathParam = path.join('/');
20+
21+
const { repoName, revisionName, path: filePath, pathType } = getBrowseParamsFromPathParam(pathParam);
22+
23+
// Build the base repository and revision string.
24+
const cleanRepoName = repoName.split('/').slice(1).join('/'); // Remove the version control system prefix
25+
const repoAndRevision = `${cleanRepoName}${revisionName ? ` @ ${revisionName}` : ''}`;
26+
27+
switch (pathType) {
28+
case 'blob': {
29+
// For blobs, get the filename from the end of the path.
30+
const fileName = filePath.split('/').pop() || filePath;
31+
return `${fileName} - ${repoAndRevision}`;
32+
}
33+
case 'tree': {
34+
// If the path is empty, it's the repo root.
35+
if (filePath === '' || filePath === '/') {
36+
return repoAndRevision;
37+
}
38+
// Otherwise, show the directory path.
39+
const directoryPath = filePath.endsWith('/') ? filePath : `${filePath}/`;
40+
return `${directoryPath} - ${repoAndRevision}`;
41+
}
42+
}
43+
}
844

945
type Props = {
1046
params: Promise<{
@@ -21,8 +57,6 @@ export async function generateMetadata({ params: paramsPromise }: Props): Promis
2157
title = parsePathForTitle(params.path);
2258

2359
} catch (error) {
24-
// TODO: Maybe I need to look into a better way of handling this error.
25-
// for now, it is just a log, fallback tab title and prevents the app from crashing.
2660
console.error("Failed to generate metadata title from path:", error);
2761
}
2862

packages/web/src/lib/utils.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -487,44 +487,4 @@ export const isHttpError = (error: unknown, status: number): boolean => {
487487
&& typeof error === 'object'
488488
&& 'status' in error
489489
&& error.status === status;
490-
}
491-
492-
/**
493-
* Parses the URL path to generate a descriptive title.
494-
* It handles three cases:
495-
* 1. File view (`blob`): "filename.ts - owner/repo"
496-
* 2. Directory view (`tree`): "directory/ - owner/repo"
497-
* 3. Repository root: "owner/repo"
498-
*
499-
* @param path The array of path segments from Next.js params.
500-
* @returns A formatted title string.
501-
*/
502-
export const parsePathForTitle = (path: string[]): string => {
503-
const pathParam = path.join('/');
504-
505-
const { repoName, revisionName, path: filePath, pathType } = getBrowseParamsFromPathParam(pathParam);
506-
507-
// Build the base repository and revision string.
508-
const cleanRepoName = repoName.split('/').slice(1).join('/'); // Remove the version control system prefix
509-
const repoAndRevision = `${cleanRepoName}${revisionName ? ` @ ${revisionName}` : ''}`;
510-
511-
switch (pathType) {
512-
case 'blob': {
513-
// For blobs, get the filename from the end of the path.
514-
const fileName = filePath.split('/').pop() || filePath;
515-
return `${fileName} - ${repoAndRevision}`;
516-
}
517-
case 'tree': {
518-
// If the path is empty, it's the repo root.
519-
if (filePath === '' || filePath === '/') {
520-
return repoAndRevision;
521-
}
522-
// Otherwise, show the directory path.
523-
const directoryPath = filePath.endsWith('/') ? filePath : `${filePath}/`;
524-
return `${directoryPath} - ${repoAndRevision}`;
525-
}
526-
default:
527-
// Fallback to just the repository name.
528-
return repoAndRevision;
529-
}
530490
}

0 commit comments

Comments
 (0)