Bug 1836986 - Hide tags field in the Star ("Bookmark this page") panel when the user has no tags. r=dao,mak

Differential Revision: https://phabricator.services.mozilla.com/D181557
This commit is contained in:
Karandeep 2023-06-25 11:19:13 +00:00
parent 9ad1fbfdc4
commit d31e56f7b3
5 changed files with 43 additions and 5 deletions

View file

@ -32,6 +32,7 @@ ChromeUtils.defineESModuleGetters(this, {
});
var StarUI = {
userHasTags: undefined,
_itemGuids: null,
_isNewBookmark: false,
_isComposing: false,
@ -257,10 +258,24 @@ var StarUI = {
{ capture: true, once: true }
);
};
let hiddenRows = ["location", "keyword"];
if (this.userHasTags === undefined) {
// Cache must be initialized
const fetchedTags = await PlacesUtils.bookmarks.fetchTags();
this.userHasTags = !!fetchedTags.length;
}
if (!this.userHasTags) {
// Hide tags ui because user has no tags defined
hiddenRows.push("tags");
}
await gEditItemOverlay.initPanel({
node: aNode,
onPanelReady,
hiddenRows: ["location", "keyword"],
hiddenRows,
focusedElement: "preferred",
isNewBookmark: this._isNewBookmark,
});
@ -2028,6 +2043,9 @@ var BookmarkingUI = {
1
);
}
if (ev.parentGuid == PlacesUtils.bookmarks.tagsGuid) {
StarUI.userHasTags = true;
}
break;
case "bookmark-removed":
// If one of the tracked bookmarks has been removed, unregister it.

View file

@ -398,6 +398,7 @@ var gEditItemOverlay = {
// Note: since all controls are hidden by default, we don't get the
// default XUL dialog behavior, that selects the first control, so we set
// the focus explicitly.
let elt;
if (focusedElement === "preferred") {
elt = this._element(
@ -405,9 +406,16 @@ var gEditItemOverlay = {
"browser.bookmarks.editDialog.firstEditField"
)
);
} else if (focusedElement === "first") {
elt = document.querySelector('input:not([hidden="true"])');
if (elt.parentNode.hidden) {
focusedElement = "first";
}
}
if (focusedElement === "first") {
elt = document
.getElementById("editBookmarkPanelContent")
.querySelector('input:not([hidden="true"])');
}
if (elt) {
elt.focus({ preventScroll: true });
elt.select();

View file

@ -29,6 +29,14 @@ registerCleanupFunction(async () => {
add_task(async function test_add_bookmark_tags_from_bookmarkProperties() {
const TEST_URL = "about:robots";
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "about:buildconfig",
title: "Bookmark Title",
});
PlacesUtils.tagging.tagURI(makeURI("about:buildconfig"), ["tag0"]);
let win = await BrowserTestUtils.openNewBrowserWindow();
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser: win.gBrowser,

View file

@ -302,7 +302,7 @@ add_task(async function panel_shown_for_new_bookmark_close_with_ESC() {
},
shouldAutoClose: true,
popupHideFn() {
EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, win);
EventUtils.synthesizeKey("VK_ESCAPE", {}, win);
},
isBookmarkRemoved: true,
});
@ -316,7 +316,7 @@ add_task(async function panel_shown_for_editing_no_autoclose_close_with_ESC() {
},
shouldAutoClose: false,
popupHideFn() {
EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }, win);
EventUtils.synthesizeKey("VK_ESCAPE", {}, win);
},
isBookmarkRemoved: false,
});

View file

@ -15,6 +15,8 @@ add_task(async function test() {
url: testURI,
});
PlacesUtils.tagging.tagURI(makeURI(TEST_URL), ["tag0"]);
const win = await BrowserTestUtils.openNewBrowserWindow();
registerCleanupFunction(async () => {
await BrowserTestUtils.closeWindow(win);
@ -31,10 +33,12 @@ add_task(async function test() {
await TestUtils.waitForCondition(
() => BookmarkingUI.status !== BookmarkingUI.STATUS_UPDATING
);
await clickBookmarkStar(win);
// add a tag
await fillBookmarkTextField("editBMPanel_tagsField", testTag, win);
let promiseNotification = PlacesTestUtils.waitForNotification(
"bookmark-tags-changed"
);