Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/13911 order edit duplicate tabs #3330

Merged
merged 7 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- 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))
- Order statuses with long names no longer line wrap on the Orders index page. ([#3335](https://github.com/craftcms/commerce/issues/3335))
- Fixed duplicate validate errors that occurred when submitting a zero quantity to the cart. ([3334](https://github.com/craftcms/commerce/issues/3334))
- Fixed a bug where tab selection was inconsistent on the Edit Order page.

## 4.3.2 - 2023-10-31

Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/commerceui/dist/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/commerceui/dist/js/app.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/web/assets/commerceui/src/js/order/apps/OrderActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},

methods: {
...mapActions(['edit']),
...mapActions(['edit', 'handleTabs']),

cancel() {
window.location.reload();
Expand All @@ -69,6 +69,12 @@
}
});

// re-init the tabs after hiding the non-static ones
// see: https://github.com/craftcms/cms/issues/13911 for more details
Craft.cp.initTabs();
// and handle tabs dropdown
this.handleTabs();

// For custom tabs, if the selected tab is dynamic, find corresponding static tab and select it instead.
const $selectedTabLink = window.document.querySelector(
'#tabs a.custom-tab.sel'
Expand Down
64 changes: 64 additions & 0 deletions src/web/assets/commerceui/src/js/order/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,37 @@ export default new Vuex.Store({
let $transactionsTabContent =
window.document.querySelector('#transactionsTab');
$transactionsTabContent.classList.add('hidden');

// for the dropdown tab menu
const tabManager = Craft.cp.tabManager;
const tabsDropdownMenu = tabManager.$menuBtn.data('menubtn').menu;
const transactionsOption = tabsDropdownMenu.$container.find(
'[data-id="order-transactions"]'
);

// this will disable clicking on the transactions option in the dropdown tab menu
if (transactionsOption.length > 0) {
$(transactionsOption)
.disable()
.attr('disabled', 'disabled')
.css('pointer-events', 'none');
}

// and this is a fallback for selecting the transactions tab differently
let $prevSelectedTab = null;
let $selectedTab = tabManager.$selectedTab[0];

tabManager.on('selectTab', function (ev) {
$prevSelectedTab = $selectedTab;
$selectedTab = $(ev.$tab[0]);
});

tabsDropdownMenu.on('optionselect', function (ev) {
let $selectedOption = $(ev.selectedOption);
if ($selectedOption.data('id') === 'order-transactions') {
$prevSelectedTab.trigger('click');
}
});
},

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

// Update `editing` state
commit('updateEditing', true);

// handle duplicate content (fields) tabs
dispatch('handleTabs');
},

handleTabs({state}) {
const tabManagerMenuBtn = Craft.cp.tabManager.$menuBtn.data('menubtn');
const tabsDropdownMenu = tabManagerMenuBtn.menu;
if (tabsDropdownMenu !== undefined) {
const optionSelector =
'[id^="' + tabsDropdownMenu.menuId + '-option-"]';

const staticOptions = tabsDropdownMenu.$container.find(
optionSelector + '[data-id^="static-fields-"]'
);
const fieldsOptions = tabsDropdownMenu.$container.find(
optionSelector + '[data-id^="fields-"]'
);

if (state.editing) {
staticOptions.disable();
staticOptions.parent().addClass('hidden');

fieldsOptions.enable();
fieldsOptions.parent().removeClass('hidden');
} else {
staticOptions.enable();
staticOptions.parent().removeClass('hidden');

fieldsOptions.disable();
fieldsOptions.parent().addClass('hidden');
}
}
},

getOrder({state, commit}) {
Expand Down
Loading