Skip to content

Commit

Permalink
Bug 1840143 - Create stale analysis warning component r=desktop-theme…
Browse files Browse the repository at this point in the history
…-reviewers,shopping-reviewers,fluent-reviewers,niklas,Gijs

Differential Revision: https://phabricator.services.mozilla.com/D183411
  • Loading branch information
kpatenio committed Jul 25, 2023
1 parent d8fbf6a commit d1525c4
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 0 deletions.
5 changes: 5 additions & 0 deletions browser/components/shopping/content/shopping-container.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import "chrome://browser/content/shopping/adjusted-rating.mjs";
import "chrome://browser/content/shopping/reliability.mjs";
// eslint-disable-next-line import/no-unassigned-import
import "chrome://browser/content/shopping/analysis-explainer.mjs";
// eslint-disable-next-line import/no-unassigned-import
import "chrome://browser/content/shopping/shopping-message-bar.mjs";

export class ShoppingContainer extends MozLitElement {
#productURL;
Expand Down Expand Up @@ -114,6 +116,9 @@ export class ShoppingContainer extends MozLitElement {
></button>
</div>
<div id="content">
${this.data.needs_analysis && this.data.product_id
? html`<shopping-message-bar type="stale"></shopping-message-bar>`
: null}
<review-reliability letter=${this.data.grade}></review-reliability>
<adjusted-rating
rating=${this.data.adjusted_rating}
Expand Down
18 changes: 18 additions & 0 deletions browser/components/shopping/content/shopping-message-bar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

@import url("chrome://global/skin/in-content/common.css");

:host {
display: block;
border-radius: 4px;
}

#message-bar-container {
display: flex;
flex-direction: column;
gap: 4px;
padding: 0;
margin: 0;
}
68 changes: 68 additions & 0 deletions browser/components/shopping/content/shopping-message-bar.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { html } from "chrome://global/content/vendor/lit.all.mjs";
import { MozLitElement } from "chrome://global/content/lit-utils.mjs";

class ShoppingMessageBar extends MozLitElement {
#MESSAGE_TYPES_RENDER_TEMPLATE_MAPPING = new Map([
["stale", this.getStaleWarningTemplate()],
]);

static properties = {
type: { type: String },
};

getStaleWarningTemplate() {
// TODO: Bug 1843142 - add proper stale analysis link once finalized
return html` <message-bar type="warning">
<article id="message-bar-container" aria-labelledby="header">
<strong
id="header"
data-l10n-id="shopping-message-bar-warning-stale-analysis-title"
></strong>
<span
data-l10n-id="shopping-message-bar-warning-stale-analysis-message"
></span>
<a
target="_blank"
data-l10n-id="shopping-message-bar-warning-stale-analysis-link"
href="#"
></a>
</article>
</message-bar>`;
}

render() {
let messageBarTemplate = this.#MESSAGE_TYPES_RENDER_TEMPLATE_MAPPING.get(
this.type
);
if (messageBarTemplate) {
return html`
<link
rel="stylesheet"
href="chrome://browser/content/shopping/shopping-message-bar.css"
/>
${messageBarTemplate}
`;
}
return null;
}

firstUpdated() {
// message-bar does not support adding a header and does not align it with the icon.
// Override styling to make them align.
let messageBar = this.renderRoot.querySelector("message-bar");
let messageBarContainer = messageBar.shadowRoot.querySelector(".container");
let icon = messageBarContainer.querySelector(".icon");

messageBarContainer.style.alignItems = "start";
messageBarContainer.style.padding = "0.5rem 0.75rem";
messageBarContainer.style.gap = "0.75rem";
icon.style.paddingBlockStart = "0";
}
}

customElements.define("shopping-message-bar", ShoppingMessageBar);
6 changes: 6 additions & 0 deletions browser/components/shopping/content/shopping.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ shopping-letter-grade-description-df = Unreliable reviews
shopping-letter-grade-tooltip =
.title = { $letter } - { $description }
## Strings for the shopping message-bar

shopping-message-bar-warning-stale-analysis-title = Updates available
shopping-message-bar-warning-stale-analysis-message = Re-analyze the reviews for this product, so you have the latest info.
shopping-message-bar-warning-stale-analysis-link = Re-analyze reviews
## Strings for the product review snippets card

shopping-highlights-label =
Expand Down
2 changes: 2 additions & 0 deletions browser/components/shopping/jar.mn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ browser.jar:
content/browser/shopping/shopping.html (content/shopping.html)
content/browser/shopping/shopping-container.css (content/shopping-container.css)
content/browser/shopping/shopping-sidebar.js (content/shopping-sidebar.js)
content/browser/shopping/shopping-message-bar.css (content/shopping-message-bar.css)
content/browser/shopping/shopping-message-bar.mjs (content/shopping-message-bar.mjs)
content/browser/shopping/highlights.mjs (content/highlights.mjs)
content/browser/shopping/highlight-item.css (content/highlight-item.css)
content/browser/shopping/highlight-item.mjs (content/highlight-item.mjs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// eslint-disable-next-line import/no-unresolved
import { html, ifDefined } from "lit.all.mjs";
// eslint-disable-next-line import/no-unassigned-import
import "browser/components/shopping/content/shopping-message-bar.mjs";

export default {
title: "Domain-specific UI Widgets/Shopping/Shopping Message Bar",
component: "shopping-message-bar",
argTypes: {
type: {
control: {
type: "select",
options: ["stale"],
},
},
},
parameters: {
status: "in-development",
fluent: `
shopping-message-bar-warning-stale-analysis-title = Updates available
shopping-message-bar-warning-stale-analysis-message = Re-analyze the reviews for this product, so you have the latest info.
shopping-message-bar-warning-stale-analysis-link = Re-analyze reviews
`,
},
};

const Template = ({ type }) => html`
<shopping-message-bar type=${ifDefined(type)}></shopping-message-bar>
`;

export const DefaultShoppingMessageBar = Template.bind({});
DefaultShoppingMessageBar.args = {
type: "stale",
};

0 comments on commit d1525c4

Please sign in to comment.