From 3ce3889d73a4b29d560f754db8ec1450c5b2bed6 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Wed, 16 Mar 2022 22:18:56 +0100 Subject: [PATCH 1/3] fix(bcd): sort history by version Previously, we would simply expect that the BCD history is ordered by version number, but this is not always the case. Now, we reorder the BCD history ourselves, to be sure. --- build/document-extractor.js | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/build/document-extractor.js b/build/document-extractor.js index af852198f972..8f65b94b6ee8 100644 --- a/build/document-extractor.js +++ b/build/document-extractor.js @@ -441,6 +441,9 @@ function _addSingleSpecialSection($) { } } } + info.sort((a, b) => + _compareVersions(_getFirstVersion(b), _getFirstVersion(a)) + ); } } } @@ -460,6 +463,60 @@ function _addSingleSpecialSection($) { ]; } + /** + * @param {object} support + * @returns {string} + */ + function _getFirstVersion(support) { + if (typeof support.version_added === "string") { + return support.version_added; + } else if (typeof support.version_removed === "string") { + return support.version_removed; + } else { + return "0"; + } + } + + /** + * @param {string} a + * @param {string} b + */ + function _compareVersions(a, b) { + const x = _splitVersion(a); + const y = _splitVersion(b); + + return _compareNumberArray(x, y); + } + + /** + * @param {number[]} a + * @param {number[]} b + * @return {number} + */ + function _compareNumberArray(a, b) { + while (a.length || b.length) { + const x = a.shift() || 0; + const y = b.shift() || 0; + if (x !== y) { + return x - y; + } + } + + return 0; + } + + /** + * @param {string} version + * @return {number[]} + */ + function _splitVersion(version) { + if (version.startsWith("≤")) { + version = version.slice(1); + } + + return version.split(".").map(Number); + } + function _buildSpecialSpecSection() { // Collect spec URLs from a BCD feature, a 'spec-urls' value, or both; // For a BCD feature, it can either be a string or an array of strings. From 336b4a764f847c74968ac3c26ac77bf12a28a001 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Wed, 16 Mar 2022 22:53:12 +0100 Subject: [PATCH 2/3] fix(bcd): show history chronologically Previously, the support history was going backward. This was misleading, because notes appeared at the wrong position. Now, we show the history in chronological order, starting with the oldest entry (version), and going forward. --- .../ingredients/browser-compatibility-table/feature-row.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx b/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx index cdc11524d924..f0373f19612c 100644 --- a/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx +++ b/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx @@ -333,6 +333,8 @@ function getNotes( ) { if (support) { return asList(support) + .slice() + .reverse() .flatMap((item, i) => { const supportNotes = [ item.version_removed From 34cb4e4bd94cdffd2bef19a73eedcfd17b930009 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Thu, 17 Mar 2022 15:26:42 +0100 Subject: [PATCH 3/3] chore(bcd): hint type of support object Co-authored-by: Schalk Neethling --- build/document-extractor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/document-extractor.js b/build/document-extractor.js index 8f65b94b6ee8..e290d7b5b3b6 100644 --- a/build/document-extractor.js +++ b/build/document-extractor.js @@ -464,7 +464,7 @@ function _addSingleSpecialSection($) { } /** - * @param {object} support + * @param {object} support - {bcd.SimpleSupportStatement} * @returns {string} */ function _getFirstVersion(support) {