1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 14:34:19 +00:00
pds-2021-g2-nest/nest_frontend/components/interactive/SummaryRepository.js

82 lines
2.9 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-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 {@link SummaryBase} representing a repository.
*
* @param repo - The repository to display.
* @param view - Function with no parameters to call when the view repository button is clicked.
* @param archive - Function with no parameters to call when the archive repository button is clicked.
* @param edit - Function with no parameters to call when the edit repository button is clicked.
* @param destroy - Function with no parameters to call when the delete repository button is clicked.
* @param running - If an action is running on the viewset.
* @param className - Additional class(es) to append to the summary.
* @param props - Additional props to pass to the summary.
* @returns {JSX.Element}
* @constructor
*/
2021-05-11 16:24:51 +00:00
export default function SummaryRepository(
{ repo, view, archive, edit, destroy, running, className, ...props },
) {
2021-05-18 00:48:34 +00:00
const { strings } = useContext(ContextLanguage)
2021-05-10 13:22:07 +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={view}
/>
<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}
/>
{destroy ?
2021-05-20 10:16:01 +00:00
<SummaryButton
color={"Red"}
icon={faTrash}
onClick={() => destroy(repo["id"])}
disabled={running}
>
{strings.delete}
</SummaryButton>
: null}
{archive ?
2021-05-20 10:16:01 +00:00
<SummaryButton
color={"Grey"}
icon={faArchive}
onClick={() => archive(repo["id"])}
disabled={running}
>
{strings.archive}
</SummaryButton>
: null}
{edit ?
2021-05-20 10:16:01 +00:00
<SummaryButton
color={"Yellow"}
icon={faPencilAlt}
onClick={() => edit(repo["id"])}
disabled={running}
>
{strings.edit}
</SummaryButton>
: null}
<SummaryRight/>
</SummaryBase>
)
}