-
Notifications
You must be signed in to change notification settings - Fork 172
Change {{compat}} to work with new BCD data structure #272
Conversation
For more details see mdn/browser-compat-data#304 and mdn/browser-compat-data#283
This isn't working for me. I've generated new-style data using
I point my local KS at your clone/branch, and check that the macros are the same version as in this PR. Then I try this in a page:
This gives me this output:
Trying to debug a bit, it looks like the
|
If you change cc/ @escattone who might have additional hints on how to fiddle with modules locally. |
Sorry @wbamberg and @Elchi3 , looking into this more, I realized that I was confused about how I think @Elchi3 is absolutely right-on here, in that @wbamberg I think all you should have to do is restart the kumascript container using |
I've not yet reviewed the code here, just looking at the output. I've generated a few representative tables from the WebExtension data:
The first thing is that I'm not sure whether the font colors for the "standard" table combine well with the background colors for WE tables. Especially red font on reddish background for "No". The second thing is that this doesn't exactly replace the "aggregate tables". I'm not sure that the approach this takes, where there's just one type of table, and you use depth and note-hiding to adjust the output, is viable. I think of aggregate tables and feature tables as quite distinct things. The closest thing to a table like this one: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json#Browser_compatibility is I think (2) in the screenshot - "All manifest keys, depth of 1, with notes". But there are a couple of differences:
Feature tables are supposed to provide complete info for a given "feature", where a feature is basically a thing that has its own docs page. So I guess feature tables should iterate all the way through subfeatures, no matter how deep? Should there be a way to indicate that in the macro call? Or just pass Then we have to deal with flattening though. The flattening implemented here loses information that makes the tables be not understandable. For example, in (3), "homepage" is a subfeature of "chrome_settings_overrides" but that's not indicated. What if another feature also has a subfeature called "homepage" - which one is which? We talked about this I think, and the most obvious approach seems to be: if the subfeature has a description, then write something like:
If the subfeature does not have a description, then write something like "feature.subfeature". For example:
or:
The last thing I can see here is that given a macro call like:
...if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is mostly correct, although I think the interaction of CSS classes and complex support statements might not work.
But as I said in the last comment, I'm not sure if this is quite the output that we want.
macros/Compat.ejs
Outdated
$0 – A query string indicating for which feature to retrieve compat data for. | ||
$0 – A query string indicating for which feature to retrieve compat data for. | ||
$1 – A depth setting indicating how deep sub features should be added to the table | ||
(flattened, default: 1 level) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could perhaps clarify this to say that (IIRC) 1 gives you compat data for the given feature, if it has any, plus compat data for any of its immediate children.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
macros/Compat.ejs
Outdated
$0 – A query string indicating for which feature to retrieve compat data for. | ||
$1 – A depth setting indicating how deep sub features should be added to the table | ||
(flattened, default: 1 level) | ||
$2 – A boolean setting whether to hide notes or not (defaults to false). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a double negative (hideNotes==false, so show notes by default) is harder to understand than a single positive (showNotes defaulting to true).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
macros/Compat.ejs
Outdated
`browserPlatformType` is either "mobile" or "desktop" | ||
`browserNames` is either the "mobileBrowsers" or "desktopBrowsers" object | ||
`browserPlatformType` is either "mobile", "desktop" or "webextensions" | ||
`browserNames` is either the "mobileBrowsers", "desktopBrowsers" or "webExtBrowserNames" object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's odd that this takes both these arguments, when you could derive one from the other. Why not just pass browserPlatformType
and use that to look up the right browserNames
in a map-type thing?
This is implicit at line 96 where you actually use the webExtBrowserNames
variable directly, instead of the browserNames
argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored this to have a browser map and to only pass browserPlatformType
to the various functions.
macros/Compat.ejs
Outdated
return `<span title="${localize(compatStrings, 'supportsShort_unknown_title')}" | ||
style="color: rgb(255, 153, 0);">${localize(compatStrings, 'supportsShort_unknown')}</span>`; | ||
break; | ||
return {class: 'unknown-support', text: `<span title="${localize(compatStrings, 'supportsShort_unknown_title')}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole business of changing this from returning a string to returning an object is a bit awkward IMO.
First the comment at line 112 talks about a string, so does the function name. Then it breaks the convention in this file generally, where writeXYZ()
functions return a string called output
.
Then I think it also breaks when you have multiple support statements, or when you have version_added
and version_removed
.
For example, IIUC this is a valid support_statement structure:
{
"version_added": "3.5",
"version_removed": "9"
}
This says that the feature is not currently supported, but as I understand the logic in here, the call at line 211 will get us a CSS class of full-support
.
I think it might be cleaner to have separate functions to get the text string and to get the CSS class. Then you could call the CSS class one from writeSupportCells
, which AIUI is the only place you need to know the class.
Also, is it a problem that class
is a JS keyword? Anyway, that doesn't seem like very good practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I originally backported this from the webext compat macro, but you are right: The whole business of getting a CSS class is actually not straight forward and is now in an own function getSupportClass
.
macros/Compat.ejs
Outdated
} else { // this browser has no info, it's unknown | ||
supportInfo = writeSupportInfo(null); | ||
supportInfo = writeSupportInfo(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
|
||
for (let subfeature of Object.keys(json_subfeature_set)) { | ||
let support = json_subfeature_set[subfeature]['support']; | ||
for (let row of features) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a bit weird to refer to this features
global here, especially where it's not initialized above this function. I guess this is just a style thing, but I would have had it as a parameter.
macros/Compat.ejs
Outdated
function traverseFeatures(obj, depth, identifier) { | ||
depth--; | ||
if (depth >= 0) { | ||
for (i in obj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (let i in obj)
macros/Compat.ejs
Outdated
for (i in obj) { | ||
if (!!obj[i] && typeof(obj[i])=="object" && i !== '__compat') { | ||
if (obj[i].__compat) { | ||
// [identifier + '.' + i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comment, and I'm not sure what identifier
is doing here in general. Should [i]
in the next line be [identifier]
, so you get dotted identifiers for child features?
macros/WebExtAllCompatTables.ejs
Outdated
|
||
function writeTableForModule(data, moduleName) { | ||
var table = `<h2>${moduleName}</h2>`; | ||
table += template("WebExtBrowserCompatTable", [data, `${webExtAPIBaseUrl}/${moduleName}`]); | ||
var table = `<h2><a href="${webExtAPIBaseUrl}/${moduleName}">${moduleName}</a></h2>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have heard, that it's not considered to be good practice in MDN to have headers be links. I think I tend to agree with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I will remove this when I have a implemented a way to have feature labels linked to MDN pages in "aggregate" tables.
- remove text coloring (will be redone in the redesign anyway) - Update depth parameter comment - change hideNotes to showNotes - Create a map of browsers - Change writeTableHead, writeTable and writeSupportCells to use a map of browsers and browserPlatformType - Change getVersionString back to just return a string - Add a function getSupportClass that returns a proper CSS class for a cell - Implement labels that represent the hierarchies that are lost due to flattening for the 2D table
Thanks a lot for your extensive feedback! I've added a commit that does some cleanup regarding the code style and the nits you've mentioned. Regarding the general output of this, I think I see two things that we want to implement before this might be good to go.
Another thing that I read in your feedback but I don't think it's critical at the moment:
|
What do you think of: if the depth param is omitted, iterate through all subfeatures? This saves us from some hacky approach, and I think this will probably be the most common choice (for feature tables anyway). |
I think this would be cleaner: mdn/browser-compat-data#320. |
* re-introduce "Basic support" * introduce aggregateMode param (instead of showNotes) * remove links from WebExt modules headlines
I think this gives us mostly what we have right now. Given that we want to redesign the tables soon and that this contains already many major changes, I think we could live with minor glitches. Can you give this another look? |
For comparison, here's the output with the same macro calls as in #272 (comment): |
Some comments on the output:
Apart from that, it looks great! I guess as part of updating the data we'll be adding For the Extensions docs, will be update every page to call |
let cssClass = 'unknown-support'; | ||
|
||
if (Array.isArray(supportInfo)) { | ||
// the first entry should be the most relevant/recent and will be treated as "the truth" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the first, or the last?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be the first. When I look at the table cells, I think I like seeing the most relevant compat data first. So, for example, if there is unpreffed support from Firefox 51, I think that is the most relevant information. Then only after that I'll see that there was also preffed support from versions 34-50.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of something like this, in which as far as I can tell, the feature is no longer supported. But the syntax has multiple support statements, and only looking at the first would make it look like it's supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, but:
-
this question: Change {{compat}} to work with new BCD data structure #272 (review) should be answered (I think the code is wrong, but I might be the one that's wrong :)
-
I'd like the asterisks to account for subfeatures, as noted here: Change {{compat}} to work with new BCD data structure #272 (comment).
-
I don't think asterisk-linking is needed to land this.
-
I'd like to consider explicitly whether to shim the WE macros now, in the expectation that we will have to change the compat macro interfaces when table redesign happens.
Yes, that makes sense to me. I'll try to get this implemented.
Yes, I think partial support might be indicated differently in the redesigned tables (I think I remember a yellow cell background instead of an asterisk), so lets not worry about this one.
I think that the {{Compat}} macro parameter aren't changing as they are about data querying and not so much about data displaying. They are also used this way on many web docs already. Maybe we will fiddle again with the Is a shim straight-forward to implement? I would love to get rid of the whole URL hackery that is currently done to determine what to query and I expect most {{compat}} calls to just have the |
I think so (without having actually tried :). The WebExt macros would just map the current URL onto the query string and call Compat.ejs.
Agreed, but this will involve editing 400-odd pages, and I don't want to do that more than once. So unless we are confident that the table redesign will not change the macro interface, I would lean towards shimming it until the table redesign.
Yes, I guess so. |
I've added a shim for the WebExt macro and implemented a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shim will never generate an aggregate table. The old macro would generate an aggregate table table when the data didn't contain "__compat": https://github.com/mdn/kumascript/blob/master/macros/WebExtBrowserCompatTable.ejs#L244.
Since we're now representing that explicitly, the shim needs to figure out whether we want an aggregate table or a feature table. I think a reasonable heuristic is that if the page is directly under "API", build an aggregate table.
Apart from that, I think this is good!
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Good catch, I completely forgot about the aggregate tables for the main Extension API pages. Should be fixed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for your patience @Elchi3 !
* mdn/kumascript#272 - Compat, etc. - new BCD data structure * mdn/kumascript#284 - SpecName, spec2: Remove outdated specs * mdn/kumascript#287 - ListGroups: new macro * mdn/kumascript#288 - HTTPSidebar: Add HTTP Guide, Protocol upgrade * mdn/kumascript#289 - CSS_Ref: Add shape and basic-shape cases
* mdn/kumascript#272 - Compat, etc. - new BCD data structure * mdn/kumascript#284 - SpecName, spec2: Remove outdated specs * mdn/kumascript#287 - ListGroups: new macro * mdn/kumascript#288 - HTTPSidebar: Add HTTP Guide, Protocol upgrade * mdn/kumascript#289 - CSS_Ref: Add shape and basic-shape cases
* mdn/kumascript#272 - Compat, etc. - new BCD data structure * mdn/kumascript#284 - SpecName, spec2: Remove outdated specs * mdn/kumascript#287 - ListGroups: new macro * mdn/kumascript#288 - HTTPSidebar: Add HTTP Guide, Protocol upgrade * mdn/kumascript#289 - CSS_Ref: Add shape and basic-shape cases
For more details see mdn/browser-compat-data#304
and mdn/browser-compat-data#283
To test this you'll have to:
depth
parameter.This can't land at the moment. Maybe not yet exhaustive, but a start of a checklist for this: