import './CustomTimePicker.styles.scss'; import { Button, DatePicker } from 'antd'; import cx from 'classnames'; import ROUTES from 'constants/routes'; import { DateTimeRangeType } from 'container/TopNav/CustomDateTimeModal'; import { LexicalContext, 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'; interface CustomTimePickerPopoverContentProps { options: any[]; setIsOpen: Dispatch>; customDateTimeVisible: boolean; setCustomDTPickerVisible: Dispatch>; onCustomDateHandler: ( dateTimeRange: DateTimeRangeType, lexicalContext?: LexicalContext, ) => void; onSelectHandler: (label: string, value: string) => void; handleGoLive: () => void; selectedTime: string; } function CustomTimePickerPopoverContent({ options, setIsOpen, customDateTimeVisible, setCustomDTPickerVisible, onCustomDateHandler, onSelectHandler, 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 (
{options.map((option) => ( ))}
); } return (
{isLogsExplorerPage && ( )} {options.map((option) => ( ))}
{selectedTime === 'custom' || customDateTimeVisible ? ( ) : (
RELATIVE TIMES
{getTimeChips(RelativeDurationSuggestionOptions)}
)}
); } export default CustomTimePickerPopoverContent;