@@ -500,39 +500,26 @@ export function TimeDropdown({
500500 }
501501 } ) ( ) ;
502502
503- const applySelection = useCallback ( ( ) => {
504- setValidationError ( null ) ;
505-
506- if ( exceedsMaxPeriod ) {
507- setValidationError (
508- `Your plan allows a maximum of ${ maxPeriodDays } days. Upgrade for longer retention.`
509- ) ;
510- return ;
511- }
503+ const applyPeriod = useCallback (
504+ ( periodToApply : string ) => {
505+ setValidationError ( null ) ;
512506
513- if ( activeSection === "duration" ) {
514- // Validate custom duration
515- if ( selectedPeriod === "custom" && ! isCustomDurationValid ) {
516- setValidationError ( "Please enter a valid custom duration" ) ;
507+ if ( maxPeriodDays && periodToDays ( periodToApply ) > maxPeriodDays ) {
508+ setValidationError (
509+ `Your plan allows a maximum of ${ maxPeriodDays } days. Upgrade for longer retention.`
510+ ) ;
517511 return ;
518512 }
519513
520- let periodToApply = selectedPeriod ;
521- if ( selectedPeriod === "custom" ) {
522- periodToApply = `${ customValue } ${ customUnit } ` ;
523- }
524-
525514 const values : TimeFilterApplyValues = {
526515 period : periodToApply ,
527516 from : undefined ,
528517 to : undefined ,
529518 } ;
530519
531520 if ( onValueChange ) {
532- // Controlled mode - just call the handler
533521 onValueChange ( values ) ;
534522 } else {
535- // URL mode - navigate
536523 replace ( {
537524 period : periodToApply ,
538525 cursor : undefined ,
@@ -546,6 +533,30 @@ export function TimeDropdown({
546533 setToValue ( undefined ) ;
547534 setOpen ( false ) ;
548535 onApply ?.( values ) ;
536+ } ,
537+ [ maxPeriodDays , onValueChange , replace , onApply ]
538+ ) ;
539+
540+ const applySelection = useCallback ( ( ) => {
541+ setValidationError ( null ) ;
542+
543+ if ( exceedsMaxPeriod ) {
544+ setValidationError (
545+ `Your plan allows a maximum of ${ maxPeriodDays } days. Upgrade for longer retention.`
546+ ) ;
547+ return ;
548+ }
549+
550+ if ( activeSection === "duration" ) {
551+ // Validate custom duration
552+ if ( selectedPeriod === "custom" && ! isCustomDurationValid ) {
553+ setValidationError ( "Please enter a valid custom duration" ) ;
554+ return ;
555+ }
556+
557+ const periodToApply =
558+ selectedPeriod === "custom" ? `${ customValue } ${ customUnit } ` : selectedPeriod ;
559+ applyPeriod ( periodToApply ) ;
549560 } else {
550561 // Validate date range
551562 if ( ! fromValue && ! toValue ) {
@@ -593,6 +604,7 @@ export function TimeDropdown({
593604 onValueChange ,
594605 exceedsMaxPeriod ,
595606 maxPeriodDays ,
607+ applyPeriod ,
596608 ] ) ;
597609
598610 return (
@@ -703,7 +715,7 @@ export function TimeDropdown({
703715 setCustomValue ( parsed . value . toString ( ) ) ;
704716 setCustomUnit ( parsed . unit ) ;
705717 }
706- setValidationError ( null ) ;
718+ applyPeriod ( p . value ) ;
707719 } }
708720 fullWidth
709721 type = "button"
0 commit comments