Skip to content

Commit 9a0aa2e

Browse files
committed
PB-235: Story Bug for PB-107: Adding Condition Filter will Not Update Total until After Saving Edit Form & Reopening
- cancel query when modal is closed - fix static errors - fix how category & skus changes are listened for
1 parent c067006 commit 9a0aa2e

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

app/code/Magento/PageBuilder/view/adminhtml/ui_component/pagebuilder_products_form.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,12 @@
231231
<dataType>text</dataType>
232232
<imports>
233233
<link name="conditionOption">ns = ${ $.ns }, index = condition_option:value</link>
234-
<link name="category_ids">ns = ${ $.ns }, index = category_ids:value</link>
235-
<link name="updateProductTotals">ns = ${ $.ns }, index = sku:value</link>
236234
<link name="conditionValue">ns = ${ $.ns }, index = conditions_form:value</link>
237235
</imports>
236+
<listens>
237+
<link name="${ $.ns }.${ $.ns }.appearance_fieldset.category_ids:value">updateProductTotals</link>
238+
<link name="${ $.ns }.${ $.ns }.appearance_fieldset.sku:value">updateProductTotals</link>
239+
</listens>
238240
</settings>
239241
</field>
240242
</container>

app/code/Magento/PageBuilder/view/adminhtml/web/css/source/form/element/_product-totals.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
// */
55

66
[data-index='product_totals'] .spinner {
7-
font-size: 2.8em;
7+
font-size: 2em;
88
}

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/product-totals.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ define([
2121
totalDisabledProducts: 0,
2222
totalNotVisibleProducts: 0,
2323
totalOutOfStockProducts: 0,
24-
category_ids: '',
2524
listens: {
2625
conditionOption: 'updateProductTotals',
2726
conditionValue: 'updateProductTotals',
28-
category_ids: 'updateProductTotals'
2927
},
3028
imports: {
3129
formData: '${ $.provider }:data'
@@ -39,7 +37,21 @@ define([
3937
notVisiblePlaceholder: $t('%1 not visible'),
4038
outOfStockPlaceholder: $t('%1 out of stock'),
4139
showSpinner: true,
42-
loading: false
40+
loading: false,
41+
jqXHR: null
42+
},
43+
44+
initialize: function() {
45+
$('.cms-page-edit .modals-wrapper').on('modalclosed', function () {
46+
this.abortRunningRequest();
47+
}.bind(this));
48+
return this._super();
49+
},
50+
51+
abortRunningRequest: function() {
52+
if (this.jqXHR && this.jqXHR.readyState !== 4) {
53+
this.jqXHR.abort();
54+
}
4355
},
4456

4557
/** @inheritdoc */
@@ -49,9 +61,13 @@ define([
4961
'totalOutOfStockProducts loading');
5062
},
5163

64+
callSuperError: function (jqXHR) {
65+
var superError = $.ajaxSettings.error.bind(window, jqXHR);
66+
superError();
67+
},
68+
5269
/**
5370
* Update product count.
54-
*
5571
*/
5672
updateProductTotals: _.debounce(function () {
5773
var totalText,
@@ -61,20 +77,26 @@ define([
6177
return;
6278
}
6379

64-
if (this.conditionOption === 'category_ids' && typeof this.formData['category_ids'] != 'string') {
80+
if (this.conditionOption === 'category_ids' && typeof this.formData['category_ids'] !== 'string') {
6581
this.formData['category_ids'] = '';
6682
}
6783

6884
_.extend(this.formData, this.conditionValue);
6985
conditionsDataProcessor(this.formData, this.conditionOption + '_source');
7086

7187
this.loading(true);
72-
$.ajax({
88+
this.abortRunningRequest();
89+
this.jqXHR = $.ajax({
7390
url: this.url,
7491
method: 'POST',
7592
data: {
7693
conditionValue: this.formData['conditions_encoded']
77-
}
94+
},
95+
error: function (jqXHR) {
96+
if (jqXHR.statusText !== 'abort') {
97+
this.callSuperError(jqXHR)
98+
}
99+
}.bind(this)
78100
}).done(function (response) {
79101
this.totalProductCount(parseInt(response.total, 10));
80102
this.totalDisabledProducts(parseInt(response.disabled, 10));
@@ -102,7 +124,9 @@ define([
102124
this.value(totalText);
103125
this.loading(false);
104126
}.bind(this)).fail(function () {
105-
this.value($t('An unknown error occurred. Please try again.'));
127+
if (this.jqXHR.statusText !== 'abort') {
128+
this.value($t('An unknown error occurred. Please try again.'));
129+
}
106130
this.loading(false);
107131
}.bind(this));
108132
}, 10)

0 commit comments

Comments
 (0)