-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIssues.tsx
More file actions
105 lines (96 loc) · 2.63 KB
/
Issues.tsx
File metadata and controls
105 lines (96 loc) · 2.63 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
import React, { useState } from "react";
import { PluginContextLocation } from "@cortexapps/plugin-core";
import {
SimpleTable,
Box,
Text,
Loader,
usePluginContext,
} from "@cortexapps/plugin-core/components";
import "../baseStyles.css";
import { getGithubDetailsFromEntity } from "../lib/parseEntity";
interface GitIssuesProps {
entityYaml: Record<string, any>;
}
// Set your GitHub url. Cloud is https://api.github.com
const ghURL = `https://api.github.com/`;
const Issues: React.FC<GitIssuesProps> = ({ entityYaml }) => {
const [hasIssues, setHasIssues] = useState(false);
const context = usePluginContext();
const [posts, setPosts] = React.useState([]);
const [isLoading, setIsLoading] = React.useState(
context.location === PluginContextLocation.Entity
);
const { owner, repo, basepath } = getGithubDetailsFromEntity(entityYaml) as {
owner: string;
repo: string;
basepath: string;
};
React.useEffect(() => {
const fetchData = async (): Promise<void> => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const cortexTag = context.entity!.tag;
try {
const issueUrl = basepath
? `${ghURL}repos/${owner}/${repo}/issues?labels=${cortexTag}`
: `${ghURL}repos/${owner}/${repo}/issues?direction=asc`;
const issuesResult = await fetch(issueUrl);
const issuesJson = await issuesResult.json();
if (issuesJson.length > 0) {
setHasIssues(true);
setPosts(issuesJson);
}
} catch (err) {
console.error(`Error fetching issues:`, err);
}
setIsLoading(false);
};
void fetchData();
}, []);
const config = {
columns: [
{
Cell: (number: string) => (
<Box>
<Text>{number}</Text>
</Box>
),
accessor: "number",
id: "number",
title: "Number",
width: "10%",
},
{
Cell: (title: string) => (
<Box>
<Text>{title}</Text>
</Box>
),
accessor: "title",
id: "title",
title: "Short Description",
width: "65%",
},
{
Cell: (state: string) => (
<Box>
<Text>{state}</Text>
</Box>
),
accessor: "state",
id: "state",
title: "State",
},
],
};
return isLoading ? (
<Loader />
) : hasIssues ? (
<SimpleTable config={config} items={posts} />
) : (
<Box backgroundColor="light" padding={3} borderRadius={2}>
<Text>We could not find any issues associated with this entity</Text>
</Box>
);
};
export default Issues;