feat: override productsToDisplay to remove hardcoded product limit for progressive rendering
This commit is contained in:
parent
e2fd06fbd6
commit
ffb9d3feaf
@ -4,11 +4,71 @@ import { PosStore } from "@point_of_sale/app/services/pos_store";
|
|||||||
import { patch } from "@web/core/utils/patch";
|
import { patch } from "@web/core/utils/patch";
|
||||||
|
|
||||||
patch(PosStore.prototype, {
|
patch(PosStore.prototype, {
|
||||||
|
get productsToDisplay() {
|
||||||
|
// We override this getter to remove Odoo's hardcoded 100-product limit.
|
||||||
|
// Because our custom UI optimization module uses progressive rendering (lazy loading)
|
||||||
|
// on scroll, we can safely return the entire product list without risking browser freezing.
|
||||||
|
const searchWord = this.searchProductWord.trim();
|
||||||
|
let recordIterator;
|
||||||
|
const isSearchByWord = searchWord !== "";
|
||||||
|
|
||||||
|
const productTemplateModel = this.models["product.template"].toRaw();
|
||||||
|
if (isSearchByWord) {
|
||||||
|
if (!this._searchTriggered) {
|
||||||
|
this.setSelectedCategory(0);
|
||||||
|
this._searchTriggered = true;
|
||||||
|
}
|
||||||
|
recordIterator = this.getProductsBySearchWord(
|
||||||
|
searchWord,
|
||||||
|
this.selectedCategory?.id
|
||||||
|
? this.selectedCategory.associatedProducts.values()
|
||||||
|
: productTemplateModel.getIterator()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this._searchTriggered = false;
|
||||||
|
if (this.selectedCategory?.id) {
|
||||||
|
recordIterator = this.selectedCategory.associatedProducts;
|
||||||
|
} else {
|
||||||
|
recordIterator = productTemplateModel.getIterator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const filteredList = [];
|
||||||
|
const excludedProductIds = new Set(this.getExcludedProductIds());
|
||||||
|
const availableCateg = new Set(
|
||||||
|
(this.config.iface_available_categ_ids || []).map((c) => c.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const p of recordIterator) {
|
||||||
|
// Remove the 100 items limit because our custom progressive rendering handles lazy loading.
|
||||||
|
if (excludedProductIds.has(p.id) || !p.canBeDisplayed) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
availableCateg.size &&
|
||||||
|
!this.config._pos_special_display_products_ids?.includes(p.id) &&
|
||||||
|
!p.pos_categ_ids.some((c) => availableCateg.has(c.id))
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredList.push(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!isSearchByWord &&
|
||||||
|
!this.selectedCategory?.id &&
|
||||||
|
this.areAllProductsSpecial(filteredList)
|
||||||
|
) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.orderProductBySequenceAndFav(filteredList);
|
||||||
|
},
|
||||||
|
|
||||||
get productToDisplayByCateg() {
|
get productToDisplayByCateg() {
|
||||||
// We override this getter to remove Odoo's hardcoded 100-product category limit.
|
// We override this getter to remove Odoo's hardcoded 100-product category limit.
|
||||||
// Because our custom UI optimization module uses progressive rendering (lazy loading)
|
|
||||||
// on scroll, we can safely return the entire category's product list without risking
|
|
||||||
// browser freeze or UI lockups.
|
|
||||||
const sortedProducts = this.productsToDisplay;
|
const sortedProducts = this.productsToDisplay;
|
||||||
if (!this.config.iface_group_by_categ) {
|
if (!this.config.iface_group_by_categ) {
|
||||||
return sortedProducts.length ? [["0", sortedProducts]] : [];
|
return sortedProducts.length ? [["0", sortedProducts]] : [];
|
||||||
@ -53,7 +113,6 @@ patch(PosStore.prototype, {
|
|||||||
if (filtered.length) {
|
if (filtered.length) {
|
||||||
const sorted = this.orderProductBySequenceAndFav(filtered);
|
const sorted = this.orderProductBySequenceAndFav(filtered);
|
||||||
// Return the complete list instead of splicing to 100 items.
|
// Return the complete list instead of splicing to 100 items.
|
||||||
// Our lazy loading mechanism will handle rendering chunk-by-chunk.
|
|
||||||
results.push([catId, sorted]);
|
results.push([catId, sorted]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user