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/element index handle empty view menu #16242

Merged
merged 4 commits into from
Dec 2, 2024
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 @@ -4,6 +4,7 @@

- Reduced the likelihood of a deadlock error occurring when updating search indexes. ([#15221](https://github.com/craftcms/cms/issues/15221))
- The PHP Info utility is no longer shown in environments where the `phpinfo()` function is disabled. ([#16229](https://github.com/craftcms/cms/pull/16229))
- “View” buttons within element indexes are now disabled when the selected view mode has no applicable settings. ([#16242](https://github.com/craftcms/cms/pull/16242))
- Fixed an error that could occur when duplicating an element with an Assets field that had a dynamic subpath. ([#16214](https://github.com/craftcms/cms/issues/16214))
- Fixed a bug where renaming asset folders could move them to the webroot on Windows. ([#16215](https://github.com/craftcms/cms/issues/16215))
- Fixed a bug where utilities’ `isSelectable()` methods weren’t being respected.
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

58 changes: 50 additions & 8 deletions src/web/assets/cp/src/js/BaseElementIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,15 @@ Craft.BaseElementIndex = Garnish.Base.extend(
}
this.activeViewMenu = this.viewMenus[this.sourceKey];
this.activeViewMenu.showTrigger();

// check if we should show the View button (ViewMenu.$trigger)
if (this.activeViewMenu) {
if (!this.activeViewMenu?.menuHasContent()) {
this.activeViewMenu.disableTrigger();
} else {
this.activeViewMenu.enableTrigger();
}
}
}
},

Expand Down Expand Up @@ -2566,6 +2575,15 @@ Craft.BaseElementIndex = Garnish.Base.extend(
.addClass('active')
.attr('aria-pressed', 'true');
}

// check if we should show the View button (ViewMenu.$trigger)
if (this.activeViewMenu) {
if (!this.activeViewMenu?.menuHasContent()) {
this.activeViewMenu.disableTrigger();
} else {
this.activeViewMenu.enableTrigger();
}
}
},

createView: function (mode, settings) {
Expand Down Expand Up @@ -4034,14 +4052,6 @@ const ViewMenu = Garnish.Base.extend({

this.menu.on('show', () => {
this.$trigger.addClass('active');
this.updateSortField();
this.updateTableFieldVisibility();
if (
this.elementIndex.getSelectedSourceState('mode') !==
this.elementIndex.defaultViewMode
) {
this._createRevertBtn();
}
});

this.menu.on('hide', () => {
Expand All @@ -4054,6 +4064,26 @@ const ViewMenu = Garnish.Base.extend({
});
},

updateMenuContent: function () {
this.updateSortField();
this.updateTableFieldVisibility();
if (
this.elementIndex.getSelectedSourceState('mode') !==
this.elementIndex.defaultViewMode
) {
this._createRevertBtn();
}
},

menuHasContent: function () {
this.updateMenuContent();
if (this.$sortField == null && this.$tableColumnsField.hasClass('hidden')) {
return false;
}

return true;
},

showTrigger: function () {
this.$trigger.removeClass('hidden');
},
Expand All @@ -4064,6 +4094,18 @@ const ViewMenu = Garnish.Base.extend({
this.menu.hide();
},

enableTrigger: function () {
this.$trigger.removeClass('disabled');
this.$trigger.attr('aria-disabled', false);
},

disableTrigger: function () {
this.$trigger.data('trigger').hide();
this.$trigger.addClass('disabled');
this.$trigger.attr('aria-disabled', true);
this.menu.hide();
},

updateTableFieldVisibility: function () {
// we only want to show the "Table Columns" checkboxes and "Use defaults" btn in table and structure views
if (
Expand Down