@tscircuit/fake-snippets 0.0.104 → 0.0.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/generated-index.js +1 -1
- package/bun-tests/fake-snippets-api/routes/package_builds/get.test.ts +294 -0
- package/bun-tests/fake-snippets-api/routes/package_builds/list.test.ts +304 -0
- package/dist/bundle.js +864 -390
- package/dist/index.d.ts +142 -4
- package/dist/index.js +175 -6
- package/dist/schema.d.ts +198 -1
- package/dist/schema.js +28 -1
- package/fake-snippets-api/lib/db/db-client.ts +51 -3
- package/fake-snippets-api/lib/db/schema.ts +28 -0
- package/fake-snippets-api/lib/db/seed.ts +125 -2
- package/fake-snippets-api/lib/public-mapping/public-map-package-build.ts +41 -0
- package/fake-snippets-api/routes/api/github/repos/refresh.ts +44 -0
- package/fake-snippets-api/routes/api/package_builds/get.ts +70 -0
- package/fake-snippets-api/routes/api/package_builds/latest.ts +109 -0
- package/fake-snippets-api/routes/api/package_builds/list.ts +98 -0
- package/package.json +1 -1
- package/src/App.tsx +2 -1
- package/src/components/ViewPackagePage/components/sidebar-releases-section.tsx +8 -7
- package/src/components/dialogs/GitHubRepositorySelector.tsx +185 -52
- package/src/components/preview/BuildsList.tsx +267 -188
- package/src/components/preview/ConnectedPackagesList.tsx +36 -24
- package/src/components/preview/ConnectedRepoDashboard.tsx +19 -13
- package/src/components/preview/ConnectedRepoOverview.tsx +52 -34
- package/src/components/preview/index.tsx +13 -73
- package/src/hooks/use-package-builds.ts +135 -0
- package/src/pages/view-connected-repo.tsx +38 -7
|
@@ -10,15 +10,12 @@ import {
|
|
|
10
10
|
} from "@/components/ui/dropdown-menu"
|
|
11
11
|
import {
|
|
12
12
|
Activity,
|
|
13
|
-
Settings,
|
|
14
13
|
List,
|
|
15
14
|
Github,
|
|
16
15
|
MoreHorizontal,
|
|
17
16
|
Zap,
|
|
18
17
|
Clock,
|
|
19
18
|
GitBranch,
|
|
20
|
-
Hash,
|
|
21
|
-
User,
|
|
22
19
|
Eye,
|
|
23
20
|
} from "lucide-react"
|
|
24
21
|
import { useLocation } from "wouter"
|
|
@@ -26,22 +23,25 @@ import { ConnectedRepoOverview } from "./ConnectedRepoOverview"
|
|
|
26
23
|
import { BuildsList } from "./BuildsList"
|
|
27
24
|
import Header from "../Header"
|
|
28
25
|
import { formatTimeAgo } from "@/lib/utils/formatTimeAgo"
|
|
26
|
+
import { getBuildStatus } from "."
|
|
27
|
+
import { PrefetchPageLink } from "../PrefetchPageLink"
|
|
29
28
|
import {
|
|
30
|
-
|
|
29
|
+
Package,
|
|
31
30
|
PackageBuild,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} from "."
|
|
35
|
-
import { PrefetchPageLink } from "../PrefetchPageLink"
|
|
31
|
+
PackageRelease,
|
|
32
|
+
} from "fake-snippets-api/lib/db/schema"
|
|
36
33
|
|
|
37
34
|
export const ConnectedRepoDashboard = ({
|
|
38
35
|
latestBuild,
|
|
36
|
+
pkg,
|
|
37
|
+
packageRelease,
|
|
39
38
|
}: {
|
|
40
39
|
latestBuild: PackageBuild
|
|
40
|
+
pkg: Package
|
|
41
|
+
packageRelease: PackageRelease
|
|
41
42
|
}) => {
|
|
42
43
|
const [activeTab, setActiveTab] = useState("overview")
|
|
43
44
|
const [, setLocation] = useLocation()
|
|
44
|
-
const pkg = getPackageFromBuild(latestBuild)
|
|
45
45
|
const handleSelectBuild = (build: PackageBuild) => {
|
|
46
46
|
setLocation(`/build/${build.package_build_id}`)
|
|
47
47
|
setActiveTab("overview")
|
|
@@ -115,7 +115,7 @@ export const ConnectedRepoDashboard = ({
|
|
|
115
115
|
<Clock className="w-4 h-4 flex-shrink-0" />
|
|
116
116
|
<span>
|
|
117
117
|
<time dateTime={latestBuild.created_at}>
|
|
118
|
-
Last
|
|
118
|
+
Last built {formatTimeAgo(latestBuild.created_at)}
|
|
119
119
|
</time>
|
|
120
120
|
</span>
|
|
121
121
|
</div>
|
|
@@ -161,8 +161,8 @@ export const ConnectedRepoDashboard = ({
|
|
|
161
161
|
className="flex items-center gap-2 justify-center min-w-[120px] h-9 bg-black text-white"
|
|
162
162
|
>
|
|
163
163
|
<Zap className="w-4 h-4" />
|
|
164
|
-
<span className="hidden sm:inline">
|
|
165
|
-
<span className="sm:hidden">
|
|
164
|
+
<span className="hidden sm:inline">Rebuild</span>
|
|
165
|
+
<span className="sm:hidden">Rebuild</span>
|
|
166
166
|
</Button>
|
|
167
167
|
<DropdownMenu>
|
|
168
168
|
<DropdownMenuTrigger asChild>
|
|
@@ -229,7 +229,13 @@ export const ConnectedRepoDashboard = ({
|
|
|
229
229
|
</TabsList>
|
|
230
230
|
|
|
231
231
|
<TabsContent value="overview" className="space-y-6">
|
|
232
|
-
{latestBuild &&
|
|
232
|
+
{latestBuild && (
|
|
233
|
+
<ConnectedRepoOverview
|
|
234
|
+
build={latestBuild}
|
|
235
|
+
pkg={pkg}
|
|
236
|
+
packageRelease={packageRelease}
|
|
237
|
+
/>
|
|
238
|
+
)}
|
|
233
239
|
</TabsContent>
|
|
234
240
|
|
|
235
241
|
<TabsContent value="builds" className="space-y-6">
|
|
@@ -11,22 +11,30 @@ import {
|
|
|
11
11
|
ChevronRight,
|
|
12
12
|
User,
|
|
13
13
|
Hash,
|
|
14
|
+
GitCommit,
|
|
14
15
|
} from "lucide-react"
|
|
15
16
|
import {
|
|
16
17
|
Collapsible,
|
|
17
18
|
CollapsibleContent,
|
|
18
19
|
CollapsibleTrigger,
|
|
19
20
|
} from "@/components/ui/collapsible"
|
|
20
|
-
import { getBuildStatus,
|
|
21
|
+
import { getBuildStatus, StatusIcon } from "."
|
|
21
22
|
import { formatTimeAgo } from "@/lib/utils/formatTimeAgo"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
import {
|
|
24
|
+
Package,
|
|
25
|
+
PackageBuild,
|
|
26
|
+
PackageRelease,
|
|
27
|
+
} from "fake-snippets-api/lib/db/schema"
|
|
26
28
|
|
|
27
29
|
export const ConnectedRepoOverview = ({
|
|
28
30
|
build,
|
|
29
|
-
|
|
31
|
+
pkg,
|
|
32
|
+
packageRelease,
|
|
33
|
+
}: {
|
|
34
|
+
build: PackageBuild
|
|
35
|
+
pkg: Package
|
|
36
|
+
packageRelease: PackageRelease
|
|
37
|
+
}) => {
|
|
30
38
|
const { status, label } = getBuildStatus(build)
|
|
31
39
|
const [openSections, setOpenSections] = useState({
|
|
32
40
|
transpilation: false,
|
|
@@ -52,9 +60,9 @@ export const ConnectedRepoOverview = ({
|
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
const getStepStatus = (
|
|
55
|
-
error
|
|
56
|
-
completed
|
|
57
|
-
inProgress
|
|
63
|
+
error?: string | null,
|
|
64
|
+
completed?: string | null,
|
|
65
|
+
inProgress?: boolean,
|
|
58
66
|
) => {
|
|
59
67
|
if (error) return "error"
|
|
60
68
|
if (completed) return "success"
|
|
@@ -63,8 +71,8 @@ export const ConnectedRepoOverview = ({
|
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
const getStepDuration = (
|
|
66
|
-
started
|
|
67
|
-
completed
|
|
74
|
+
started?: string | null,
|
|
75
|
+
completed?: string | null,
|
|
68
76
|
) => {
|
|
69
77
|
if (started && completed) {
|
|
70
78
|
const duration = Math.floor(
|
|
@@ -85,11 +93,13 @@ export const ConnectedRepoOverview = ({
|
|
|
85
93
|
<div className="flex-1">
|
|
86
94
|
<div className="flex flex-col sm:flex-row sm:items-center sm:gap-3">
|
|
87
95
|
<h1 className="text-xl sm:text-2xl font-semibold text-gray-900">
|
|
88
|
-
|
|
96
|
+
Build {label}
|
|
89
97
|
</h1>
|
|
90
98
|
</div>
|
|
91
99
|
<p className="text-sm text-gray-600 mt-1">
|
|
92
|
-
|
|
100
|
+
<time dateTime={build.created_at}>
|
|
101
|
+
Built {formatTimeAgo(build.created_at)}
|
|
102
|
+
</time>
|
|
93
103
|
</p>
|
|
94
104
|
</div>
|
|
95
105
|
</div>
|
|
@@ -101,7 +111,7 @@ export const ConnectedRepoOverview = ({
|
|
|
101
111
|
onClick={() => window.open(build.preview_url!, "_blank")}
|
|
102
112
|
>
|
|
103
113
|
<ExternalLink className="w-3 h-3" />
|
|
104
|
-
Preview
|
|
114
|
+
Preview Build
|
|
105
115
|
</Button>
|
|
106
116
|
)}
|
|
107
117
|
</div>
|
|
@@ -119,7 +129,7 @@ export const ConnectedRepoOverview = ({
|
|
|
119
129
|
<div className="flex items-center gap-2">
|
|
120
130
|
<button
|
|
121
131
|
onClick={() => copyToClipboard(build.package_build_id)}
|
|
122
|
-
className="group-hover:text-blue-500 rounded
|
|
132
|
+
className="group-hover:text-blue-500 rounded text-left transition-colors"
|
|
123
133
|
>
|
|
124
134
|
{build.package_build_id}
|
|
125
135
|
</button>
|
|
@@ -128,13 +138,21 @@ export const ConnectedRepoOverview = ({
|
|
|
128
138
|
</div>
|
|
129
139
|
|
|
130
140
|
<div className="flex items-center gap-3 group">
|
|
131
|
-
|
|
141
|
+
{packageRelease?.is_pr_preview ? (
|
|
142
|
+
<GitBranch className="w-4 h-4 text-gray-500 group-hover:text-blue-500 transition-colors" />
|
|
143
|
+
) : (
|
|
144
|
+
<GitCommit className="w-4 h-4 text-gray-500 group-hover:text-blue-500 transition-colors" />
|
|
145
|
+
)}
|
|
132
146
|
<div>
|
|
133
147
|
<p className="text-xs text-gray-500 uppercase tracking-wide">
|
|
134
|
-
Branch
|
|
148
|
+
{packageRelease?.is_pr_preview ? "PR" : "Branch"}
|
|
135
149
|
</p>
|
|
136
150
|
<a
|
|
137
|
-
href={
|
|
151
|
+
href={
|
|
152
|
+
packageRelease?.is_pr_preview
|
|
153
|
+
? `https://github.com/${pkg.github_repo_full_name}/pull/${packageRelease.github_pr_number}`
|
|
154
|
+
: `https://github.com/${pkg.github_repo_full_name}/tree/${build.branch_name || "main"}`
|
|
155
|
+
}
|
|
138
156
|
target="_blank"
|
|
139
157
|
rel="noopener noreferrer"
|
|
140
158
|
className="inline-block"
|
|
@@ -143,7 +161,9 @@ export const ConnectedRepoOverview = ({
|
|
|
143
161
|
variant="outline"
|
|
144
162
|
className="text-xs mt-1 hover:bg-gray-100 cursor-pointer transition-colors"
|
|
145
163
|
>
|
|
146
|
-
{
|
|
164
|
+
{packageRelease?.is_pr_preview
|
|
165
|
+
? `#${packageRelease.github_pr_number}`
|
|
166
|
+
: build?.branch_name || "main"}
|
|
147
167
|
</Badge>
|
|
148
168
|
</a>
|
|
149
169
|
</div>
|
|
@@ -166,22 +186,20 @@ export const ConnectedRepoOverview = ({
|
|
|
166
186
|
</div>
|
|
167
187
|
</div>
|
|
168
188
|
|
|
169
|
-
|
|
170
|
-
<
|
|
171
|
-
|
|
172
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
</p>
|
|
182
|
-
</div>
|
|
189
|
+
<div className="flex items-center gap-3 group">
|
|
190
|
+
<Clock className="w-4 h-4 text-gray-500 group-hover:text-blue-500 transition-colors" />
|
|
191
|
+
<div>
|
|
192
|
+
<p className="text-xs text-gray-500 uppercase tracking-wide">
|
|
193
|
+
Duration
|
|
194
|
+
</p>
|
|
195
|
+
<p
|
|
196
|
+
className="text-sm font-medium hover:text-blue-500 transition-colors cursor-help"
|
|
197
|
+
title={`Build started at ${build.build_started_at}`}
|
|
198
|
+
>
|
|
199
|
+
{buildDuration}s
|
|
200
|
+
</p>
|
|
183
201
|
</div>
|
|
184
|
-
|
|
202
|
+
</div>
|
|
185
203
|
</div>
|
|
186
204
|
|
|
187
205
|
{build.commit_message && (
|
|
@@ -1,54 +1,33 @@
|
|
|
1
1
|
export { ConnectedRepoOverview } from "./ConnectedRepoOverview"
|
|
2
2
|
export { BuildsList } from "./BuildsList"
|
|
3
3
|
export { ConnectedRepoDashboard } from "./ConnectedRepoDashboard"
|
|
4
|
-
|
|
4
|
+
import {
|
|
5
|
+
Package,
|
|
6
|
+
PackageBuild,
|
|
7
|
+
PackageRelease,
|
|
8
|
+
} from "fake-snippets-api/lib/db/schema"
|
|
9
|
+
import { Clock, CheckCircle, AlertCircle, Loader2 } from "lucide-react"
|
|
5
10
|
export const getBuildStatus = (build: PackageBuild) => {
|
|
6
11
|
if (
|
|
7
|
-
build
|
|
8
|
-
build
|
|
9
|
-
build
|
|
12
|
+
build?.build_error ||
|
|
13
|
+
build?.transpilation_error ||
|
|
14
|
+
build?.circuit_json_build_error
|
|
10
15
|
) {
|
|
11
16
|
return { status: "error", label: "Failed" }
|
|
12
17
|
}
|
|
13
18
|
if (
|
|
14
|
-
build
|
|
15
|
-
build
|
|
16
|
-
build
|
|
19
|
+
build?.build_in_progress ||
|
|
20
|
+
build?.transpilation_in_progress ||
|
|
21
|
+
build?.circuit_json_build_in_progress
|
|
17
22
|
) {
|
|
18
23
|
return { status: "building", label: "Building" }
|
|
19
24
|
}
|
|
20
|
-
if (build
|
|
25
|
+
if (build?.build_completed_at && build?.transpilation_completed_at) {
|
|
21
26
|
return { status: "success", label: "Ready" }
|
|
22
27
|
}
|
|
23
28
|
return { status: "queued", label: "Queued" }
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
export interface PackageBuild {
|
|
27
|
-
package_build_id: string
|
|
28
|
-
package_release_id: string | null
|
|
29
|
-
created_at: string
|
|
30
|
-
transpilation_in_progress: boolean
|
|
31
|
-
transpilation_started_at: string | null
|
|
32
|
-
transpilation_completed_at: string | null
|
|
33
|
-
transpilation_logs: any[]
|
|
34
|
-
transpilation_error: string | null
|
|
35
|
-
circuit_json_build_in_progress: boolean
|
|
36
|
-
circuit_json_build_started_at: string | null
|
|
37
|
-
circuit_json_build_completed_at: string | null
|
|
38
|
-
circuit_json_build_logs: any[]
|
|
39
|
-
circuit_json_build_error: string | null
|
|
40
|
-
build_in_progress: boolean
|
|
41
|
-
build_started_at: string | null
|
|
42
|
-
build_completed_at: string | null
|
|
43
|
-
build_error: string | null
|
|
44
|
-
build_error_last_updated_at: string
|
|
45
|
-
preview_url: string | null
|
|
46
|
-
build_logs: string | null
|
|
47
|
-
branch_name: string | null
|
|
48
|
-
commit_message: string | null
|
|
49
|
-
commit_author: string | null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
31
|
export const MOCK_DEPLOYMENTS: PackageBuild[] = [
|
|
53
32
|
{
|
|
54
33
|
package_build_id: "pb_1a2b3c4d",
|
|
@@ -191,8 +170,6 @@ export const MOCK_DEPLOYMENTS: PackageBuild[] = [
|
|
|
191
170
|
},
|
|
192
171
|
]
|
|
193
172
|
|
|
194
|
-
import { Package, PackageRelease } from "fake-snippets-api/lib/db/schema"
|
|
195
|
-
import { Clock, CheckCircle, AlertCircle, Loader2 } from "lucide-react"
|
|
196
173
|
export const StatusIcon = ({ status }: { status: string }) => {
|
|
197
174
|
switch (status) {
|
|
198
175
|
case "success":
|
|
@@ -209,40 +186,3 @@ export const StatusIcon = ({ status }: { status: string }) => {
|
|
|
209
186
|
export const getLatestBuildForPackage = (pkg: Package): PackageBuild => {
|
|
210
187
|
return MOCK_DEPLOYMENTS[0]
|
|
211
188
|
}
|
|
212
|
-
export const getLatestBuildFromPackageRelease = (
|
|
213
|
-
pkg: PackageRelease,
|
|
214
|
-
): PackageBuild => {
|
|
215
|
-
return MOCK_DEPLOYMENTS[0]
|
|
216
|
-
}
|
|
217
|
-
export const getPackageFromBuild = (build: PackageBuild): Package => {
|
|
218
|
-
return {
|
|
219
|
-
ai_description: "placeholder ai description",
|
|
220
|
-
ai_usage_instructions: "placeholder ai usage instructions",
|
|
221
|
-
created_at: "2025-08-06T14:37:05.802Z",
|
|
222
|
-
creator_account_id: "account-1234",
|
|
223
|
-
default_view: "files",
|
|
224
|
-
description: "placeholder ai description",
|
|
225
|
-
github_repo_full_name: "testuser/pcb-designs",
|
|
226
|
-
is_board: false,
|
|
227
|
-
is_footprint: false,
|
|
228
|
-
is_model: false,
|
|
229
|
-
is_package: false,
|
|
230
|
-
is_private: false,
|
|
231
|
-
is_public: true,
|
|
232
|
-
is_snippet: false,
|
|
233
|
-
is_source_from_github: false,
|
|
234
|
-
is_unlisted: false,
|
|
235
|
-
latest_package_release_fs_sha: "md5-425b47ef26be8f0863eca9e63e516dfa",
|
|
236
|
-
latest_package_release_id: "package_release_1754491026466",
|
|
237
|
-
latest_version: "0.0.1",
|
|
238
|
-
license: null,
|
|
239
|
-
name: "testuser/untitled-package-0",
|
|
240
|
-
owner_github_username: "testuser",
|
|
241
|
-
owner_org_id: "org-1234",
|
|
242
|
-
package_id: "package_1754491025802",
|
|
243
|
-
star_count: 0,
|
|
244
|
-
unscoped_name: "untitled-package-0",
|
|
245
|
-
updated_at: "2025-08-06T14:37:25.083Z",
|
|
246
|
-
website: "",
|
|
247
|
-
}
|
|
248
|
-
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { useQuery } from "react-query"
|
|
2
|
+
import { useAxios } from "./use-axios"
|
|
3
|
+
import { PackageBuild } from "fake-snippets-api/lib/db/schema"
|
|
4
|
+
|
|
5
|
+
interface UsePackageBuildsParams {
|
|
6
|
+
package_id?: string
|
|
7
|
+
package_release_id?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const usePackageBuilds = (params: UsePackageBuildsParams | null) => {
|
|
11
|
+
const axios = useAxios()
|
|
12
|
+
|
|
13
|
+
return useQuery<PackageBuild[], Error & { status: number }>(
|
|
14
|
+
["packageBuilds", params],
|
|
15
|
+
async () => {
|
|
16
|
+
if (!params || (!params.package_id && !params.package_release_id)) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
"Either package_id or package_release_id must be provided",
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { data } = await axios.get<{ package_builds: PackageBuild[] }>(
|
|
23
|
+
"/package_builds/list",
|
|
24
|
+
{
|
|
25
|
+
params: {
|
|
26
|
+
...(params.package_id ? { package_id: params.package_id } : {}),
|
|
27
|
+
...(params.package_release_id
|
|
28
|
+
? { package_release_id: params.package_release_id }
|
|
29
|
+
: {}),
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
if (!data.package_builds) {
|
|
35
|
+
return []
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return data.package_builds
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
enabled: Boolean(
|
|
42
|
+
params && (params.package_id || params.package_release_id),
|
|
43
|
+
),
|
|
44
|
+
retry: false,
|
|
45
|
+
refetchOnWindowFocus: false,
|
|
46
|
+
staleTime: 0,
|
|
47
|
+
},
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const usePackageBuildsByPackageId = (packageId: string | null) => {
|
|
52
|
+
return usePackageBuilds(packageId ? { package_id: packageId } : null)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const usePackageBuildsByReleaseId = (releaseId?: string | null) => {
|
|
56
|
+
return usePackageBuilds(releaseId ? { package_release_id: releaseId } : null)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const usePackageBuild = (packageBuildId: string | null) => {
|
|
60
|
+
const axios = useAxios()
|
|
61
|
+
|
|
62
|
+
return useQuery<PackageBuild, Error & { status: number }>(
|
|
63
|
+
["packageBuild", packageBuildId],
|
|
64
|
+
async () => {
|
|
65
|
+
if (!packageBuildId) {
|
|
66
|
+
throw new Error("package_build_id is required")
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const { data } = await axios.get("/package_builds/get", {
|
|
70
|
+
params: {
|
|
71
|
+
package_build_id: packageBuildId,
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
if (!data.package_build) {
|
|
76
|
+
throw new Error("Package build not found")
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return data.package_build
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
enabled: Boolean(packageBuildId),
|
|
83
|
+
retry: false,
|
|
84
|
+
refetchOnWindowFocus: false,
|
|
85
|
+
},
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const useLatestPackageBuild = (
|
|
90
|
+
params: { package_id?: string; package_release_id?: string } | null,
|
|
91
|
+
) => {
|
|
92
|
+
const axios = useAxios()
|
|
93
|
+
|
|
94
|
+
return useQuery<PackageBuild | null, Error & { status: number }>(
|
|
95
|
+
["latestPackageBuild", params],
|
|
96
|
+
async () => {
|
|
97
|
+
if (!params || (!params.package_id && !params.package_release_id)) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
"Either package_id or package_release_id must be provided",
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const { data } = await axios.get<{ package_build: PackageBuild }>(
|
|
104
|
+
"/package_builds/latest",
|
|
105
|
+
{
|
|
106
|
+
params: {
|
|
107
|
+
...(params.package_id ? { package_id: params.package_id } : {}),
|
|
108
|
+
...(params.package_release_id
|
|
109
|
+
? { package_release_id: params.package_release_id }
|
|
110
|
+
: {}),
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
return data.package_build
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
enabled: Boolean(
|
|
119
|
+
params && (params.package_id || params.package_release_id),
|
|
120
|
+
),
|
|
121
|
+
retry: false,
|
|
122
|
+
refetchOnWindowFocus: false,
|
|
123
|
+
},
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const useLatestPackageBuildByPackageId = (packageId: string | null) => {
|
|
128
|
+
return useLatestPackageBuild(packageId ? { package_id: packageId } : null)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export const useLatestPackageBuildByReleaseId = (releaseId?: string | null) => {
|
|
132
|
+
return useLatestPackageBuild(
|
|
133
|
+
releaseId ? { package_release_id: releaseId } : null,
|
|
134
|
+
)
|
|
135
|
+
}
|
|
@@ -1,18 +1,49 @@
|
|
|
1
1
|
import { useParams } from "wouter"
|
|
2
2
|
import NotFoundPage from "./404"
|
|
3
|
-
import { ConnectedRepoDashboard
|
|
3
|
+
import { ConnectedRepoDashboard } from "@/components/preview"
|
|
4
|
+
import { usePackageBuild } from "@/hooks/use-package-builds"
|
|
5
|
+
import { usePackageReleaseById } from "@/hooks/use-package-release"
|
|
6
|
+
import { usePackageById } from "@/hooks/use-package-by-package-id"
|
|
4
7
|
|
|
5
8
|
export default function ViewConnectedRepoOverview() {
|
|
6
9
|
const params = useParams<{ buildId: string }>()
|
|
7
|
-
const
|
|
10
|
+
const {
|
|
11
|
+
data: packageBuild,
|
|
12
|
+
isLoading: isLoadingBuild,
|
|
13
|
+
error: buildError,
|
|
14
|
+
} = usePackageBuild(params?.buildId)
|
|
15
|
+
const {
|
|
16
|
+
data: packageRelease,
|
|
17
|
+
isLoading: isLoadingRelease,
|
|
18
|
+
error: releaseError,
|
|
19
|
+
} = usePackageReleaseById(packageBuild?.package_release_id)
|
|
20
|
+
const {
|
|
21
|
+
data: buildPackage,
|
|
22
|
+
isLoading: isLoadingPackage,
|
|
23
|
+
error: packageError,
|
|
24
|
+
} = usePackageById(String(packageRelease?.package_id))
|
|
8
25
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
26
|
+
if (isLoadingBuild || isLoadingRelease || isLoadingPackage) {
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
12
29
|
|
|
13
|
-
if (!
|
|
30
|
+
if (buildError?.status === 404 || !packageBuild) {
|
|
14
31
|
return <NotFoundPage heading="Build Not Found" />
|
|
15
32
|
}
|
|
16
33
|
|
|
17
|
-
|
|
34
|
+
if (releaseError?.status === 404 || !packageRelease) {
|
|
35
|
+
return <NotFoundPage heading="Package Release Not Found" />
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (packageError?.status === 404 || !buildPackage) {
|
|
39
|
+
return <NotFoundPage heading="Package Not Found" />
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<ConnectedRepoDashboard
|
|
44
|
+
latestBuild={packageBuild}
|
|
45
|
+
pkg={buildPackage}
|
|
46
|
+
packageRelease={packageRelease}
|
|
47
|
+
/>
|
|
48
|
+
)
|
|
18
49
|
}
|