-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathstatus.tsx
148 lines (136 loc) · 4.6 KB
/
status.tsx
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
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
import { HttpError, RouteConfig } from "fresh";
import { define } from "../util.ts";
import type {
PublishingTask,
PublishingTaskStatus,
} from "../utils/api_types.ts";
import { path } from "../utils/api.ts";
import { packageData } from "../utils/data.ts";
import { PackageHeader } from "./package/(_components)/PackageHeader.tsx";
import { PackageNav } from "./package/(_components)/PackageNav.tsx";
import { timeAgo } from "../utils/timeAgo.ts";
import PublishingTaskRequeue from "../islands/PublishingTaskRequeue.tsx";
import { TbAlertCircle, TbCheck, TbClockHour3 } from "@preact-icons/tb";
import { scopeIAM } from "../utils/iam.ts";
export default define.page<typeof handler>(function PackageListPage({
data,
state,
}) {
const iam = scopeIAM(state, data.member);
return (
<div class="mb-24 space-y-16">
<div>
<PackageHeader package={data.package} />
<PackageNav
currentTab="Versions"
versionCount={data.package.versionCount}
iam={iam}
params={{ scope: data.package.scope, package: data.package.name }}
latestVersion={data.package.latestVersion}
/>
<div class="mt-8 space-y-2">
<h2 class="text-xl font-sans font-bold">
Publishing Status
</h2>
<div>
<p>
<span class="font-semibold">Version:</span>{" "}
{data.publishingTask.packageVersion}
</p>
<p>
<span class="font-semibold">Task ID:</span>{" "}
<span class="font-mono">{data.publishingTask.id}</span>
</p>
<p>
<span class="font-semibold">Created:</span>{" "}
{timeAgo(new Date(data.publishingTask.createdAt))}
</p>
{data.publishingTask.userId && (
<p>
<span class="font-semibold">Submitter:</span>{" "}
<a
class="link italic"
href={`/user/${data.publishingTask.userId}`}
>
View user
</a>
</p>
)}
<p class="flex items-center gap-1">
<span class="font-semibold">Status:</span>{" "}
{StatusToIcon(data.publishingTask.status)}{" "}
{data.publishingTask.status}
</p>
</div>
{data.publishingTask.error && (
<div class="bg-red-100 rounded border-2 border-red-200 py-1.5 px-3 flex justify-between gap-3">
<div class="space-y-1.5">
<div class="font-bold text-xl">
{data.publishingTask.error.code}
</div>
<div>
{data.publishingTask.error.message}
</div>
</div>
</div>
)}
{data.publishingTask.status === "success" && (
<p>
<a
href={`/@${data.publishingTask.packageScope}/${data.publishingTask.packageName}@${data.publishingTask.packageVersion}`}
class="link"
>
View published version
</a>
</p>
)}
{iam.isStaff && (
<PublishingTaskRequeue publishingTask={data.publishingTask} />
)}
</div>
</div>
</div>
);
});
export function StatusToIcon(status: PublishingTaskStatus) {
switch (status) {
case "pending":
case "processing":
case "processed":
return <TbClockHour3 class="size-6 stroke-blue-500 stroke-2" />;
case "success":
return <TbCheck class="size-6 stroke-green-500 stroke-2" />;
case "failure":
return <TbAlertCircle class="size-6 stroke-red-500 stroke-2" />;
}
}
export const handler = define.handlers({
async GET(ctx) {
const publishingTaskResp = await ctx.state.api.get<PublishingTask>(
path`/publishing_tasks/${ctx.params.publishingTask}`,
);
if (!publishingTaskResp.ok) throw publishingTaskResp; // gracefully handle this
const res = await packageData(
ctx.state,
publishingTaskResp.data.packageScope,
publishingTaskResp.data.packageName,
);
if (res === null) {
throw new HttpError(404, "The package was not found.");
}
ctx.state.meta = {
title: `Publishing Task ${publishingTaskResp.data.id} - JSR`,
};
return {
data: {
package: res.pkg,
member: res.scopeMember,
publishingTask: publishingTaskResp.data,
},
};
},
});
export const config: RouteConfig = {
routeOverride: "/status/:publishingTask",
};