-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathpublishingTasks.tsx
126 lines (122 loc) · 4.11 KB
/
publishingTasks.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
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
import { define } from "../../util.ts";
import { Table, TableData, TableRow } from "../../components/Table.tsx";
import { AdminNav } from "./(_components)/AdminNav.tsx";
import { path } from "../../utils/api.ts";
import { List, PublishingTask } from "../../utils/api_types.ts";
import { URLQuerySearch } from "../../components/URLQuerySearch.tsx";
import { timeAgo } from "../../utils/timeAgo.ts";
import PublishingTaskRequeue from "../../islands/PublishingTaskRequeue.tsx";
export default define.page<typeof handler>(function PublishingTasks({
data,
url,
}) {
return (
<div class="mb-20">
<AdminNav currentTab="publishingTasks" />
<URLQuerySearch query={data.query} />
<Table
class="mt-8"
columns={[
{ title: "ID", class: "w-auto" },
{ title: "Status", class: "w-0" },
{ title: "User ID", class: "w-0" },
{ title: "Package Scope", class: "w-0" },
{ title: "Package Name", class: "w-0" },
{ title: "Package Version", class: "w-0" },
{ title: "Created", class: "w-0" },
{ title: "Updated", class: "w-0" },
{ title: "", class: "w-0", align: "right" },
]}
pagination={data}
currentUrl={url}
>
{data.publishingTasks.map((publishingTask) => (
<TableRow key={publishingTask.id}>
<TableData>
<a href={`/status/${publishingTask.id}`}>{publishingTask.id}</a>
</TableData>
<TableData
title={publishingTask.status === "failure" && publishingTask.error
? `Error ${publishingTask.error.code}: ${publishingTask.error.message}`
: ""}
>
{publishingTask.status}
<br />
{publishingTask.status === "failure" && publishingTask.error &&
`Error ${publishingTask.error.code}: ${publishingTask.error.message}`}
</TableData>
<TableData>
<a href={`/user/${publishingTask.userId}`}>
{publishingTask.userId}
</a>
</TableData>
<TableData>
<a href={`/@${publishingTask.packageScope}`}>
{publishingTask.packageScope}
</a>
</TableData>
<TableData>
<a
href={`/@${publishingTask.packageScope}/${publishingTask.packageName}`}
>
{publishingTask.packageName}
</a>
</TableData>
<TableData>
<a
href={`/@${publishingTask.packageScope}/${publishingTask.packageName}/${publishingTask.packageVersion}`}
>
{publishingTask.packageVersion}
</a>
</TableData>
<TableData
title={new Date(publishingTask.createdAt).toISOString().slice(
0,
10,
)}
>
{timeAgo(new Date(publishingTask.createdAt))}
</TableData>
<TableData
title={new Date(publishingTask.updatedAt).toISOString().slice(
0,
10,
)}
>
{timeAgo(new Date(publishingTask.updatedAt))}
</TableData>
<TableData>
<PublishingTaskRequeue publishingTask={publishingTask} />
</TableData>
</TableRow>
))}
</Table>
</div>
);
});
export const handler = define.handlers({
async GET(ctx) {
const query = ctx.url.searchParams.get("search") || "";
const page = +(ctx.url.searchParams.get("page") || 1);
const limit = +(ctx.url.searchParams.get("limit") || 20);
const resp = await ctx.state.api.get<List<PublishingTask>>(
path`/admin/publishing_tasks`,
{
query,
page,
limit,
},
);
if (!resp.ok) throw resp; // gracefully handle this
return {
data: {
publishingTasks: resp.data.items,
query,
page,
limit,
total: resp.data.total,
},
};
},
});