-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add filters to the admin panel #54
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good, nice work! As a general remark, it would be nice if you could add a few comments here and there explaining what each function does, since the names are not always too clear. Also sorry for the late review! ^_^
const filters = { | ||
category: "", | ||
status: "", | ||
name: "" | ||
}; | ||
|
||
//Check if filter exists then assign value in object | ||
strings.forEach(string => { | ||
let [type, value] = string.toLowerCase().split(":"); | ||
if (value != undefined) { | ||
if (filters.hasOwnProperty(type)) { | ||
filters[type] = value; | ||
} | ||
} else { | ||
product.style.display = "none"; | ||
filters.name += type + " "; | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of hardcoding the filter types like that, so i propose to make a list of filter names to look for, and if it is found then add it the filters
object. Something along the lines of the following:
const filterNames = ["category", "status", "name"];
function getFilters(filterString) {
const strings = filterString.split(" ");
const filters = {};
const searchTerms = [];
for (const string of strings) {
const [type, value] = string.toLowerCase().split(":");
if (value && filterNames.includes(type)) {
filters[type] = value;
} else {
searchTerms.push(string.trim());
}
}
return [searchTerm.join(" "), filters];
}
Co-authored-by: Job Vonk <[email protected]>
Co-authored-by: Job Vonk <[email protected]>
Closes #48