-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathIssueListItem.tsx
102 lines (91 loc) · 3.1 KB
/
IssueListItem.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
import { Action, ActionPanel, Icon, List, open, useNavigation } from "@raycast/api";
import { MutatePromise, usePromise } from "@raycast/utils";
import { format } from "date-fns";
import { UIColors } from "../../constants";
import {
IssueFieldsFragment,
SearchCreatedIssuesQuery,
SearchOpenIssuesQuery,
UserFieldsFragment,
} from "../generated/graphql";
import { getIssueAuthor, getIssueStatus } from "../helpers/issue";
import OpenInGitpod, { getPreferencesForContext } from "../helpers/openInGitpod";
import ContextPreferences from "../preferences/context_preferences";
type IssueListItemProps = {
issue: IssueFieldsFragment;
viewer?: UserFieldsFragment;
mutateList?:
| MutatePromise<SearchCreatedIssuesQuery | undefined>
| MutatePromise<SearchOpenIssuesQuery | undefined>
| MutatePromise<IssueFieldsFragment[] | undefined>;
};
export default function IssueListItem({ issue }: IssueListItemProps) {
const { push } = useNavigation();
const updatedAt = new Date(issue.updatedAt);
const author = getIssueAuthor(issue);
const status = getIssueStatus(issue);
const { data: preferences, revalidate } = usePromise(
async () => {
const response = await getPreferencesForContext("Issue", issue.repository.nameWithOwner, issue.title);
return response;
},
);
const accessories: List.Item.Accessory[] = [
{
date: updatedAt,
tooltip: `Updated: ${format(updatedAt, "EEEE d MMMM yyyy 'at' HH:mm")}`,
},
{
text: {
value: preferences?.preferredEditorClass === "g1-large" ? "L" : "S",
},
icon: {
source: Icon.ComputerChip,
tintColor: UIColors.gitpod_gold,
},
tooltip: `Editor: ${preferences?.preferredEditor}, Class: ${preferences?.preferredEditorClass} `
},
{
icon: author.icon,
tooltip: `Author: ${author.text}`,
},
];
if (issue.comments.totalCount > 0) {
accessories.unshift({
text: `${issue.comments.totalCount}`,
icon: Icon.Bubble,
});
}
const keywords = [`${issue.number}`];
if (issue.author?.login) {
keywords.push(issue.author.login);
}
return (
<List.Item
key={issue.id}
title={issue.title}
subtitle={{ value: `#${issue.number}`, tooltip: `Repository: ${issue.repository.nameWithOwner}` }}
icon={{ value: status.icon, tooltip: `Status: ${status.text}` }}
keywords={keywords}
accessories={accessories}
actions={
<ActionPanel>
<Action
title="Open Issue in Gitpod"
onAction={() => {
OpenInGitpod(issue.url, "Issue", issue.repository.nameWithOwner, issue.title)
}}
shortcut={{ modifiers: ["cmd"], key: "g" }}
/>
<Action
title="View Issue in GitHub"
onAction={() => {
open(issue.url);
}}
/>
<Action title="Configure Workspace" onAction={() => push(<ContextPreferences revalidate={revalidate} repository={issue.repository.nameWithOwner} type="Issue" context={issue.title} />)} shortcut={{ modifiers: ["cmd"], key: "w" }} />
</ActionPanel>
}
/>
);
}