Skip to content

Commit

Permalink
chore: break category filter out to it's function
Browse files Browse the repository at this point in the history
  • Loading branch information
rudouglas committed Sep 14, 2021
1 parent aedc710 commit ed7e369
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/pages/instant-observability.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ const filterBySearch = (search) => ({ name, description }) => {
* @returns {(Object) => Boolean} Callback function to be used by filter.
*/
const filterByContentType = (type) => (quickstart) => {
return (
!type ||
(quickstart[type] && quickstart[type].length > 0) ||
(quickstart.keywords && quickstart.keywords.includes(type))
);
return !type || (quickstart[type] && quickstart[type].length > 0);
};

/**
* Filters a quickstart based on a category.
* @param {String} type The category type (e.g. 'featured').
* @returns {(Object) => Boolean} Callback function to be used by filter.
*/
const filterByCategoryType = (type) => (quickstart) => {
return !type || (quickstart.keywords && quickstart.keywords.includes(type));
};

const QuickstartsPage = ({ data, location }) => {
Expand Down Expand Up @@ -133,14 +138,14 @@ const QuickstartsPage = ({ data, location }) => {
const filteredQuickstarts = sortedQuickstarts
.filter(filterBySearch(search))
.filter(filterByContentType(filter))
.filter(filterByContentType(category));
.filter(filterByCategoryType(category));

const filtersWithCount = FILTERS.map((filter) => ({
...filter,
count: quickstarts
.filter(filterBySearch(search))
.filter(filterByContentType(filter.type))
.filter(filterByContentType(category)).length,
.filter(filterByCategoryType(category)).length,
}));

return (
Expand Down

0 comments on commit ed7e369

Please sign in to comment.