forked from Cloud-Pipelines/pipeline-editor
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRunRow.tsx
More file actions
146 lines (129 loc) · 4.51 KB
/
RunRow.tsx
File metadata and controls
146 lines (129 loc) · 4.51 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
import { useQuery } from "@tanstack/react-query";
import { useNavigate } from "@tanstack/react-router";
import { type MouseEvent } from "react";
import type { PipelineRunResponse } from "@/api/types.gen";
import { CopyText } from "@/components/shared/CopyText/CopyText";
import { FavoriteToggle } from "@/components/shared/FavoriteToggle";
import { StatusBar, StatusIcon } from "@/components/shared/Status";
import { TagList } from "@/components/shared/Tags/TagList";
import { Button } from "@/components/ui/button";
import { InlineStack } from "@/components/ui/layout";
import { TableCell, TableRow } from "@/components/ui/table";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import useToastNotification from "@/hooks/useToastNotification";
import { useBackend } from "@/providers/BackendProvider";
import { APP_ROUTES } from "@/routes/router";
import { fetchRunAnnotations } from "@/services/pipelineRunService";
import { getPipelineTagsFromAnnotations } from "@/utils/annotations";
import { TWENTY_FOUR_HOURS_IN_MS } from "@/utils/constants";
import { formatDate } from "@/utils/date";
import { getOverallExecutionStatusFromStats } from "@/utils/executionStatus";
const RunRow = ({ run }: { run: PipelineRunResponse }) => {
const navigate = useNavigate();
const notify = useToastNotification();
const { backendUrl } = useBackend();
const runId = `${run.id}`;
const { data: annotations } = useQuery({
queryKey: ["pipeline-run-annotations", runId],
queryFn: () => fetchRunAnnotations(runId, backendUrl),
enabled: !!runId,
refetchOnWindowFocus: false,
staleTime: TWENTY_FOUR_HOURS_IN_MS,
});
const name = run.pipeline_name ?? "Unknown pipeline";
const tags = getPipelineTagsFromAnnotations(annotations);
const createdBy = run.created_by ?? "Unknown user";
const truncatedCreatedBy = truncateMiddle(createdBy);
const isTruncated = createdBy !== truncatedCreatedBy;
const handleCopy = (e: MouseEvent) => {
e.stopPropagation();
navigator.clipboard.writeText(createdBy);
notify(`"${createdBy}" copied to clipboard`, "success");
};
const overallStatus = getOverallExecutionStatusFromStats(
run.execution_status_stats ?? undefined,
);
const clickThroughUrl = `${APP_ROUTES.RUNS}/${runId}`;
const handleRowClick = (e: MouseEvent<HTMLElement>) => {
if (e.target instanceof HTMLElement && e.target.closest("button")) {
return;
}
if (e.ctrlKey || e.metaKey) {
window.open(clickThroughUrl, "_blank");
return;
}
navigate({ to: clickThroughUrl });
};
const createdByButton = (
<Button
className="truncate underline"
onClick={handleCopy}
tabIndex={0}
variant="ghost"
>
{truncatedCreatedBy}
</Button>
);
const createdByButtonWithTooltip = (
<Tooltip>
<TooltipTrigger asChild>{createdByButton}</TooltipTrigger>
<TooltipContent>
<span>{createdBy}</span>
</TooltipContent>
</Tooltip>
);
return (
<TableRow
onClick={handleRowClick}
className="cursor-pointer text-gray-500 text-xs h-10"
>
<TableCell>
<InlineStack gap="2" blockAlign="center" wrap="nowrap">
<StatusIcon status={overallStatus} />
<span
className="truncate max-w-100 text-sm text-foreground"
title={name}
>
{name}
</span>
<div
onClick={(e) => e.stopPropagation()}
className="flex items-center text-sm"
>
#
<CopyText size="sm" className="text-muted-foreground">
{runId}
</CopyText>
</div>
</InlineStack>
</TableCell>
<TableCell>
<div className="w-2/3">
<StatusBar executionStatusStats={run.execution_status_stats} />
</div>
</TableCell>
<TableCell>
{run.created_at ? formatDate(run.created_at) : "Data not found..."}
</TableCell>
<TableCell>
{isTruncated ? createdByButtonWithTooltip : createdByButton}
</TableCell>
<TableCell className="max-w-64">
{tags && tags.length > 0 && <TagList tags={tags} />}
</TableCell>
<TableCell className="w-0">
<FavoriteToggle type="run" id={runId} name={name} />
</TableCell>
</TableRow>
);
};
export default RunRow;
function truncateMiddle(str: string, maxLength = 28) {
if (!str || str.length <= maxLength) return str;
const keep = Math.floor((maxLength - 3) / 2);
return str.slice(0, keep) + "..." + str.slice(-keep);
}