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

feedback on pr 3518 #294

Merged
merged 1 commit into from
Apr 22, 2021
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
75 changes: 50 additions & 25 deletions build/document-extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,44 @@ function _addSingleSpecialSection($) {
}
const query = dataQuery.replace(/^bcd:/, "");
const { browsers, data } = packageBCD(query);
if (data === undefined) {
return [
{
type: specialSectionType,
value: {
title,
id,
isH3,
data: null,
query,
browsers: null,
},
},
];
}

if (specialSectionType === "browser_compatibility") {
if (data === undefined) {
return [
{
type: specialSectionType,
value: {
title,
id,
isH3,
data: null,
query,
browsers: null,
},
},
];
}
return _buildSpecialBCDSection();
} else if (specialSectionType === "specifications") {
if (data === undefined) {
return [
{
type: specialSectionType,
value: {
title,
id,
isH3,
query,
specifications: [],
},
},
];
}
return _buildSpecialSpecSection();
}
Elchi3 marked this conversation as resolved.
Show resolved Hide resolved

throw new Error(`Unrecognized special section type '${specialSectionType}'`);
Elchi3 marked this conversation as resolved.
Show resolved Hide resolved

function _buildSpecialBCDSection() {
// First extract a map of all release data, keyed by (normalized) browser
// name and the versions.
Expand Down Expand Up @@ -400,17 +416,26 @@ function _addSingleSpecialSection($) {

// Use BCD specURLs to look up more specification data
// from the browser-specs package
let specifications = [];
const specifications = specURLs
.map((specURL) => {
const spec = specs.find(
(spec) =>
specURL.startsWith(spec.url) || specURL.startsWith(spec.nightly.url)
);
if (spec) {
// We only want to return exactly the keys that we will use in the
// client code that renders this in React.
Elchi3 marked this conversation as resolved.
Show resolved Hide resolved
return {
bcdSpecificationURL: specURL,
title: spec.title,
shortTitle: spec.shortTitle,
Copy link
Author

Choose a reason for hiding this comment

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

The TypeScript React code assumes that title and shortTitle is always a string. THis might not be safe! I haven't looked deeper into browser-specs but could it be that some entries in there have null on the shortTitle, for example? If so we need to guard better.

Copy link
Owner

Choose a reason for hiding this comment

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

They use a schema to validate their data https://github.com/w3c/browser-specs/blob/master/schema/definitions.json. So, shortTitle is defined as a string.

I don't really know a lot about TypeScript but maybe it would make sense if browser-specs had a TypeScript definition file? I know BCD has this for that reason, too.

};
}
})
.filter(Boolean);

specURLs.forEach((url) => {
let spec = specs.find(
(spec) => url.startsWith(spec.url) || url.startsWith(spec.nightly.url)
);
if (spec) {
spec.bcdSpecificationURL = url;
specifications.push(spec);
}
});
console.log("HERE!!");
console.log(specifications);
Copy link
Author

Choose a reason for hiding this comment

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

Sorry. :)


return [
{
Expand Down
67 changes: 34 additions & 33 deletions client/src/document/spec-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,46 @@ export function SpecificationTable({
}>;
query: string;
}) {
if (specifications) {
const rows = specifications.map((spec) => (
<tr key={spec.bcdSpecificationURL}>
<td>
<a href={spec.bcdSpecificationURL}>{spec.title}</a>
</td>
</tr>
));
return (
<>
{title && !isH3 && <DisplayH2 id={id} title={title} />}
{title && isH3 && <DisplayH3 id={id} title={title} />}

return (
<>
{title && !isH3 && <DisplayH2 id={id} title={title} />}
{title && isH3 && <DisplayH3 id={id} title={title} />}
{/* XXX We could have a third condition; the specURL worked but yielded
exactly 0 specifications. If that's the case, perhaps the messaging
should be different. */}
{specifications.length > 0 ? (
<table className="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
</tr>
</thead>
{rows}
<tbody>
{specifications.map((spec) => (
<tr key={spec.bcdSpecificationURL}>
<td>
<a href={spec.bcdSpecificationURL}>{spec.title}</a>
</td>
</tr>
))}
</tbody>
</table>
</>
);
} else {
return (
<>
{title && !isH3 && <DisplayH2 id={id} title={title} />}
{title && isH3 && <DisplayH3 id={id} title={title} />}
<p>
No specification data found for <code>{query}</code>.<br />
<a href="#on-github">Check for problems with this page</a> or
contribute a missing <code>spec_url</code> to{" "}
<a href="https://github.com/mdn/browser-compat-data">
mdn/browser-compat-data
</a>
. Also make sure the specification is included in{" "}
<a href="https://github.com/w3c/browser-specs">w3c/browser-specs</a>.
</p>
</>
);
}
) : (
<div className="notecard warning">
<p>
No specification data found for <code>{query}</code>.<br />
<a href="#on-github">Check for problems with this page</a> or
contribute a missing <code>spec_url</code> to{" "}
<a href="https://github.com/mdn/browser-compat-data">
mdn/browser-compat-data
</a>
. Also make sure the specification is included in{" "}
<a href="https://github.com/w3c/browser-specs">w3c/browser-specs</a>
.
</p>
</div>
)}
</>
);
Elchi3 marked this conversation as resolved.
Show resolved Hide resolved
}