From e97a28a814409c946c591f64da8c8a91d159261d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20F=C3=A9lix?= Date: Thu, 14 Nov 2019 11:36:51 +0000 Subject: [PATCH] refactor: move selected date container up Allows reuse of the date range picker by making the display of the selected range independent from the picker. --- .../src/components/LogsDownloaderPopover.js | 100 ++++++++++++++++-- .../date-range-picker/DateRangePicker.js | 92 +--------------- 2 files changed, 96 insertions(+), 96 deletions(-) diff --git a/new-lamassu-admin/src/components/LogsDownloaderPopover.js b/new-lamassu-admin/src/components/LogsDownloaderPopover.js index 77fcf69a..10ca75dc 100644 --- a/new-lamassu-admin/src/components/LogsDownloaderPopover.js +++ b/new-lamassu-admin/src/components/LogsDownloaderPopover.js @@ -5,15 +5,72 @@ import { toInteger } from 'lodash/fp' import moment from 'moment' import { makeStyles } from '@material-ui/core' +import { ReactComponent as Arrow } from '../styling/icons/arrow/download_logs.svg' import typographyStyles from '../components/typography/styles' -import { primaryColor } from '../styling/variables' +import { primaryColor, offColor, zircon } from '../styling/variables' import { Link } from './buttons' import { RadioGroup } from './inputs' import Popover from './Popover' import DateRangePicker from './date-range-picker/DateRangePicker' -const { h4 } = typographyStyles +const { info1, label1, label2, h4 } = typographyStyles + +const dateContainerStyles = { + wrapper: { + height: 46, + width: 99 + }, + container: { + display: 'flex' + }, + monthWeekDayContainer: { + display: 'flex', + flexDirection: 'column' + }, + label: { + extend: label1, + lineHeight: 1.33, + color: primaryColor + }, + bigNumber: { + extend: info1, + lineHeight: 1, + marginRight: 7 + }, + monthYear: { + extend: label2, + lineHeight: 1.17, + color: primaryColor + }, + weekDay: { + extend: label1, + lineHeight: 1.33, + color: offColor + } +} + +const dateContainerUseStyles = makeStyles(dateContainerStyles) + +const DateContainer = ({ date, children, ...props }) => { + const classes = dateContainerUseStyles() + + return ( +
+
{children}
+ {date && + <> +
+
{date.format('D')}
+
+ {`${date.format('MMM')} ${date.format('YYYY')}`} + {date.format('dddd')} +
+
+ } +
+ ) +} const styles = { popoverContent: { @@ -42,6 +99,23 @@ const styles = { }, download: { padding: [[10, 15]] + }, + dateContainerWrapper: { + display: 'flex', + justifyContent: 'space-between', + alignItems: 'center', + position: 'relative', + backgroundColor: zircon, + padding: [[0, 15]], + minHeight: 70 + }, + arrowContainer: { + position: 'absolute', + left: 116, + top: 26 + }, + arrow: { + margin: 'auto' } } @@ -99,11 +173,23 @@ const LogsDownloaderPopover = ({ id, open, anchorEl, onClose, logsResponse, ...p className={classes.radioButtons} /> - +
+
+ {range && ( + <> + From +
+ +
+ To + + )} +
+ +
{ - const classes = dateContainerUseStyles() - - return ( -
-
{children}
- {date && - <> -
-
{date.format('D')}
-
- {`${date.format('MMM')} ${date.format('YYYY')}`} - {date.format('dddd')} -
-
- } -
- ) -} - const styles = { wrapper: { backgroundColor: 'white', borderRadius: 10 - }, - dateThingyContainer: { - display: 'flex', - justifyContent: 'space-between', - alignItems: 'center', - position: 'relative', - backgroundColor: zircon, - padding: [[0, 15]], - minHeight: 70 - }, - arrowContainer: { - position: 'absolute', - left: 116, - top: 26 - }, - arrow: { - margin: 'auto' } } const useStyles = makeStyles(styles) -const DateRangePicker = ({ minDate, maxDate, className, handleChange, ...props }) => { +const DateRangePicker = ({ minDate, maxDate, className, onRangeChange, ...props }) => { const [from, setFrom] = useState(null) const [to, setTo] = useState(null) useEffect(() => { - handleChange(from, to) - }, [to]) + onRangeChange(from, to) + }, [from, to]) const classes = useStyles() @@ -120,13 +41,6 @@ const DateRangePicker = ({ minDate, maxDate, className, handleChange, ...props } return ( <>
-
- From -
- -
- To -