Skip to content

feat(site): add date range picker for the template insights #8976

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

Merged
merged 5 commits into from
Aug 8, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add custom filters
  • Loading branch information
BrunoQuaresma committed Aug 8, 2023
commit 224bbb904d25634a0b10dd2e0872057f173caadd
48 changes: 46 additions & 2 deletions site/src/pages/TemplatePage/TemplateInsightsPage/DateRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ import "react-date-range/dist/theme/default.css"
import Button from "@mui/material/Button"
import ArrowRightAltOutlined from "@mui/icons-material/ArrowRightAltOutlined"
import Popover from "@mui/material/Popover"
import { DateRangePicker } from "react-date-range"
import { format } from "date-fns"
import { DateRangePicker, createStaticRanges } from "react-date-range"
import { format, subDays } from "date-fns"

// The type definition from @types is wrong
declare module "react-date-range" {
export function createStaticRanges(
ranges: Omit<StaticRange, "isSelected">[],
): StaticRange[]
}

export type DateRangeValue = {
startDate: Date
Expand Down Expand Up @@ -92,6 +99,43 @@ export const DateRange = ({
ranges={ranges}
maxDate={new Date()}
direction="horizontal"
staticRanges={createStaticRanges([
{
label: "Today",
range: () => ({
startDate: new Date(),
endDate: new Date(),
}),
},
{
label: "Yesterday",
range: () => ({
startDate: subDays(new Date(), 1),
endDate: subDays(new Date(), 1),
}),
},
{
label: "Last 7 days",
range: () => ({
startDate: subDays(new Date(), 6),
endDate: new Date(),
}),
},
{
label: "Last 15 days",
range: () => ({
startDate: subDays(new Date(), 14),
endDate: new Date(),
}),
},
{
label: "Last 30 days",
range: () => ({
startDate: subDays(new Date(), 29),
endDate: new Date(),
}),
},
])}
/>
</Popover>
</>
Expand Down