1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 04:54:18 +00:00

Create Alerts page

This commit is contained in:
Steffo 2021-05-24 03:42:30 +02:00
parent a11c1a16a3
commit a85c3da096
Signed by: steffo
GPG key ID: 6965406171929D01
8 changed files with 88 additions and 43 deletions

View file

@ -15,6 +15,9 @@ import PageShare from "./routes/PageShare"
export default function PageSwitcher({ ...props }) { export default function PageSwitcher({ ...props }) {
return ( return (
<Switch {...props}> <Switch {...props}>
<Route path={"/repositories/:id/alerts"} exact={true}>
<PageAlerts/>
</Route>
<Route path={"/repositories/:id/share"} exact={true}> <Route path={"/repositories/:id/share"} exact={true}>
<PageShare/> <PageShare/>
</Route> </Route>
@ -33,9 +36,6 @@ export default function PageSwitcher({ ...props }) {
<Route path={"/repositories"} exact={true}> <Route path={"/repositories"} exact={true}>
<PageRepositories/> <PageRepositories/>
</Route> </Route>
<Route path={"/alerts"} exact={true}>
<PageAlerts/>
</Route>
<Route path={"/settings"} exact={true}> <Route path={"/settings"} exact={true}>
<PageSettings/> <PageSettings/>
</Route> </Route>

View file

@ -11,6 +11,7 @@ import ContextUser from "../../contexts/ContextUser"
* *
* @param repositories - The repositories to list. * @param repositories - The repositories to list.
* @param view - Function with a single "id" parameter to call when the view repository button is clicked. * @param view - Function with a single "id" parameter to call when the view repository button is clicked.
* @param alerts - Function with a single "id" parameter to call when the alerts button is clicked.
* @param archive - Function with a single "id" parameter to call when the archive repository button is clicked. * @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 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 destroy - Function with a single "id" parameter to call when the delete repository button is clicked.
@ -25,6 +26,7 @@ export default function BoxRepositories(
{ {
repositories, repositories,
view, view,
alerts,
share, share,
archive, archive,
edit, edit,
@ -50,6 +52,7 @@ export default function BoxRepositories(
key={repo["id"]} key={repo["id"]}
repo={repo} repo={repo}
view={view ? () => view(repo["id"]) : null} view={view ? () => view(repo["id"]) : null}
alerts={alerts ? () => alerts(repo["id"]) : null}
share={(share && user["email"] === repo["owner"]["email"]) ? () => share(repo["id"]) : null} share={(share && user["email"] === repo["owner"]["email"]) ? () => share(repo["id"]) : null}
archive={archive ? () => archive(repo["id"]) : null} archive={archive ? () => archive(repo["id"]) : null}
edit={edit ? () => edit(repo["id"]) : null} edit={edit ? () => edit(repo["id"]) : null}

View file

@ -28,7 +28,6 @@ export default function Sidebar({ className, ...props }) {
<> <>
<ButtonSidebar to={"/dashboard"} icon={faHome}>{strings.dashboard}</ButtonSidebar> <ButtonSidebar to={"/dashboard"} icon={faHome}>{strings.dashboard}</ButtonSidebar>
<ButtonSidebar to={"/repositories"} icon={faFolder}>{strings.repositories}</ButtonSidebar> <ButtonSidebar to={"/repositories"} icon={faFolder}>{strings.repositories}</ButtonSidebar>
<ButtonSidebar to={"/alerts"} icon={faExclamationTriangle}>{strings.alerts}</ButtonSidebar>
<ButtonSidebar to={"/settings"} icon={faCog}>{strings.settings}</ButtonSidebar> <ButtonSidebar to={"/settings"} icon={faCog}>{strings.settings}</ButtonSidebar>
</> </>
: :

View file

@ -1,5 +1,13 @@
import React, { useContext } from "react" import React, { useContext } from "react"
import { faArchive, faFolder, faFolderOpen, faPencilAlt, faShare, faTrash } from "@fortawesome/free-solid-svg-icons" import {
faArchive,
faBell,
faFolder,
faFolderOpen,
faPencilAlt,
faShare,
faTrash,
} from "@fortawesome/free-solid-svg-icons"
import ContextLanguage from "../../contexts/ContextLanguage" import ContextLanguage from "../../contexts/ContextLanguage"
import SummaryBase from "../base/summary/SummaryBase" import SummaryBase from "../base/summary/SummaryBase"
import SummaryLeft from "../base/summary/SummaryLeft" import SummaryLeft from "../base/summary/SummaryLeft"
@ -13,7 +21,8 @@ import SummaryRight from "../base/summary/SummaryRight"
* *
* @param repo - The repository to display. * @param repo - The repository to display.
* @param view - Function with no parameters to call when the view repository button is clicked. * @param view - Function with no parameters to call when the view repository button is clicked.
* @param share - Function with no parameters to call when the archive repository button is clicked. * @param alerts - Function with no parameters to call when the alerts button is clicked.
* @param share - Function with no parameters to call when the share repository button is clicked.
* @param archive - Function with no parameters to call when the archive 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 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 destroy - Function with no parameters to call when the delete repository button is clicked.
@ -24,7 +33,7 @@ import SummaryRight from "../base/summary/SummaryRight"
* @constructor * @constructor
*/ */
export default function SummaryRepository( export default function SummaryRepository(
{ repo, view, share, archive, edit, destroy, running, className, ...props }, { repo, view, alerts, share, archive, edit, destroy, running, className, ...props },
) { ) {
const { strings } = useContext(ContextLanguage) const { strings } = useContext(ContextLanguage)
@ -47,7 +56,7 @@ export default function SummaryRepository(
{share ? {share ?
<SummaryButton <SummaryButton
color={"Green"} color={"Grey"}
icon={faShare} icon={faShare}
onClick={() => share()} onClick={() => share()}
disabled={running} disabled={running}
@ -56,25 +65,14 @@ export default function SummaryRepository(
</SummaryButton> </SummaryButton>
: null} : null}
{destroy ? {alerts ?
<SummaryButton <SummaryButton
color={"Red"} color={"Green"}
icon={faTrash} icon={faBell}
onClick={() => destroy()} onClick={() => alerts()}
disabled={running} disabled={running}
> >
{strings.delete} {strings.alerts}
</SummaryButton>
: null}
{archive ?
<SummaryButton
color={"Grey"}
icon={faArchive}
onClick={() => archive()}
disabled={running}
>
{strings.archive}
</SummaryButton> </SummaryButton>
: null} : null}
@ -89,6 +87,28 @@ export default function SummaryRepository(
</SummaryButton> </SummaryButton>
: null} : null}
{archive ?
<SummaryButton
color={"Grey"}
icon={faArchive}
onClick={() => archive()}
disabled={running}
>
{strings.archive}
</SummaryButton>
: null}
{destroy ?
<SummaryButton
color={"Red"}
icon={faTrash}
onClick={() => destroy()}
disabled={running}
>
{strings.delete}
</SummaryButton>
: null}
<SummaryRight/> <SummaryRight/>
</SummaryBase> </SummaryBase>
) )

View file

@ -3,13 +3,19 @@ import Style from "./PageAlerts.module.css"
import classNames from "classnames" import classNames from "classnames"
import BoxFull from "../components/base/BoxFull" import BoxFull from "../components/base/BoxFull"
import ContextLanguage from "../contexts/ContextLanguage" import ContextLanguage from "../contexts/ContextLanguage"
import BoxHeader from "../components/base/BoxHeader"
import { useParams } from "react-router"
export default function PageAlerts({ children, className, ...props }) { export default function PageAlerts({ children, className, ...props }) {
const { strings } = useContext(ContextLanguage) const { strings } = useContext(ContextLanguage)
const { id } = useParams()
return ( return (
<div className={classNames(Style.PageAlerts, className)} {...props}> <div className={classNames(Style.PageAlerts, className)} {...props}>
<BoxHeader className={Style.Header}>
{strings.alerts}
</BoxHeader>
<BoxFull header={strings.alertTitle} className={Style.YourAlerts}> <BoxFull header={strings.alertTitle} className={Style.YourAlerts}>
{strings.notImplemented} {strings.notImplemented}
</BoxFull> </BoxFull>

View file

@ -3,7 +3,9 @@
grid-template-areas: grid-template-areas:
"a" "a"
"b"; "b"
"c";
grid-template-rows: auto 1fr 1fr;
grid-gap: 10px; grid-gap: 10px;
@ -11,10 +13,14 @@
height: 100%; height: 100%;
} }
.YourAlerts { .Header {
grid-area: a; grid-area: a;
} }
.CreateAlert { .YourAlerts {
grid-area: b; grid-area: b;
} }
.CreateAlert {
grid-area: c;
}

View file

@ -32,6 +32,7 @@ export default function PageRepositories({ children, className, ...props }) {
repositories={bv.resources.filter(r => r.is_active)} repositories={bv.resources.filter(r => r.is_active)}
view={pk => history.push(`/repositories/${pk}`)} view={pk => history.push(`/repositories/${pk}`)}
share={pk => history.push(`/repositories/${pk}/share`)} share={pk => history.push(`/repositories/${pk}/share`)}
alerts={pk => history.push(`/repositories/${pk}/alerts`)}
archive={archive} archive={archive}
edit={pk => history.push(`/repositories/${pk}/edit`)} edit={pk => history.push(`/repositories/${pk}/edit`)}
/> />

View file

@ -11,22 +11,15 @@ import ContextUser from "../contexts/ContextUser"
export default function PageShare({ className, ...props }) { export default function PageShare({ className, ...props }) {
const { strings } = useContext(ContextLanguage) const { strings } = useContext(ContextLanguage)
const {user: loggedUser} = useContext(ContextUser) const { user: loggedUser } = useContext(ContextUser)
const { id } = useParams() const { id } = useParams()
const {resources: users, running: usersBvRunning} = useBackendViewset(
"/api/v1/users/", const {
"email", resources: authorizations,
{ createResource: createAuthorization,
list: true, destroyResource: destroyAuthorization,
create: false, running: authBvRunning
retrieve: false, } = useBackendViewset(
edit: false,
destroy: false,
command: false,
action: false,
}
)
const {resources: authorizations, createResource: createAuthorization, destroyResource: destroyAuthorization, running: authBvRunning} = useBackendViewset(
`/api/v1/repositories/${id}/authorizations/`, `/api/v1/repositories/${id}/authorizations/`,
"email", "email",
{ {
@ -40,6 +33,23 @@ export default function PageShare({ className, ...props }) {
} }
) )
const {
resources: users,
running: usersBvRunning
} = useBackendViewset(
"/api/v1/users/",
"email",
{
list: true,
create: false,
retrieve: false,
edit: false,
destroy: false,
command: false,
action: false,
}
)
const shareWith = useCallback( const shareWith = useCallback(
user => { user => {
console.info("Authorizing ", user, " ...") console.info("Authorizing ", user, " ...")