feat: enhance dual-range-slider handling in DynamicFilter component
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 12m44s

This commit is contained in:
2025-07-04 23:11:01 +05:00
parent f6e60c0188
commit f4c34d3b7b

View File

@ -315,25 +315,14 @@ export default function DynamicFilter<
}> = []; }> = [];
for (const input of inputs) { for (const input of inputs) {
const urlValue = searchParams.get(input.name); if (input.type === "dual-range-slider") {
if (urlValue) { const minValue = searchParams.get(`${input.name}_min`);
if (input.type === "checkbox-group") { const maxValue = searchParams.get(`${input.name}_max`);
const deserialize = input.deserialize || defaultDeserialize; if (minValue && maxValue) {
const deserialized = deserialize(urlValue); const parsedMin = Number(minValue);
if (deserialized.length > 0) { const parsedMax = Number(maxValue);
filters.push({ // Only show as applied filter if values are different from defaults
key: input.name, if (parsedMin !== input.min || parsedMax !== input.max) {
value: deserialized,
label: input.label,
config: input,
});
}
} else if (input.type === "dual-range-slider") {
const minValue = searchParams.get(`${input.name}_min`);
const maxValue = searchParams.get(`${input.name}_max`);
if (minValue && maxValue) {
const parsedMin = Number(minValue);
const parsedMax = Number(maxValue);
filters.push({ filters.push({
key: input.name, key: input.name,
value: [parsedMin, parsedMax], value: [parsedMin, parsedMax],
@ -341,13 +330,29 @@ export default function DynamicFilter<
config: input, config: input,
}); });
} }
} else { }
filters.push({ } else {
key: input.name, const urlValue = searchParams.get(input.name);
value: urlValue, if (urlValue) {
label: input.label, if (input.type === "checkbox-group") {
config: input, const deserialize = input.deserialize || defaultDeserialize;
}); const deserialized = deserialize(urlValue);
if (deserialized.length > 0) {
filters.push({
key: input.name,
value: deserialized,
label: input.label,
config: input,
});
}
} else {
filters.push({
key: input.name,
value: urlValue,
label: input.label,
config: input,
});
}
} }
} }
} }