diff options
| author | Joseph Caburnay <jcb@odoo.com> | 2020-06-23 14:02:00 +0000 |
|---|---|---|
| committer | Joseph Caburnay <jcb@odoo.com> | 2020-08-19 07:34:04 +0000 |
| commit | e2cac8339492cb8b38b15c45a4a1e7086f013477 (patch) | |
| tree | ecd15f8a3fc24405bf0969f5e94e941d7f167e52 /addons | |
| parent | 9f2913a0760783af859dfe1d75b5ad2067f4f544 (diff) | |
[REF] point_of_sale: defer the selection of item in confirm
Every time we select an item in the selection popup, the item corresponding
the selected item is computed immediately. Instead, we defer this computation
during confirmation (when getPayload is called).
This implementation is lighter than previous because the component doesn't
need to listen to changes in an array, rather in a single number state.
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/point_of_sale/static/src/js/Popups/SelectionPopup.js | 14 | ||||
| -rw-r--r-- | addons/point_of_sale/static/src/xml/Popups/SelectionPopup.xml | 2 |
2 files changed, 5 insertions, 11 deletions
diff --git a/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js b/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js index 8e9f7456aea..5321fdea0fe 100644 --- a/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js @@ -1,4 +1,4 @@ -odoo.define('point_of_sale.SelectionPopup', function(require) { +odoo.define('point_of_sale.SelectionPopup', function (require) { 'use strict'; const { useState } = owl.hooks; @@ -26,16 +26,10 @@ odoo.define('point_of_sale.SelectionPopup', function(require) { */ constructor() { super(...arguments); - this.list = useState([...this.props.list]); + this.state = useState({ selectedId: this.props.list.find((item) => item.isSelected) }); } selectItem(itemId) { - for (let item of this.list) { - if (item.id === itemId) { - item.isSelected = true; - } else { - item.isSelected = false; - } - } + this.state.selectedId = itemId; this.confirm(); } /** @@ -44,7 +38,7 @@ odoo.define('point_of_sale.SelectionPopup', function(require) { * @override */ getPayload() { - const selected = this.props.list.find(item => item.isSelected); + const selected = this.props.list.find((item) => this.state.selectedId === item.id); return selected && selected.item; } } diff --git a/addons/point_of_sale/static/src/xml/Popups/SelectionPopup.xml b/addons/point_of_sale/static/src/xml/Popups/SelectionPopup.xml index 4048edd7b3d..b9ca1bc78b3 100644 --- a/addons/point_of_sale/static/src/xml/Popups/SelectionPopup.xml +++ b/addons/point_of_sale/static/src/xml/Popups/SelectionPopup.xml @@ -9,7 +9,7 @@ <t t-esc="props.title" /> </header> <div class="selection scrollable-y"> - <t t-foreach="props.list" t-as="item" t-key="item._id"> + <t t-foreach="props.list" t-as="item" t-key="item.id"> <div class="selection-item" t-att-class="{ selected: item.isSelected }" t-on-click="selectItem(item.id)"> <t t-esc="item.label" /> |
