-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathBulkActionPresenter.server.ts
More file actions
73 lines (67 loc) · 1.92 KB
/
BulkActionPresenter.server.ts
File metadata and controls
73 lines (67 loc) · 1.92 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
import { getUsername } from "~/utils/username";
import { BasePresenter } from "./basePresenter.server";
import { type BulkActionMode } from "~/components/BulkActionFilterSummary";
import { parseRunListInputOptions } from "~/services/runsRepository/runsRepository.server";
import { TaskRunListSearchFilters } from "~/components/runs/v3/RunFilters";
type BulkActionOptions = {
environmentId: string;
bulkActionId: string;
};
export class BulkActionPresenter extends BasePresenter {
public async call({ environmentId, bulkActionId }: BulkActionOptions) {
const bulkAction = await this._replica.bulkActionGroup.findFirst({
select: {
friendlyId: true,
name: true,
status: true,
type: true,
createdAt: true,
completedAt: true,
totalCount: true,
successCount: true,
failureCount: true,
user: {
select: {
name: true,
displayName: true,
avatarUrl: true,
},
},
params: true,
project: {
select: {
id: true,
organizationId: true,
},
},
},
where: {
environmentId,
friendlyId: bulkActionId,
},
});
if (!bulkAction) {
throw new Error("Bulk action not found");
}
//parse filters
const filtersParsed = TaskRunListSearchFilters.safeParse(
bulkAction.params && typeof bulkAction.params === "object" ? bulkAction.params : {}
);
let mode: BulkActionMode = "filter";
if (
filtersParsed.success &&
Object.keys(filtersParsed.data).length === 1 &&
filtersParsed.data.runId?.length
) {
mode = "selected";
}
return {
...bulkAction,
user: bulkAction.user
? { name: getUsername(bulkAction.user), avatarUrl: bulkAction.user.avatarUrl }
: undefined,
filters: filtersParsed.data ?? {},
mode,
};
}
}