2021-05-13 15:05:33 +00:00
|
|
|
import React from "react"
|
2021-04-29 14:58:31 +00:00
|
|
|
import Button from "../base/Button"
|
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-11 16:34:07 +00:00
|
|
|
import Summary from "../base/Summary"
|
2021-05-17 22:22:11 +00:00
|
|
|
import Localization from "../../Localization"
|
2021-04-24 02:23:23 +00:00
|
|
|
|
|
|
|
|
2021-04-25 15:22:52 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2021-04-25 15:22:52 +00:00
|
|
|
* @param canDelete - If the Delete button should be displayed or not.
|
2021-05-12 23:07:17 +00:00
|
|
|
* @param deleteSelf - Function to call when the Delete button is pressed.
|
2021-04-25 15:22:52 +00:00
|
|
|
* @param canEdit - If the Edit button should be displayed or not.
|
|
|
|
* @param canArchive - If the Archive button should be displayed or not.
|
2021-05-12 23:07:17 +00:00
|
|
|
* @param archiveSelf - Function to call when the Archive button is pressed.
|
|
|
|
* @param running - If an action is currently running.
|
2021-04-25 15:22:52 +00:00
|
|
|
* @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(
|
2021-05-12 23:07:17 +00:00
|
|
|
{ repo, refresh, canDelete, deleteSelf, canEdit, canArchive, archiveSelf, running, className, ...props },
|
2021-04-25 15:22:52 +00:00
|
|
|
) {
|
2021-05-10 15:17:16 +00:00
|
|
|
const history = useHistory()
|
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
|
|
|
}
|
|
|
|
|
2021-05-11 16:34:07 +00:00
|
|
|
const buttons = <>
|
|
|
|
{canDelete ?
|
|
|
|
<Button
|
|
|
|
color={"Red"}
|
|
|
|
icon={faTrash}
|
2021-05-12 23:07:17 +00:00
|
|
|
onClick={deleteSelf}
|
|
|
|
disabled={running}
|
2021-05-11 16:34:07 +00:00
|
|
|
>
|
2021-05-17 22:22:11 +00:00
|
|
|
{Localization.delete}
|
2021-05-11 16:34:07 +00:00
|
|
|
</Button>
|
|
|
|
: null}
|
|
|
|
{canEdit ?
|
|
|
|
<Button
|
|
|
|
color={"Yellow"}
|
|
|
|
icon={faPencilAlt}
|
|
|
|
onClick={onEditClick}
|
2021-05-12 23:07:17 +00:00
|
|
|
disabled={running}
|
2021-05-11 16:34:07 +00:00
|
|
|
>
|
2021-05-17 22:22:11 +00:00
|
|
|
{Localization.Edit}
|
2021-05-11 16:34:07 +00:00
|
|
|
</Button>
|
|
|
|
: null}
|
|
|
|
{canArchive ?
|
|
|
|
<Button
|
|
|
|
color={"Grey"}
|
|
|
|
icon={faArchive}
|
2021-05-12 23:07:17 +00:00
|
|
|
onClick={archiveSelf}
|
|
|
|
disabled={running}
|
2021-05-11 16:34:07 +00:00
|
|
|
>
|
2021-05-17 22:22:11 +00:00
|
|
|
{Localization.achive}
|
2021-05-11 16:34:07 +00:00
|
|
|
</Button>
|
|
|
|
: null}
|
|
|
|
</>
|
|
|
|
|
2021-04-24 02:23:23 +00:00
|
|
|
return (
|
2021-05-11 16:34:07 +00:00
|
|
|
<Summary
|
|
|
|
icon={repo.is_active ? faFolderOpen : faFolder}
|
|
|
|
title={repo.name}
|
2021-05-11 16:35:44 +00:00
|
|
|
subtitle={repo.owner ? repo.owner.username : null}
|
2021-05-12 02:34:54 +00:00
|
|
|
onClick={onRepoClick}
|
2021-05-17 22:22:11 +00:00
|
|
|
upperLabel={Localization.created}
|
2021-05-11 16:34:07 +00:00
|
|
|
upperValue={repo.start ? new Date(repo.start).toLocaleString() : null}
|
2021-05-17 22:22:11 +00:00
|
|
|
lowerLabel={Localization.archived}
|
2021-05-11 16:34:07 +00:00
|
|
|
lowerValue={repo.end ? new Date(repo.end).toLocaleString() : null}
|
|
|
|
buttons={buttons}
|
|
|
|
{...props}
|
|
|
|
/>
|
2021-04-24 02:23:23 +00:00
|
|
|
)
|
|
|
|
}
|