diff --git a/frontend/app/components/shared/SelectDateRange/SelectDateRange.tsx b/frontend/app/components/shared/SelectDateRange/SelectDateRange.tsx index 367611866..017ddab56 100644 --- a/frontend/app/components/shared/SelectDateRange/SelectDateRange.tsx +++ b/frontend/app/components/shared/SelectDateRange/SelectDateRange.tsx @@ -1,16 +1,14 @@ +import React from 'react'; import { DownOutlined } from '@ant-design/icons'; import Period from 'Types/app/period'; -import { Dropdown, Button } from 'antd'; +import { Dropdown, Button, Menu, Space, MenuProps } from 'antd'; import cn from 'classnames'; import { observer } from 'mobx-react-lite'; -import React from 'react'; -import { components } from 'react-select'; import { CUSTOM_RANGE, DATE_RANGE_OPTIONS } from 'App/dateRange'; import DateRangePopup from 'Shared/DateRangeDropdown/DateRangePopup'; import OutsideClickDetectingDiv from 'Shared/OutsideClickDetectingDiv'; -import Select from 'Shared/Select'; interface Props { period: any; @@ -25,7 +23,7 @@ interface Props { [x: string]: any; } -function SelectDateRange(props: Props) { +const SelectDateRange: React.FC = (props: Props) => { const [isCustom, setIsCustom] = React.useState(false); const { right = false, period, disableCustom = false, timezone, useButtonStyle = false } = props; let selectedValue = DATE_RANGE_OPTIONS.find( @@ -35,21 +33,21 @@ function SelectDateRange(props: Props) { disableCustom ? obj.value !== CUSTOM_RANGE : true ); - const onChange = (value: any) => { - if (value === CUSTOM_RANGE) { + const onChange = (e: any) => { + if (e.key === CUSTOM_RANGE) { setTimeout(() => { setIsCustom(true); }, 1); } else { - props.onChange(new Period({ rangeName: value })); + props.onChange(Period({ rangeName: e.key })); } }; const onApplyDateRange = (value: any) => { - const range = new Period({ + const range = Period({ rangeName: CUSTOM_RANGE, start: value.start, - end: value.end, + end: value.end }); props.onChange(range); setIsCustom(false); @@ -58,91 +56,27 @@ function SelectDateRange(props: Props) { const isCustomRange = period.rangeName === CUSTOM_RANGE; const customRange = isCustomRange ? period.rangeFormatted() : ''; - if (props.isAnt) { - const menuProps = { - items: options.map((opt) => ({ - label: opt.label, - key: opt.value, - })), - defaultSelectedKeys: selectedValue?.value ? [selectedValue.value] : undefined, - onClick: (e: any) => { - onChange(e.key); - }, - }; - - return ( -
- - {useButtonStyle ? ( - - ) : ( -
- {isCustomRange ? customRange : selectedValue?.label} - -
- )} -
- {isCustom && ( - { - if ( - e.target.parentElement.parentElement.classList.contains( - 'rc-time-picker-panel-select' - ) || - e.target.parentElement.parentElement.classList[0]?.includes( - '-menu' - ) || - e.target.className.includes('ant-picker') - ) { - return false; - } - setIsCustom(false); - }} - > -
- setIsCustom(false)} - selectedDateRange={period.range} - /> -
-
- )} -
- ); - } + const menuItems: MenuProps['items'] = options.map((opt) => ({ + key: opt.value, + label: opt.label, + className: opt.value === selectedValue?.value ? 'ant-select-item-option-selected' : '', + })); return ( -
-