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

Fix/date range picker history #1094

Merged
merged 17 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
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
23 changes: 18 additions & 5 deletions packages/boba/gateway/src/containers/history/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useRef, useState, useEffect, useCallback } from 'react'
import React, { useRef, useState, useEffect, useCallback } from 'react'
import { subMonths } from 'date-fns'
import {
DatePickerDropdown,
Expand All @@ -13,6 +13,8 @@ export interface IDatePickerProps {
selected: Date
timeFormat?: string
onChange: Function
minDate?: Date
maxDate?: Date
range?: boolean
onChangeFrom?: Function
onChangeTo?: Function
Expand All @@ -38,8 +40,17 @@ const DatePicker = (props: IDatePickerProps) => {
}, [dropdownRef])

const [selectedDate, setSelectedDate] = useState<Date>(props.selected)
const [isOpen, setIsOpen] = useState(false)
const today = new Date()
const pastDate = new Date(2015, 7, 30)

const disabledPeriod = {
before: props.minDate ? props.minDate : pastDate,
after: props.maxDate ? props.maxDate : today,
}
const disabledDays = [disabledPeriod]

const [isOpen, setIsOpen] = useState(false)

const defaultSelectedRange: DateRange = {
from: subMonths(today, 6),
to: today,
Expand Down Expand Up @@ -83,13 +94,14 @@ const DatePicker = (props: IDatePickerProps) => {
{dateRangeString}
</DatePickerHeader>
{isOpen && (
<DatePickerDropdown>
<DatePickerDropdown isRange={true}>
<DayPicker
id="rangeDatePicker"
mode="range"
defaultMonth={selectedRange?.from}
defaultMonth={selectedRange?.to}
selected={selectedRange}
onSelect={(range) => handleRangeChange(range)}
disabled={disabledDays}
/>
</DatePickerDropdown>
)}
Expand All @@ -103,12 +115,13 @@ const DatePicker = (props: IDatePickerProps) => {
{formatDate(selectedDate.getTime() / 1000, props.timeFormat)}
</DatePickerHeader>
{isOpen && (
<DatePickerDropdown>
<DatePickerDropdown isRange={false}>
<DayPicker
mode="single"
defaultMonth={selectedDate}
selected={selectedDate}
onSelect={(date) => handleDateChange(date)}
disabled={disabledDays}
/>
</DatePickerDropdown>
)}
Expand Down
3 changes: 3 additions & 0 deletions packages/boba/gateway/src/containers/history/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ const History = () => {
{...(range
? { onChangeFrom: setFilterStartDate, onChangeTo: setFilterEndDate }
: {})}
{...(label === 'To'
? { minDate: filterStartDate }
: { maxDate: filterEndDate })}
/>
)
}
Expand Down
54 changes: 42 additions & 12 deletions packages/boba/gateway/src/containers/history/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export const DatePickerHeadersContainer = styled.div`
flex-direction: row;
`

export const DatePickerDropdown = styled.div`
export const DatePickerDropdown = styled.div<{ isRange?: boolean }>`
transition: 0.25s all;
position: absolute;
width: 250px;
Expand All @@ -776,23 +776,20 @@ export const DatePickerDropdown = styled.div`
color: ${colors.gray[800]};
background: ${colors.gray[50]};
border: 1px solid ${colors.gray[500]};
.rdp-day_selected {
border: 1px solid ${colors.gray[600]};
color: ${colors.gray[800]};
}
`
: css`
color: ${colors.gray[50]};
background: ${colors.gray[500]};
border: 1px solid ${colors.gray[300]};
.rdp-day_selected {
border: 1px solid ${colors.gray[100]};
}
${(isRange) =>
!isRange &&
css`
.rdp-day_selected {
border: 1px solid ${colors.gray[100]};
}
`}
`}

.rdp-day {
border-radius: 20%;
}
.rdp {
--rdp-cell-size: 30px;
--rdp-caption-font-size: 14px;
Expand All @@ -801,6 +798,38 @@ export const DatePickerDropdown = styled.div`
--rdp-accent-color: ${(props) => props.theme.colors.gray[400]};
--rdp-background-color: ${(props) => props.theme.colors.gray[400]};
}
${(props) =>
props.isRange &&
props.theme.name === 'light' &&
css`
.rdp-day_selected {
border: 1px solid ${props.theme.colors.gray[600]};
color: ${props.theme.colors.gray[800]};
}
`}
${(props) =>
!props.isRange &&
props.theme.name === 'dark' &&
css`
.rdp-day_selected {
border: 1px solid ${props.theme.colors.gray[100]};
}
`}

${(props) =>
!props.isRange &&
css`
.rdp-day {
border-radius: 20%;
}
`}
${(props) =>
props.isRange &&
css`
.rdp-day {
border: none !important;
}
`}
`

export const DatePickerContainer = styled.div`
Expand All @@ -811,6 +840,7 @@ export const DatePickerContainer = styled.div`
width: 100%;
transition: 0.25s all;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
${(props) =>
props.theme.name === 'light' &&
css`
Expand All @@ -820,5 +850,5 @@ export const DatePickerContainer = styled.div`
props.theme.name === 'dark' &&
css`
color: ${props.theme.colors.gray[50]};
`}
`};
`
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Testing history page Date Picker 1`] = `
<DocumentFragment>
<div
class="sc-cNNTdL bOhmqZ"
class="sc-cNNTdL XooGL"
>
<div
class="sc-iWxGtA kjxmRV"
Expand Down Expand Up @@ -48,7 +48,7 @@ exports[`Testing history page Test History Page 1`] = `
Date Range From
</p>
<div
class="sc-cNNTdL kTLOBq"
class="sc-cNNTdL iedVlo"
>
<div
class="sc-iWxGtA cdSvk"
Expand All @@ -62,7 +62,7 @@ exports[`Testing history page Test History Page 1`] = `
To
</p>
<div
class="sc-cNNTdL kTLOBq"
class="sc-cNNTdL iedVlo"
>
<div
class="sc-iWxGtA cdSvk"
Expand All @@ -80,7 +80,7 @@ exports[`Testing history page Test History Page 1`] = `
Date Range
</p>
<div
class="sc-cNNTdL kTLOBq"
class="sc-cNNTdL iedVlo"
>
<div
class="sc-iWxGtA cdSvk"
Expand Down
Loading