Update report parameters.

This commit is contained in:
Mike Cao 2023-05-30 16:49:22 -07:00
parent e9b0d3f796
commit 43f5854f15
5 changed files with 27 additions and 20 deletions

View file

@ -8,6 +8,8 @@ export const ReportContext = createContext(null);
export function Report({ reportId, defaultParameters, children, ...props }) {
const report = useReport(reportId, defaultParameters);
//console.log(report);
return (
<ReportContext.Provider value={{ ...report }}>
<Page {...props} className={styles.container}>

View file

@ -20,15 +20,16 @@ export function ReportHeader({ icon }) {
post(`/reports/${data.id}`, data),
);
const { websiteId, name, dateRange } = report || {};
const { name, parameters } = report || {};
const { websiteId, dateRange } = parameters || {};
const { value, startDate, endDate } = dateRange || {};
const handleSelect = websiteId => {
updateReport({ websiteId });
const handleWebsiteSelect = websiteId => {
updateReport({ parameters: { websiteId } });
};
const handleDateChange = value => {
updateReport({ dateRange: { ...parseDateRange(value) } });
updateReport({ parameters: { dateRange: { ...parseDateRange(value) } } });
};
const handleSave = async () => {
@ -71,7 +72,7 @@ export function ReportHeader({ icon }) {
onChange={handleDateChange}
showAllTime
/>
<WebsiteSelect websiteId={websiteId} onSelect={handleSelect} />
<WebsiteSelect websiteId={websiteId} onSelect={handleWebsiteSelect} />
<LoadingButton
variant="primary"
loading={isCreating || isUpdating}