Skip to content

Commit

Permalink
Reprioritize support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhjacobs committed Apr 13, 2022
1 parent e39f759 commit 4f33aae
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type bcd from "@mdn/browser-compat-data/types";
import { BrowserInfoContext } from "./browser-info";
import {
asList,
getFirst,
getCurrent,
hasNoteworthyNotes,
isFullySupportedWithoutLimitation,
isNotSupportedAtAll,
Expand Down Expand Up @@ -46,7 +46,7 @@ function getSupportClassName(
}

let { flags, version_added, version_removed, partial_implementation } =
getFirst(support);
getCurrent(support);

let className;
if (version_added === null) {
Expand Down Expand Up @@ -80,7 +80,7 @@ function getSupportBrowserReleaseDate(
if (!support) {
return undefined;
}
return getFirst(support).release_date;
return getCurrent(support).release_date;
}

function StatusIcons({ status }: { status: bcd.StatusBlock }) {
Expand Down Expand Up @@ -142,12 +142,7 @@ const CellText = React.memo(
support: bcd.SupportStatement | undefined;
browser: bcd.BrowserStatement;
}) => {
const currentSupport =
(support &&
asList(support).find((item) =>
isFullySupportedWithoutLimitation(item)
)) ??
getFirst(support);
const currentSupport = getCurrent(support);

const added = currentSupport?.version_added ?? null;
const removed = currentSupport?.version_removed ?? null;
Expand Down Expand Up @@ -287,7 +282,7 @@ function Icon({ name }: { name: string }) {
}

function CellIcons({ support }: { support: bcd.SupportStatement | undefined }) {
const supportItem = getFirst(support);
const supportItem = getCurrent(support);
if (!supportItem) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ export function hasNoteworthyNotes(support: bcd.SimpleSupportStatement) {
}

function hasLimitation(support: bcd.SimpleSupportStatement) {
return hasMajorLimitation(support) || support.notes;
}

function hasMajorLimitation(support: bcd.SimpleSupportStatement) {
return (
support.partial_implementation ||
support.alternative_name ||
support.flags ||
support.prefix ||
support.version_removed ||
support.notes
support.version_removed
);
}

Expand Down Expand Up @@ -112,3 +115,45 @@ export function isFullySupportedWithoutLimitation(
export function isNotSupportedAtAll(support: bcd.SimpleSupportStatement) {
return !support.version_added && !hasLimitation(support);
}

function isFullySupportedWithMinorLimitation(
support: bcd.SimpleSupportStatement
) {
return support.version_added && !hasMajorLimitation(support);
}

export function getCurrent<T>(a: T | T[]): T;
// Prioritizes support items
export function getCurrent(support: bcd.SupportStatement | undefined) {
if (!support) return getFirst(support);
// Full support without limitation
const noLimitationSupportItem = asList(support).find((item) =>
isFullySupportedWithoutLimitation(item)
);
if (noLimitationSupportItem) return noLimitationSupportItem;
// Full support with only notes and version_added
const minorLimitationSupportItem = asList(support).find((item) =>
isFullySupportedWithMinorLimitation(item)
);
if (minorLimitationSupportItem) return minorLimitationSupportItem;
// Full support with altname/prefix
const altnamePrefixSupportItem = asList(support).find(
(item) => !item.version_removed && (item.prefix || item.alternative_name)
);
if (altnamePrefixSupportItem) return altnamePrefixSupportItem;
// Partial support
const partialSupportItem = asList(support).find(
(item) => !item.version_removed && item.partial_implementation
);
if (partialSupportItem) return partialSupportItem;
// Support with flags only
const flagSupportItem = asList(support).find(
(item) => !item.version_removed && item.flags
);
if (flagSupportItem) return flagSupportItem;
// No/Inactive support
const noSupportItem = asList(support).find((item) => item.version_removed);
if (noSupportItem) return noSupportItem;
// Default (likely never reached)
return getFirst(support);
}

0 comments on commit 4f33aae

Please sign in to comment.