Skip to content

Instantly share code, notes, and snippets.

@dpmango
Last active October 12, 2021 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpmango/df1c71c7bb29a3b71a34707218abd114 to your computer and use it in GitHub Desktop.
Save dpmango/df1c71c7bb29a3b71a34707218abd114 to your computer and use it in GitHub Desktop.
getCategoryFilters = computedFn((cat_id) => {
const DEV_perf = performance.now();
if (this.categoriesList && this.categoriesList.length) {
// get depths first
const category = findNodeById(this.categoriesList, cat_id);
if (category) {
const processFilters = (cat_filters) => {
// passing display list of select filters
// find store items matching filters (table display list)
let matchedCatalogList = [];
if (ui.query.search) {
const { results } = this.searchCatalog(ui.query.search, cat_id);
matchedCatalogList = results;
} else {
const { results } = this.catalogList(cat_id);
matchedCatalogList = results;
}
const mappedFilter = matchedCatalogList.map((x) => {
return { size: x.size, mark: x.mark, length: x.length };
});
const sizesMatched = mappedFilter.map((catMap) => catMap.size);
const marksMatched = mappedFilter.map((catMap) => catMap.mark);
const lengthsMatched = mappedFilter.map((catMap) => catMap.length);
const clearValue = (x) => {
return !x ? 'не указано' : x;
};
// filtering thought mapped available/disabled state
const filterSize = (size) => {
return {
value: clearValue(size),
isPopular: size.isPopular !== undefined ? mark.isPopular : false,
available: sizesMatched.includes(size),
};
};
const filterMark = (mark) => {
return {
value: clearValue(mark.name),
isPopular: mark.isPopular !== undefined ? mark.isPopular : false,
available: marksMatched.includes(mark.name),
};
};
const filterLength = (length) => {
return {
value: clearValue(length),
isPopular: length.isPopular !== undefined ? length.isPopular : false,
available: lengthsMatched.includes(length),
};
};
return {
size: cat_filters.size.map(filterSize),
mark: cat_filters.mark.map(filterMark),
length: cat_filters.length.map(filterLength),
};
};
const result = {
id: cat_id,
title: category.name,
filters: category.filters ? processFilters(category.filters) : null,
};
PerformanceLog(DEV_perf, 'getCategoryFilters');
return result;
}
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment