@smg-automotive/filters 2.1.0 → 2.1.1-fix-declarations.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +629 -735
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +630 -736
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +436 -20
- package/dist/translations.cjs.js +5 -5
- package/dist/translations.cjs.js.map +1 -1
- package/dist/translations.esm.js +5 -5
- package/dist/translations.esm.js.map +1 -1
- package/package.json +7 -5
- package/dist/api/filtersClient.d.ts +0 -1
- package/dist/cjs/api/filtersClient.d.ts +0 -1
- package/dist/cjs/contexts/Filter.d.ts +0 -15
- package/dist/cjs/filters/__tests__/createTestFilterComponent.d.ts +0 -23
- package/dist/cjs/filters/__tests__/createTestHistogramRanges.d.ts +0 -2
- package/dist/cjs/filters/__tests__/createTestReferenceData.d.ts +0 -8
- package/dist/cjs/filters/useBatteryHealthPercentageFilter.d.ts +0 -3
- package/dist/cjs/filters/useBodyTypeFilter.d.ts +0 -6
- package/dist/cjs/filters/useConditionTypeFilter.d.ts +0 -4
- package/dist/cjs/filters/useDriveTypeFilter.d.ts +0 -4
- package/dist/cjs/filters/useFirstRegistrationYearFilter.d.ts +0 -3
- package/dist/cjs/filters/useFuelTypeFilter.d.ts +0 -4
- package/dist/cjs/filters/useHasBatteryCertificateKeyOnlyFilter.d.ts +0 -5
- package/dist/cjs/filters/useMileageFilter.d.ts +0 -3
- package/dist/cjs/filters/usePriceFilter.d.ts +0 -3
- package/dist/cjs/filters/useTransmissionTypeFilter.d.ts +0 -4
- package/dist/cjs/hooks/useBooleanFilter.d.ts +0 -24
- package/dist/cjs/hooks/useCheckboxFilter.d.ts +0 -22
- package/dist/cjs/hooks/useCheckboxFilterReducer.d.ts +0 -49
- package/dist/cjs/hooks/useRangeFilter.d.ts +0 -50
- package/dist/cjs/index.d.ts +0 -20
- package/dist/cjs/translations/index.d.ts +0 -11
- package/dist/cjs/types/brand.d.ts +0 -4
- package/dist/cjs/types/enums.d.ts +0 -206
- package/dist/cjs/types/facets.d.ts +0 -14
- package/dist/cjs/types/interval.d.ts +0 -7
- package/dist/cjs/types/query.d.ts +0 -104
- package/dist/cjs/types/referenceData.d.ts +0 -23
- package/dist/cjs/types/useFilter.d.ts +0 -39
- package/dist/cjs/utilities/__tests__/scales.d.ts +0 -1
- package/dist/cjs/utilities/boolean.d.ts +0 -8
- package/dist/cjs/utilities/checkbox.d.ts +0 -63
- package/dist/cjs/utilities/cleanQuery.d.ts +0 -98
- package/dist/cjs/utilities/fetchReferenceData.d.ts +0 -2
- package/dist/cjs/utilities/fetchSearchConfiguration.d.ts +0 -2
- package/dist/cjs/utilities/formatWithUnit.d.ts +0 -28
- package/dist/cjs/utilities/isInArray.d.ts +0 -1
- package/dist/cjs/utilities/range.d.ts +0 -51
- package/dist/cjs/utilities/resetAllFilters.d.ts +0 -2
- package/dist/cjs/utilities/scales.d.ts +0 -5
- package/dist/contexts/Filter.d.ts +0 -15
- package/dist/esm/api/filtersClient.d.ts +0 -1
- package/dist/esm/contexts/Filter.d.ts +0 -15
- package/dist/esm/filters/__tests__/createTestFilterComponent.d.ts +0 -23
- package/dist/esm/filters/__tests__/createTestHistogramRanges.d.ts +0 -2
- package/dist/esm/filters/__tests__/createTestReferenceData.d.ts +0 -8
- package/dist/esm/filters/useBatteryHealthPercentageFilter.d.ts +0 -3
- package/dist/esm/filters/useBodyTypeFilter.d.ts +0 -6
- package/dist/esm/filters/useConditionTypeFilter.d.ts +0 -4
- package/dist/esm/filters/useDriveTypeFilter.d.ts +0 -4
- package/dist/esm/filters/useFirstRegistrationYearFilter.d.ts +0 -3
- package/dist/esm/filters/useFuelTypeFilter.d.ts +0 -4
- package/dist/esm/filters/useHasBatteryCertificateKeyOnlyFilter.d.ts +0 -5
- package/dist/esm/filters/useMileageFilter.d.ts +0 -3
- package/dist/esm/filters/usePriceFilter.d.ts +0 -3
- package/dist/esm/filters/useTransmissionTypeFilter.d.ts +0 -4
- package/dist/esm/hooks/useBooleanFilter.d.ts +0 -24
- package/dist/esm/hooks/useCheckboxFilter.d.ts +0 -22
- package/dist/esm/hooks/useCheckboxFilterReducer.d.ts +0 -49
- package/dist/esm/hooks/useRangeFilter.d.ts +0 -50
- package/dist/esm/index.d.ts +0 -20
- package/dist/esm/translations/index.d.ts +0 -11
- package/dist/esm/types/brand.d.ts +0 -4
- package/dist/esm/types/enums.d.ts +0 -206
- package/dist/esm/types/facets.d.ts +0 -14
- package/dist/esm/types/interval.d.ts +0 -7
- package/dist/esm/types/query.d.ts +0 -104
- package/dist/esm/types/referenceData.d.ts +0 -23
- package/dist/esm/types/useFilter.d.ts +0 -39
- package/dist/esm/utilities/__tests__/scales.d.ts +0 -1
- package/dist/esm/utilities/boolean.d.ts +0 -8
- package/dist/esm/utilities/checkbox.d.ts +0 -63
- package/dist/esm/utilities/cleanQuery.d.ts +0 -98
- package/dist/esm/utilities/fetchReferenceData.d.ts +0 -2
- package/dist/esm/utilities/fetchSearchConfiguration.d.ts +0 -2
- package/dist/esm/utilities/formatWithUnit.d.ts +0 -28
- package/dist/esm/utilities/isInArray.d.ts +0 -1
- package/dist/esm/utilities/range.d.ts +0 -51
- package/dist/esm/utilities/resetAllFilters.d.ts +0 -2
- package/dist/esm/utilities/scales.d.ts +0 -5
- package/dist/filters/__tests__/createTestFilterComponent.d.ts +0 -23
- package/dist/filters/__tests__/createTestHistogramRanges.d.ts +0 -2
- package/dist/filters/__tests__/createTestReferenceData.d.ts +0 -8
- package/dist/filters/useBatteryHealthPercentageFilter.d.ts +0 -3
- package/dist/filters/useBodyTypeFilter.d.ts +0 -6
- package/dist/filters/useConditionTypeFilter.d.ts +0 -4
- package/dist/filters/useDriveTypeFilter.d.ts +0 -4
- package/dist/filters/useFirstRegistrationYearFilter.d.ts +0 -3
- package/dist/filters/useFuelTypeFilter.d.ts +0 -4
- package/dist/filters/useHasBatteryCertificateKeyOnlyFilter.d.ts +0 -5
- package/dist/filters/useMileageFilter.d.ts +0 -3
- package/dist/filters/usePriceFilter.d.ts +0 -3
- package/dist/filters/useTransmissionTypeFilter.d.ts +0 -4
- package/dist/hooks/useBooleanFilter.d.ts +0 -24
- package/dist/hooks/useCheckboxFilter.d.ts +0 -22
- package/dist/hooks/useCheckboxFilterReducer.d.ts +0 -49
- package/dist/hooks/useRangeFilter.d.ts +0 -50
- package/dist/translations/index.d.ts +0 -11
- package/dist/types/brand.d.ts +0 -4
- package/dist/types/enums.d.ts +0 -206
- package/dist/types/facets.d.ts +0 -14
- package/dist/types/interval.d.ts +0 -7
- package/dist/types/query.d.ts +0 -104
- package/dist/types/referenceData.d.ts +0 -23
- package/dist/types/useFilter.d.ts +0 -39
- package/dist/utilities/__tests__/scales.d.ts +0 -1
- package/dist/utilities/boolean.d.ts +0 -8
- package/dist/utilities/checkbox.d.ts +0 -63
- package/dist/utilities/cleanQuery.d.ts +0 -98
- package/dist/utilities/fetchReferenceData.d.ts +0 -2
- package/dist/utilities/fetchSearchConfiguration.d.ts +0 -2
- package/dist/utilities/formatWithUnit.d.ts +0 -28
- package/dist/utilities/isInArray.d.ts +0 -1
- package/dist/utilities/range.d.ts +0 -51
- package/dist/utilities/resetAllFilters.d.ts +0 -2
- package/dist/utilities/scales.d.ts +0 -5
package/dist/cjs/index.js
CHANGED
|
@@ -216,131 +216,37 @@ exports.LicenseCategory = void 0;
|
|
|
216
216
|
LicenseCategory["M"] = "m";
|
|
217
217
|
})(exports.LicenseCategory || (exports.LicenseCategory = {}));
|
|
218
218
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
219
|
+
const FilterContext = React.createContext(null);
|
|
220
|
+
const useFilterContext = () => {
|
|
221
|
+
const context = React.useContext(FilterContext);
|
|
222
222
|
if (!context) {
|
|
223
223
|
throw new Error('useFilterContext must be used within a FilterProvider');
|
|
224
224
|
}
|
|
225
225
|
return context;
|
|
226
226
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}); }, [t, brand, histogramRanges, referenceData, language]);
|
|
227
|
+
const FilterProvider = ({ t, histogramRanges, brand, referenceData, language, children, }) => {
|
|
228
|
+
const context = React.useMemo(() => ({
|
|
229
|
+
t,
|
|
230
|
+
brand,
|
|
231
|
+
histogramRanges,
|
|
232
|
+
referenceData,
|
|
233
|
+
language,
|
|
234
|
+
}), [t, brand, histogramRanges, referenceData, language]);
|
|
236
235
|
return (React.createElement(FilterContext.Provider, { value: context }, children));
|
|
237
236
|
};
|
|
238
237
|
|
|
239
|
-
|
|
238
|
+
const resetAllFilters = () => {
|
|
240
239
|
if (typeof window !== 'undefined') {
|
|
241
240
|
window.dispatchEvent(new Event('reset-all-filters'));
|
|
242
241
|
}
|
|
243
242
|
};
|
|
244
|
-
|
|
245
|
-
React.useEffect(
|
|
243
|
+
const useResetAllFilters = (reset) => {
|
|
244
|
+
React.useEffect(() => {
|
|
246
245
|
window.addEventListener('reset-all-filters', reset);
|
|
247
|
-
return
|
|
246
|
+
return () => window.removeEventListener('reset-all-filters', reset);
|
|
248
247
|
}, [reset]);
|
|
249
248
|
};
|
|
250
249
|
|
|
251
|
-
/******************************************************************************
|
|
252
|
-
Copyright (c) Microsoft Corporation.
|
|
253
|
-
|
|
254
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
255
|
-
purpose with or without fee is hereby granted.
|
|
256
|
-
|
|
257
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
258
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
259
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
260
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
261
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
262
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
263
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
264
|
-
***************************************************************************** */
|
|
265
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
var __assign = function() {
|
|
269
|
-
__assign = Object.assign || function __assign(t) {
|
|
270
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
271
|
-
s = arguments[i];
|
|
272
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
273
|
-
}
|
|
274
|
-
return t;
|
|
275
|
-
};
|
|
276
|
-
return __assign.apply(this, arguments);
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
function __rest(s, e) {
|
|
280
|
-
var t = {};
|
|
281
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
282
|
-
t[p] = s[p];
|
|
283
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
284
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
285
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
286
|
-
t[p[i]] = s[p[i]];
|
|
287
|
-
}
|
|
288
|
-
return t;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
292
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
293
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
294
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
295
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
296
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
297
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function __generator(thisArg, body) {
|
|
302
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
303
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
304
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
305
|
-
function step(op) {
|
|
306
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
307
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
308
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
309
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
310
|
-
switch (op[0]) {
|
|
311
|
-
case 0: case 1: t = op; break;
|
|
312
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
313
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
314
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
315
|
-
default:
|
|
316
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
317
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
318
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
319
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
320
|
-
if (t[2]) _.ops.pop();
|
|
321
|
-
_.trys.pop(); continue;
|
|
322
|
-
}
|
|
323
|
-
op = body.call(thisArg, _);
|
|
324
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
325
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function __spreadArray(to, from, pack) {
|
|
330
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
331
|
-
if (ar || !(i in from)) {
|
|
332
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
333
|
-
ar[i] = from[i];
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
340
|
-
var e = new Error(message);
|
|
341
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
342
|
-
};
|
|
343
|
-
|
|
344
250
|
var Brand;
|
|
345
251
|
(function (Brand) {
|
|
346
252
|
Brand["AutoScout24"] = "autoscout24";
|
|
@@ -348,17 +254,16 @@ var Brand;
|
|
|
348
254
|
})(Brand || (Brand = {}));
|
|
349
255
|
|
|
350
256
|
/** @internal */
|
|
351
|
-
|
|
352
|
-
baseUrl:
|
|
257
|
+
const filtersClient = apiClientPkg.ApiClient({
|
|
258
|
+
baseUrl: `https://${process.env.API_ROOT}/${process.env.API_VERSION}`,
|
|
353
259
|
});
|
|
354
260
|
|
|
355
261
|
function transformSearchConfigurationResponse(data) {
|
|
356
|
-
|
|
357
|
-
for (
|
|
358
|
-
|
|
359
|
-
var arr = data[key];
|
|
262
|
+
const result = {};
|
|
263
|
+
for (const key of Object.keys(data)) {
|
|
264
|
+
const arr = data[key];
|
|
360
265
|
if (Array.isArray(arr)) {
|
|
361
|
-
result[key] = arr.reduce(
|
|
266
|
+
result[key] = arr.reduce((acc, value) => {
|
|
362
267
|
acc[value] = 0;
|
|
363
268
|
return acc;
|
|
364
269
|
}, {});
|
|
@@ -366,46 +271,28 @@ function transformSearchConfigurationResponse(data) {
|
|
|
366
271
|
}
|
|
367
272
|
return result;
|
|
368
273
|
}
|
|
369
|
-
|
|
370
|
-
function fetchSearchConfiguration() {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
body = response.body;
|
|
390
|
-
if (!body) {
|
|
391
|
-
throw new Error("Empty search configuration response for brand ".concat(brand));
|
|
392
|
-
}
|
|
393
|
-
return [2 /*return*/, transformSearchConfigurationResponse(body)];
|
|
394
|
-
}
|
|
395
|
-
});
|
|
396
|
-
}); }))];
|
|
397
|
-
case 1:
|
|
398
|
-
_a = _c.sent(), autoscout24Data = _a[0], motoscout24Data = _a[1];
|
|
399
|
-
return [2 /*return*/, (_b = {},
|
|
400
|
-
_b[Brand.AutoScout24] = autoscout24Data,
|
|
401
|
-
_b[Brand.MotoScout24] = motoscout24Data,
|
|
402
|
-
_b)];
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
});
|
|
274
|
+
const brands = [Brand.AutoScout24, Brand.MotoScout24];
|
|
275
|
+
async function fetchSearchConfiguration() {
|
|
276
|
+
const [autoscout24Data, motoscout24Data] = await Promise.all(brands.map(async (brand) => {
|
|
277
|
+
const response = await filtersClient
|
|
278
|
+
.path('search-configuration')
|
|
279
|
+
.get({ searchParams: { brand } });
|
|
280
|
+
if (!response.ok) {
|
|
281
|
+
throw new Error(`Failed to fetch search configuration for ${brand}: ${response.status}`);
|
|
282
|
+
}
|
|
283
|
+
const body = response.body;
|
|
284
|
+
if (!body) {
|
|
285
|
+
throw new Error(`Empty search configuration response for brand ${brand}`);
|
|
286
|
+
}
|
|
287
|
+
return transformSearchConfigurationResponse(body);
|
|
288
|
+
}));
|
|
289
|
+
return {
|
|
290
|
+
[Brand.AutoScout24]: autoscout24Data,
|
|
291
|
+
[Brand.MotoScout24]: motoscout24Data,
|
|
292
|
+
};
|
|
406
293
|
}
|
|
407
294
|
|
|
408
|
-
|
|
295
|
+
const vehicleCategories = [
|
|
409
296
|
exports.VehicleCategory.Car,
|
|
410
297
|
exports.VehicleCategory.Utility,
|
|
411
298
|
exports.VehicleCategory.Motorcycle,
|
|
@@ -413,46 +300,28 @@ var vehicleCategories = [
|
|
|
413
300
|
exports.VehicleCategory.Trailer,
|
|
414
301
|
exports.VehicleCategory.Camper,
|
|
415
302
|
];
|
|
416
|
-
function fetchReferenceData() {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
return [2 /*return*/, body];
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
}); }))];
|
|
443
|
-
case 1:
|
|
444
|
-
_a = _c.sent(), car = _a[0], utility = _a[1], motorcycle = _a[2], truck = _a[3], trailer = _a[4], camper = _a[5];
|
|
445
|
-
return [2 /*return*/, (_b = {},
|
|
446
|
-
_b[exports.VehicleCategory.Car] = car,
|
|
447
|
-
_b[exports.VehicleCategory.Utility] = utility,
|
|
448
|
-
_b[exports.VehicleCategory.Motorcycle] = motorcycle,
|
|
449
|
-
_b[exports.VehicleCategory.Truck] = truck,
|
|
450
|
-
_b[exports.VehicleCategory.Trailer] = trailer,
|
|
451
|
-
_b[exports.VehicleCategory.Camper] = camper,
|
|
452
|
-
_b)];
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
});
|
|
303
|
+
async function fetchReferenceData() {
|
|
304
|
+
const [car, utility, motorcycle, truck, trailer, camper] = await Promise.all(vehicleCategories.map(async (vehicleCategory) => {
|
|
305
|
+
const response = await filtersClient
|
|
306
|
+
.path('reference-data')
|
|
307
|
+
.get({ searchParams: { vehicleCategory } });
|
|
308
|
+
if (!response.ok) {
|
|
309
|
+
throw new Error(`Failed to fetch reference data for ${vehicleCategory}: ${response.status}`);
|
|
310
|
+
}
|
|
311
|
+
const body = response.body;
|
|
312
|
+
if (!body) {
|
|
313
|
+
throw new Error(`Empty reference data response for vehicle category ${vehicleCategory}`);
|
|
314
|
+
}
|
|
315
|
+
return body;
|
|
316
|
+
}));
|
|
317
|
+
return {
|
|
318
|
+
[exports.VehicleCategory.Car]: car,
|
|
319
|
+
[exports.VehicleCategory.Utility]: utility,
|
|
320
|
+
[exports.VehicleCategory.Motorcycle]: motorcycle,
|
|
321
|
+
[exports.VehicleCategory.Truck]: truck,
|
|
322
|
+
[exports.VehicleCategory.Trailer]: trailer,
|
|
323
|
+
[exports.VehicleCategory.Camper]: camper,
|
|
324
|
+
};
|
|
456
325
|
}
|
|
457
326
|
|
|
458
327
|
var batteryHealthPercentage$3 = "Batteria (SoH)";
|
|
@@ -935,18 +804,18 @@ var de = {
|
|
|
935
804
|
"bodyType.wood-transporter": "Holz-Transporter"
|
|
936
805
|
};
|
|
937
806
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
807
|
+
const filterTranslationsDe = de;
|
|
808
|
+
const filterTranslationsEn = en;
|
|
809
|
+
const filterTranslationsFr = fr;
|
|
810
|
+
const filterTranslationsIt = it;
|
|
811
|
+
const filterTranslations = {
|
|
943
812
|
de: filterTranslationsDe,
|
|
944
813
|
en: filterTranslationsEn,
|
|
945
814
|
fr: filterTranslationsFr,
|
|
946
815
|
it: filterTranslationsIt,
|
|
947
816
|
};
|
|
948
817
|
|
|
949
|
-
|
|
818
|
+
const validQueryKeys = {
|
|
950
819
|
ageFrom: true,
|
|
951
820
|
availableForExchangeOnly: true,
|
|
952
821
|
axisFrom: true,
|
|
@@ -1042,26 +911,23 @@ var validQueryKeys = {
|
|
|
1042
911
|
weightTotalFrom: true,
|
|
1043
912
|
weightTotalTo: true,
|
|
1044
913
|
};
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
for (var _i = 0, _b = Object.keys(query); _i < _b.length; _i++) {
|
|
1049
|
-
var key = _b[_i];
|
|
914
|
+
const cleanQuery = (query) => {
|
|
915
|
+
const acc = {};
|
|
916
|
+
for (const key of Object.keys(query)) {
|
|
1050
917
|
if (key in validQueryKeys) {
|
|
1051
|
-
Object.assign(acc,
|
|
918
|
+
Object.assign(acc, { [key]: query[key] });
|
|
1052
919
|
}
|
|
1053
920
|
}
|
|
1054
921
|
return acc;
|
|
1055
922
|
};
|
|
1056
923
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
intervalList.forEach(
|
|
1060
|
-
|
|
1061
|
-
var currentRangeFrom = from;
|
|
924
|
+
const convertIntervalListToFacetRange = (intervalList) => {
|
|
925
|
+
const generatedFacetRanges = [];
|
|
926
|
+
intervalList.forEach(({ from, to, increment }) => {
|
|
927
|
+
let currentRangeFrom = from;
|
|
1062
928
|
while (currentRangeFrom < to) {
|
|
1063
|
-
|
|
1064
|
-
|
|
929
|
+
const currentRangeTo = Math.min(currentRangeFrom + increment, to);
|
|
930
|
+
const rangeKey = `${currentRangeFrom}-${currentRangeTo}`;
|
|
1065
931
|
generatedFacetRanges.push({
|
|
1066
932
|
from: currentRangeFrom,
|
|
1067
933
|
to: currentRangeTo,
|
|
@@ -1070,55 +936,52 @@ var convertIntervalListToFacetRange = function (intervalList) {
|
|
|
1070
936
|
currentRangeFrom = currentRangeTo;
|
|
1071
937
|
}
|
|
1072
938
|
});
|
|
1073
|
-
|
|
939
|
+
const { to: lastIntervalTo } = intervalList[intervalList.length - 1];
|
|
1074
940
|
generatedFacetRanges.push({
|
|
1075
941
|
from: lastIntervalTo,
|
|
1076
942
|
to: undefined,
|
|
1077
|
-
key:
|
|
943
|
+
key: `${lastIntervalTo}-*`,
|
|
1078
944
|
});
|
|
1079
945
|
return generatedFacetRanges;
|
|
1080
946
|
};
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
return from;
|
|
1084
|
-
}); };
|
|
1085
|
-
var batteryHealthPercentageScale = convertIntervalListToRangeSliderScale([{ from: 10, to: 100, increment: 5 }]);
|
|
947
|
+
const convertIntervalListToRangeSliderScale = (intervalList) => convertIntervalListToFacetRange(intervalList).map(({ from }) => from);
|
|
948
|
+
const batteryHealthPercentageScale = convertIntervalListToRangeSliderScale([{ from: 10, to: 100, increment: 5 }]);
|
|
1086
949
|
|
|
1087
|
-
|
|
950
|
+
const Unit = {
|
|
1088
951
|
kilometers: 'km',
|
|
1089
952
|
swissFrancs: 'CHF',
|
|
1090
953
|
percentage: '%',
|
|
1091
954
|
};
|
|
1092
|
-
|
|
955
|
+
const formatNumber = (value) => {
|
|
1093
956
|
return (value || 0).toLocaleString('de-ch').replace(/’/g, "'");
|
|
1094
957
|
};
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
958
|
+
const formatPriceWithCurrency = (price, options = { minimumFractionDigits: 2, maximumFractionDigits: 2 }) => typeof price === 'number' && !Number.isNaN(price)
|
|
959
|
+
? price
|
|
960
|
+
.toLocaleString('de-ch', {
|
|
961
|
+
...options,
|
|
962
|
+
currency: 'CHF',
|
|
963
|
+
currencyDisplay: 'symbol',
|
|
964
|
+
style: 'currency',
|
|
965
|
+
})
|
|
966
|
+
.replace('.00', '.–')
|
|
967
|
+
.replace(/’/g, "'")
|
|
968
|
+
: null;
|
|
969
|
+
const formatValueWithUnit = ({ value, unit, options = { thousandSeparator: true }, }) => {
|
|
970
|
+
const parsedValue = parseFloat(value);
|
|
1108
971
|
if (Number.isNaN(parsedValue)) {
|
|
1109
972
|
return null;
|
|
1110
973
|
}
|
|
1111
974
|
if (unit === Unit.swissFrancs) {
|
|
1112
975
|
return formatPriceWithCurrency(parsedValue, {
|
|
1113
|
-
maximumFractionDigits:
|
|
1114
|
-
minimumFractionDigits:
|
|
976
|
+
maximumFractionDigits: options?.fixedDecimalSpaces ?? 0,
|
|
977
|
+
minimumFractionDigits: options?.fixedDecimalSpaces ?? 0,
|
|
1115
978
|
});
|
|
1116
979
|
}
|
|
1117
|
-
|
|
1118
|
-
if (options
|
|
980
|
+
let formattedNumber = value;
|
|
981
|
+
if (options?.fixedDecimalSpaces) {
|
|
1119
982
|
formattedNumber = parsedValue.toFixed(options.fixedDecimalSpaces);
|
|
1120
983
|
}
|
|
1121
|
-
if (options
|
|
984
|
+
if (options?.thousandSeparator) {
|
|
1122
985
|
formattedNumber = parsedValue
|
|
1123
986
|
.toLocaleString('de-ch', {
|
|
1124
987
|
maximumFractionDigits: options.fixedDecimalSpaces,
|
|
@@ -1126,26 +989,24 @@ var formatValueWithUnit = function (_a) {
|
|
|
1126
989
|
})
|
|
1127
990
|
.replace(/’/g, "'");
|
|
1128
991
|
}
|
|
1129
|
-
return
|
|
992
|
+
return `${formattedNumber} ${unit}`;
|
|
1130
993
|
};
|
|
1131
994
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
: function (value) { return value; };
|
|
995
|
+
const getRangeDisplayValue = ({ from, to, unit, t, }) => {
|
|
996
|
+
const formatter = unit
|
|
997
|
+
? (value) => formatValueWithUnit({ value, unit })
|
|
998
|
+
: (value) => value;
|
|
1137
999
|
if (from && to)
|
|
1138
|
-
return
|
|
1000
|
+
return `${formatter(from)} - ${formatter(to)}`;
|
|
1139
1001
|
if (from)
|
|
1140
|
-
return
|
|
1002
|
+
return `${t('filtersPkg.from')} ${formatter(from)}`;
|
|
1141
1003
|
if (to)
|
|
1142
|
-
return
|
|
1004
|
+
return `${t('filtersPkg.to')} ${formatter(to)}`;
|
|
1143
1005
|
return null;
|
|
1144
1006
|
};
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
var hasMinValue = typeof minValue === 'number';
|
|
1007
|
+
const inRange = ({ value, minValue, maxValue, }) => {
|
|
1008
|
+
const hasMaxValue = typeof maxValue === 'number';
|
|
1009
|
+
const hasMinValue = typeof minValue === 'number';
|
|
1149
1010
|
if (hasMaxValue && hasMinValue) {
|
|
1150
1011
|
return value >= minValue && value <= maxValue;
|
|
1151
1012
|
}
|
|
@@ -1157,145 +1018,140 @@ var inRange = function (_a) {
|
|
|
1157
1018
|
}
|
|
1158
1019
|
return true;
|
|
1159
1020
|
};
|
|
1160
|
-
|
|
1021
|
+
const getMaxValueFromFacetRangeGroups = (facets) => {
|
|
1161
1022
|
if (!facets) {
|
|
1162
1023
|
return '';
|
|
1163
1024
|
}
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1025
|
+
const intervalList = Object.keys(facets).map((el) => {
|
|
1026
|
+
const [, to] = el.split('-');
|
|
1027
|
+
const parsedStringToNumber = Number(to);
|
|
1167
1028
|
return Number.isFinite(parsedStringToNumber) ? parsedStringToNumber : 0;
|
|
1168
1029
|
});
|
|
1169
|
-
if (!
|
|
1030
|
+
if (!intervalList?.length)
|
|
1170
1031
|
return '';
|
|
1171
|
-
|
|
1172
|
-
return
|
|
1032
|
+
const maxValue = Math.max(...intervalList);
|
|
1033
|
+
return `${formatNumber(maxValue)}+`;
|
|
1173
1034
|
};
|
|
1174
|
-
|
|
1035
|
+
const getMaxValueFromRangeSliderScale = (scale, limit) => {
|
|
1175
1036
|
if (!scale.length) {
|
|
1176
1037
|
return '';
|
|
1177
1038
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1039
|
+
const maxValue = Math.max(...scale);
|
|
1040
|
+
const formattedMaxValue = formatNumber(maxValue);
|
|
1180
1041
|
if (maxValue === limit) {
|
|
1181
1042
|
return formattedMaxValue;
|
|
1182
1043
|
}
|
|
1183
|
-
return
|
|
1044
|
+
return `${formattedMaxValue}+`;
|
|
1184
1045
|
};
|
|
1185
|
-
|
|
1186
|
-
var defaultFacets = _a.defaultFacets, facets = _a.facets;
|
|
1046
|
+
const convertFacetRangesToHistogramFacet = ({ defaultFacets, facets, }) => {
|
|
1187
1047
|
if (!defaultFacets) {
|
|
1188
1048
|
return [];
|
|
1189
1049
|
}
|
|
1190
|
-
return Object.entries(defaultFacets).map(
|
|
1191
|
-
|
|
1192
|
-
var _b = key.split('-'), from = _b[0], to = _b[1];
|
|
1050
|
+
return Object.entries(defaultFacets).map(([key, value]) => {
|
|
1051
|
+
const [from, to] = key.split('-');
|
|
1193
1052
|
return {
|
|
1194
1053
|
from: Number(from),
|
|
1195
1054
|
to: Number.isFinite(Number(to)) ? Number(to) : undefined,
|
|
1196
|
-
value:
|
|
1055
|
+
value: facets?.[key] || value,
|
|
1197
1056
|
};
|
|
1198
1057
|
});
|
|
1199
1058
|
};
|
|
1200
|
-
|
|
1059
|
+
const getRangeSliderScale = (defaultFacets) => {
|
|
1201
1060
|
return Object.keys(defaultFacets)
|
|
1202
|
-
.map(
|
|
1203
|
-
|
|
1061
|
+
.map((key) => {
|
|
1062
|
+
const [_from, to] = key.split('-');
|
|
1204
1063
|
return Number(to);
|
|
1205
1064
|
})
|
|
1206
1065
|
.filter(Boolean);
|
|
1207
1066
|
};
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
var histogramFacet = loadHistogram
|
|
1067
|
+
const getFacetConfig = ({ brand, facets, loadHistogram, chartHeight = '3xl', histogramRangesWithDefaultValue, name, }) => {
|
|
1068
|
+
const defaultFacets = histogramRangesWithDefaultValue?.[brand][name] || {};
|
|
1069
|
+
const histogramFacet = loadHistogram
|
|
1212
1070
|
? convertFacetRangesToHistogramFacet({
|
|
1213
|
-
defaultFacets
|
|
1214
|
-
facets: facets
|
|
1071
|
+
defaultFacets,
|
|
1072
|
+
facets: facets?.[name],
|
|
1215
1073
|
})
|
|
1216
1074
|
: null;
|
|
1217
|
-
|
|
1218
|
-
? { facets: histogramFacet, chartHeight
|
|
1075
|
+
const scaleProps = loadHistogram && histogramFacet
|
|
1076
|
+
? { facets: histogramFacet, chartHeight }
|
|
1219
1077
|
: {
|
|
1220
1078
|
rangeSliderScale: getRangeSliderScale(defaultFacets),
|
|
1221
1079
|
};
|
|
1222
1080
|
return {
|
|
1223
|
-
defaultFacets
|
|
1224
|
-
scaleProps
|
|
1081
|
+
defaultFacets,
|
|
1082
|
+
scaleProps,
|
|
1225
1083
|
};
|
|
1226
1084
|
};
|
|
1227
1085
|
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
React.useEffect(function () {
|
|
1239
|
-
setRange(function (prevState) {
|
|
1240
|
-
var _a;
|
|
1086
|
+
const useRangeFilter = ({ from, to, minValue, maxValue, filters, onAddFilter, onChange, unit, toPlaceholder, fromPlaceholder, }) => {
|
|
1087
|
+
const { t } = useFilterContext();
|
|
1088
|
+
const filterFromValue = filters[from];
|
|
1089
|
+
const filterToValue = filters[to];
|
|
1090
|
+
const [range, setRange] = React.useState({
|
|
1091
|
+
[from]: filterFromValue,
|
|
1092
|
+
[to]: filterToValue,
|
|
1093
|
+
});
|
|
1094
|
+
React.useEffect(() => {
|
|
1095
|
+
setRange((prevState) => {
|
|
1241
1096
|
if (prevState[from] === filterFromValue &&
|
|
1242
1097
|
prevState[to] === filterToValue)
|
|
1243
1098
|
return prevState;
|
|
1244
|
-
return
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1099
|
+
return {
|
|
1100
|
+
[from]: filterFromValue,
|
|
1101
|
+
[to]: filterToValue,
|
|
1102
|
+
};
|
|
1248
1103
|
});
|
|
1249
1104
|
}, [filterFromValue, filterToValue, from, to]);
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
var value = _a.value, name = _a.name, changeType = _a.changeType;
|
|
1253
|
-
var isValid = function () {
|
|
1105
|
+
const handleChange = ({ value, name, changeType, }) => {
|
|
1106
|
+
const isValid = () => {
|
|
1254
1107
|
if (!value)
|
|
1255
1108
|
return true;
|
|
1256
|
-
return inRange({ value
|
|
1109
|
+
return inRange({ value, minValue, maxValue });
|
|
1257
1110
|
};
|
|
1258
1111
|
if (!isValid() || value === range[name])
|
|
1259
1112
|
return;
|
|
1260
|
-
|
|
1113
|
+
const newState = {
|
|
1114
|
+
...range,
|
|
1115
|
+
[name]: value ?? undefined,
|
|
1116
|
+
};
|
|
1261
1117
|
setRange(newState);
|
|
1262
|
-
onChange
|
|
1118
|
+
onChange?.(newState);
|
|
1263
1119
|
if (value && onAddFilter) {
|
|
1264
1120
|
onAddFilter({
|
|
1265
1121
|
appliedFilter: name,
|
|
1266
|
-
value
|
|
1122
|
+
value,
|
|
1267
1123
|
formattedValue: unit
|
|
1268
|
-
? formatValueWithUnit({ value
|
|
1124
|
+
? formatValueWithUnit({ value, unit })
|
|
1269
1125
|
: value.toString(),
|
|
1270
|
-
changeType
|
|
1126
|
+
changeType,
|
|
1271
1127
|
});
|
|
1272
1128
|
}
|
|
1273
1129
|
};
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
_a);
|
|
1130
|
+
const reset = () => {
|
|
1131
|
+
const resetQuery = {
|
|
1132
|
+
[from]: undefined,
|
|
1133
|
+
[to]: undefined,
|
|
1134
|
+
};
|
|
1280
1135
|
setRange(resetQuery);
|
|
1281
1136
|
return resetQuery;
|
|
1282
1137
|
};
|
|
1283
1138
|
useResetAllFilters(reset);
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
unit
|
|
1139
|
+
const valueFrom = range[from];
|
|
1140
|
+
const valueTo = range[to];
|
|
1141
|
+
const numberOfAppliedFilters = [valueFrom, valueTo].filter(Boolean).length;
|
|
1142
|
+
const props = {
|
|
1143
|
+
unit,
|
|
1289
1144
|
from: {
|
|
1290
1145
|
name: from,
|
|
1291
1146
|
value: valueFrom,
|
|
1292
|
-
placeholder: fromPlaceholder
|
|
1147
|
+
placeholder: fromPlaceholder ?? minValue?.toString(),
|
|
1293
1148
|
ariaLabel: t('filtersPkg.from'),
|
|
1294
1149
|
},
|
|
1295
1150
|
to: {
|
|
1296
1151
|
name: to,
|
|
1297
1152
|
value: valueTo,
|
|
1298
|
-
placeholder: toPlaceholder
|
|
1153
|
+
placeholder: toPlaceholder ??
|
|
1154
|
+
(typeof maxValue === 'number' ? `${maxValue}+` : undefined),
|
|
1299
1155
|
ariaLabel: t('filtersPkg.to'),
|
|
1300
1156
|
},
|
|
1301
1157
|
onChange: handleChange,
|
|
@@ -1304,78 +1160,74 @@ var useRangeFilter = function (_a) {
|
|
|
1304
1160
|
max: maxValue,
|
|
1305
1161
|
};
|
|
1306
1162
|
return {
|
|
1307
|
-
numberOfAppliedFilters
|
|
1163
|
+
numberOfAppliedFilters,
|
|
1308
1164
|
isApplied: !!numberOfAppliedFilters,
|
|
1309
|
-
props
|
|
1165
|
+
props,
|
|
1310
1166
|
state: range,
|
|
1311
|
-
reset
|
|
1167
|
+
reset,
|
|
1312
1168
|
};
|
|
1313
1169
|
};
|
|
1314
1170
|
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
var _b = useRangeFilter({
|
|
1171
|
+
const unit$2 = Unit.percentage;
|
|
1172
|
+
const useBatteryHealthPercentageFilter = ({ filters, onAddFilter, onChange }) => {
|
|
1173
|
+
const { t } = useFilterContext();
|
|
1174
|
+
const { props, ...rest } = useRangeFilter({
|
|
1320
1175
|
unit: unit$2,
|
|
1321
|
-
filters
|
|
1176
|
+
filters,
|
|
1322
1177
|
toPlaceholder: getMaxValueFromRangeSliderScale(batteryHealthPercentageScale, 100),
|
|
1323
1178
|
from: 'batteryHealthPercentageFrom',
|
|
1324
1179
|
to: 'batteryHealthPercentageTo',
|
|
1325
1180
|
minValue: 10,
|
|
1326
1181
|
maxValue: 100,
|
|
1327
|
-
onAddFilter
|
|
1328
|
-
onChange
|
|
1329
|
-
})
|
|
1330
|
-
return
|
|
1331
|
-
|
|
1182
|
+
onAddFilter,
|
|
1183
|
+
onChange,
|
|
1184
|
+
});
|
|
1185
|
+
return {
|
|
1186
|
+
ui: (React.createElement(components.RangeFilterInputWithSlider, { ...props, rangeSliderScale: batteryHealthPercentageScale })),
|
|
1187
|
+
...rest,
|
|
1188
|
+
label: t('filtersPkg.batteryHealthPercentage'),
|
|
1189
|
+
getDisplayValue: (query) => {
|
|
1190
|
+
const { batteryHealthPercentageFrom, batteryHealthPercentageTo } = query || rest.state;
|
|
1332
1191
|
return (getRangeDisplayValue({
|
|
1333
1192
|
from: batteryHealthPercentageFrom,
|
|
1334
1193
|
to: batteryHealthPercentageTo,
|
|
1335
1194
|
unit: unit$2,
|
|
1336
|
-
t
|
|
1195
|
+
t,
|
|
1337
1196
|
}) || '');
|
|
1338
|
-
}
|
|
1197
|
+
},
|
|
1198
|
+
};
|
|
1339
1199
|
};
|
|
1340
1200
|
|
|
1341
|
-
|
|
1342
|
-
var _a, _b;
|
|
1201
|
+
const getFacetForBooleanCheckboxFilter = (facets, key) => {
|
|
1343
1202
|
if (!facets)
|
|
1344
1203
|
return null;
|
|
1345
|
-
return
|
|
1204
|
+
return facets?.[key]?.['true'] ?? 0;
|
|
1346
1205
|
};
|
|
1347
|
-
|
|
1348
|
-
var label = _a.label, filterKey = _a.filterKey, filters = _a.filters;
|
|
1206
|
+
const getBooleanDisplayValue = ({ label, filterKey, filters, }) => {
|
|
1349
1207
|
return filters[filterKey] === true ? label : '';
|
|
1350
1208
|
};
|
|
1351
1209
|
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
return Object.fromEntries(options.map(function (_a) {
|
|
1357
|
-
var key = _a.key;
|
|
1358
|
-
return [key, filters[key]];
|
|
1359
|
-
}));
|
|
1210
|
+
const useBooleanFilter = ({ filters, getFacet, options, onChange, onAddFilter, }) => {
|
|
1211
|
+
const { t } = useFilterContext();
|
|
1212
|
+
const generateState = React.useCallback(() => {
|
|
1213
|
+
return Object.fromEntries(options.map(({ key }) => [key, filters[key]]));
|
|
1360
1214
|
}, [filters, options]);
|
|
1361
|
-
|
|
1362
|
-
React.useEffect(
|
|
1363
|
-
setState(
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
return prevState[key] !== newState[key];
|
|
1367
|
-
});
|
|
1215
|
+
const [state, setState] = React.useState(generateState());
|
|
1216
|
+
React.useEffect(() => {
|
|
1217
|
+
setState((prevState) => {
|
|
1218
|
+
const newState = generateState();
|
|
1219
|
+
const hasChanged = Object.keys(newState).some((key) => prevState[key] !== newState[key]);
|
|
1368
1220
|
return hasChanged ? newState : prevState;
|
|
1369
1221
|
});
|
|
1370
1222
|
}, [generateState]);
|
|
1371
|
-
|
|
1223
|
+
const items = options.map((option) => ({
|
|
1372
1224
|
key: option.key,
|
|
1373
1225
|
label: t(option.translationKey),
|
|
1374
1226
|
isChecked: !!state[option.key],
|
|
1375
1227
|
facet: getFacet(option.key),
|
|
1376
|
-
})
|
|
1377
|
-
|
|
1378
|
-
|
|
1228
|
+
}));
|
|
1229
|
+
const reset = () => {
|
|
1230
|
+
const newState = options.reduce((acc, option) => {
|
|
1379
1231
|
acc[option.key] = undefined;
|
|
1380
1232
|
return acc;
|
|
1381
1233
|
}, {});
|
|
@@ -1383,11 +1235,13 @@ var useBooleanFilter = function (_a) {
|
|
|
1383
1235
|
return newState;
|
|
1384
1236
|
};
|
|
1385
1237
|
useResetAllFilters(reset);
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1238
|
+
const onApply = (updatedItem) => {
|
|
1239
|
+
const newState = {
|
|
1240
|
+
...state,
|
|
1241
|
+
[updatedItem.key]: updatedItem.isChecked || undefined,
|
|
1242
|
+
};
|
|
1389
1243
|
setState(newState);
|
|
1390
|
-
onChange
|
|
1244
|
+
onChange?.(newState);
|
|
1391
1245
|
if (updatedItem.isChecked && onAddFilter) {
|
|
1392
1246
|
onAddFilter({
|
|
1393
1247
|
appliedFilter: updatedItem.key,
|
|
@@ -1396,157 +1250,167 @@ var useBooleanFilter = function (_a) {
|
|
|
1396
1250
|
});
|
|
1397
1251
|
}
|
|
1398
1252
|
};
|
|
1399
|
-
|
|
1400
|
-
|
|
1253
|
+
const numberOfAppliedFilters = items.filter((item) => item.isChecked).length;
|
|
1254
|
+
const isApplied = !!numberOfAppliedFilters;
|
|
1401
1255
|
return {
|
|
1402
|
-
items
|
|
1403
|
-
reset
|
|
1404
|
-
state
|
|
1405
|
-
isApplied
|
|
1406
|
-
numberOfAppliedFilters
|
|
1407
|
-
onApply
|
|
1256
|
+
items,
|
|
1257
|
+
reset,
|
|
1258
|
+
state,
|
|
1259
|
+
isApplied,
|
|
1260
|
+
numberOfAppliedFilters,
|
|
1261
|
+
onApply,
|
|
1408
1262
|
};
|
|
1409
1263
|
};
|
|
1410
1264
|
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
key
|
|
1414
|
-
translationKey:
|
|
1265
|
+
const key = 'hasBatteryCertificateOnly';
|
|
1266
|
+
const option = {
|
|
1267
|
+
key,
|
|
1268
|
+
translationKey: `filtersPkg.${key}`,
|
|
1415
1269
|
};
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1270
|
+
const options = [option];
|
|
1271
|
+
const useHasBatteryCertificateKeyOnlyFilter = ({ filters, onAddFilter, onChange, facets }) => {
|
|
1272
|
+
const { t, language } = useFilterContext();
|
|
1273
|
+
const label = t(option.translationKey);
|
|
1274
|
+
const { items, onApply, ...rest } = useBooleanFilter({
|
|
1275
|
+
filters,
|
|
1276
|
+
options,
|
|
1277
|
+
getFacet: (facetKey) => getFacetForBooleanCheckboxFilter(facets ?? null, facetKey),
|
|
1278
|
+
onAddFilter,
|
|
1279
|
+
onChange,
|
|
1280
|
+
});
|
|
1281
|
+
return {
|
|
1282
|
+
ui: React.createElement(components.CheckboxFilter, { items: items, onApply: onApply, language: language }),
|
|
1283
|
+
label,
|
|
1284
|
+
getDisplayValue: (query) => getBooleanDisplayValue({
|
|
1285
|
+
label,
|
|
1286
|
+
filterKey: key,
|
|
1287
|
+
filters: query || rest.state,
|
|
1288
|
+
}),
|
|
1289
|
+
...rest,
|
|
1290
|
+
};
|
|
1437
1291
|
};
|
|
1438
1292
|
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
chartHeight: chartHeight,
|
|
1293
|
+
const minValue = 1900;
|
|
1294
|
+
const useFirstRegistrationYearFilter = ({ filters, facets, onAddFilter, onChange, loadHistogram, chartHeight, }) => {
|
|
1295
|
+
const { t, brand, histogramRanges } = useFilterContext();
|
|
1296
|
+
const maxValue = new Date().getFullYear();
|
|
1297
|
+
const { scaleProps } = getFacetConfig({
|
|
1298
|
+
brand,
|
|
1299
|
+
facets,
|
|
1300
|
+
loadHistogram,
|
|
1301
|
+
chartHeight,
|
|
1449
1302
|
histogramRangesWithDefaultValue: histogramRanges,
|
|
1450
1303
|
name: 'firstRegistrationYearRanges',
|
|
1451
|
-
})
|
|
1452
|
-
|
|
1453
|
-
filters
|
|
1304
|
+
});
|
|
1305
|
+
const { props, ...rest } = useRangeFilter({
|
|
1306
|
+
filters,
|
|
1454
1307
|
toPlaceholder: maxValue.toString(),
|
|
1455
1308
|
from: 'firstRegistrationYearFrom',
|
|
1456
1309
|
to: 'firstRegistrationYearTo',
|
|
1457
|
-
minValue
|
|
1458
|
-
maxValue
|
|
1459
|
-
onAddFilter
|
|
1460
|
-
onChange
|
|
1461
|
-
})
|
|
1462
|
-
return
|
|
1463
|
-
|
|
1310
|
+
minValue,
|
|
1311
|
+
maxValue,
|
|
1312
|
+
onAddFilter,
|
|
1313
|
+
onChange,
|
|
1314
|
+
});
|
|
1315
|
+
return {
|
|
1316
|
+
ui: React.createElement(components.RangeFilterInputWithSlider, { ...props, ...scaleProps }),
|
|
1317
|
+
...rest,
|
|
1318
|
+
label: t('filtersPkg.firstRegistrationYear'),
|
|
1319
|
+
getDisplayValue: (query) => {
|
|
1320
|
+
const { firstRegistrationYearFrom, firstRegistrationYearTo } = query || rest.state;
|
|
1464
1321
|
return (getRangeDisplayValue({
|
|
1465
1322
|
from: firstRegistrationYearFrom,
|
|
1466
1323
|
to: firstRegistrationYearTo,
|
|
1467
|
-
t
|
|
1324
|
+
t,
|
|
1468
1325
|
}) || '');
|
|
1469
|
-
}
|
|
1326
|
+
},
|
|
1327
|
+
};
|
|
1470
1328
|
};
|
|
1471
1329
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
chartHeight: chartHeight,
|
|
1330
|
+
const unit$1 = Unit.kilometers;
|
|
1331
|
+
const useMileageFilter = ({ filters, facets, onAddFilter, onChange, loadHistogram, chartHeight, }) => {
|
|
1332
|
+
const { t, brand, histogramRanges } = useFilterContext();
|
|
1333
|
+
const { defaultFacets, scaleProps } = getFacetConfig({
|
|
1334
|
+
brand,
|
|
1335
|
+
facets,
|
|
1336
|
+
loadHistogram,
|
|
1337
|
+
chartHeight,
|
|
1481
1338
|
histogramRangesWithDefaultValue: histogramRanges,
|
|
1482
1339
|
name: 'mileageRanges',
|
|
1483
|
-
})
|
|
1484
|
-
|
|
1340
|
+
});
|
|
1341
|
+
const { props, ...rest } = useRangeFilter({
|
|
1485
1342
|
unit: unit$1,
|
|
1486
|
-
filters
|
|
1343
|
+
filters,
|
|
1487
1344
|
toPlaceholder: getMaxValueFromFacetRangeGroups(defaultFacets),
|
|
1488
1345
|
from: 'mileageFrom',
|
|
1489
1346
|
to: 'mileageTo',
|
|
1490
1347
|
minValue: 0,
|
|
1491
1348
|
maxValue: 99999999,
|
|
1492
|
-
onAddFilter
|
|
1493
|
-
onChange
|
|
1494
|
-
})
|
|
1495
|
-
return
|
|
1496
|
-
|
|
1349
|
+
onAddFilter,
|
|
1350
|
+
onChange,
|
|
1351
|
+
});
|
|
1352
|
+
return {
|
|
1353
|
+
ui: React.createElement(components.RangeFilterInputWithSlider, { ...props, ...scaleProps }),
|
|
1354
|
+
...rest,
|
|
1355
|
+
label: t('filtersPkg.mileage'),
|
|
1356
|
+
getDisplayValue: (query) => {
|
|
1357
|
+
const { mileageFrom, mileageTo } = query || rest.state;
|
|
1497
1358
|
return (getRangeDisplayValue({
|
|
1498
1359
|
from: mileageFrom,
|
|
1499
1360
|
to: mileageTo,
|
|
1500
1361
|
unit: unit$1,
|
|
1501
|
-
t
|
|
1362
|
+
t,
|
|
1502
1363
|
}) || '');
|
|
1503
|
-
}
|
|
1364
|
+
},
|
|
1365
|
+
};
|
|
1504
1366
|
};
|
|
1505
1367
|
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
chartHeight: chartHeight,
|
|
1368
|
+
const unit = Unit.swissFrancs;
|
|
1369
|
+
const usePriceFilter = ({ filters, facets, onAddFilter, onChange, loadHistogram, chartHeight, }) => {
|
|
1370
|
+
const { t, brand, histogramRanges } = useFilterContext();
|
|
1371
|
+
const { defaultFacets, scaleProps } = getFacetConfig({
|
|
1372
|
+
brand,
|
|
1373
|
+
facets,
|
|
1374
|
+
loadHistogram,
|
|
1375
|
+
chartHeight,
|
|
1515
1376
|
histogramRangesWithDefaultValue: histogramRanges,
|
|
1516
1377
|
name: 'priceRanges',
|
|
1517
|
-
})
|
|
1518
|
-
|
|
1519
|
-
unit
|
|
1520
|
-
filters
|
|
1378
|
+
});
|
|
1379
|
+
const { props, ...rest } = useRangeFilter({
|
|
1380
|
+
unit,
|
|
1381
|
+
filters,
|
|
1521
1382
|
toPlaceholder: getMaxValueFromFacetRangeGroups(defaultFacets),
|
|
1522
1383
|
from: 'priceFrom',
|
|
1523
1384
|
to: 'priceTo',
|
|
1524
1385
|
minValue: 0,
|
|
1525
1386
|
maxValue: 9999999,
|
|
1526
|
-
onAddFilter
|
|
1527
|
-
onChange
|
|
1528
|
-
})
|
|
1529
|
-
return
|
|
1530
|
-
|
|
1387
|
+
onAddFilter,
|
|
1388
|
+
onChange,
|
|
1389
|
+
});
|
|
1390
|
+
return {
|
|
1391
|
+
ui: React.createElement(components.RangeFilterInputWithSlider, { ...props, ...scaleProps }),
|
|
1392
|
+
...rest,
|
|
1393
|
+
label: t('filtersPkg.price'),
|
|
1394
|
+
getDisplayValue: (query) => {
|
|
1395
|
+
const { priceFrom, priceTo } = query || rest.state;
|
|
1531
1396
|
return (getRangeDisplayValue({
|
|
1532
1397
|
from: priceFrom,
|
|
1533
1398
|
to: priceTo,
|
|
1534
|
-
unit
|
|
1535
|
-
t
|
|
1399
|
+
unit,
|
|
1400
|
+
t,
|
|
1536
1401
|
}) || '');
|
|
1537
|
-
}
|
|
1402
|
+
},
|
|
1403
|
+
};
|
|
1538
1404
|
};
|
|
1539
1405
|
|
|
1540
|
-
|
|
1406
|
+
const isInArray = (item, array) => array.includes(item);
|
|
1541
1407
|
|
|
1542
|
-
|
|
1543
|
-
if (language === void 0) { language = 'de'; }
|
|
1544
|
-
if (customOrder === void 0) { customOrder = null; }
|
|
1408
|
+
const sortCheckboxOptions = (a, b, language = 'de', customOrder = null) => {
|
|
1545
1409
|
if (!customOrder || !a.key || !b.key) {
|
|
1546
1410
|
return a.label.localeCompare(b.label, language, { sensitivity: 'base' });
|
|
1547
1411
|
}
|
|
1548
|
-
|
|
1549
|
-
|
|
1412
|
+
const indexA = customOrder.indexOf(a.key);
|
|
1413
|
+
const indexB = customOrder.indexOf(b.key);
|
|
1550
1414
|
if (indexA === -1 && indexB === -1) {
|
|
1551
1415
|
return a.label.localeCompare(b.label, language, { sensitivity: 'base' });
|
|
1552
1416
|
}
|
|
@@ -1558,25 +1422,21 @@ var sortCheckboxOptions = function (a, b, language, customOrder) {
|
|
|
1558
1422
|
}
|
|
1559
1423
|
return indexA - indexB;
|
|
1560
1424
|
};
|
|
1561
|
-
|
|
1562
|
-
var _b;
|
|
1563
|
-
var key = _a.key, filterName = _a.filterName, facets = _a.facets;
|
|
1425
|
+
const getFacet = ({ key, filterName, facets, }) => {
|
|
1564
1426
|
if (!facets)
|
|
1565
1427
|
return null;
|
|
1566
|
-
return (filterName &&
|
|
1428
|
+
return (filterName && facets[filterName]?.[key]) || 0;
|
|
1567
1429
|
};
|
|
1568
|
-
|
|
1430
|
+
const getCheckboxDisplayValue = (options, filters) => {
|
|
1569
1431
|
return options
|
|
1570
|
-
.reduce(
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
if (isInArray(parent.key, (_b = filters[filterName]) !== null && _b !== void 0 ? _b : [])) {
|
|
1432
|
+
.reduce((acc, parent) => {
|
|
1433
|
+
const filterName = parent.filterName ?? '';
|
|
1434
|
+
if (isInArray(parent.key, filters[filterName] ?? [])) {
|
|
1574
1435
|
acc.push(parent.label);
|
|
1575
1436
|
}
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
if (isInArray(child.key, (_b = filters[childFilterName]) !== null && _b !== void 0 ? _b : [])) {
|
|
1437
|
+
parent.childCheckboxes?.forEach((child) => {
|
|
1438
|
+
const childFilterName = child.filterName ?? '';
|
|
1439
|
+
if (isInArray(child.key, filters[childFilterName] ?? [])) {
|
|
1580
1440
|
acc.push(child.label);
|
|
1581
1441
|
}
|
|
1582
1442
|
});
|
|
@@ -1584,30 +1444,27 @@ var getCheckboxDisplayValue = function (options, filters) {
|
|
|
1584
1444
|
}, [])
|
|
1585
1445
|
.join(', ');
|
|
1586
1446
|
};
|
|
1587
|
-
|
|
1588
|
-
var item = _a.item, filterName = _a.filterName, translationKey = _a.translationKey, t = _a.t, getFacetFn = _a.getFacet;
|
|
1447
|
+
const mapCheckboxItem = ({ item, filterName, translationKey, t, getFacet: getFacetFn, }) => {
|
|
1589
1448
|
return {
|
|
1590
|
-
filterName
|
|
1449
|
+
filterName,
|
|
1591
1450
|
key: item,
|
|
1592
|
-
label: t(['filtersPkg',
|
|
1451
|
+
label: t(['filtersPkg', `${translationKey}.${item}`]),
|
|
1593
1452
|
facet: getFacetFn({
|
|
1594
1453
|
key: item,
|
|
1595
|
-
filterName
|
|
1454
|
+
filterName,
|
|
1596
1455
|
}),
|
|
1597
1456
|
};
|
|
1598
1457
|
};
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
groups: groups.reduce(function (acc, group) {
|
|
1458
|
+
const mapTypesToGroups = ({ options, groups, mapping, }) => {
|
|
1459
|
+
const result = {
|
|
1460
|
+
groups: groups.reduce((acc, group) => {
|
|
1603
1461
|
acc[group] = [];
|
|
1604
1462
|
return acc;
|
|
1605
1463
|
}, {}),
|
|
1606
1464
|
options: [],
|
|
1607
1465
|
};
|
|
1608
|
-
for (
|
|
1609
|
-
|
|
1610
|
-
var group = mapping && mapping[option];
|
|
1466
|
+
for (const option of options) {
|
|
1467
|
+
const group = mapping && mapping[option];
|
|
1611
1468
|
if (group) {
|
|
1612
1469
|
result.groups[group].push(option);
|
|
1613
1470
|
}
|
|
@@ -1617,68 +1474,80 @@ var mapTypesToGroups = function (_a) {
|
|
|
1617
1474
|
}
|
|
1618
1475
|
return result;
|
|
1619
1476
|
};
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
var getImage = options === null || options === void 0 ? void 0 : options.getImage;
|
|
1477
|
+
const generateCheckboxFilterItems = ({ options, groups, groupMapping, getFacet: getFacetFn, t, language, customOrder = null, }) => {
|
|
1478
|
+
const hasOptions = !!options?.items.length;
|
|
1479
|
+
const hasGroups = !!groups?.items.length;
|
|
1480
|
+
const getImage = options?.getImage;
|
|
1625
1481
|
if (!hasGroups && !hasOptions) {
|
|
1626
1482
|
return [];
|
|
1627
1483
|
}
|
|
1628
|
-
|
|
1484
|
+
const sortItems = (a, b) => {
|
|
1629
1485
|
return sortCheckboxOptions(a, b, language, customOrder);
|
|
1630
1486
|
};
|
|
1631
1487
|
if (!hasGroups && hasOptions && options.key) {
|
|
1632
1488
|
return options.items
|
|
1633
|
-
.map(
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1489
|
+
.map((option) => ({
|
|
1490
|
+
...mapCheckboxItem({
|
|
1491
|
+
item: option,
|
|
1492
|
+
filterName: options.key,
|
|
1493
|
+
translationKey: options.translationKey,
|
|
1494
|
+
t,
|
|
1495
|
+
getFacet: getFacetFn,
|
|
1496
|
+
}),
|
|
1497
|
+
image: getImage?.(option),
|
|
1498
|
+
childCheckboxes: [],
|
|
1499
|
+
}))
|
|
1640
1500
|
.sort(sortItems);
|
|
1641
1501
|
}
|
|
1642
1502
|
if (hasGroups && groups.key && !hasOptions) {
|
|
1643
1503
|
return groups.items
|
|
1644
|
-
.map(
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1504
|
+
.map((group) => ({
|
|
1505
|
+
...mapCheckboxItem({
|
|
1506
|
+
item: group,
|
|
1507
|
+
filterName: groups.key,
|
|
1508
|
+
translationKey: groups.translationKey,
|
|
1509
|
+
t,
|
|
1510
|
+
getFacet: getFacetFn,
|
|
1511
|
+
}),
|
|
1512
|
+
childCheckboxes: [],
|
|
1513
|
+
}))
|
|
1651
1514
|
.sort(sortItems);
|
|
1652
1515
|
}
|
|
1653
|
-
|
|
1654
|
-
options:
|
|
1655
|
-
groups:
|
|
1516
|
+
const mappedOptions = mapTypesToGroups({
|
|
1517
|
+
options: options?.items || [],
|
|
1518
|
+
groups: groups?.items || [],
|
|
1656
1519
|
mapping: groupMapping,
|
|
1657
1520
|
});
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
return (__assign(__assign({}, mapCheckboxItem({
|
|
1521
|
+
const groupEntries = Object.entries(mappedOptions.groups).map(([group, types]) => ({
|
|
1522
|
+
...mapCheckboxItem({
|
|
1661
1523
|
item: group,
|
|
1662
|
-
filterName: groups
|
|
1663
|
-
translationKey:
|
|
1664
|
-
t
|
|
1524
|
+
filterName: groups?.key,
|
|
1525
|
+
translationKey: groups?.translationKey || '',
|
|
1526
|
+
t,
|
|
1665
1527
|
getFacet: getFacetFn,
|
|
1666
|
-
})
|
|
1528
|
+
}),
|
|
1529
|
+
childCheckboxes: types.map((type) => ({
|
|
1530
|
+
...mapCheckboxItem({
|
|
1667
1531
|
item: type,
|
|
1668
|
-
filterName: options
|
|
1669
|
-
translationKey:
|
|
1670
|
-
t
|
|
1532
|
+
filterName: options?.key,
|
|
1533
|
+
translationKey: options?.translationKey || '',
|
|
1534
|
+
t,
|
|
1671
1535
|
getFacet: getFacetFn,
|
|
1672
|
-
})
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1536
|
+
}),
|
|
1537
|
+
})),
|
|
1538
|
+
}));
|
|
1539
|
+
const ungroupedOptions = mappedOptions.options.map((option) => ({
|
|
1540
|
+
...mapCheckboxItem({
|
|
1541
|
+
item: option,
|
|
1542
|
+
filterName: options?.key,
|
|
1543
|
+
translationKey: options?.translationKey || '',
|
|
1544
|
+
t,
|
|
1545
|
+
getFacet: getFacetFn,
|
|
1546
|
+
}),
|
|
1547
|
+
image: getImage?.(option),
|
|
1548
|
+
childCheckboxes: [],
|
|
1549
|
+
}));
|
|
1550
|
+
return [...groupEntries, ...ungroupedOptions].sort(sortItems);
|
|
1682
1551
|
};
|
|
1683
1552
|
|
|
1684
1553
|
var ActionType;
|
|
@@ -1691,31 +1560,51 @@ var ActionType;
|
|
|
1691
1560
|
ActionType["SetFilter"] = "SET_FILTER";
|
|
1692
1561
|
ActionType["Reset"] = "RESET";
|
|
1693
1562
|
})(ActionType || (ActionType = {}));
|
|
1694
|
-
|
|
1695
|
-
var _a, _b;
|
|
1563
|
+
const reducer = (state, action) => {
|
|
1696
1564
|
switch (action.type) {
|
|
1697
1565
|
case ActionType.DeselectChildOption:
|
|
1698
|
-
return
|
|
1566
|
+
return {
|
|
1567
|
+
...state,
|
|
1568
|
+
options: state.options.filter((option) => option !== action.payload?.key),
|
|
1569
|
+
};
|
|
1699
1570
|
case ActionType.SelectChildOption:
|
|
1700
|
-
return
|
|
1571
|
+
return {
|
|
1572
|
+
...state,
|
|
1573
|
+
options: [...state.options, action.payload?.key],
|
|
1574
|
+
};
|
|
1701
1575
|
case ActionType.DeselectGroup:
|
|
1702
|
-
return
|
|
1576
|
+
return {
|
|
1577
|
+
...state,
|
|
1578
|
+
groups: state.groups.filter((group) => group !== action.payload?.key),
|
|
1579
|
+
};
|
|
1703
1580
|
case ActionType.SelectGroup:
|
|
1704
|
-
return
|
|
1581
|
+
return {
|
|
1582
|
+
...state,
|
|
1583
|
+
options: state.options.filter((option) => !action.payload.parentGroupChildItems.includes(option)),
|
|
1584
|
+
groups: [...state.groups, action.payload?.key],
|
|
1585
|
+
};
|
|
1705
1586
|
case ActionType.DeselectChildAndGroupAndAddAllOtherChildOptions: {
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
return
|
|
1587
|
+
const { parentGroup, parentGroupChildItems, key } = action.payload;
|
|
1588
|
+
const updatedOptions = parentGroupChildItems?.filter((option) => option !== key);
|
|
1589
|
+
const updatedGroups = state.groups.filter((group) => group !== parentGroup);
|
|
1590
|
+
return {
|
|
1591
|
+
...state,
|
|
1592
|
+
options: [...state.options, ...(updatedOptions ?? [])],
|
|
1593
|
+
groups: updatedGroups,
|
|
1594
|
+
};
|
|
1710
1595
|
}
|
|
1711
1596
|
case ActionType.SetFilter: {
|
|
1712
|
-
|
|
1597
|
+
const isStateDifferent = (arr1, arr2) => {
|
|
1713
1598
|
return (arr1.length !== arr2.length ||
|
|
1714
|
-
!arr1.every(
|
|
1599
|
+
!arr1.every((option) => arr2.includes(option)));
|
|
1715
1600
|
};
|
|
1716
1601
|
if (isStateDifferent(action.payload.options, state.options) ||
|
|
1717
1602
|
isStateDifferent(action.payload.groups, state.groups)) {
|
|
1718
|
-
return
|
|
1603
|
+
return {
|
|
1604
|
+
...state,
|
|
1605
|
+
options: action.payload.options,
|
|
1606
|
+
groups: action.payload.groups,
|
|
1607
|
+
};
|
|
1719
1608
|
}
|
|
1720
1609
|
return state;
|
|
1721
1610
|
}
|
|
@@ -1728,49 +1617,38 @@ var reducer = function (state, action) {
|
|
|
1728
1617
|
return state;
|
|
1729
1618
|
}
|
|
1730
1619
|
};
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
React.useEffect(function () {
|
|
1620
|
+
const useCheckboxFilterReducer = ({ initialState, onChange, }) => {
|
|
1621
|
+
const [state, dispatchBase] = React.useReducer(reducer, initialState);
|
|
1622
|
+
const onChangeRef = React.useRef(onChange);
|
|
1623
|
+
const lastActionType = React.useRef(null);
|
|
1624
|
+
React.useEffect(() => {
|
|
1737
1625
|
onChangeRef.current = onChange;
|
|
1738
1626
|
}, [onChange]);
|
|
1739
|
-
React.useEffect(
|
|
1740
|
-
var _a;
|
|
1627
|
+
React.useEffect(() => {
|
|
1741
1628
|
if (![ActionType.Reset, ActionType.SetFilter].includes(lastActionType.current)) {
|
|
1742
|
-
|
|
1629
|
+
onChangeRef.current?.(state);
|
|
1743
1630
|
}
|
|
1744
1631
|
}, [state]);
|
|
1745
|
-
|
|
1632
|
+
const dispatch = React.useCallback((action) => {
|
|
1746
1633
|
lastActionType.current = action.type;
|
|
1747
1634
|
dispatchBase(action);
|
|
1748
1635
|
}, []);
|
|
1749
|
-
return { state
|
|
1636
|
+
return { state, dispatch };
|
|
1750
1637
|
};
|
|
1751
1638
|
|
|
1752
|
-
|
|
1753
|
-
var itemKey = _a.itemKey, mapping = _a.mapping;
|
|
1639
|
+
const getParentGroupWithChildItems = ({ itemKey, mapping, }) => {
|
|
1754
1640
|
if (!mapping)
|
|
1755
1641
|
return { parentGroup: null, parentGroupChildItems: [] };
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
.filter(
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
})
|
|
1762
|
-
.map(function (_a) {
|
|
1763
|
-
var key = _a[0];
|
|
1764
|
-
return key;
|
|
1765
|
-
});
|
|
1766
|
-
return { parentGroup: parentGroup, parentGroupChildItems: parentGroupChildItems };
|
|
1642
|
+
const parentGroup = mapping[itemKey];
|
|
1643
|
+
const parentGroupChildItems = Object.entries(mapping)
|
|
1644
|
+
.filter(([, group]) => group === parentGroup)
|
|
1645
|
+
.map(([key]) => key);
|
|
1646
|
+
return { parentGroup, parentGroupChildItems };
|
|
1767
1647
|
};
|
|
1768
|
-
|
|
1769
|
-
return items.map(
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
var children = (_a = item.childCheckboxes) === null || _a === void 0 ? void 0 : _a.map(function (child) {
|
|
1773
|
-
var _a;
|
|
1648
|
+
const mapToSearchableListItems = (items, handleApply) => {
|
|
1649
|
+
return items.map((item) => {
|
|
1650
|
+
const isParentSelected = item.isChecked;
|
|
1651
|
+
const children = item.childCheckboxes?.map((child) => {
|
|
1774
1652
|
return {
|
|
1775
1653
|
key: child.key,
|
|
1776
1654
|
value: child.key,
|
|
@@ -1779,48 +1657,47 @@ var mapToSearchableListItems = function (items, handleApply) {
|
|
|
1779
1657
|
isSelected: isParentSelected || !!child.isChecked,
|
|
1780
1658
|
showChevron: false,
|
|
1781
1659
|
isCheckbox: true,
|
|
1782
|
-
onClick:
|
|
1783
|
-
facet:
|
|
1660
|
+
onClick: () => handleApply(child),
|
|
1661
|
+
facet: child.facet?.toString(),
|
|
1784
1662
|
};
|
|
1785
1663
|
});
|
|
1786
|
-
|
|
1664
|
+
const isIndeterminate = !item.isChecked && children?.some((child) => child.isSelected);
|
|
1787
1665
|
return {
|
|
1788
1666
|
key: item.key,
|
|
1789
1667
|
label: item.label,
|
|
1790
1668
|
value: item.key,
|
|
1791
1669
|
filterName: item.filterName,
|
|
1792
1670
|
isSelected: !!item.isChecked,
|
|
1793
|
-
onClick:
|
|
1671
|
+
onClick: () => handleApply(item),
|
|
1794
1672
|
showChevron: false,
|
|
1795
1673
|
isCheckbox: true,
|
|
1796
1674
|
isIndeterminate: !!isIndeterminate,
|
|
1797
|
-
facet:
|
|
1798
|
-
children
|
|
1675
|
+
facet: item.facet?.toString(),
|
|
1676
|
+
children,
|
|
1799
1677
|
};
|
|
1800
1678
|
});
|
|
1801
1679
|
};
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
var initOptionParam = React.useMemo(function () { var _a; return (_a = (optionFilterName && filters[optionFilterName])) !== null && _a !== void 0 ? _a : []; }, [filters, optionFilterName]);
|
|
1810
|
-
var initGroupParam = React.useMemo(function () { var _a; return (_a = (groupFilterName && filters[groupFilterName])) !== null && _a !== void 0 ? _a : []; }, [filters, groupFilterName]);
|
|
1811
|
-
var _f = useCheckboxFilterReducer({
|
|
1680
|
+
const useCheckboxFilter = ({ filters, onAddFilter, onChange: onFilterChange, ...generateCheckboxFilterItemsArgs }) => {
|
|
1681
|
+
const { language } = useFilterContext();
|
|
1682
|
+
const groupFilterName = generateCheckboxFilterItemsArgs.groups?.key;
|
|
1683
|
+
const optionFilterName = generateCheckboxFilterItemsArgs.options?.key;
|
|
1684
|
+
const initOptionParam = React.useMemo(() => (optionFilterName && filters[optionFilterName]) ?? [], [filters, optionFilterName]);
|
|
1685
|
+
const initGroupParam = React.useMemo(() => (groupFilterName && filters[groupFilterName]) ?? [], [filters, groupFilterName]);
|
|
1686
|
+
const { state: { options, groups }, dispatch, } = useCheckboxFilterReducer({
|
|
1812
1687
|
initialState: {
|
|
1813
1688
|
groups: initGroupParam,
|
|
1814
1689
|
options: initOptionParam,
|
|
1815
1690
|
},
|
|
1816
|
-
onChange:
|
|
1817
|
-
var _a, _b;
|
|
1691
|
+
onChange: (state) => {
|
|
1818
1692
|
if (!onFilterChange)
|
|
1819
1693
|
return;
|
|
1820
|
-
onFilterChange(
|
|
1694
|
+
onFilterChange({
|
|
1695
|
+
...(groupFilterName ? { [groupFilterName]: state.groups } : {}),
|
|
1696
|
+
...(optionFilterName ? { [optionFilterName]: state.options } : {}),
|
|
1697
|
+
});
|
|
1821
1698
|
},
|
|
1822
|
-
})
|
|
1823
|
-
React.useEffect(
|
|
1699
|
+
});
|
|
1700
|
+
React.useEffect(() => {
|
|
1824
1701
|
dispatch({
|
|
1825
1702
|
type: ActionType.SetFilter,
|
|
1826
1703
|
payload: {
|
|
@@ -1829,19 +1706,16 @@ var useCheckboxFilter = function (_a) {
|
|
|
1829
1706
|
},
|
|
1830
1707
|
});
|
|
1831
1708
|
}, [initOptionParam, initGroupParam, dispatch]);
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
var key = updatedItem.key;
|
|
1709
|
+
const handleGroupApply = React.useCallback((updatedItem) => {
|
|
1710
|
+
const { key } = updatedItem;
|
|
1835
1711
|
if (isInArray(key, groups)) {
|
|
1836
1712
|
return dispatch({
|
|
1837
1713
|
type: ActionType.DeselectGroup,
|
|
1838
|
-
payload: { key
|
|
1714
|
+
payload: { key },
|
|
1839
1715
|
});
|
|
1840
1716
|
}
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
})) !== null && _b !== void 0 ? _b : [];
|
|
1844
|
-
onAddFilter === null || onAddFilter === void 0 ? void 0 : onAddFilter({
|
|
1717
|
+
const selectedParentGroupChildItems = updatedItem.childCheckboxes?.filter((child) => isInArray(child.key, options)) ?? [];
|
|
1718
|
+
onAddFilter?.({
|
|
1845
1719
|
appliedFilter: updatedItem.filterName,
|
|
1846
1720
|
value: updatedItem.key,
|
|
1847
1721
|
formattedValue: updatedItem.label,
|
|
@@ -1850,35 +1724,35 @@ var useCheckboxFilter = function (_a) {
|
|
|
1850
1724
|
dispatch({
|
|
1851
1725
|
type: ActionType.SelectGroup,
|
|
1852
1726
|
payload: {
|
|
1853
|
-
key
|
|
1854
|
-
parentGroupChildItems: selectedParentGroupChildItems.map(
|
|
1727
|
+
key,
|
|
1728
|
+
parentGroupChildItems: selectedParentGroupChildItems.map((option) => option.key),
|
|
1855
1729
|
},
|
|
1856
1730
|
});
|
|
1857
1731
|
}, [groups, dispatch, onAddFilter, options]);
|
|
1858
|
-
|
|
1859
|
-
|
|
1732
|
+
const handleOptionApply = React.useCallback((updatedItem) => {
|
|
1733
|
+
const { key } = updatedItem;
|
|
1860
1734
|
if (isInArray(key, options)) {
|
|
1861
1735
|
return dispatch({
|
|
1862
1736
|
type: ActionType.DeselectChildOption,
|
|
1863
|
-
payload: { key
|
|
1737
|
+
payload: { key },
|
|
1864
1738
|
});
|
|
1865
1739
|
}
|
|
1866
|
-
|
|
1740
|
+
const { parentGroup, parentGroupChildItems } = getParentGroupWithChildItems({
|
|
1867
1741
|
itemKey: updatedItem.key,
|
|
1868
1742
|
mapping: generateCheckboxFilterItemsArgs.groupMapping,
|
|
1869
|
-
})
|
|
1743
|
+
});
|
|
1870
1744
|
if (parentGroup && groups.includes(parentGroup)) {
|
|
1871
1745
|
return dispatch({
|
|
1872
1746
|
type: ActionType.DeselectChildAndGroupAndAddAllOtherChildOptions,
|
|
1873
|
-
payload: { key
|
|
1747
|
+
payload: { key, parentGroup, parentGroupChildItems },
|
|
1874
1748
|
});
|
|
1875
1749
|
}
|
|
1876
|
-
|
|
1877
|
-
return parentGroupChildItems
|
|
1750
|
+
const optionsFromParentGroupInCurrentState = options.filter((type) => {
|
|
1751
|
+
return parentGroupChildItems?.includes(type);
|
|
1878
1752
|
});
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
onAddFilter
|
|
1753
|
+
const allParentGroupTypesSelected = optionsFromParentGroupInCurrentState.length + 1 ===
|
|
1754
|
+
parentGroupChildItems?.length;
|
|
1755
|
+
onAddFilter?.({
|
|
1882
1756
|
appliedFilter: updatedItem.filterName,
|
|
1883
1757
|
value: updatedItem.key,
|
|
1884
1758
|
formattedValue: updatedItem.label,
|
|
@@ -1887,12 +1761,12 @@ var useCheckboxFilter = function (_a) {
|
|
|
1887
1761
|
if (allParentGroupTypesSelected && parentGroup) {
|
|
1888
1762
|
return dispatch({
|
|
1889
1763
|
type: ActionType.SelectGroup,
|
|
1890
|
-
payload: { key: parentGroup, parentGroupChildItems
|
|
1764
|
+
payload: { key: parentGroup, parentGroupChildItems },
|
|
1891
1765
|
});
|
|
1892
1766
|
}
|
|
1893
1767
|
dispatch({
|
|
1894
1768
|
type: ActionType.SelectChildOption,
|
|
1895
|
-
payload: { key
|
|
1769
|
+
payload: { key },
|
|
1896
1770
|
});
|
|
1897
1771
|
}, [
|
|
1898
1772
|
dispatch,
|
|
@@ -1901,7 +1775,7 @@ var useCheckboxFilter = function (_a) {
|
|
|
1901
1775
|
onAddFilter,
|
|
1902
1776
|
options,
|
|
1903
1777
|
]);
|
|
1904
|
-
|
|
1778
|
+
const handleApply = React.useCallback((updatedItem) => {
|
|
1905
1779
|
if (updatedItem.filterName === optionFilterName) {
|
|
1906
1780
|
handleOptionApply(updatedItem);
|
|
1907
1781
|
}
|
|
@@ -1909,14 +1783,15 @@ var useCheckboxFilter = function (_a) {
|
|
|
1909
1783
|
handleGroupApply(updatedItem);
|
|
1910
1784
|
}
|
|
1911
1785
|
}, [groupFilterName, handleGroupApply, handleOptionApply, optionFilterName]);
|
|
1912
|
-
|
|
1913
|
-
var _a, _b;
|
|
1786
|
+
const reset = () => {
|
|
1914
1787
|
dispatch({ type: ActionType.Reset });
|
|
1915
|
-
return
|
|
1788
|
+
return {
|
|
1789
|
+
...(groupFilterName ? { [groupFilterName]: [] } : {}),
|
|
1790
|
+
...(optionFilterName ? { [optionFilterName]: [] } : {}),
|
|
1791
|
+
};
|
|
1916
1792
|
};
|
|
1917
1793
|
useResetAllFilters(reset);
|
|
1918
|
-
|
|
1919
|
-
var filterName = _a.filterName, key = _a.key;
|
|
1794
|
+
const isChecked = React.useCallback(({ filterName, key, }) => {
|
|
1920
1795
|
if (filterName === optionFilterName) {
|
|
1921
1796
|
return isInArray(key, options);
|
|
1922
1797
|
}
|
|
@@ -1925,47 +1800,56 @@ var useCheckboxFilter = function (_a) {
|
|
|
1925
1800
|
}
|
|
1926
1801
|
return false;
|
|
1927
1802
|
}, [groupFilterName, groups, optionFilterName, options]);
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1803
|
+
const items = generateCheckboxFilterItems({
|
|
1804
|
+
...generateCheckboxFilterItemsArgs,
|
|
1805
|
+
language,
|
|
1806
|
+
});
|
|
1807
|
+
const itemsWithCheckedState = React.useMemo(() => {
|
|
1808
|
+
return items.map((item) => {
|
|
1809
|
+
return {
|
|
1810
|
+
...item,
|
|
1811
|
+
isChecked: isChecked({
|
|
1933
1812
|
filterName: item.filterName,
|
|
1934
1813
|
key: item.key,
|
|
1935
|
-
}),
|
|
1936
|
-
|
|
1814
|
+
}),
|
|
1815
|
+
childCheckboxes: item.childCheckboxes?.map((childItem) => {
|
|
1816
|
+
return {
|
|
1817
|
+
...childItem,
|
|
1818
|
+
isChecked: isChecked({
|
|
1937
1819
|
filterName: childItem.filterName,
|
|
1938
1820
|
key: childItem.key,
|
|
1939
|
-
})
|
|
1940
|
-
|
|
1821
|
+
}),
|
|
1822
|
+
};
|
|
1823
|
+
}),
|
|
1824
|
+
};
|
|
1941
1825
|
});
|
|
1942
1826
|
}, [items, isChecked]);
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
: itemsWithCheckedState;
|
|
1947
|
-
}, [
|
|
1827
|
+
const checkboxItems = React.useMemo(() => generateCheckboxFilterItemsArgs.isSearchable
|
|
1828
|
+
? mapToSearchableListItems(itemsWithCheckedState, handleApply)
|
|
1829
|
+
: itemsWithCheckedState, [
|
|
1948
1830
|
itemsWithCheckedState,
|
|
1949
1831
|
generateCheckboxFilterItemsArgs.isSearchable,
|
|
1950
1832
|
handleApply,
|
|
1951
1833
|
]);
|
|
1952
|
-
|
|
1834
|
+
const numberOfAppliedFilters = groups.length + options.length;
|
|
1953
1835
|
return {
|
|
1954
|
-
state:
|
|
1955
|
-
|
|
1836
|
+
state: {
|
|
1837
|
+
...(groupFilterName ? { [groupFilterName]: groups } : {}),
|
|
1838
|
+
...(optionFilterName ? { [optionFilterName]: options } : {}),
|
|
1839
|
+
},
|
|
1840
|
+
checkboxItems,
|
|
1956
1841
|
onApply: handleApply,
|
|
1957
|
-
numberOfAppliedFilters
|
|
1842
|
+
numberOfAppliedFilters,
|
|
1958
1843
|
isApplied: !!numberOfAppliedFilters,
|
|
1959
|
-
reset
|
|
1844
|
+
reset,
|
|
1960
1845
|
};
|
|
1961
1846
|
};
|
|
1962
1847
|
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
filters: filters,
|
|
1848
|
+
const useFuelTypeFilter = ({ filters, vehicleCategory, facets, onAddFilter, onChange }) => {
|
|
1849
|
+
const { t, referenceData, language } = useFilterContext();
|
|
1850
|
+
const categoryData = referenceData[vehicleCategory];
|
|
1851
|
+
const { checkboxItems, onApply, ...rest } = useCheckboxFilter({
|
|
1852
|
+
filters,
|
|
1969
1853
|
isSearchable: false,
|
|
1970
1854
|
options: {
|
|
1971
1855
|
items: categoryData.fuelTypes,
|
|
@@ -1978,7 +1862,7 @@ var useFuelTypeFilter = function (_a) {
|
|
|
1978
1862
|
translationKey: 'fuelTypeGroup',
|
|
1979
1863
|
},
|
|
1980
1864
|
groupMapping: categoryData.fuelTypeGroupMapping,
|
|
1981
|
-
getFacet:
|
|
1865
|
+
getFacet: (args) => getFacet({ ...args, facets }),
|
|
1982
1866
|
customOrder: [
|
|
1983
1867
|
exports.FuelTypeGroup.Petrol,
|
|
1984
1868
|
exports.FuelTypeGroup.Diesel,
|
|
@@ -1987,21 +1871,23 @@ var useFuelTypeFilter = function (_a) {
|
|
|
1987
1871
|
exports.FuelTypeGroup.Gas,
|
|
1988
1872
|
exports.FuelTypeGroup.Other,
|
|
1989
1873
|
],
|
|
1990
|
-
t
|
|
1991
|
-
onAddFilter
|
|
1992
|
-
onChange
|
|
1993
|
-
})
|
|
1994
|
-
return
|
|
1995
|
-
|
|
1996
|
-
|
|
1874
|
+
t,
|
|
1875
|
+
onAddFilter,
|
|
1876
|
+
onChange,
|
|
1877
|
+
});
|
|
1878
|
+
return {
|
|
1879
|
+
ui: (React.createElement(components.CheckboxFilter, { items: checkboxItems, onApply: onApply, language: language })),
|
|
1880
|
+
label: t('filtersPkg.fuelType'),
|
|
1881
|
+
getDisplayValue: (query) => getCheckboxDisplayValue(checkboxItems, query || rest.state),
|
|
1882
|
+
...rest,
|
|
1883
|
+
};
|
|
1997
1884
|
};
|
|
1998
1885
|
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
filters: filters,
|
|
1886
|
+
const useConditionTypeFilter = ({ filters, vehicleCategory, facets, onAddFilter, onChange }) => {
|
|
1887
|
+
const { t, referenceData, language } = useFilterContext();
|
|
1888
|
+
const categoryData = referenceData[vehicleCategory];
|
|
1889
|
+
const { checkboxItems, onApply, ...rest } = useCheckboxFilter({
|
|
1890
|
+
filters,
|
|
2005
1891
|
isSearchable: false,
|
|
2006
1892
|
options: {
|
|
2007
1893
|
items: categoryData.conditionTypes,
|
|
@@ -2014,30 +1900,32 @@ var useConditionTypeFilter = function (_a) {
|
|
|
2014
1900
|
translationKey: 'conditionTypeGroup',
|
|
2015
1901
|
},
|
|
2016
1902
|
groupMapping: categoryData.conditionTypeGroupMapping,
|
|
2017
|
-
getFacet:
|
|
2018
|
-
t
|
|
2019
|
-
onAddFilter
|
|
2020
|
-
onChange
|
|
2021
|
-
})
|
|
2022
|
-
return
|
|
2023
|
-
|
|
2024
|
-
|
|
1903
|
+
getFacet: (args) => getFacet({ ...args, facets }),
|
|
1904
|
+
t,
|
|
1905
|
+
onAddFilter,
|
|
1906
|
+
onChange,
|
|
1907
|
+
});
|
|
1908
|
+
return {
|
|
1909
|
+
ui: (React.createElement(components.CheckboxFilter, { items: checkboxItems, onApply: onApply, language: language })),
|
|
1910
|
+
label: t('filtersPkg.conditionType'),
|
|
1911
|
+
getDisplayValue: (query) => getCheckboxDisplayValue(checkboxItems, query || rest.state),
|
|
1912
|
+
...rest,
|
|
1913
|
+
};
|
|
2025
1914
|
};
|
|
2026
1915
|
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
_b[exports.VehicleCategory.Car] = [
|
|
1916
|
+
const bodyTypeIconMap = {
|
|
1917
|
+
[exports.BodyType.Bus]: components.VanIcon,
|
|
1918
|
+
[exports.BodyType.Cabriolet]: components.CabrioletIcon,
|
|
1919
|
+
[exports.BodyType.Coupe]: components.CoupeIcon,
|
|
1920
|
+
[exports.BodyType.Estate]: components.WagonIcon,
|
|
1921
|
+
[exports.BodyType.Minivan]: components.MiniVanIcon,
|
|
1922
|
+
[exports.BodyType.Pickup]: components.PickUpIcon,
|
|
1923
|
+
[exports.BodyType.Saloon]: components.SedanIcon,
|
|
1924
|
+
[exports.BodyType.Smallcar]: components.SmallCarIcon,
|
|
1925
|
+
[exports.BodyType.SUV]: components.SuvIcon,
|
|
1926
|
+
};
|
|
1927
|
+
const bodyTypeCustomOrder = {
|
|
1928
|
+
[exports.VehicleCategory.Car]: [
|
|
2041
1929
|
exports.BodyType.Estate,
|
|
2042
1930
|
exports.BodyType.SUV,
|
|
2043
1931
|
exports.BodyType.Saloon,
|
|
@@ -2048,66 +1936,69 @@ var bodyTypeCustomOrder = (_b = {},
|
|
|
2048
1936
|
exports.BodyType.Minivan,
|
|
2049
1937
|
exports.BodyType.Bus,
|
|
2050
1938
|
],
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
filters: filters,
|
|
1939
|
+
};
|
|
1940
|
+
const useBodyTypeFilter = ({ filters, vehicleCategory, facets, onAddFilter, onChange, numberOfColumnsOnDesktop, }) => {
|
|
1941
|
+
const { t, referenceData, language } = useFilterContext();
|
|
1942
|
+
const categoryData = referenceData[vehicleCategory];
|
|
1943
|
+
const { checkboxItems, onApply, ...rest } = useCheckboxFilter({
|
|
1944
|
+
filters,
|
|
2058
1945
|
isSearchable: false,
|
|
2059
1946
|
options: {
|
|
2060
1947
|
items: categoryData.bodyTypes,
|
|
2061
1948
|
key: 'bodyTypes',
|
|
2062
1949
|
translationKey: 'bodyType',
|
|
2063
|
-
getImage:
|
|
1950
|
+
getImage: (key) => {
|
|
2064
1951
|
if (vehicleCategory !== exports.VehicleCategory.Car)
|
|
2065
1952
|
return null;
|
|
2066
|
-
|
|
1953
|
+
const Icon = bodyTypeIconMap[key];
|
|
2067
1954
|
if (!Icon)
|
|
2068
1955
|
return null;
|
|
2069
1956
|
return React.createElement(Icon, { w: 75, h: 51 });
|
|
2070
1957
|
},
|
|
2071
1958
|
},
|
|
2072
1959
|
customOrder: bodyTypeCustomOrder[vehicleCategory],
|
|
2073
|
-
getFacet:
|
|
2074
|
-
t
|
|
2075
|
-
onAddFilter
|
|
2076
|
-
onChange
|
|
2077
|
-
})
|
|
2078
|
-
return
|
|
2079
|
-
|
|
2080
|
-
|
|
1960
|
+
getFacet: (args) => getFacet({ ...args, facets }),
|
|
1961
|
+
t,
|
|
1962
|
+
onAddFilter,
|
|
1963
|
+
onChange,
|
|
1964
|
+
});
|
|
1965
|
+
return {
|
|
1966
|
+
ui: (React.createElement(components.CheckboxFilter, { items: checkboxItems, onApply: onApply, language: language, numberOfColumnsOnDesktop: numberOfColumnsOnDesktop })),
|
|
1967
|
+
label: t('filtersPkg.bodyType'),
|
|
1968
|
+
getDisplayValue: (query) => getCheckboxDisplayValue(checkboxItems, query || rest.state),
|
|
1969
|
+
...rest,
|
|
1970
|
+
};
|
|
2081
1971
|
};
|
|
2082
1972
|
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
filters: filters,
|
|
1973
|
+
const useDriveTypeFilter = ({ filters, vehicleCategory, facets, onAddFilter, onChange }) => {
|
|
1974
|
+
const { t, referenceData, language } = useFilterContext();
|
|
1975
|
+
const categoryData = referenceData[vehicleCategory];
|
|
1976
|
+
const { checkboxItems, onApply, ...rest } = useCheckboxFilter({
|
|
1977
|
+
filters,
|
|
2089
1978
|
isSearchable: false,
|
|
2090
1979
|
options: {
|
|
2091
1980
|
items: categoryData.driveTypes,
|
|
2092
1981
|
key: 'driveTypes',
|
|
2093
1982
|
translationKey: 'driveType',
|
|
2094
1983
|
},
|
|
2095
|
-
getFacet:
|
|
2096
|
-
t
|
|
2097
|
-
onAddFilter
|
|
2098
|
-
onChange
|
|
2099
|
-
})
|
|
2100
|
-
return
|
|
2101
|
-
|
|
2102
|
-
|
|
1984
|
+
getFacet: (args) => getFacet({ ...args, facets }),
|
|
1985
|
+
t,
|
|
1986
|
+
onAddFilter,
|
|
1987
|
+
onChange,
|
|
1988
|
+
});
|
|
1989
|
+
return {
|
|
1990
|
+
ui: (React.createElement(components.CheckboxFilter, { items: checkboxItems, onApply: onApply, language: language })),
|
|
1991
|
+
label: t('filtersPkg.driveType'),
|
|
1992
|
+
getDisplayValue: (query) => getCheckboxDisplayValue(checkboxItems, query || rest.state),
|
|
1993
|
+
...rest,
|
|
1994
|
+
};
|
|
2103
1995
|
};
|
|
2104
1996
|
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
filters: filters,
|
|
1997
|
+
const useTransmissionTypeFilter = ({ filters, vehicleCategory, facets, onAddFilter, onChange }) => {
|
|
1998
|
+
const { t, referenceData, language } = useFilterContext();
|
|
1999
|
+
const categoryData = referenceData[vehicleCategory];
|
|
2000
|
+
const { checkboxItems, onApply, ...rest } = useCheckboxFilter({
|
|
2001
|
+
filters,
|
|
2111
2002
|
isSearchable: false,
|
|
2112
2003
|
options: {
|
|
2113
2004
|
items: categoryData.transmissionTypes,
|
|
@@ -2120,14 +2011,17 @@ var useTransmissionTypeFilter = function (_a) {
|
|
|
2120
2011
|
translationKey: 'transmissionTypeGroup',
|
|
2121
2012
|
},
|
|
2122
2013
|
groupMapping: categoryData.transmissionTypeGroupMapping,
|
|
2123
|
-
getFacet:
|
|
2124
|
-
t
|
|
2125
|
-
onAddFilter
|
|
2126
|
-
onChange
|
|
2127
|
-
})
|
|
2128
|
-
return
|
|
2129
|
-
|
|
2130
|
-
|
|
2014
|
+
getFacet: (args) => getFacet({ ...args, facets }),
|
|
2015
|
+
t,
|
|
2016
|
+
onAddFilter,
|
|
2017
|
+
onChange,
|
|
2018
|
+
});
|
|
2019
|
+
return {
|
|
2020
|
+
ui: (React.createElement(components.CheckboxFilter, { items: checkboxItems, onApply: onApply, language: language })),
|
|
2021
|
+
label: t('filtersPkg.transmissionType'),
|
|
2022
|
+
getDisplayValue: (query) => getCheckboxDisplayValue(checkboxItems, query || rest.state),
|
|
2023
|
+
...rest,
|
|
2024
|
+
};
|
|
2131
2025
|
};
|
|
2132
2026
|
|
|
2133
2027
|
exports.FilterProvider = FilterProvider;
|