Skip to content

Commit ec844e6

Browse files
authored
Merge pull request #3330 from craftcms/bugfix/13911-order-edit-duplicate-tabs
Bugfix/13911 order edit duplicate tabs
2 parents 5a191c0 + c1940de commit ec844e6

File tree

5 files changed

+74
-3
lines changed

5 files changed

+74
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Improved the performance of the `craft\commerce\elements\db\VariantQuery::hasProduct()` and `craft\commerce\elements\db\ProductQuery::hasVariant()` query params. ([#3325](https://github.com/craftcms/commerce/pull/3325))
66
- Order statuses with long names no longer line wrap on the Orders index page. ([#3335](https://github.com/craftcms/commerce/issues/3335))
77
- Fixed duplicate validate errors that occurred when submitting a zero quantity to the cart. ([3334](https://github.com/craftcms/commerce/issues/3334))
8+
- Fixed a bug where tab selection was inconsistent on the Edit Order page.
89

910
## 4.3.2 - 2023-10-31
1011

src/web/assets/commerceui/dist/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/commerceui/dist/js/app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/commerceui/src/js/order/apps/OrderActions.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
5353
methods: {
54-
...mapActions(['edit']),
54+
...mapActions(['edit', 'handleTabs']),
5555
5656
cancel() {
5757
window.location.reload();
@@ -69,6 +69,12 @@
6969
}
7070
});
7171
72+
// re-init the tabs after hiding the non-static ones
73+
// see: https://github.com/craftcms/cms/issues/13911 for more details
74+
Craft.cp.initTabs();
75+
// and handle tabs dropdown
76+
this.handleTabs();
77+
7278
// For custom tabs, if the selected tab is dynamic, find corresponding static tab and select it instead.
7379
const $selectedTabLink = window.document.querySelector(
7480
'#tabs a.custom-tab.sel'

src/web/assets/commerceui/src/js/order/store/index.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,37 @@ export default new Vuex.Store({
262262
let $transactionsTabContent =
263263
window.document.querySelector('#transactionsTab');
264264
$transactionsTabContent.classList.add('hidden');
265+
266+
// for the dropdown tab menu
267+
const tabManager = Craft.cp.tabManager;
268+
const tabsDropdownMenu = tabManager.$menuBtn.data('menubtn').menu;
269+
const transactionsOption = tabsDropdownMenu.$container.find(
270+
'[data-id="order-transactions"]'
271+
);
272+
273+
// this will disable clicking on the transactions option in the dropdown tab menu
274+
if (transactionsOption.length > 0) {
275+
$(transactionsOption)
276+
.disable()
277+
.attr('disabled', 'disabled')
278+
.css('pointer-events', 'none');
279+
}
280+
281+
// and this is a fallback for selecting the transactions tab differently
282+
let $prevSelectedTab = null;
283+
let $selectedTab = tabManager.$selectedTab[0];
284+
285+
tabManager.on('selectTab', function (ev) {
286+
$prevSelectedTab = $selectedTab;
287+
$selectedTab = $(ev.$tab[0]);
288+
});
289+
290+
tabsDropdownMenu.on('optionselect', function (ev) {
291+
let $selectedOption = $(ev.selectedOption);
292+
if ($selectedOption.data('id') === 'order-transactions') {
293+
$prevSelectedTab.trigger('click');
294+
}
295+
});
265296
},
266297

267298
edit({commit, state, dispatch}) {
@@ -330,6 +361,39 @@ export default new Vuex.Store({
330361

331362
// Update `editing` state
332363
commit('updateEditing', true);
364+
365+
// handle duplicate content (fields) tabs
366+
dispatch('handleTabs');
367+
},
368+
369+
handleTabs({state}) {
370+
const tabManagerMenuBtn = Craft.cp.tabManager.$menuBtn.data('menubtn');
371+
const tabsDropdownMenu = tabManagerMenuBtn.menu;
372+
if (tabsDropdownMenu !== undefined) {
373+
const optionSelector =
374+
'[id^="' + tabsDropdownMenu.menuId + '-option-"]';
375+
376+
const staticOptions = tabsDropdownMenu.$container.find(
377+
optionSelector + '[data-id^="static-fields-"]'
378+
);
379+
const fieldsOptions = tabsDropdownMenu.$container.find(
380+
optionSelector + '[data-id^="fields-"]'
381+
);
382+
383+
if (state.editing) {
384+
staticOptions.disable();
385+
staticOptions.parent().addClass('hidden');
386+
387+
fieldsOptions.enable();
388+
fieldsOptions.parent().removeClass('hidden');
389+
} else {
390+
staticOptions.enable();
391+
staticOptions.parent().removeClass('hidden');
392+
393+
fieldsOptions.disable();
394+
fieldsOptions.parent().addClass('hidden');
395+
}
396+
}
333397
},
334398

335399
getOrder({state, commit}) {

0 commit comments

Comments
 (0)