Skip to content

Commit

Permalink
Fix/date range picker history (#1094)
Browse files Browse the repository at this point in the history
* add react date picker modal

* add date time range picker

* added new date picker

* adjust date picker style and functionality

* added test for date picker

* resolving remaining merge conflicts

* change:
 - removed breaking code in getCoinImage
 - added png files for boba icons
 - loaded the icons for network and coin wherever required.
 - fix console crash for gasSwitcher
 - fix hover issue on history page
 - fix classNames for avaxIcons.

* commented out the date picker as needs some more time

* add date picker back

* updated snapshot and breaking change

* navgation links for stake & dao only for ETH network

* boba logo update across app

* added functionality/styling to date picker

---------

Co-authored-by: Sahil Kashetwar <sahil@enya.ai>
Co-authored-by: Sahil K <86316370+sk-enya@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 9, 2023
1 parent f5717f3 commit e43f32a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 21 deletions.
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

0 comments on commit e43f32a

Please sign in to comment.