1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-29 16:04:18 +00:00
pds-2021-g2-nest/nest_frontend/components/interactive/SummaryRepository.js

89 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-05-18 00:04:06 +00:00
import React, { useContext } from "react"
2021-05-11 16:24:51 +00:00
import { faArchive, faFolder, faFolderOpen, faPencilAlt, faTrash } from "@fortawesome/free-solid-svg-icons"
2021-05-10 13:22:07 +00:00
import { useHistory } from "react-router"
2021-05-18 00:04:06 +00:00
import ContextLanguage from "../../contexts/ContextLanguage"
import SummaryBase from "../base/summary/SummaryBase"
import SummaryLeft from "../base/summary/SummaryLeft"
import SummaryLabels from "../base/summary/SummaryLabels"
import SummaryButton from "../base/summary/SummaryButton"
import SummaryRight from "../base/summary/SummaryRight"
/**
* A long line representing a repository in a list.
*
2021-05-11 16:24:51 +00:00
* @param repo - The repository object.
2021-05-11 14:33:12 +00:00
* @param refresh - Function that can be called to refresh the repositories list.
* @param canDelete - If the Delete button should be displayed or not.
* @param deleteSelf - Function to call when the Delete button is pressed.
* @param canEdit - If the Edit button should be displayed or not.
* @param canArchive - If the Archive button should be displayed or not.
* @param archiveSelf - Function to call when the Archive button is pressed.
* @param running - If an action is currently running.
* @param className - Additional class(es) to be added to the outer box.
* @param props - Additional props to pass to the outer box.
* @returns {JSX.Element}
* @constructor
*/
2021-05-11 16:24:51 +00:00
export default function SummaryRepository(
{ repo, refresh, canDelete, deleteSelf, canEdit, canArchive, archiveSelf, running, className, ...props },
) {
2021-05-10 15:17:16 +00:00
const history = useHistory()
2021-05-18 00:48:34 +00:00
const { strings } = useContext(ContextLanguage)
2021-05-10 13:22:07 +00:00
2021-05-12 02:34:54 +00:00
const onRepoClick = () => {
history.push(`/repositories/${repo.id}`)
}
2021-05-11 16:24:51 +00:00
const onEditClick = () => {
history.push(`/repositories/${repo.id}/edit`)
2021-05-11 14:33:12 +00:00
}
return (
2021-05-18 17:15:53 +00:00
<SummaryBase {...props}>
<SummaryLeft
icon={repo.is_active ? faFolderOpen : faFolder}
title={repo.name}
subtitle={repo.owner ? repo.owner.username : null}
onClick={onRepoClick}
/>
<SummaryLabels
upperLabel={strings.created}
upperValue={repo.start ? new Date(repo.start).toLocaleString() : null}
lowerLabel={strings.archived}
lowerValue={repo.end ? new Date(repo.end).toLocaleString() : null}
/>
{canDelete ?
<SummaryButton
color={"Red"}
icon={faTrash}
onClick={deleteSelf}
disabled={running}
>
{strings.delete}
</SummaryButton>
: null}
{canEdit ?
<SummaryButton
color={"Yellow"}
icon={faPencilAlt}
onClick={onEditClick}
disabled={running}
>
{strings.edit}
</SummaryButton>
: null}
{canArchive ?
<SummaryButton
color={"Grey"}
icon={faArchive}
onClick={archiveSelf}
disabled={running}
>
{strings.archive}
</SummaryButton>
: null}
<SummaryRight/>
</SummaryBase>
)
}