From ad5d51afe750f5028da0648c2c590947459aabc3 Mon Sep 17 00:00:00 2001 From: Andrey Kozlov Date: Mon, 14 Nov 2022 08:39:43 +0000 Subject: [PATCH] support filtering by specification --- src/script.js | 14 +++++++------- src/types/fields.js | 13 +++++++++++++ src/utils/itemsCalculator.js | 3 ++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/script.js b/src/script.js index 1d0a7aa3..aa9f68fe 100644 --- a/src/script.js +++ b/src/script.js @@ -177,7 +177,7 @@ const CncfLandscapeApp = { const linkState = this.parseUrl({search: groupingInternalLinkEl.getAttribute('href'), pathname: '', hash: ''}); const f = (name, x) => this.calculateFullSelection(name, x); - const allowedProps = ['grouping', 'sort', 'bestpractices', 'enduser', 'parent', 'language']; + const allowedProps = ['grouping', 'sort', 'bestpractices', 'enduser', 'parent', 'language', 'specification']; const otherProps = ['category', 'project', 'license', 'organization', 'headquarters', 'company-type', 'industries'] for (let key of allowedProps) { newState[key] = linkState[key] || CncfLandscapeApp.initialState[key]; @@ -205,7 +205,7 @@ const CncfLandscapeApp = { // Only set certain properties: filterable + invisible filters // for visible filter we need to always expand a current selection const f = (name, x) => this.calculateFullSelection(name, x); - const allowedProps = ['grouping', 'sort', 'bestpractices', 'enduser', 'parent', 'language']; + const allowedProps = ['grouping', 'sort', 'bestpractices', 'enduser', 'parent', 'language', 'specification']; const otherProps = ['category', 'project', 'license', 'organization', 'headquarters', 'company-type', 'industries'] for (let key of allowedProps) { newState[key] = linkState[key] || CncfLandscapeApp.initialState[key]; @@ -282,7 +282,7 @@ const CncfLandscapeApp = { const newState = {...CncfLandscapeApp.state }; const f = (name, x) => this.calculateFullSelection(name, x); - const allowedProps = ['bestpractices', 'enduser', 'parent', 'language']; + const allowedProps = ['bestpractices', 'enduser', 'parent', 'language', 'specification']; const otherProps = ['category', 'project', 'license', 'organization', 'headquarters', 'company-type', 'industries'] for (let key of allowedProps) { newState[key] = CncfLandscapeApp.initialState[key]; @@ -689,6 +689,7 @@ const CncfLandscapeApp = { enduser: params.get('enduser') || '', parent: params.get('parent') || '', language: params.get('language') || '', + specification: params.get('specification') || '', selected: params.get('selected') || null, embed: params.has('embed'), showModal: params.has('showmodal'), @@ -843,7 +844,7 @@ const CncfLandscapeApp = { params[field] = CncfLandscapeApp.calculateShortSelection(field).url } // no fields for certain filters yet - for (let field of ['sort', 'grouping', 'bestpractices', 'enduser', 'parent', 'language']) { + for (let field of ['sort', 'grouping', 'bestpractices', 'enduser', 'parent', 'language', 'specification']) { params[field] = state[field] } @@ -876,8 +877,7 @@ const CncfLandscapeApp = { } } // no fields for certain filters yet - for (let field of ['grouping', 'sort', 'selected', 'bestpractices', 'enduser', 'parent', 'language', - 'fullscreen', 'embed']) { + for (let field of ['grouping', 'sort', 'selected', 'bestpractices', 'enduser', 'parent', 'language', 'specification', 'fullscreen', 'embed']) { if (state[field] !== initialState[field]) { params[field] = state[field] } @@ -1063,7 +1063,7 @@ const CncfLandscapeApp = { // edge case: we just opened a tab without filters - then just display everything! if (this.state.mode === this.initialMode) { - const allowedProps = ['bestpractices', 'enduser', 'parent', 'language']; + const allowedProps = ['bestpractices', 'enduser', 'parent', 'language', 'specification']; const otherProps = ['project', 'license', 'organization', 'headquarters', 'company-type', 'industries'] let same = true; for (let key of [...allowedProps, ...otherProps]) { diff --git a/src/types/fields.js b/src/types/fields.js index 28057dfd..ae7632bf 100644 --- a/src/types/fields.js +++ b/src/types/fields.js @@ -233,6 +233,19 @@ const fields = { }, values: [{id: true, label: 'Yes', url: 'yes'}, {id: false, label: 'No', url: 'no'}] }, + specification: { + id: 'extra', + label: 'Specification', + url: 'specification', + filterFn: function(filter, value, item) { + if (filter === null) { + return true; + } + const isSpecification = item.extra && (item.extra.specification === true || item.extra.specification === 'yes' || item.extra.specification === 'true'); + return filter === true ? isSpecification : !isSpecification; + }, + values: [{id: true, label: 'Yes', url: 'yes'}, {id: false, label: 'No', url: 'no'}] + }, parents: { id: 'parent', url: 'parent', diff --git a/src/utils/itemsCalculator.js b/src/utils/itemsCalculator.js index c5c743de..f017eab8 100644 --- a/src/utils/itemsCalculator.js +++ b/src/utils/itemsCalculator.js @@ -35,8 +35,9 @@ const getFilteredItems = module.exports.getFilteredItems = function({data, filte var filterByLanguage = filterFn({field: 'language', filters}); var filterByCompanyType = filterFn({field: 'companyType', filters}); var filterByIndustries = filterFn({field: 'industries', filters}); + var filterBySpecification = filterFn({field: 'specification', filters}); return data.filter(function(x) { - return filterHostedProject(x) && filterByLicense(x) && filterByOrganization(x) && filterByHeadquarters(x) && filterByLandscape(x) && filterByBestPractices(x) && filterByEnduser(x) && filterByParent(x) && filterByLanguage(x) && filterByCompanyType(x) && filterByIndustries(x); + return filterHostedProject(x) && filterByLicense(x) && filterByOrganization(x) && filterByHeadquarters(x) && filterByLandscape(x) && filterByBestPractices(x) && filterByEnduser(x) && filterByParent(x) && filterByLanguage(x) && filterByCompanyType(x) && filterByIndustries(x) && filterBySpecification(x); }); }