-
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.
Added the genre statistics report to the UI
- Loading branch information
1 parent
fb2ee8a
commit a772fee
Showing
12 changed files
with
244 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import config from "../config.json"; | ||
|
||
/** | ||
* Format a value as a date and time using the locale from the config file | ||
* @param {*} param0 | ||
* @returns | ||
*/ | ||
const DateAndTimeFormatter = ({ value }) => { | ||
// Check there's a value to format | ||
if (value != null) { | ||
// Create a formatter to format the value | ||
const formatter = new Intl.DateTimeFormat(config.region.locale, { | ||
dateStyle: "short", | ||
timeStyle: "medium", | ||
}); | ||
|
||
// Format the value | ||
const dateToFormat = new Date(value); | ||
const formattedValue = formatter.format(dateToFormat); | ||
|
||
return <>{formattedValue}</>; | ||
} else { | ||
return <></>; | ||
} | ||
}; | ||
|
||
export default DateAndTimeFormatter; |
94 changes: 94 additions & 0 deletions
94
src/music-catalogue-ui/components/genreStatisticsReport.js
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,94 @@ | ||
import React, { useCallback, useState } from "react"; | ||
import styles from "./reports.module.css"; | ||
import Select from "react-select"; | ||
import "react-datepicker/dist/react-datepicker.css"; | ||
import { apiGenreStatisticsReport } from "@/helpers/apiReports"; | ||
import GenreStatisticsRow from "./genreStatisticsRow"; | ||
|
||
/** | ||
* Component to display the job status search page and its results | ||
* @param {*} logout | ||
* @returns | ||
*/ | ||
const GenreStatisticsReport = ({ logout }) => { | ||
const [catalogue, setCatalogue] = useState(0); | ||
const [records, setRecords] = useState(null); | ||
|
||
// Callback to request the genre statistics report from the API | ||
const getReportCallback = useCallback( | ||
async (e) => { | ||
// Prevent the default action associated with the click event | ||
e.preventDefault(); | ||
|
||
// Set the wishlist flag from the drop-down selection | ||
const forWishList = catalogue.value == "wishlist"; | ||
|
||
// Fetch the report | ||
const fetchedRecords = await apiGenreStatisticsReport( | ||
forWishList, | ||
logout | ||
); | ||
setRecords(fetchedRecords); | ||
}, | ||
[catalogue, logout] | ||
); | ||
|
||
// Construct a list of select list options for the directory | ||
const options = [ | ||
{ value: "catalogue", label: "Main Catalogue" }, | ||
{ value: "wishlist", label: "Wish List" }, | ||
]; | ||
|
||
return ( | ||
<> | ||
<div className="row mb-2 pageTitle"> | ||
<h5 className="themeFontColor text-center">Genre Statistics Report</h5> | ||
</div> | ||
<div className={styles.reportFormContainer}> | ||
<form className={styles.reportForm}> | ||
<div className="row" align="center"> | ||
<div className="mt-3"> | ||
<div className="d-inline-flex align-items-center"> | ||
<label className={styles.reportFormLabel}> | ||
Generate Report For | ||
</label> | ||
<Select | ||
className={styles.reportCatalogueSelector} | ||
defaultValue={catalogue} | ||
onChange={setCatalogue} | ||
options={options} | ||
/> | ||
</div> | ||
<button | ||
className="btn btn-primary" | ||
onClick={(e) => getReportCallback(e)} | ||
> | ||
Search | ||
</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
<table className="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Genre</th> | ||
<th>Artists</th> | ||
<th>Albums</th> | ||
<th>Tracks</th> | ||
<th>Total Spend</th> | ||
</tr> | ||
</thead> | ||
{records != null && ( | ||
<tbody> | ||
{records.map((r) => ( | ||
<GenreStatisticsRow key={r.id} record={r} /> | ||
))} | ||
</tbody> | ||
)} | ||
</table> | ||
</> | ||
); | ||
}; | ||
|
||
export default GenreStatisticsReport; |
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,22 @@ | ||
import CurrencyFormatter from "./currencyFormatter"; | ||
|
||
/** | ||
* Component to render a row containing the details for a single genre statistics record | ||
* @param {*} record | ||
* @returns | ||
*/ | ||
const GenreStatisticsRow = ({ record }) => { | ||
return ( | ||
<tr> | ||
<td>{record.genre}</td> | ||
<td>{record.artists}</td> | ||
<td>{record.albums}</td> | ||
<td>{record.tracks}</td> | ||
<td> | ||
<CurrencyFormatter value={record.spend} renderZeroAsBlank={true} /> | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
export default GenreStatisticsRow; |
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 |
---|---|---|
|
@@ -24,3 +24,7 @@ | |
.lookupButton { | ||
float: right; | ||
} | ||
|
||
.lookupCatalogueSelector { | ||
width: 300px; | ||
} |
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,32 @@ | ||
.reportFormContainer { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.reportForm { | ||
width: 100vw; | ||
padding-top: 20px; | ||
padding-bottom: 20px; | ||
} | ||
|
||
.reportFormLabel { | ||
margin-right: 20px; | ||
font-size: 14px; | ||
font-weight: 600; | ||
color: rgb(34, 34, 34); | ||
} | ||
|
||
.reportForm * input { | ||
margin-left: 20px; | ||
margin-right: 20px; | ||
} | ||
|
||
.reportForm * button { | ||
margin-left: 20px; | ||
margin-right: 20px; | ||
} | ||
|
||
.reportCatalogueSelector { | ||
width: 300px; | ||
} |
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