Skip to content

Commit

Permalink
fix: additional fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohan Bansal committed Dec 22, 2023
1 parent b02b940 commit c211af7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions inventory_tools/inventory_tools/faceted_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def get_specification_items(doctype: str, attribute_name: str, attribute_values:
filters=[
["reference_doctype", "=", doctype],
["attribute", "=", attribute_name],
["value", ">", attribute_values[0]],
["value", "<", attribute_values[1]],
["value", ">=", attribute_values[0]],
["value", "<=", attribute_values[1]],
],
pluck="reference_name",
)
Expand Down
18 changes: 12 additions & 6 deletions inventory_tools/public/js/faceted_search/FacetedSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default {
update_filters(values) {
console.log('update_filters', values)
this.filterValues[values.attribute_name] = { attribute_id: values.attribute_id, values: values.values }
// need to debounce here instead of timeout
setTimeout(() => {
this.setFilterValues()
Expand Down Expand Up @@ -81,12 +82,17 @@ export default {
let filters = listview.filter_area.get()
for (const [key, value] of Object.entries(this.filterValues)) {
const values = value.values
const attribute = this.searchComponents.find(comp => comp.attribute_name === key)
if (attribute.field) {
if (Array.isArray(value)) {
if (value.length > 0) {
filters.push([this.doctype, attribute.field, 'in', value])
if (Array.isArray(values)) {
if (values.length > 0) {
if (!values[0] && !values[1]) {
// TODO: handle case where numeric range is unset
} else {
filters.push([this.doctype, attribute.field, 'in', values])
}
} else {
filters = filters.filter(filter => filter[1] !== attribute.field)
}
Expand All @@ -96,15 +102,15 @@ export default {
// TODO: handle edge-case?
}
} else {
if (Array.isArray(value)) {
if (!value[0] && !value[1]) {
if (Array.isArray(values)) {
if (!values[0] && !values[1]) {
// TODO: handle case where numeric range is unset
} else {
frappe
.xcall('inventory_tools.inventory_tools.faceted_search.get_specification_items', {
doctype: this.doctype,
attribute_name: key,
attribute_values: value,
attribute_values: values,
})
.then(items => {
const existing_name_filter = filters.filter(filter => filter[1] === 'name')
Expand Down

0 comments on commit c211af7

Please sign in to comment.