Fix review issues in cookie pattern handling
- Fix DurationInput fallback unit from "minutes" to "seconds" and add seconds as a selectable unit to prevent silent duration inflation - Use parseFloat instead of parseInt for duration input to preserve fractional values - Scope prefix merge groups by category ID to prevent cross-category merging - Relink cookies and delete exact patterns even when prefix pattern already exists - Prefer exact matches and longest prefix in pattern selection query - Fix wrong error type in GetCookiePattern (ErrCookiePatternNotFound) - Handle singular/plural in humanizeSeconds fallback branch Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
import { Input } from "@probo/ui";
|
||||
|
||||
const UNITS: { value: string; label: string; seconds: number }[] = [
|
||||
{ value: "seconds", label: "seconds", seconds: 1 },
|
||||
{ value: "minutes", label: "minutes", seconds: 60 },
|
||||
{ value: "hours", label: "hours", seconds: 3600 },
|
||||
{ value: "days", label: "days", seconds: 86400 },
|
||||
@@ -24,11 +25,11 @@ const UNITS: { value: string; label: string; seconds: number }[] = [
|
||||
];
|
||||
|
||||
export function toMaxAgeSeconds(value: string, unit: string): number | null {
|
||||
const num = parseInt(value, 10);
|
||||
const num = parseFloat(value);
|
||||
if (isNaN(num) || num <= 0) return null;
|
||||
const u = UNITS.find(u => u.value === unit);
|
||||
if (!u) return null;
|
||||
return num * u.seconds;
|
||||
return Math.round(num * u.seconds);
|
||||
}
|
||||
|
||||
export function fromMaxAgeSeconds(seconds: number | null): { value: string; unit: string } {
|
||||
@@ -38,7 +39,7 @@ export function fromMaxAgeSeconds(seconds: number | null): { value: string; unit
|
||||
return { value: String(seconds / u.seconds), unit: u.value };
|
||||
}
|
||||
}
|
||||
return { value: String(seconds), unit: "minutes" };
|
||||
return { value: String(seconds), unit: "seconds" };
|
||||
}
|
||||
|
||||
interface DurationInputProps {
|
||||
|
||||
Reference in New Issue
Block a user