2024-02-12 00:23:19 +05:30
|
|
|
import './CustomTimePicker.styles.scss';
|
|
|
|
|
|
2024-12-16 10:27:20 +04:30
|
|
|
import { Color } from '@signozhq/design-tokens';
|
2024-03-11 14:39:17 +05:30
|
|
|
import { Button } from 'antd';
|
2024-12-20 11:38:36 +04:30
|
|
|
import logEvent from 'api/common/logEvent';
|
2024-02-12 00:23:19 +05:30
|
|
|
import cx from 'classnames';
|
|
|
|
|
import ROUTES from 'constants/routes';
|
|
|
|
|
import { DateTimeRangeType } from 'container/TopNav/CustomDateTimeModal';
|
|
|
|
|
import {
|
2025-05-29 10:53:47 +07:00
|
|
|
CustomTimeType,
|
2024-02-22 16:32:30 +05:30
|
|
|
LexicalContext,
|
2024-02-12 00:23:19 +05:30
|
|
|
Option,
|
|
|
|
|
RelativeDurationSuggestionOptions,
|
2025-05-29 10:53:47 +07:00
|
|
|
Time,
|
2024-02-12 00:23:19 +05:30
|
|
|
} from 'container/TopNav/DateTimeSelectionV2/config';
|
2024-12-16 10:27:20 +04:30
|
|
|
import { Clock, PenLine } from 'lucide-react';
|
|
|
|
|
import { useTimezone } from 'providers/Timezone';
|
2024-02-12 00:23:19 +05:30
|
|
|
import { Dispatch, SetStateAction, useMemo } from 'react';
|
|
|
|
|
import { useLocation } from 'react-router-dom';
|
2024-03-11 14:39:17 +05:30
|
|
|
|
|
|
|
|
import RangePickerModal from './RangePickerModal';
|
2024-12-16 10:27:20 +04:30
|
|
|
import TimezonePicker from './TimezonePicker';
|
2024-02-12 00:23:19 +05:30
|
|
|
|
|
|
|
|
interface CustomTimePickerPopoverContentProps {
|
|
|
|
|
options: any[];
|
|
|
|
|
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
|
|
|
|
customDateTimeVisible: boolean;
|
|
|
|
|
setCustomDTPickerVisible: Dispatch<SetStateAction<boolean>>;
|
2024-02-22 16:32:30 +05:30
|
|
|
onCustomDateHandler: (
|
|
|
|
|
dateTimeRange: DateTimeRangeType,
|
|
|
|
|
lexicalContext?: LexicalContext,
|
|
|
|
|
) => void;
|
2024-02-12 00:23:19 +05:30
|
|
|
onSelectHandler: (label: string, value: string) => void;
|
|
|
|
|
handleGoLive: () => void;
|
|
|
|
|
selectedTime: string;
|
2024-12-16 10:27:20 +04:30
|
|
|
activeView: 'datetime' | 'timezone';
|
|
|
|
|
setActiveView: Dispatch<SetStateAction<'datetime' | 'timezone'>>;
|
|
|
|
|
isOpenedFromFooter: boolean;
|
|
|
|
|
setIsOpenedFromFooter: Dispatch<SetStateAction<boolean>>;
|
2025-05-29 10:53:47 +07:00
|
|
|
onTimeChange?: (
|
|
|
|
|
interval: Time | CustomTimeType,
|
|
|
|
|
dateTimeRange?: [number, number],
|
|
|
|
|
) => void;
|
2024-02-12 00:23:19 +05:30
|
|
|
}
|
|
|
|
|
|
2024-12-16 10:27:20 +04:30
|
|
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
2024-02-12 00:23:19 +05:30
|
|
|
function CustomTimePickerPopoverContent({
|
|
|
|
|
options,
|
|
|
|
|
setIsOpen,
|
|
|
|
|
customDateTimeVisible,
|
|
|
|
|
setCustomDTPickerVisible,
|
|
|
|
|
onCustomDateHandler,
|
|
|
|
|
onSelectHandler,
|
|
|
|
|
handleGoLive,
|
|
|
|
|
selectedTime,
|
2024-12-16 10:27:20 +04:30
|
|
|
activeView,
|
|
|
|
|
setActiveView,
|
|
|
|
|
isOpenedFromFooter,
|
|
|
|
|
setIsOpenedFromFooter,
|
2025-05-29 10:53:47 +07:00
|
|
|
onTimeChange,
|
2024-02-12 00:23:19 +05:30
|
|
|
}: CustomTimePickerPopoverContentProps): JSX.Element {
|
|
|
|
|
const { pathname } = useLocation();
|
|
|
|
|
|
|
|
|
|
const isLogsExplorerPage = useMemo(() => pathname === ROUTES.LOGS_EXPLORER, [
|
|
|
|
|
pathname,
|
|
|
|
|
]);
|
2024-12-16 10:27:20 +04:30
|
|
|
const { timezone } = useTimezone();
|
|
|
|
|
const activeTimezoneOffset = timezone.offset;
|
2024-02-12 00:23:19 +05:30
|
|
|
|
|
|
|
|
function getTimeChips(options: Option[]): JSX.Element {
|
|
|
|
|
return (
|
|
|
|
|
<div className="relative-date-time-section">
|
|
|
|
|
{options.map((option) => (
|
|
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
className="time-btns"
|
|
|
|
|
key={option.label + option.value}
|
|
|
|
|
onClick={(): void => {
|
|
|
|
|
onSelectHandler(option.label, option.value);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{option.label}
|
|
|
|
|
</Button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-16 10:27:20 +04:30
|
|
|
const handleTimezoneHintClick = (): void => {
|
|
|
|
|
setActiveView('timezone');
|
|
|
|
|
setIsOpenedFromFooter(true);
|
2024-12-20 11:38:36 +04:30
|
|
|
logEvent(
|
|
|
|
|
'DateTimePicker: Timezone picker opened from time range picker footer',
|
|
|
|
|
{
|
|
|
|
|
page: pathname,
|
|
|
|
|
},
|
|
|
|
|
);
|
2024-12-16 10:27:20 +04:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (activeView === 'timezone') {
|
|
|
|
|
return (
|
|
|
|
|
<div className="date-time-popover">
|
|
|
|
|
<TimezonePicker
|
|
|
|
|
setActiveView={setActiveView}
|
|
|
|
|
setIsOpen={setIsOpen}
|
|
|
|
|
isOpenedFromFooter={isOpenedFromFooter}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-12 00:23:19 +05:30
|
|
|
return (
|
2024-12-16 10:27:20 +04:30
|
|
|
<>
|
|
|
|
|
<div className="date-time-popover">
|
|
|
|
|
<div className="date-time-options">
|
|
|
|
|
{isLogsExplorerPage && (
|
|
|
|
|
<Button className="data-time-live" type="text" onClick={handleGoLive}>
|
|
|
|
|
Live
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
{options.map((option) => (
|
|
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
key={option.label + option.value}
|
|
|
|
|
onClick={(): void => {
|
|
|
|
|
onSelectHandler(option.label, option.value);
|
|
|
|
|
}}
|
|
|
|
|
className={cx(
|
|
|
|
|
'date-time-options-btn',
|
|
|
|
|
customDateTimeVisible
|
|
|
|
|
? option.value === 'custom' && 'active'
|
|
|
|
|
: selectedTime === option.value && 'active',
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{option.label}
|
|
|
|
|
</Button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
className={cx(
|
|
|
|
|
'relative-date-time',
|
|
|
|
|
selectedTime === 'custom' || customDateTimeVisible
|
|
|
|
|
? 'date-picker'
|
|
|
|
|
: 'relative-times',
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{selectedTime === 'custom' || customDateTimeVisible ? (
|
|
|
|
|
<RangePickerModal
|
|
|
|
|
setCustomDTPickerVisible={setCustomDTPickerVisible}
|
|
|
|
|
setIsOpen={setIsOpen}
|
|
|
|
|
onCustomDateHandler={onCustomDateHandler}
|
|
|
|
|
selectedTime={selectedTime}
|
2025-05-29 10:53:47 +07:00
|
|
|
onTimeChange={onTimeChange}
|
2024-12-16 10:27:20 +04:30
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="relative-times-container">
|
|
|
|
|
<div className="time-heading">RELATIVE TIMES</div>
|
|
|
|
|
<div>{getTimeChips(RelativeDurationSuggestionOptions)}</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2024-02-12 00:23:19 +05:30
|
|
|
</div>
|
2024-12-16 10:27:20 +04:30
|
|
|
|
|
|
|
|
<div className="date-time-popover__footer">
|
|
|
|
|
<div className="timezone-container">
|
|
|
|
|
<Clock
|
|
|
|
|
color={Color.BG_VANILLA_400}
|
|
|
|
|
className="timezone-container__clock-icon"
|
|
|
|
|
height={12}
|
|
|
|
|
width={12}
|
2024-02-12 00:23:19 +05:30
|
|
|
/>
|
2024-12-16 10:27:20 +04:30
|
|
|
<span className="timezone__icon">Current timezone</span>
|
|
|
|
|
<div>⎯</div>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="timezone"
|
|
|
|
|
onClick={handleTimezoneHintClick}
|
|
|
|
|
>
|
|
|
|
|
<span>{activeTimezoneOffset}</span>
|
|
|
|
|
<PenLine
|
|
|
|
|
color={Color.BG_VANILLA_100}
|
|
|
|
|
className="timezone__icon"
|
|
|
|
|
size={10}
|
|
|
|
|
/>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2024-02-12 00:23:19 +05:30
|
|
|
</div>
|
2024-12-16 10:27:20 +04:30
|
|
|
</>
|
2024-02-12 00:23:19 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-29 10:53:47 +07:00
|
|
|
CustomTimePickerPopoverContent.defaultProps = {
|
|
|
|
|
onTimeChange: undefined,
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-12 00:23:19 +05:30
|
|
|
export default CustomTimePickerPopoverContent;
|