-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Melon Head: Spike dashboard page (#95)
Implements basic dashboard (as homepage) and 404 page.
- Loading branch information
1 parent
24cfd8f
commit 3721eb3
Showing
20 changed files
with
314 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
@module external styles: {..} = "./Dashboard/styles.module.scss" | ||
|
||
open Belt | ||
|
||
module ViewBool = { | ||
@react.component | ||
let make = (~value: bool) => {value ? React.string("yes") : React.string("no")} | ||
} | ||
|
||
module RowBasedTable = { | ||
@react.component | ||
let make = (~rows: array<(string, 'a => React.element)>, ~data: Api.webData<'a>, ~title=None) => { | ||
let viewRow = (index, (name, getter)) => | ||
<tr key={Int.toString(index)}> | ||
<td> {React.string(name)} </td> | ||
<td> {data->RemoteData.unwrap(getter, ~default=React.null)} </td> | ||
</tr> | ||
|
||
let viewRows = rows->Array.mapWithIndex(viewRow)->React.array | ||
|
||
<div className={styles["row-table-wrapper"]}> | ||
{switch title { | ||
| Some(str) => <h2 className={styles["row-table-title"]}> {React.string(str)} </h2> | ||
| None => React.null | ||
}} | ||
<table className={styles["row-table-table"]}> | ||
<tbody> viewRows </tbody> | ||
</table> | ||
{switch data { | ||
| Loading => | ||
<div className={styles["row-table-loading"]}> | ||
<Icons.Loading variant=Icons.Dark /> | ||
</div> | ||
| Failure(err) => | ||
<div className={styles["row-table-error"]}> | ||
<h4> {React.string("Error loading data")} </h4> | ||
<pre> {React.string(Api.showError(err))} </pre> | ||
</div> | ||
| _ => React.null | ||
}} | ||
</div> | ||
} | ||
} | ||
|
||
@react.component | ||
let make = (~session: Api.webData<Session.t>, ~api: Api.t) => { | ||
open Stats | ||
|
||
let (basicStats, setBasicStats) = React.useState(RemoteData.init) | ||
|
||
React.useEffect0(() => { | ||
let req = api->Api.getJson(~path="/stats/basic", ~decoder=Stats.Decode.basic) | ||
setBasicStats(RemoteData.setLoading) | ||
|
||
req->Future.get(res => { | ||
setBasicStats(_ => RemoteData.fromResult(res)) | ||
}) | ||
|
||
Some(() => Future.cancel(req)) | ||
}) | ||
|
||
let applicationsRows = [ | ||
("Waiting for email verification", ({unverified}) => React.string(unverified->Int.toString)), | ||
("In processing", ({processing}) => React.string(processing->Int.toString)), | ||
("Accpted", ({accepted}) => React.string(accepted->Int.toString)), | ||
("Rejected", ({rejected}) => React.string(rejected->Int.toString)), | ||
] | ||
|
||
let permissionsRows = [ | ||
( | ||
"List all applications in the system", | ||
session => {<ViewBool value={Session.hasRole(session, ~role=Session.ListApplications)} />}, | ||
), | ||
] | ||
|
||
<Page> | ||
<Page.Title> {React.string("Dashboard")} </Page.Title> | ||
<div className={styles["stats-grid"]}> | ||
<RowBasedTable rows=applicationsRows data=basicStats title=Some("Current Applications") /> | ||
<RowBasedTable rows=permissionsRows data=session title=Some("Your Permissions/Roles") /> | ||
</div> | ||
</Page> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
.stats-grid { | ||
display: grid; | ||
grid-template-columns: 25% 25% 25% 25%; | ||
gap: 12px; | ||
} | ||
|
||
.row-table-wrapper { | ||
position: relative; | ||
border-radius: 4px; | ||
border: 4px solid rgba(#211D22, .4); | ||
border-radius: 5px; | ||
overflow: hidden; | ||
} | ||
|
||
.row-table-title { | ||
background:rgba(#211D22, .4); | ||
font-size: 16px; | ||
line-height: 1.5em; | ||
font-weight: 600; | ||
padding: 0 12px 4px; | ||
color: white; | ||
} | ||
|
||
.row-table-table { | ||
width: 100%; | ||
|
||
tr:first-child td { | ||
border-top: none; | ||
} | ||
|
||
td { | ||
padding: 12px; | ||
border-top: 1px solid rgba(#211D22, .4); | ||
|
||
&:first-child { | ||
font-weight: 600; | ||
} | ||
|
||
&:last-child { | ||
text-align: right; | ||
} | ||
} | ||
} | ||
|
||
@mixin overlay { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
} | ||
|
||
.row-table-loading { | ||
@include overlay; | ||
background: rgba(white, 0.6); | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.row-table-error { | ||
@include overlay; | ||
background: #EF562E; | ||
padding: 12px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.