Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Add filters to the admin panel #54

wants to merge 8 commits into from

Conversation

DavidVanDeursen
Copy link

Closes #48

Copy link
Member

@stickyPiston stickyPiston left a 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! ^_^

admin_board_view/static/AdminBoardView/products.js Outdated Show resolved Hide resolved
admin_board_view/static/AdminBoardView/products.js Outdated Show resolved Hide resolved
admin_board_view/static/AdminBoardView/products.js Outdated Show resolved Hide resolved
Comment on lines 168 to 184
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 + " ";
}
});
Copy link
Member

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];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to sort products
2 participants