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

feat(baseline): update widget to reflect new definition #10128

Merged
merged 17 commits into from
Dec 5, 2023
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
45 changes: 44 additions & 1 deletion build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
BuiltDocument,
renderContributorsTxt,
} from "./index.js";
import { DocMetadata, Flaws } from "../libs/types/document.js";
import { Doc, DocMetadata, Flaws } from "../libs/types/document.js";
import SearchIndex from "./search-index.js";
import { makeSitemapXML, makeSitemapIndexXML } from "./sitemaps.js";
import { humanFileSize } from "./utils.js";
Expand All @@ -52,6 +52,10 @@ interface GlobalMetadata {
[locale: string]: Array<DocMetadata>;
}

interface BuildMetadata {
[locale: string]: any;
}

async function buildDocumentInteractive(
documentPath: string,
interactive: boolean,
Expand Down Expand Up @@ -132,6 +136,33 @@ async function buildDocuments(
}

const metadata: GlobalMetadata = {};
const buildMetadata: BuildMetadata = {};

function updateBaselineBuildMetadata(doc: Doc) {
if (typeof doc.baseline?.baseline === "undefined") {
return;
}

if (typeof buildMetadata[doc.locale] === "undefined") {
buildMetadata[doc.locale] = {};
}
if (typeof buildMetadata[doc.locale].baseline === "undefined") {
buildMetadata[doc.locale].baseline = {
total: 0,
high: 0,
highPaths: [],
low: 0,
lowPaths: [],
not: 0,
notPaths: [],
};
}

buildMetadata[doc.locale].baseline.total++;
const key = doc.baseline.baseline || "not";
buildMetadata[doc.locale].baseline[key]++;
buildMetadata[doc.locale].baseline[`${key}Paths`].push(doc.mdn_url);
}

const documents = await Document.findAll(findAllOptions);
const progressBar = new cliProgress.SingleBar(
Expand Down Expand Up @@ -188,6 +219,10 @@ async function buildDocuments(
appendTotalFlaws(builtDocument.flaws);
}

if (builtDocument.baseline) {
updateBaselineBuildMetadata(builtDocument);
}

if (!noHTML) {
fs.writeFileSync(
path.join(outPath, "index.html"),
Expand Down Expand Up @@ -330,6 +365,14 @@ async function buildDocuments(
[...allBrowserCompat].sort().join(" ")
);

for (const [locale, meta] of Object.entries(buildMetadata)) {
// have to write per-locale because we build each locale concurrently
fs.writeFileSync(
path.join(BUILD_OUT_ROOT, locale.toLowerCase(), "build.json"),
JSON.stringify(meta)
);
}

return { slugPerLocale: docPerLocale, peakHeapBytes, totalFlaws };
}

Expand Down
15 changes: 4 additions & 11 deletions build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
MacroRedirectedLinkError,
} from "../kumascript/src/errors.js";

import { Doc, WebFeatureStatus } from "../libs/types/document.js";
import { Doc } from "../libs/types/document.js";
import { Document, execGit, slugToFolder } from "../content/index.js";
import { CONTENT_ROOT, REPOSITORY_URLS } from "../libs/env/index.js";
import * as kumascript from "../kumascript/index.js";
Expand Down Expand Up @@ -380,7 +380,7 @@ export async function buildDocument(
browserCompat &&
(Array.isArray(browserCompat) ? browserCompat : [browserCompat]);

doc.baseline = await addBaseline(doc);
doc.baseline = addBaseline(doc);

// If the document contains <math> HTML, it will set `doc.hasMathML=true`.
// The client (<Document/> component) needs to know this for loading polyfills.
Expand Down Expand Up @@ -558,16 +558,9 @@ export async function buildDocument(
return { doc: doc as Doc, liveSamples, fileAttachmentMap };
}

async function addBaseline(
doc: Partial<Doc>
): Promise<WebFeatureStatus | undefined> {
function addBaseline(doc: Partial<Doc>) {
if (doc.browserCompat) {
const filteredBrowserCompat = doc.browserCompat.filter(
(query) =>
// temporary blocklist while we wait for an updated baseline definition/designs
!["css.properties.grid-template-columns.subgrid"].includes(query)
);
return await getWebFeatureStatus(...filteredBrowserCompat);
return getWebFeatureStatus(...doc.browserCompat);
}
}

Expand Down
18 changes: 2 additions & 16 deletions build/web-features.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
import { WebFeature, WebFeatureStatus } from "../libs/types/document.js";
import { importJSON } from "./utils.js";
import webFeatures from "web-features";

let promise: Promise<Record<string, WebFeature>> | null = null;

export async function getWebFeatures(): Promise<Record<string, WebFeature>> {
if (!promise) {
promise = importJSON<Record<string, WebFeature>>("web-features/index.json");
}

return promise;
}

export async function getWebFeatureStatus(
...features: string[]
): Promise<WebFeatureStatus | undefined> {
export function getWebFeatureStatus(...features: string[]) {
if (features.length === 0) {
return;
}

const webFeatures = await getWebFeatures();
for (const feature of Object.values(webFeatures)) {
if (
feature.status &&
Expand Down
12 changes: 12 additions & 0 deletions client/src/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,15 @@ sup.new {
top: 0;
z-index: var(--z-index-main-header);
}

.feedback-link::before {
background-color: var(--feedback-link-icon, var(--text-link));
content: "";
display: inline-flex;
height: 1em;
margin-right: 0.4em;
mask-image: url("./assets/icons/feedback.svg");
mask-size: cover;
vertical-align: middle;
width: 1em;
}
1 change: 0 additions & 1 deletion client/src/assets/icons/baseline/check-dark.svg

This file was deleted.

1 change: 0 additions & 1 deletion client/src/assets/icons/baseline/check.svg

This file was deleted.

1 change: 0 additions & 1 deletion client/src/assets/icons/baseline/cross-dark.svg

This file was deleted.

1 change: 0 additions & 1 deletion client/src/assets/icons/baseline/cross.svg

This file was deleted.

1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/high-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/high.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/limited-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/limited.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/low-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/baseline/low.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/src/assets/icons/feedback.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 48 additions & 11 deletions client/src/document/baseline-indicator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,32 @@
$browsers: "chrome", "edge", "firefox", "safari";

.baseline-indicator {
--baseline-bg: var(--baseline-unsupported-bg);
--baseline-engine-bg: var(--baseline-unsupported-engine-bg);
--baseline-img: var(--baseline-unsupported-img);
--baseline-bg: var(--baseline-limited-bg);
--baseline-engine-bg: var(--baseline-limited-engine-bg);
--baseline-img: var(--baseline-limited-img);
--baseline-check: var(--baseline-limited-check);
--baseline-cross: var(--baseline-limited-cross);
--feedback-link-icon: #666;

background: var(--baseline-bg);
border-radius: 0.25rem;
margin: 1rem 0;
padding-left: 3.8125rem;

&.supported {
--baseline-bg: var(--baseline-supported-bg);
--baseline-engine-bg: var(--baseline-supported-engine-bg);
--baseline-img: var(--baseline-supported-img);
&.high {
--baseline-bg: var(--baseline-high-bg);
--baseline-engine-bg: var(--baseline-high-engine-bg);
--baseline-img: var(--baseline-high-img);
--baseline-check: var(--baseline-high-check);
}

&.low {
--baseline-bg: var(--baseline-low-bg);
--baseline-engine-bg: var(--baseline-low-engine-bg);
--baseline-img: var(--baseline-low-img);
--baseline-check: var(--baseline-low-check);
--baseline-pill-bg: var(--baseline-low-pill-bg);
--baseline-pill-color: var(--baseline-low-pill-color);
}

&[open] {
Expand All @@ -34,6 +47,7 @@ $browsers: "chrome", "edge", "firefox", "safari";
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
justify-content: space-between;
padding: 1rem 0;
padding-right: calc(
var(--chevron-padding-left) + var(--chevron-size) +
Expand Down Expand Up @@ -67,14 +81,24 @@ $browsers: "chrome", "edge", "firefox", "safari";
letter-spacing: 0;
line-height: 1.5;
margin: 0;
margin-right: auto;
padding: 0.375rem 0;

.not-bold {
font-weight: normal;
}
}

.pill {
background: var(--baseline-pill-bg);
border-radius: 0.125rem;
color: var(--baseline-pill-color);
font-size: 0.75rem;
font-weight: 600;
margin-right: auto;
padding: 0 0.25rem;
text-transform: uppercase;
}

.browsers {
display: flex;
flex-wrap: wrap;
Expand Down Expand Up @@ -107,7 +131,7 @@ $browsers: "chrome", "edge", "firefox", "safari";
}

&::after {
background-color: var(--baseline-browser-unsupported-bg);
background-color: var(--baseline-cross);
content: "";
display: block;
height: 1.25rem;
Expand All @@ -118,7 +142,7 @@ $browsers: "chrome", "edge", "firefox", "safari";
}

&.supported::after {
background-color: var(--baseline-browser-supported-bg);
background-color: var(--baseline-check);
mask-image: url("../assets/icons/baseline/browser-check.svg");
}
}
Expand Down Expand Up @@ -155,8 +179,21 @@ $browsers: "chrome", "edge", "firefox", "safari";
list-style: none;
margin: 0;

&:first-child a {
&,
&:active,
&:visited {
background: none;
color: var(--text-link);
}
}

&:not(:first-child) a {
color: var(--text-primary);
&,
&:active {
background: none;
color: var(--text-primary);
}
Comment on lines +182 to +196
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use classes instead of the first-child/last-child distinction?

}
}
}
Expand Down
Loading