Skip to content

Commit

Permalink
support filtering by specification
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kozlov authored and Andrey Kozlov committed Nov 14, 2022
1 parent a49ff4b commit ad5d51a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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]
}

Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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]) {
Expand Down
13 changes: 13 additions & 0 deletions src/types/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion src/utils/itemsCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down

0 comments on commit ad5d51a

Please sign in to comment.