diff --git a/frontend/src/components/CustomTimePicker/CustomTimePicker.tsx b/frontend/src/components/CustomTimePicker/CustomTimePicker.tsx index 8be31b78e9..a29f0180b4 100644 --- a/frontend/src/components/CustomTimePicker/CustomTimePicker.tsx +++ b/frontend/src/components/CustomTimePicker/CustomTimePicker.tsx @@ -115,6 +115,9 @@ function CustomTimePicker({ const handleOpenChange = (newOpen: boolean): void => { setOpen(newOpen); + if (!newOpen) { + setCustomDTPickerVisible?.(false); + } }; const debouncedHandleInputChange = debounce((inputValue): void => { diff --git a/frontend/src/components/CustomTimePicker/CustomTimePickerPopoverContent.tsx b/frontend/src/components/CustomTimePicker/CustomTimePickerPopoverContent.tsx index 8fafe40b00..4a41bec4f5 100644 --- a/frontend/src/components/CustomTimePicker/CustomTimePickerPopoverContent.tsx +++ b/frontend/src/components/CustomTimePicker/CustomTimePickerPopoverContent.tsx @@ -1,6 +1,6 @@ import './CustomTimePicker.styles.scss'; -import { Button, DatePicker } from 'antd'; +import { Button } from 'antd'; import cx from 'classnames'; import ROUTES from 'constants/routes'; import { DateTimeRangeType } from 'container/TopNav/CustomDateTimeModal'; @@ -9,12 +9,10 @@ import { Option, RelativeDurationSuggestionOptions, } from 'container/TopNav/DateTimeSelectionV2/config'; -import dayjs, { Dayjs } from 'dayjs'; import { Dispatch, SetStateAction, useMemo } from 'react'; -import { useSelector } from 'react-redux'; import { useLocation } from 'react-router-dom'; -import { AppState } from 'store/reducers'; -import { GlobalReducer } from 'types/reducer/globalTime'; + +import RangePickerModal from './RangePickerModal'; interface CustomTimePickerPopoverContentProps { options: any[]; @@ -40,35 +38,12 @@ function CustomTimePickerPopoverContent({ handleGoLive, selectedTime, }: CustomTimePickerPopoverContentProps): JSX.Element { - const { RangePicker } = DatePicker; const { pathname } = useLocation(); - const { maxTime, minTime } = useSelector( - (state) => state.globalTime, - ); - const isLogsExplorerPage = useMemo(() => pathname === ROUTES.LOGS_EXPLORER, [ pathname, ]); - const disabledDate = (current: Dayjs): boolean => { - const currentDay = dayjs(current); - return currentDay.isAfter(dayjs()); - }; - - const onPopoverClose = (visible: boolean): void => { - if (!visible) { - setCustomDTPickerVisible(false); - } - setIsOpen(visible); - }; - - const onModalOkHandler = (date_time: any): void => { - if (date_time?.[1]) { - onPopoverClose(false); - } - onCustomDateHandler(date_time, LexicalContext.CUSTOM_DATE_PICKER); - }; function getTimeChips(options: Option[]): JSX.Element { return (
@@ -105,7 +80,9 @@ function CustomTimePickerPopoverContent({ }} className={cx( 'date-time-options-btn', - selectedTime === option.value && 'active', + customDateTimeVisible + ? option.value === 'custom' && 'active' + : selectedTime === option.value && 'active', )} > {option.label} @@ -121,14 +98,11 @@ function CustomTimePickerPopoverContent({ )} > {selectedTime === 'custom' || customDateTimeVisible ? ( - ) : (
diff --git a/frontend/src/components/CustomTimePicker/RangePickerModal.styles.scss b/frontend/src/components/CustomTimePicker/RangePickerModal.styles.scss new file mode 100644 index 0000000000..58ebe060d4 --- /dev/null +++ b/frontend/src/components/CustomTimePicker/RangePickerModal.styles.scss @@ -0,0 +1,4 @@ +.custom-date-picker { + display: flex; + flex-direction: column; +} diff --git a/frontend/src/components/CustomTimePicker/RangePickerModal.tsx b/frontend/src/components/CustomTimePicker/RangePickerModal.tsx new file mode 100644 index 0000000000..24ba0e2b01 --- /dev/null +++ b/frontend/src/components/CustomTimePicker/RangePickerModal.tsx @@ -0,0 +1,68 @@ +import './RangePickerModal.styles.scss'; + +import { DatePicker } from 'antd'; +import { DateTimeRangeType } from 'container/TopNav/CustomDateTimeModal'; +import { LexicalContext } from 'container/TopNav/DateTimeSelectionV2/config'; +import dayjs, { Dayjs } from 'dayjs'; +import { Dispatch, SetStateAction } from 'react'; +import { useSelector } from 'react-redux'; +import { AppState } from 'store/reducers'; +import { GlobalReducer } from 'types/reducer/globalTime'; + +interface RangePickerModalProps { + setCustomDTPickerVisible: Dispatch>; + setIsOpen: Dispatch>; + onCustomDateHandler: ( + dateTimeRange: DateTimeRangeType, + lexicalContext?: LexicalContext | undefined, + ) => void; + selectedTime: string; +} + +function RangePickerModal(props: RangePickerModalProps): JSX.Element { + const { + setCustomDTPickerVisible, + setIsOpen, + onCustomDateHandler, + selectedTime, + } = props; + const { RangePicker } = DatePicker; + const { maxTime, minTime } = useSelector( + (state) => state.globalTime, + ); + + const disabledDate = (current: Dayjs): boolean => { + const currentDay = dayjs(current); + return currentDay.isAfter(dayjs()); + }; + + const onPopoverClose = (visible: boolean): void => { + if (!visible) { + setCustomDTPickerVisible(false); + } + setIsOpen(visible); + }; + + const onModalOkHandler = (date_time: any): void => { + if (date_time?.[1]) { + onPopoverClose(false); + } + onCustomDateHandler(date_time, LexicalContext.CUSTOM_DATE_PICKER); + }; + return ( +
+ +
+ ); +} + +export default RangePickerModal; diff --git a/frontend/src/container/TopNav/DateTimeSelectionV2/DateTimeSelectionV2.styles.scss b/frontend/src/container/TopNav/DateTimeSelectionV2/DateTimeSelectionV2.styles.scss index d02df41929..bd4cc3cdb1 100644 --- a/frontend/src/container/TopNav/DateTimeSelectionV2/DateTimeSelectionV2.styles.scss +++ b/frontend/src/container/TopNav/DateTimeSelectionV2/DateTimeSelectionV2.styles.scss @@ -133,8 +133,8 @@ padding: 13px 14px; &.date-picker { - width: 340px; - height: 380px; + width: 480px; + height: 430px; } &.relative-times { diff --git a/frontend/src/container/TopNav/DateTimeSelectionV2/index.tsx b/frontend/src/container/TopNav/DateTimeSelectionV2/index.tsx index 6e5c0c5b48..3ef5125ad7 100644 --- a/frontend/src/container/TopNav/DateTimeSelectionV2/index.tsx +++ b/frontend/src/container/TopNav/DateTimeSelectionV2/index.tsx @@ -44,7 +44,6 @@ import { DateTimeRangeType } from '../CustomDateTimeModal'; import { getDefaultOption, getOptions, - LexicalContext, LocalStorageTimeRange, Time, TimeRange, @@ -319,22 +318,12 @@ function DateTimeSelection({ onLastRefreshHandler(); }; - const onCustomDateHandler = ( - dateTimeRange: DateTimeRangeType, - lexicalContext?: LexicalContext, - ): void => { + const onCustomDateHandler = (dateTimeRange: DateTimeRangeType): void => { if (dateTimeRange !== null) { const [startTimeMoment, endTimeMoment] = dateTimeRange; if (startTimeMoment && endTimeMoment) { - let startTime = startTimeMoment; - let endTime = endTimeMoment; - if ( - lexicalContext && - lexicalContext === LexicalContext.CUSTOM_DATE_PICKER - ) { - startTime = startTime.startOf('day'); - endTime = endTime.endOf('day'); - } + const startTime = startTimeMoment; + const endTime = endTimeMoment; setCustomDTPickerVisible(false); updateTimeInterval('custom', [ startTime.toDate().getTime(),