Skip to content
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

feat(1-3262): initial impl of new month/range picker #9122

Merged
merged 8 commits into from
Jan 21, 2025

Conversation

thomasheartman
Copy link
Contributor

@thomasheartman thomasheartman commented Jan 20, 2025

This PR implements a first version of the new month/range picker for the data usage graphs. It's minimally hooked up to the existing functionality to not take anything away.

This primary purpose of this PR is to get the design and interaction out on sandbox so that UX can have a look and we can make adjustments.

As such, there are a few things in the code that we'll want to clean up before removing the flag later:

  • for faster iteration, I've used a lot of CSS nesting and element selectors. this isn't usually how we do it here, so we'll probably want to extract into styled components later
  • there is a temporary override of the value in the period selector so that you can select ranges. It won't affect the chart state, but it affects the selector state. Again, this lets you see how it acts and works.
  • I've added a NewHeader component because the existing setup smushed the selector (it's a MUI grid setup, which isn't very flexible). I don't know what we want to do with this in the end, but the existing chart does have some problems when you resize your window, at least (although this is likely due to the chart, and can be solved in the same way that we did for the personal dashboards).

image

Copy link

vercel bot commented Jan 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 21, 2025 9:03am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Jan 21, 2025 9:03am

Copy link
Contributor

github-actions bot commented Jan 20, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

Comment on lines +4 to +59
export type Period = {
key: string;
dayCount: number;
label: string;
year: number;
month: number;
selectable: boolean;
shortLabel: string;
};

export const toSelectablePeriod = (
date: Date,
label?: string,
selectable = true,
): Period => {
const year = date.getFullYear();
const month = date.getMonth();
const period = `${year}-${(month + 1).toString().padStart(2, '0')}`;
const dayCount = new Date(year, month + 1, 0).getDate();
return {
key: period,
year,
month,
dayCount,
shortLabel: date.toLocaleString('en-US', {
month: 'short',
}),
label:
label ||
date.toLocaleString('en-US', { month: 'long', year: 'numeric' }),
selectable,
};
};

const currentDate = new Date(Date.now());
const currentPeriod = toSelectablePeriod(currentDate, 'Current month');

const getSelectablePeriods = (): Period[] => {
const selectablePeriods = [currentPeriod];
for (
let subtractMonthCount = 1;
subtractMonthCount < 12;
subtractMonthCount++
) {
// JavaScript wraps around the year, so we don't need to handle that.
const date = new Date(
currentDate.getFullYear(),
currentDate.getMonth() - subtractMonthCount,
1,
);
selectablePeriods.push(
toSelectablePeriod(date, undefined, date > new Date('2024-03-31')),
);
}
return selectablePeriods;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These functions are mostly copied from frontend/src/hooks/useTrafficData.ts, but slightly modified. We'll probably want to reconsider this as the API is built out. I don't want to touch them more than I need to right now.

@@ -48,8 +48,7 @@ const calculateTrafficDataCost = (
return unitCount * trafficUnitCost;
};

const padMonth = (month: number): string =>
month < 10 ? `0${month}` : `${month}`;
const padMonth = (month: number): string => month.toString().padStart(2, '0');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Javascript can do this for us with a builtin instead of us checking the value

@thomasheartman thomasheartman requested a review from Tymek January 21, 2025 09:55
@thomasheartman thomasheartman changed the title feat(1-3262): begin impl of new month/range picker feat(1-3262): initial impl of new month/range picker Jan 21, 2025
import { styled } from '@mui/material';
import { type FC, useState } from 'react';

export type Period = {
Copy link
Member

Choose a reason for hiding this comment

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

For me DateRange is more intuitive, and easier to find in the code.

Comment on lines +43 to +47
for (
let subtractMonthCount = 1;
subtractMonthCount < 12;
subtractMonthCount++
) {
Copy link
Member

Choose a reason for hiding this comment

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

Seeing months in reverse order looks a bit off. I'm used to pickers having same natural order, and maybe even starting line aligned to January

Comment on lines +68 to +79
button: {
cursor: 'pointer',
border: 'none',
background: 'none',
fontSize: theme.typography.body1.fontSize,
padding: theme.spacing(0.5),
borderRadius: theme.shape.borderRadius,

'&.selected': {
backgroundColor: theme.palette.secondary.light,
},
},
Copy link
Member

Choose a reason for hiding this comment

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

For this to be consistent with other parts of the codebase, it should be done with props on a component (like <StyledButton selected={...}>).

Comment on lines +124 to +126
'li + li': {
marginTop: theme.spacing(1),
},
Copy link
Member

Choose a reason for hiding this comment

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

flex + gap can do the same, and be easier to understand, modify or debug.

Comment on lines +179 to +184
className={
!tempOverride &&
period.key === selectedPeriod
? 'selected'
: ''
}
Copy link
Member

Choose a reason for hiding this comment

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

Doing this with classes + nested selector instead of props makes it harder to refactor. There a link between how this element looks like, and where it is placed.

@thomasheartman thomasheartman merged commit 857c91b into main Jan 21, 2025
12 checks passed
@thomasheartman thomasheartman deleted the feat(1-3262)/new-month-range-picker branch January 21, 2025 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants