Merge pull request #3124 from ceruleandeep/feature/actuallyCompactContextMenus Filter out hidden items in context menus

8b7a14f895399764b7eda0cbab65a88def16fd1a

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
5 files changed, +26 -33Showing whitespace changes
public/scripts/extensions/quick-reply/src/ui/ctx/ContextMenu.js+17 -3
@@ -38,7 +38,6 @@ export class ContextMenu {
3838 label: qr.label,
3939 title: qr.title,
4040 message: (chainedMessage && qr.message ? `${chainedMessage} | ` : '') + qr.message,
41- isHidden: qr.isHidden,
4241 children: [],
4342 };
4443 qr.contextList.forEach((cl) => {
@@ -47,7 +46,23 @@ export class ContextMenu {
4746 const nextHierarchy = [...hierarchy, cl.set];
4847 const nextLabelHierarchy = [...labelHierarchy, tree.label];
4948 tree.children.push(new MenuHeader(cl.set.name));
50- cl.set.qrList.forEach(subQr => {
49+
50+ // If the Quick Reply's own set is added as a context menu,
51+ // show only the sub-QRs that are Invisible but have an icon
52+ // intent: allow a QR set to be assigned to one of its own QR buttons for a "burger" menu
53+ // with "UI" QRs either in the bar or in the menu, and "library function" QRs still hidden.
54+ // - QRs already visible on the bar are filtered out,
55+ // - hidden QRs without an icon are filtered out,
56+ // - hidden QRs **with an icon** are shown in the menu
57+ // so everybody is happy
58+ const qrsOwnSetAddedAsContextMenu = cl.set.qrList.includes(qr);
59+ const visible = (subQr) => {
60+ return qrsOwnSetAddedAsContextMenu
61+ ? subQr.isHidden && !!subQr.icon // yes .isHidden gets inverted here
62+ : !subQr.isHidden;
63+ };
64+
65+ cl.set.qrList.filter(visible).forEach(subQr => {
5166 const subTree = this.build(subQr, cl.isChained ? tree.message : null, nextHierarchy, nextLabelHierarchy);
5267 tree.children.push(new MenuItem(
5368 subTree.icon,
@@ -55,7 +70,6 @@ export class ContextMenu {
5570 subTree.label,
5671 subTree.title,
5772 subTree.message,
58- subTree.isHidden,
5973 (evt) => {
6074 evt.stopPropagation();
6175 const finalQr = Object.assign(new QuickReply(), subQr);
public/scripts/extensions/quick-reply/src/ui/ctx/MenuHeader.js+1 -1
@@ -2,7 +2,7 @@ import { MenuItem } from './MenuItem.js';
22
33export class MenuHeader extends MenuItem {
44 constructor(/**@type {String}*/label) {
55 super(null, null, label, null, null, false, null, []);
66 }
77
88
public/scripts/extensions/quick-reply/src/ui/ctx/MenuItem.js+1 -29
@@ -6,7 +6,6 @@ export class MenuItem {
66 /**@type {string}*/ label;
77 /**@type {string}*/ title;
88 /**@type {object}*/ value;
9- /**@type {boolean}*/ isHidden = false;
109 /**@type {function}*/ callback;
1110 /**@type {MenuItem[]}*/ childList = [];
1211 /**@type {SubMenu}*/ subMenu;
@@ -25,44 +24,20 @@ export class MenuItem {
2524 * @param {string} label
2625 * @param {?string} title Tooltip
2726 * @param {object} value
28- * @param {boolean} isHidden QR is Invisible (auto-execute only)
2927 * @param {function} callback
3028 * @param {MenuItem[]} children
3129 */
3230 constructor(icon, showLabel, label, title, value, isHidden, callback, children = []) {
3331 this.icon = icon;
3432 this.showLabel = showLabel;
3533 this.label = label;
3634 this.title = title;
3735 this.value = value;
38- this.isHidden = isHidden;
3936 this.callback = callback;
4037 this.childList = children;
4138 }
4239
4340
44- /**
45- * Renders the MenuItem
46- *
47- * A .qr--hidden class is added to:
48- * - the item if it is "Invisible (auto-execute only)"
49- * - the icon if no icon is set
50- * - the label if an icon is set and showLabel is false
51- *
52- * There is no .qr--hidden class defined in default CSS, since having items
53- * that are invisible on the QR bar but visible in the context menu,
54- * or icon-only on the QR bar but labelled in the context menu, is a valid use case.
55- *
56- * To hide optional labels when icons are present, add this user CSS:
57- * .ctx-menu .ctx-item .qr--button-label.qr--hidden {display: none;}
58- * To hide icons when no icon is present (removes unwanted padding):
59- * .ctx-menu .ctx-item .qr--button-icon.qr--hidden {display: none;}
60- * To hide items that are set "invisible":
61- * .ctx-menu .ctx-item.qr--hidden {display: none;}
62- * To target submenus only, use .ctx-menu .ctx-sub-menu .qr--hidden {display: none;}
63- *
64- * @returns {HTMLElement}
65- */
6641 render() {
6742 if (!this.root) {
6843 const item = document.createElement('li'); {
@@ -70,9 +45,6 @@ export class MenuItem {
7045 item.classList.add('list-group-item');
7146 item.classList.add('ctx-item');
7247
73- // if this item is Invisible, add the hidden class
74- if (this.isHidden) item.classList.add('qr--hidden');
75-
7648 // if a title/tooltip is set, add it, otherwise use the QR content
7749 // same as for the main QR list
7850 item.title = this.title || this.value;
public/scripts/extensions/quick-reply/style.css+3 -0
@@ -174,6 +174,9 @@
174174 position: absolute;
175175 overflow: visible;
176176}
177+.ctx-menu .ctx-item .qr--hidden {
178+ display: none;
179+}
177180.list-group .list-group-item.ctx-header {
178181 font-weight: bold;
179182 cursor: default;
public/scripts/extensions/quick-reply/style.less+4 -0
@@ -176,6 +176,10 @@
176176 overflow: visible;
177177}
178178
179+.ctx-menu .ctx-item .qr--hidden {
180+ display: none;
181+}
182+
179183.list-group .list-group-item.ctx-header {
180184 font-weight: bold;
181185 cursor: default;