-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathindex.tsx
More file actions
148 lines (134 loc) · 5.6 KB
/
index.tsx
File metadata and controls
148 lines (134 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { getConnectionStats, getCurrentUserRole, getOrgAccountRequests, getRepos, getReposStats } from "@/actions";
import { SourcebotLogo } from "@/app/components/sourcebotLogo";
import { auth } from "@/auth";
import { Button } from "@/components/ui/button";
import { NavigationMenu as NavigationMenuBase } from "@/components/ui/navigation-menu";
import { Separator } from "@/components/ui/separator";
import { ServiceErrorException } from "@/lib/serviceError";
import { isServiceError } from "@/lib/utils";
import { OrgRole, RepoIndexingJobStatus, RepoIndexingJobType } from "@sourcebot/db";
import { env } from "@sourcebot/shared";
import Link from "next/link";
import { MeControlDropdownMenu } from "../meControlDropdownMenu";
import WhatsNewIndicator from "../whatsNewIndicator";
import { NavigationItems } from "./navigationItems";
import { ProgressIndicator } from "./progressIndicator";
import { redirect } from "next/navigation";
import { AppearanceDropdownMenu } from "../appearanceDropdownMenu";
export const NavigationMenu = async () => {
const session = await auth();
const isAuthenticated = session?.user !== undefined;
const repoStats = await getReposStats();
if (isServiceError(repoStats)) {
throw new ServiceErrorException(repoStats);
}
const role = isAuthenticated ? await getCurrentUserRole() : null;
if (isServiceError(role)) {
throw new ServiceErrorException(role);
}
const stats = await (async () => {
if (!isAuthenticated || role !== OrgRole.OWNER) {
return null;
}
const joinRequests = await getOrgAccountRequests();
if (isServiceError(joinRequests)) {
throw new ServiceErrorException(joinRequests);
}
const connectionStats = await getConnectionStats();
if (isServiceError(connectionStats)) {
throw new ServiceErrorException(connectionStats);
}
return {
numJoinRequests: joinRequests.length,
connectionStats,
};
})();
const sampleRepos = await getRepos({
where: {
jobs: {
some: {
type: RepoIndexingJobType.INDEX,
status: {
in: [
RepoIndexingJobStatus.PENDING,
RepoIndexingJobStatus.IN_PROGRESS,
]
}
},
},
indexedAt: null,
},
take: 5,
});
if (isServiceError(sampleRepos)) {
throw new ServiceErrorException(sampleRepos);
}
const {
numberOfRepos,
numberOfReposWithFirstTimeIndexingJobsInProgress,
} = repoStats;
return (
<div className="flex flex-col w-full h-fit bg-background">
<div className="flex flex-row justify-between items-center py-0.5 px-3">
<div className="flex flex-row items-center">
<Link
href="/"
className="mr-3 cursor-pointer"
>
<SourcebotLogo
className="h-11"
size="small"
/>
</Link>
<NavigationMenuBase>
<NavigationItems
numberOfRepos={numberOfRepos}
isReposButtonNotificationDotVisible={numberOfReposWithFirstTimeIndexingJobsInProgress > 0}
isSettingsButtonNotificationDotVisible={
stats ? (
stats.connectionStats.numberOfConnectionsWithFirstTimeSyncJobsInProgress > 0 ||
stats.numJoinRequests > 0
) : false
}
isAuthenticated={isAuthenticated}
isAgentsVisible={isAuthenticated && (
!!(env.GITHUB_REVIEW_AGENT_APP_ID && env.GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET && env.GITHUB_REVIEW_AGENT_APP_PRIVATE_KEY_PATH) ||
!!(env.GITLAB_REVIEW_AGENT_WEBHOOK_SECRET && env.GITLAB_REVIEW_AGENT_TOKEN)
)}
/>
</NavigationMenuBase>
</div>
<div className="flex flex-row items-center gap-2">
<ProgressIndicator
numberOfReposWithFirstTimeIndexingJobsInProgress={numberOfReposWithFirstTimeIndexingJobsInProgress}
sampleRepos={sampleRepos}
/>
<WhatsNewIndicator />
{session ? (
<MeControlDropdownMenu
session={session}
/>
) : (
<>
<form
action={async () => {
"use server";
redirect("/login");
}}
>
<Button
variant="outline"
type="submit"
>
Sign in
</Button>
</form>
<AppearanceDropdownMenu />
</>
)}
</div>
</div>
<Separator />
</div>
)
}