import React from 'react' import { type AlertProps } from '../Alerts/Alert' import type { CalloutType, ComparisonDateRangeProps, CustomAggregationsProps, DisabledTimeframeOptionsProps, TimeframeProps, } from './TimeframesType' import styles from './_timeframe-filter.module.scss' import type { SideDrawerBase } from '../SideDrawer/SideDrawer' import { c } from '../../translations/LibraryTranslationService' const HistoricalTimeframe = React.lazy(() => import( /* webpackChunkName: "historicalTimeframe" */ './TimeframeTypes/HistoricalTimeframe' ).then((mod) => ({ default: mod.HistoricalTimeframe })), ) const CurrentTimeframe = React.lazy(() => import( /* webpackChunkName: "currentTimeframe" */ './TimeframeTypes/CurrentTimeframe' ).then((mod) => ({ default: mod.CurrentTimeframe })), ) const QuarterlyTimeframe = React.lazy(() => import( /* webpackChunkName: "quarterlyTimeframe" */ './TimeframeTypes/QuarterlyTimeframe' ).then((mod) => ({ default: mod.QuarterlyTimeframe })), ) const PreviousTimeframe = React.lazy(() => import( /* webpackChunkName: "previousTimeframe" */ './TimeframeTypes/PreviousTimeframe' ).then((mod) => ({ default: mod.PreviousTimeframe })), ) const Aggregations = React.lazy( () => import( /* webpackChunkName: "timeframeAggregations" */ './TimeframeTypes/Aggregations' ), ) type AlertCalloutType = { startDate: string endDate: string comparisonStartDate: string comparisonEndDate: string } export type AlertPropsWithDates = AlertProps & { selectedDatesCallout?: ({ startDate, endDate, comparisonStartDate, comparisonEndDate, }: AlertCalloutType) => void } export type TimeframeFilterBodyProps = { /** Callout for each user action */ callout: ( calloutType: CalloutType, startDate: moment.Moment, endDate: moment.Moment, timeframe: TimeframeProps, ) => void timeframe: TimeframeProps historicalTimeframes?: Array /** Boolean: show the current timeframe options */ currentTimeframe?: boolean /** Boolean: show the previous timeframe options */ previousTimeframe?: boolean /** Boolean: show the quarterly timeframe options */ quarterlyTimeframe?: boolean /** Boolean: show the custom date calendar options */ hideCustomDateSearch?: boolean closeMenu?: () => void useTimeframeAggregations?: boolean customAggregations?: CustomAggregationsProps startDate?: string endDate?: string disableTimeFrameFilter?: boolean showHistoricTimeFrameDateRange?: boolean showHistoricTimeFrameDateRangeOnMobile?: boolean comparisonDateRange?: ComparisonDateRangeProps getComparisonDateRange?: boolean disabledTimeframeOptions?: DisabledTimeframeOptionsProps updateToValidFilterState?: ( calloutType: CalloutType, validOptions: unknown, ) => void /** Passes any optional SideDrawer props to the ComparisonDatePicker SideDrawer */ cdpSideDrawerProps?: Omit< SideDrawerBase, 'children' | 'isOpen' | 'closeCallout' > /** Boolean: Show the new trailing timeframe options */ trailingTimeframe?: boolean alertProps?: AlertPropsWithDates /** Current path from the router */ currentPath?: string /** Optional prop to add a test id to the Timeframe for QA testing */ qaTestId?: string firstRangeLabel?: string secondRangeLabel?: string } const Timeframe = ({ callout, historicalTimeframes, timeframe, // ToDo: Clean up this check once we start supporting new timeframe options across all Predict modules and Shelf app // Hence we have not updated storybook for this change trailingTimeframe = false, currentTimeframe, previousTimeframe = false, quarterlyTimeframe, closeMenu, useTimeframeAggregations = false, customAggregations, startDate, endDate, disableTimeFrameFilter = false, showHistoricTimeFrameDateRange = true, showHistoricTimeFrameDateRangeOnMobile = false, // for mobile comparisonDateRange, getComparisonDateRange, disabledTimeframeOptions = undefined, updateToValidFilterState = () => null, cdpSideDrawerProps, alertProps, currentPath, qaTestId = 'timeframe', firstRangeLabel, secondRangeLabel, }: TimeframeFilterBodyProps) => { return ( Loading...}>
{currentTimeframe ? ( <>
{c('current')}
) : null} {previousTimeframe ? ( <>
{c('previous')}
closeMenu?.()} useTimeframeAggregations={useTimeframeAggregations} customAggregations={customAggregations?.previous ?? {}} disabledTimeframeOptions={ disabledTimeframeOptions?.previous ?? [] } /> ) : null} {currentTimeframe || quarterlyTimeframe ? (
{trailingTimeframe ? c('trailing') : c('historical')}
) : null} {quarterlyTimeframe ? ( <>
{c('quarterly/yearly')}
) : null} {showHistoricTimeFrameDateRangeOnMobile ? ( <>
{c('customDate')}
) : null}
{useTimeframeAggregations ? ( ) : null}
) } export default Timeframe