2021-05-23 15:56:25 +00:00
|
|
|
import React, { useContext } from "react"
|
2021-05-19 17:56:41 +00:00
|
|
|
import BoxFullScrollable from "../base/BoxFullScrollable"
|
|
|
|
import Loading from "../base/Loading"
|
|
|
|
import SummaryRepository from "./SummaryRepository"
|
2021-05-20 09:39:40 +00:00
|
|
|
import Empty from "./Empty"
|
2021-05-23 15:56:25 +00:00
|
|
|
import ContextUser from "../../contexts/ContextUser"
|
2021-05-19 17:56:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A {@link BoxFullScrollable} listing some repositories.
|
|
|
|
*
|
|
|
|
* @param repositories - The repositories to list.
|
|
|
|
* @param view - Function with a single "id" parameter to call when the view repository button is clicked.
|
2021-05-24 01:42:30 +00:00
|
|
|
* @param alerts - Function with a single "id" parameter to call when the alerts button is clicked.
|
2021-05-19 17:56:41 +00:00
|
|
|
* @param archive - Function with a single "id" parameter to call when the archive repository button is clicked.
|
|
|
|
* @param edit - Function with a single "id" parameter to call when the edit repository button is clicked.
|
|
|
|
* @param destroy - Function with a single "id" parameter to call when the delete repository button is clicked.
|
|
|
|
* @param firstLoad - If the repositories are loading and a loading message should be displayed.
|
|
|
|
* @param running - If an action is running on the viewset.
|
|
|
|
* @param props - Additional props to pass to the box.
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2021-05-23 14:28:53 +00:00
|
|
|
export default function BoxRepositories(
|
|
|
|
{
|
|
|
|
repositories,
|
|
|
|
view,
|
2021-05-24 01:42:30 +00:00
|
|
|
alerts,
|
2021-05-23 14:28:53 +00:00
|
|
|
share,
|
|
|
|
archive,
|
|
|
|
edit,
|
|
|
|
destroy,
|
|
|
|
loading,
|
|
|
|
running,
|
|
|
|
...props
|
|
|
|
})
|
|
|
|
{
|
2021-05-23 15:56:25 +00:00
|
|
|
const {user} = useContext(ContextUser)
|
|
|
|
|
2021-05-19 17:56:41 +00:00
|
|
|
let contents
|
|
|
|
if(loading) {
|
|
|
|
contents = <Loading/>
|
|
|
|
}
|
|
|
|
else if(repositories.length === 0) {
|
2021-05-20 09:39:40 +00:00
|
|
|
contents = <Empty/>
|
2021-05-19 17:56:41 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
contents = repositories.map(repo => (
|
|
|
|
<SummaryRepository
|
|
|
|
key={repo["id"]}
|
|
|
|
repo={repo}
|
|
|
|
view={view ? () => view(repo["id"]) : null}
|
2021-05-28 12:31:26 +00:00
|
|
|
alerts={(alerts && user["email"] === repo["owner"]["email"]) ? () => alerts(repo["id"]) : null}
|
2021-05-23 15:56:25 +00:00
|
|
|
share={(share && user["email"] === repo["owner"]["email"]) ? () => share(repo["id"]) : null}
|
2021-05-28 12:31:26 +00:00
|
|
|
archive={(archive && user["email"] === repo["owner"]["email"]) ? () => archive(repo["id"]) : null}
|
|
|
|
edit={(edit && user["email"] === repo["owner"]["email"]) ? () => edit(repo["id"]) : null}
|
|
|
|
destroy={(destroy && user["email"] === repo["owner"]["email"]) ? () => destroy(repo["id"]) : null}
|
2021-05-19 17:56:41 +00:00
|
|
|
running={running}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BoxFullScrollable {...props}>
|
|
|
|
{contents}
|
|
|
|
</BoxFullScrollable>
|
|
|
|
)
|
|
|
|
}
|