2021-05-19 17:56:41 +00:00
|
|
|
import React, { useCallback, useContext } from "react"
|
2021-04-21 16:21:30 +00:00
|
|
|
import Style from "./PageRepositories.module.css"
|
|
|
|
import classNames from "classnames"
|
2021-05-12 23:07:17 +00:00
|
|
|
import useBackendViewset from "../hooks/useBackendViewset"
|
2021-05-19 17:56:41 +00:00
|
|
|
import BoxRepositories from "../components/interactive/BoxRepositories"
|
|
|
|
import { useHistory } from "react-router"
|
|
|
|
import ContextLanguage from "../contexts/ContextLanguage"
|
2021-04-21 16:21:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
export default function PageRepositories({ children, className, ...props }) {
|
2021-05-12 23:07:17 +00:00
|
|
|
const bv = useBackendViewset("/api/v1/repositories/", "id")
|
2021-05-19 17:56:41 +00:00
|
|
|
const history = useHistory()
|
2021-05-20 10:16:01 +00:00
|
|
|
const { strings } = useContext(ContextLanguage)
|
2021-05-12 23:07:17 +00:00
|
|
|
|
2021-05-19 17:56:41 +00:00
|
|
|
const archive = useCallback(
|
2021-05-12 23:07:17 +00:00
|
|
|
async (pk) => {
|
2021-05-19 17:56:41 +00:00
|
|
|
await bv.apiRequest("PATCH", `/api/v1/repositories/${pk}`, {
|
|
|
|
"close": true,
|
|
|
|
})
|
2021-05-19 22:47:59 +00:00
|
|
|
await bv.retrieveResource(pk)
|
2021-05-11 15:05:38 +00:00
|
|
|
},
|
2021-05-15 16:05:13 +00:00
|
|
|
[bv],
|
2021-05-11 15:05:38 +00:00
|
|
|
)
|
2021-05-11 14:33:12 +00:00
|
|
|
|
2021-04-21 16:21:30 +00:00
|
|
|
return (
|
|
|
|
<div className={classNames(Style.PageRepositories, className)} {...props}>
|
2021-05-19 17:56:41 +00:00
|
|
|
<BoxRepositories
|
|
|
|
header={strings.menuActive}
|
|
|
|
loading={!bv.firstLoad}
|
2021-05-12 23:07:17 +00:00
|
|
|
running={bv.running}
|
2021-05-19 17:56:41 +00:00
|
|
|
repositories={bv.resources.filter(r => r.is_active)}
|
|
|
|
view={pk => history.push(`/repositories/${pk}`)}
|
|
|
|
archive={archive}
|
2021-05-19 22:47:59 +00:00
|
|
|
edit={pk => history.push(`/repositories/${pk}/edit`)}
|
2021-05-12 23:07:17 +00:00
|
|
|
/>
|
2021-05-19 17:56:41 +00:00
|
|
|
<BoxRepositories
|
|
|
|
header={strings.menuArchived}
|
|
|
|
loading={!bv.firstLoad}
|
2021-05-12 23:07:17 +00:00
|
|
|
running={bv.running}
|
2021-05-19 17:56:41 +00:00
|
|
|
repositories={bv.resources.filter(r => !r.is_active)}
|
|
|
|
view={pk => history.push(`/repositories/${pk}`)}
|
|
|
|
destroy={bv.destroyResource}
|
2021-05-12 23:07:17 +00:00
|
|
|
/>
|
2021-04-21 16:21:30 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|