Skip to content

Commit 276a802

Browse files
improved types
1 parent d7f8af2 commit 276a802

10 files changed

Lines changed: 38 additions & 57 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const CodePreviewPanel = async ({ path, repoName, revisionName }: CodePre
5252
branchDisplayName={revisionName}
5353
/>
5454

55-
{(fileWebUrl && codeHostInfo) && (
55+
{fileWebUrl && (
5656

5757
<a
5858
href={fileWebUrl}

packages/web/src/app/[domain]/components/navigationMenu/progressIndicator.tsx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants";
1010
import { RepositoryQuery } from "@/lib/types";
1111
import { getCodeHostInfoForRepo, getShortenedNumberDisplayString } from "@/lib/utils";
1212
import clsx from "clsx";
13-
import { FileIcon, Loader2Icon, RefreshCwIcon } from "lucide-react";
13+
import { Loader2Icon, RefreshCwIcon } from "lucide-react";
1414
import Image from "next/image";
1515
import Link from "next/link";
1616
import { useRouter } from "next/navigation";
@@ -90,23 +90,14 @@ const RepoItem = ({ repo }: { repo: RepositoryQuery }) => {
9090
webUrl: repo.webUrl,
9191
});
9292

93-
if (info) {
94-
return {
95-
repoIcon: <Image
96-
src={info.icon}
97-
alt={info.codeHostName}
98-
className={`w-4 h-4 ${info.iconClassName}`}
99-
/>,
100-
displayName: info.displayName,
101-
}
102-
}
103-
10493
return {
105-
repoIcon: <FileIcon className="w-4 h-4" />,
106-
displayName: repo.repoName,
94+
repoIcon: <Image
95+
src={info.icon}
96+
alt={info.codeHostName}
97+
className={`w-4 h-4 ${info.iconClassName}`}
98+
/>,
99+
displayName: info.displayName,
107100
}
108-
109-
110101
}, [repo.repoName, repo.codeHostType, repo.repoDisplayName, repo.webUrl]);
111102

112103

packages/web/src/app/[domain]/components/pathHeader.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use client';
22

33
import { cn, getCodeHostInfoForRepo } from "@/lib/utils";
4-
import { LaptopIcon } from "@radix-ui/react-icons";
54
import Image from "next/image";
65
import { getBrowsePath } from "../browse/hooks/utils";
76
import { ChevronRight, MoreHorizontal } from "lucide-react";
@@ -17,6 +16,7 @@ import { VscodeFileIcon } from "@/app/components/vscodeFileIcon";
1716
import { CopyIconButton } from "./copyIconButton";
1817
import Link from "next/link";
1918
import { useDomain } from "@/hooks/useDomain";
19+
import { CodeHostType } from "@sourcebot/db";
2020

2121
interface FileHeaderProps {
2222
path: string;
@@ -27,7 +27,7 @@ interface FileHeaderProps {
2727
pathType?: 'blob' | 'tree';
2828
repo: {
2929
name: string;
30-
codeHostType: string;
30+
codeHostType: CodeHostType;
3131
displayName?: string;
3232
webUrl?: string;
3333
},
@@ -202,17 +202,13 @@ export const PathHeader = ({
202202
<div className="flex flex-row gap-2 items-center w-full overflow-hidden">
203203
{isCodeHostIconVisible && (
204204
<>
205-
{info?.icon ? (
206-
<a href={info.repoLink} target="_blank" rel="noopener noreferrer">
207-
<Image
208-
src={info.icon}
209-
alt={info.codeHostName}
210-
className={`w-4 h-4 ${info.iconClassName}`}
211-
/>
212-
</a>
213-
) : (
214-
<LaptopIcon className="w-4 h-4" />
215-
)}
205+
<a href={info.repoLink} target="_blank" rel="noopener noreferrer">
206+
<Image
207+
src={info.icon}
208+
alt={info.codeHostName}
209+
className={`w-4 h-4 ${info.iconClassName}`}
210+
/>
211+
</a>
216212
</>
217213
)}
218214

packages/web/src/app/[domain]/components/repositoryCarousel.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
import { captureEvent } from "@/hooks/useCaptureEvent";
99
import { RepositoryQuery } from "@/lib/types";
1010
import { getCodeHostInfoForRepo } from "@/lib/utils";
11-
import { FileIcon } from "@radix-ui/react-icons";
1211
import clsx from "clsx";
1312
import Autoscroll from "embla-carousel-auto-scroll";
1413
import Image from "next/image";
@@ -121,20 +120,13 @@ const RepositoryBadge = ({
121120
webUrl: repo.webUrl,
122121
});
123122

124-
if (info) {
125-
return {
126-
repoIcon: <Image
127-
src={info.icon}
128-
alt={info.codeHostName}
129-
className={`w-4 h-4 ${info.iconClassName}`}
130-
/>,
131-
displayName: info.displayName,
132-
}
133-
}
134-
135123
return {
136-
repoIcon: <FileIcon className="w-4 h-4" />,
137-
displayName: repo.repoName,
124+
repoIcon: <Image
125+
src={info.icon}
126+
alt={info.codeHostName}
127+
className={`w-4 h-4 ${info.iconClassName}`}
128+
/>,
129+
displayName: info.displayName,
138130
}
139131
})();
140132

packages/web/src/app/[domain]/repos/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default async function RepoDetailPage({ params }: { params: Promise<{ id:
6565
<h1 className="text-3xl font-semibold">{repo.displayName || repo.name}</h1>
6666
<p className="text-muted-foreground mt-2">{repo.name}</p>
6767
</div>
68-
{(codeHostInfo && codeHostInfo.repoLink) && (
68+
{codeHostInfo.repoLink && (
6969
<Button variant="outline" asChild>
7070
<Link href={codeHostInfo.repoLink} target="_blank" rel="noopener noreferrer" className="flex items-center">
7171
<Image

packages/web/src/app/[domain]/repos/components/reposTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export const columns: ColumnDef<Repo>[] = [
253253
<DropdownMenuItem asChild>
254254
<Link href={`/${SINGLE_TENANT_ORG_DOMAIN}/repos/${repo.id}`}>View details</Link>
255255
</DropdownMenuItem>
256-
{(repo.webUrl && codeHostInfo) && (
256+
{repo.webUrl && (
257257
<>
258258
<DropdownMenuSeparator />
259259
<DropdownMenuItem asChild>

packages/web/src/features/chat/components/chatThread/referencedFileSourceListItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { createCodeFoldingExtension } from "./codeFoldingExtension";
2020
import useCaptureEvent from "@/hooks/useCaptureEvent";
2121
import { createAuditAction } from "@/ee/features/audit/actions";
2222
import { useDomain } from "@/hooks/useDomain";
23+
import { CodeHostType } from "@sourcebot/db";
2324

2425
const lineDecoration = Decoration.line({
2526
attributes: { class: "cm-range-border-radius chat-lineHighlight" },
@@ -40,7 +41,7 @@ interface ReferencedFileSourceListItemProps {
4041
language: string;
4142
revision: string;
4243
repoName: string;
43-
repoCodeHostType: string;
44+
repoCodeHostType: CodeHostType;
4445
repoDisplayName?: string;
4546
repoWebUrl?: string;
4647
fileName: string;

packages/web/src/features/search/schemas.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @NOTE : Please keep this file in sync with @sourcebot/mcp/src/schemas.ts
2+
import { CodeHostType } from "@sourcebot/db";
23
import { z } from "zod";
34

45
export const locationSchema = z.object({
@@ -33,7 +34,7 @@ export const searchRequestSchema = z.object({
3334

3435
export const repositoryInfoSchema = z.object({
3536
id: z.number(),
36-
codeHostType: z.string(),
37+
codeHostType: z.nativeEnum(CodeHostType),
3738
name: z.string(),
3839
displayName: z.string().optional(),
3940
webUrl: z.string().optional(),
@@ -153,7 +154,7 @@ export const fileSourceResponseSchema = z.object({
153154
language: z.string(),
154155
path: z.string(),
155156
repository: z.string(),
156-
repositoryCodeHostType: z.string(),
157+
repositoryCodeHostType: z.nativeEnum(CodeHostType),
157158
repositoryDisplayName: z.string().optional(),
158159
repositoryWebUrl: z.string().optional(),
159160
branch: z.string().optional(),

packages/web/src/lib/schemas.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { checkIfOrgDomainExists } from "@/actions";
22
import { z } from "zod";
33
import { isServiceError } from "./utils";
44
import { serviceErrorSchema } from "./serviceError";
5+
import { CodeHostType } from "@sourcebot/db";
56

67
export const secretCreateRequestSchema = z.object({
78
key: z.string(),
@@ -13,7 +14,7 @@ export const secreteDeleteRequestSchema = z.object({
1314
});
1415

1516
export const repositoryQuerySchema = z.object({
16-
codeHostType: z.string(),
17+
codeHostType: z.nativeEnum(CodeHostType),
1718
repoId: z.number(),
1819
repoName: z.string(),
1920
repoDisplayName: z.string().optional(),

packages/web/src/lib/utils.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ type CodeHostInfo = {
174174
}
175175

176176
export const getCodeHostInfoForRepo = (repo: {
177-
codeHostType: string,
177+
codeHostType: CodeHostType,
178178
name: string,
179179
displayName?: string,
180180
webUrl?: string,
181-
}): CodeHostInfo | undefined => {
181+
}): CodeHostInfo => {
182182
const { codeHostType, name, displayName, webUrl } = repo;
183183

184184
switch (codeHostType) {
@@ -226,8 +226,7 @@ export const getCodeHostInfoForRepo = (repo: {
226226
iconClassName: className,
227227
}
228228
}
229-
case 'gerrit':
230-
case 'gitiles': {
229+
case 'gerrit': {
231230
const { src, className } = getCodeHostIcon('gerrit')!;
232231
return {
233232
type: "gerrit",
@@ -238,7 +237,7 @@ export const getCodeHostInfoForRepo = (repo: {
238237
iconClassName: className,
239238
}
240239
}
241-
case "bitbucket-server": {
240+
case "bitbucketServer": {
242241
const { src, className } = getCodeHostIcon('bitbucketServer')!;
243242
return {
244243
type: "bitbucketServer",
@@ -249,7 +248,7 @@ export const getCodeHostInfoForRepo = (repo: {
249248
iconClassName: className,
250249
}
251250
}
252-
case "bitbucket-cloud": {
251+
case "bitbucketCloud": {
253252
const { src, className } = getCodeHostIcon('bitbucketCloud')!;
254253
return {
255254
type: "bitbucketCloud",
@@ -260,7 +259,7 @@ export const getCodeHostInfoForRepo = (repo: {
260259
iconClassName: className,
261260
}
262261
}
263-
case "generic-git-host": {
262+
case "genericGitHost": {
264263
const { src, className } = getCodeHostIcon('genericGitHost')!;
265264
return {
266265
type: "genericGitHost",

0 commit comments

Comments
 (0)