Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions apps/webapp/app/components/runs/v3/SharedFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -500,39 +500,26 @@ export function TimeDropdown({
}
})();

const applySelection = useCallback(() => {
setValidationError(null);

if (exceedsMaxPeriod) {
setValidationError(
`Your plan allows a maximum of ${maxPeriodDays} days. Upgrade for longer retention.`
);
return;
}
const applyPeriod = useCallback(
(periodToApply: string) => {
setValidationError(null);

if (activeSection === "duration") {
// Validate custom duration
if (selectedPeriod === "custom" && !isCustomDurationValid) {
setValidationError("Please enter a valid custom duration");
if (maxPeriodDays && periodToDays(periodToApply) > maxPeriodDays) {
setValidationError(
`Your plan allows a maximum of ${maxPeriodDays} days. Upgrade for longer retention.`
);
return;
}

let periodToApply = selectedPeriod;
if (selectedPeriod === "custom") {
periodToApply = `${customValue}${customUnit}`;
}

const values: TimeFilterApplyValues = {
period: periodToApply,
from: undefined,
to: undefined,
};

if (onValueChange) {
// Controlled mode - just call the handler
onValueChange(values);
} else {
// URL mode - navigate
replace({
period: periodToApply,
cursor: undefined,
Expand All @@ -546,6 +533,30 @@ export function TimeDropdown({
setToValue(undefined);
setOpen(false);
onApply?.(values);
},
[maxPeriodDays, onValueChange, replace, onApply]
);

const applySelection = useCallback(() => {
setValidationError(null);

if (exceedsMaxPeriod) {
setValidationError(
`Your plan allows a maximum of ${maxPeriodDays} days. Upgrade for longer retention.`
);
return;
}

if (activeSection === "duration") {
// Validate custom duration
if (selectedPeriod === "custom" && !isCustomDurationValid) {
setValidationError("Please enter a valid custom duration");
return;
}

const periodToApply =
selectedPeriod === "custom" ? `${customValue}${customUnit}` : selectedPeriod;
applyPeriod(periodToApply);
} else {
// Validate date range
if (!fromValue && !toValue) {
Expand Down Expand Up @@ -593,6 +604,7 @@ export function TimeDropdown({
onValueChange,
exceedsMaxPeriod,
maxPeriodDays,
applyPeriod,
]);

return (
Expand Down Expand Up @@ -703,7 +715,7 @@ export function TimeDropdown({
setCustomValue(parsed.value.toString());
setCustomUnit(parsed.unit);
}
setValidationError(null);
applyPeriod(p.value);
}}
fullWidth
type="button"
Expand Down