-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Abhay Soni <[email protected]>
- Loading branch information
1 parent
376b04f
commit e160dd3
Showing
10 changed files
with
245 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Progress, Table, TableColumn } from '@backstage/core-components'; | ||
import { useApi } from '@backstage/core-plugin-api'; | ||
import Alert from '@material-ui/lab/Alert'; | ||
import React from 'react'; | ||
import { useAsync } from 'react-use'; | ||
import { GitlabCIApiRef } from '../../../api'; | ||
import { gitlabAppData, gitlabAppSlug } from '../../gitlabAppData'; | ||
import { IssueObject } from '../../types'; | ||
import { getElapsedTime } from '../../utils'; | ||
import { AuthorColumn, IssueStateIndicator, IssueTitle } from './columns'; | ||
|
||
// export type IssueObject = { | ||
// id: string; | ||
// project_id: string; | ||
// title: string; | ||
// state: IssueState; | ||
// type: IssueType; | ||
// description: string; | ||
// created_at: string; | ||
// updated_at: string; | ||
// author: Author; | ||
// }; | ||
|
||
export const DenseTable = ({ | ||
issuesObjects, | ||
projectName, | ||
}: { | ||
issuesObjects: IssueObject[]; | ||
projectName: string | undefined; | ||
}) => { | ||
const columns: TableColumn<IssueObject>[] = [ | ||
{ title: 'Issue ID', field: 'id' }, | ||
{ title: 'Title', render: IssueTitle }, | ||
{ title: 'Author', render: AuthorColumn }, | ||
{ title: 'Created At', field: 'created_at' }, | ||
{ title: 'Issue Type', field: 'type' }, | ||
{ title: 'Issue Status', render: IssueStateIndicator }, | ||
]; | ||
|
||
const title = 'Gitlab Issues: ' + projectName; | ||
|
||
const data = issuesObjects.map(issue => ({ | ||
...issue, | ||
created_at: getElapsedTime(issue.created_at), | ||
})); | ||
|
||
return ( | ||
<Table | ||
title={title} | ||
options={{ search: true, paging: true }} | ||
columns={columns} | ||
data={data} | ||
/> | ||
); | ||
}; | ||
|
||
export const IssuesTable = ({}) => { | ||
const { project_id } = gitlabAppData(); | ||
const { project_slug } = gitlabAppSlug(); | ||
|
||
const GitlabCIAPI = useApi(GitlabCIApiRef); | ||
|
||
const { value, loading, error } = useAsync(async (): Promise<{ | ||
data: IssueObject[]; | ||
projectName: string; | ||
}> => { | ||
let projectDetails: any = await GitlabCIAPI.getProjectDetails(project_slug); | ||
let projectId = project_id ? project_id : projectDetails?.id; | ||
let projectName = await GitlabCIAPI.getProjectName(projectId); | ||
const gitlabIssuesObject = await GitlabCIAPI.getIssuesSummary(project_id); | ||
const data = gitlabIssuesObject?.getIssuesData; | ||
let renderData: any = { data, projectName }; | ||
|
||
return renderData; | ||
}, []); | ||
|
||
if (loading) { | ||
return <Progress />; | ||
} else if (error) { | ||
return <Alert severity="error">{error.message}</Alert>; | ||
} | ||
|
||
return ( | ||
<DenseTable | ||
issuesObjects={value?.data || []} | ||
projectName={value?.projectName} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
Avatar, | ||
StatusAborted, | ||
StatusOK, | ||
StatusPending, | ||
TableColumn, | ||
} from '@backstage/core-components'; | ||
import { Box, Typography } from '@material-ui/core'; | ||
import Link from '@material-ui/core/Link'; | ||
import React from 'react'; | ||
import { IssueObject } from '../../types'; | ||
|
||
export const IssueStateIndicator = ( | ||
issueObject: IssueObject, | ||
): TableColumn<{}> => { | ||
switch (issueObject.state) { | ||
case 'opened': | ||
return <StatusPending>open</StatusPending>; | ||
case 'closed': | ||
return <StatusOK>close</StatusOK>; | ||
default: | ||
return <StatusAborted />; | ||
} | ||
}; | ||
|
||
export function IssueTitle(issueObject: IssueObject): TableColumn<{}> { | ||
return ( | ||
<Typography variant="body2" noWrap> | ||
<Box ml={1} component="span"> | ||
<Link href={issueObject.web_url} target="_blank"> | ||
{issueObject.title} | ||
</Link> | ||
</Box> | ||
</Typography> | ||
); | ||
} | ||
|
||
export function AuthorColumn(issueObject: IssueObject): TableColumn<{}> { | ||
return ( | ||
<Box sx={{ display: 'flex', alignItems: 'center' }}> | ||
<Avatar | ||
customStyles={{ width: 32, height: 32 }} | ||
picture={issueObject.author.avatar_url} | ||
displayName={issueObject.author.username} | ||
/> | ||
<Typography variant="body2" noWrap> | ||
<Box ml={1} component="span"> | ||
<Link href={issueObject.author.web_url} target="_blank"> | ||
{issueObject.author.username} | ||
</Link> | ||
</Box> | ||
</Typography> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { IssuesTable } from './IssuesTable'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
export { | ||
gitlabPlugin, | ||
EntityGitlabContent, | ||
EntityGitlabLanguageCard, | ||
EntityGitlabContributorsCard, | ||
EntityGitlabMergeRequestsTable, | ||
EntityGitlabMergeRequestStatsCard, | ||
EntityGitlabPipelinesTable, | ||
export { | ||
EntityGitlabContent, | ||
EntityGitlabContributorsCard, | ||
EntityGitlabIssuesTable, | ||
EntityGitlabLanguageCard, | ||
EntityGitlabMergeRequestsTable, | ||
EntityGitlabMergeRequestStatsCard, | ||
EntityGitlabPipelinesTable, | ||
gitlabPlugin, | ||
} from './plugin'; | ||
|
||
export { isGitlabAvailable } from './Router'; | ||
export { isGitlabAvailable } from './Router'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters