зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1845120 - Part 1: Use moz-message-bar for abuse report messages in about:addons. r=tgiles,fluent-reviewers,extension-reviewers,flod,rpl
Differential Revision: https://phabricator.services.mozilla.com/D185850
This commit is contained in:
Родитель
d8f0b627c8
Коммит
2bdc807ff5
|
@ -0,0 +1,137 @@
|
|||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
import fluent.syntax.ast as FTL
|
||||
from fluent.migrate.transforms import COPY_PATTERN, TransformPattern
|
||||
|
||||
|
||||
class STRIP_SPAN(TransformPattern):
|
||||
# Used to remove `<span data-l10n-name="addon-name"></span>` from a string
|
||||
def visit_TextElement(self, node):
|
||||
span_start = node.value.find('<span data-l10n-name="addon-name">')
|
||||
span_end = node.value.find("</span>")
|
||||
if span_start != -1 and span_end == -1:
|
||||
node.value = node.value[:span_start]
|
||||
elif span_start == -1 and span_end != -1:
|
||||
node.value = node.value[span_end + 7 :]
|
||||
|
||||
return node
|
||||
|
||||
|
||||
def migrate(ctx):
|
||||
"""Bug 1845120 - Use moz-message-bar for abuse report messages in about:addons, part {index}."""
|
||||
abuseReports_ftl = "toolkit/toolkit/about/abuseReports.ftl"
|
||||
ctx.add_transforms(
|
||||
abuseReports_ftl,
|
||||
abuseReports_ftl,
|
||||
[
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("abuse-report-messagebar-aborted2"),
|
||||
attributes=[
|
||||
FTL.Attribute(
|
||||
id=FTL.Identifier("message"),
|
||||
value=STRIP_SPAN(
|
||||
abuseReports_ftl,
|
||||
"abuse-report-messagebar-aborted",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("abuse-report-messagebar-submitting2"),
|
||||
attributes=[
|
||||
FTL.Attribute(
|
||||
id=FTL.Identifier("message"),
|
||||
value=STRIP_SPAN(
|
||||
abuseReports_ftl,
|
||||
"abuse-report-messagebar-submitting",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("abuse-report-messagebar-submitted2"),
|
||||
attributes=[
|
||||
FTL.Attribute(
|
||||
id=FTL.Identifier("message"),
|
||||
value=STRIP_SPAN(
|
||||
abuseReports_ftl,
|
||||
"abuse-report-messagebar-submitted",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("abuse-report-messagebar-submitted-noremove2"),
|
||||
attributes=[
|
||||
FTL.Attribute(
|
||||
id=FTL.Identifier("message"),
|
||||
value=COPY_PATTERN(
|
||||
abuseReports_ftl,
|
||||
"abuse-report-messagebar-submitted-noremove",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("abuse-report-messagebar-removed-extension2"),
|
||||
attributes=[
|
||||
FTL.Attribute(
|
||||
id=FTL.Identifier("message"),
|
||||
value=STRIP_SPAN(
|
||||
abuseReports_ftl,
|
||||
"abuse-report-messagebar-removed-extension",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("abuse-report-messagebar-removed-sitepermission2"),
|
||||
attributes=[
|
||||
FTL.Attribute(
|
||||
id=FTL.Identifier("message"),
|
||||
value=STRIP_SPAN(
|
||||
abuseReports_ftl,
|
||||
"abuse-report-messagebar-removed-sitepermission",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("abuse-report-messagebar-removed-theme2"),
|
||||
attributes=[
|
||||
FTL.Attribute(
|
||||
id=FTL.Identifier("message"),
|
||||
value=STRIP_SPAN(
|
||||
abuseReports_ftl,
|
||||
"abuse-report-messagebar-removed-theme",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("abuse-report-messagebar-error2"),
|
||||
attributes=[
|
||||
FTL.Attribute(
|
||||
id=FTL.Identifier("message"),
|
||||
value=STRIP_SPAN(
|
||||
abuseReports_ftl,
|
||||
"abuse-report-messagebar-error",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("abuse-report-messagebar-error-recent-submit2"),
|
||||
attributes=[
|
||||
FTL.Attribute(
|
||||
id=FTL.Identifier("message"),
|
||||
value=STRIP_SPAN(
|
||||
abuseReports_ftl,
|
||||
"abuse-report-messagebar-error-recent-submit",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
|
@ -62,7 +62,6 @@ export default class MozMessageBar extends MozLitElement {
|
|||
super();
|
||||
MozXULElement.insertFTLIfNeeded("toolkit/global/mozMessageBar.ftl");
|
||||
this.type = "info";
|
||||
this.role = "status";
|
||||
this.dismissable = false;
|
||||
}
|
||||
|
||||
|
@ -71,7 +70,13 @@ export default class MozMessageBar extends MozLitElement {
|
|||
this.actionsEl.classList.toggle("active", actions.length);
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this.setAttribute("role", "status");
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
this.dispatchEvent(new CustomEvent("message-bar:close"));
|
||||
}
|
||||
|
||||
|
|
|
@ -40,15 +40,24 @@ abuse-report-submit-button = Submit
|
|||
## Variables:
|
||||
## $addon-name (string) - Name of the add-on
|
||||
|
||||
abuse-report-messagebar-aborted = Report for <span data-l10n-name="addon-name">{ $addon-name }</span> canceled.
|
||||
abuse-report-messagebar-submitting = Sending report for <span data-l10n-name="addon-name">{ $addon-name }</span>.
|
||||
abuse-report-messagebar-submitted = Thank you for submitting a report. Do you want to remove <span data-l10n-name="addon-name">{ $addon-name }</span>?
|
||||
abuse-report-messagebar-submitted-noremove = Thank you for submitting a report.
|
||||
abuse-report-messagebar-removed-extension = Thank you for submitting a report. You’ve removed the extension <span data-l10n-name="addon-name">{ $addon-name }</span>.
|
||||
abuse-report-messagebar-removed-sitepermission = Thank you for submitting a report. You’ve removed the Site Permissions add-on <span data-l10n-name="addon-name">{ $addon-name }</span>.
|
||||
abuse-report-messagebar-removed-theme = Thank you for submitting a report. You’ve removed the theme <span data-l10n-name="addon-name">{ $addon-name }</span>.
|
||||
abuse-report-messagebar-error = There was an error sending the report for <span data-l10n-name="addon-name">{ $addon-name }</span>.
|
||||
abuse-report-messagebar-error-recent-submit = The report for <span data-l10n-name="addon-name">{ $addon-name }</span> wasn’t sent because another report was submitted recently.
|
||||
abuse-report-messagebar-aborted2 =
|
||||
.message = Report for { $addon-name } canceled.
|
||||
abuse-report-messagebar-submitting2 =
|
||||
.message = Sending report for { $addon-name }.
|
||||
abuse-report-messagebar-submitted2 =
|
||||
.message = Thank you for submitting a report. Do you want to remove { $addon-name }?
|
||||
abuse-report-messagebar-submitted-noremove2 =
|
||||
.message = Thank you for submitting a report.
|
||||
abuse-report-messagebar-removed-extension2 =
|
||||
.message = Thank you for submitting a report. You’ve removed the extension { $addon-name }.
|
||||
abuse-report-messagebar-removed-sitepermission2 =
|
||||
.message = Thank you for submitting a report. You’ve removed the Site Permissions add-on { $addon-name }.
|
||||
abuse-report-messagebar-removed-theme2 =
|
||||
.message = Thank you for submitting a report. You’ve removed the theme { $addon-name }.
|
||||
abuse-report-messagebar-error2 =
|
||||
.message = There was an error sending the report for { $addon-name }.
|
||||
abuse-report-messagebar-error-recent-submit2 =
|
||||
.message = The report for { $addon-name } wasn’t sent because another report was submitted recently.
|
||||
|
||||
## Message bars actions.
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ const ABUSE_REPORT_MESSAGE_BARS = {
|
|||
// because aborting a report is triggered by a user choice.
|
||||
ERROR_ABORTED_SUBMIT: {
|
||||
id: "aborted",
|
||||
type: "generic",
|
||||
type: "info",
|
||||
dismissable: true,
|
||||
},
|
||||
// Errors message bars.
|
||||
|
@ -145,14 +145,8 @@ function createReportMessageBar(
|
|||
throw new Error(`message-bar definition not found: ${definitionId}`);
|
||||
}
|
||||
const { id, dismissable, actions, type } = barInfo;
|
||||
const messageEl = document.createElement("span");
|
||||
|
||||
// The message element includes an addon-name span (also filled by
|
||||
// Fluent), which can be used to apply custom styles to the addon name
|
||||
// included in the message bar (if needed).
|
||||
const addonNameEl = document.createElement("span");
|
||||
addonNameEl.setAttribute("data-l10n-name", "addon-name");
|
||||
messageEl.append(addonNameEl);
|
||||
const messagebar = document.createElement("moz-message-bar");
|
||||
|
||||
// TODO(Bug 1789718): Remove after the deprecated XPIProvider-based
|
||||
// implementation is also removed.
|
||||
|
@ -160,31 +154,29 @@ function createReportMessageBar(
|
|||
addonType === "sitepermission-deprecated" ? "sitepermission" : addonType;
|
||||
|
||||
document.l10n.setAttributes(
|
||||
messageEl,
|
||||
getMessageL10n(barInfo.addonTypeSuffix ? `${id}-${mappingAddonType}` : id),
|
||||
messagebar,
|
||||
getMessageL10n(
|
||||
barInfo.addonTypeSuffix ? `${id}-${mappingAddonType}2` : `${id}2`
|
||||
),
|
||||
{ "addon-name": addonName || addonId }
|
||||
);
|
||||
messagebar.setAttribute("data-l10n-attrs", "message");
|
||||
|
||||
const barActions = actions
|
||||
? actions.map(action => {
|
||||
// Some of the message bars require a different per addonType
|
||||
// Fluent id for their actions.
|
||||
const actionId = barInfo.actionAddonTypeSuffix
|
||||
? `${action}-${mappingAddonType}`
|
||||
: action;
|
||||
const buttonEl = document.createElement("button");
|
||||
buttonEl.addEventListener("click", () => onaction && onaction(action));
|
||||
document.l10n.setAttributes(buttonEl, getActionL10n(actionId));
|
||||
return buttonEl;
|
||||
})
|
||||
: [];
|
||||
actions?.forEach(action => {
|
||||
// Some of the message bars require a different per addonType
|
||||
// Fluent id for their actions.
|
||||
const actionId = barInfo.actionAddonTypeSuffix
|
||||
? `${action}-${mappingAddonType}`
|
||||
: action;
|
||||
const buttonEl = document.createElement("button");
|
||||
buttonEl.addEventListener("click", () => onaction && onaction(action));
|
||||
document.l10n.setAttributes(buttonEl, getActionL10n(actionId));
|
||||
buttonEl.setAttribute("slot", "actions");
|
||||
messagebar.appendChild(buttonEl);
|
||||
});
|
||||
|
||||
const messagebar = document.createElement("message-bar");
|
||||
messagebar.setAttribute("type", type || "generic");
|
||||
if (dismissable) {
|
||||
messagebar.setAttribute("dismissable", "");
|
||||
}
|
||||
messagebar.append(messageEl, ...barActions);
|
||||
messagebar.setAttribute("type", type || "info");
|
||||
messagebar.dismissable = dismissable;
|
||||
messagebar.addEventListener("message-bar:close", onclose, { once: true });
|
||||
|
||||
document.getElementById("abuse-reports-messages").append(messagebar);
|
||||
|
|
|
@ -365,16 +365,28 @@ const AbuseReportTestUtils = {
|
|||
|
||||
async assertFluentStrings(containerEl) {
|
||||
// Make sure all localized elements have defined Fluent strings.
|
||||
const localizedEls = Array.from(
|
||||
let localizedEls = Array.from(
|
||||
containerEl.querySelectorAll("[data-l10n-id]")
|
||||
);
|
||||
if (containerEl.getAttribute("data-l10n-id")) {
|
||||
localizedEls.push(containerEl);
|
||||
}
|
||||
ok(localizedEls.length, "Got localized elements");
|
||||
for (let el of localizedEls) {
|
||||
const l10nId = el.getAttribute("data-l10n-id");
|
||||
await TestUtils.waitForCondition(
|
||||
() => el.textContent !== "",
|
||||
`Element with Fluent id '${l10nId}' should not be empty`
|
||||
);
|
||||
const l10nAttrs = el.getAttribute("data-l10n-attrs");
|
||||
if (!l10nAttrs) {
|
||||
await TestUtils.waitForCondition(
|
||||
() => el.textContent !== "",
|
||||
`Element with Fluent id '${l10nId}' should not be empty`
|
||||
);
|
||||
} else {
|
||||
await TestUtils.waitForCondition(
|
||||
() => el.message !== "",
|
||||
`Message attribute of the element with Fluent id '${l10nId}'
|
||||
should not be empty`
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче