Skip to content

Use the actual current period on the usage page #16474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions components/dashboard/src/components/UsageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ function UsageView({ attributionId }: UsageViewProps) {
const match = /#(\d{4}-\d{2}-\d{2}):(\d{4}-\d{2}-\d{2})/.exec(location.hash);
if (match) {
try {
setStartDate(dayjs(match[1], "YYYY-MM-DD"));
setEndDate(dayjs(match[2], "YYYY-MM-DD"));
const today = new Date();
const prevMonth = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate());
const todayStr = today.toISOString().slice(0, 10);
const prevMonthStr = prevMonth.toISOString().slice(0, 10);
Comment on lines +44 to +47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this correctly, this change would ignore the the URL hash parameter and would always set it to one month back. That's actually not the desired behaviour, as it prevents deep-linking of the current view in the URL.

Showing the last 1 month, could be the default behaviour when no hash is supplied, however, but the change as it stands does not do that. You likely want to move the handling into the !match case of this if.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks alot I was trying to find out what was causing the I have done the similar changes

setStartDate(dayjs(prevMonthStr));
setEndDate(dayjs(todayStr));
} catch (e) {
// Catches the Error
console.error(e);
}
}
Expand Down