Skip to content

Commit

Permalink
refactor(bcd): extract SupportType
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Oct 24, 2024
1 parent ddca183 commit 8aca71d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isTruthy,
versionIsPreview,
SupportStatementExtended,
SupportType,
bugURLToString,
SimpleSupportStatementExtended,
} from "./utils";
Expand All @@ -20,7 +21,7 @@ import { DEFAULT_LOCALE } from "../../../../../libs/constants";
function getCurrentSupportType(
support: SupportStatementExtended | undefined,
browser: BCD.BrowserStatement
): "no" | "yes" | "partial" | "preview" | "removed-partial" | "unknown" {
): SupportType {
if (!support) {
return "unknown";
}
Expand Down Expand Up @@ -135,40 +136,26 @@ function versionLabelFromSupport(

function getCurrentStatus(
support: BCD.SupportStatement | undefined,
supportClassName:
| "no"
| "yes"
| "partial"
| "preview"
| "removed-partial"
| "unknown",
supportType: SupportType,
browser: BCD.BrowserStatement
) {
const currentSupport = getCurrentSupport(support);

return getStatus(currentSupport, supportClassName, browser);
return getStatus(currentSupport, supportType, browser);
}

function getStatus(
currentSupport: SimpleSupportStatementExtended | undefined,
supportClassName:
| "no"
| "yes"
| "partial"
| "preview"
| "removed-partial"
| "unknown",
supportType: SupportType,
browser: BCD.BrowserStatement
) {
const added = currentSupport?.version_added ?? null;
const lastVersion = currentSupport?.version_last ?? null;

let status:
| { isSupported: "unknown" }
| {
isSupported: "no" | "yes" | "partial" | "preview" | "removed-partial";
label?: React.ReactNode;
};
let status: {
isSupported: SupportType;
label?: React.ReactNode;
};

switch (added) {
case null:
Expand All @@ -185,7 +172,7 @@ function getStatus(
break;
default:
status = {
isSupported: supportClassName,
isSupported: supportType,
label: versionLabelFromSupport(added, lastVersion, browser),
};
break;
Expand All @@ -204,8 +191,8 @@ const CellText = React.memo(
timeline?: boolean;
}) => {
const browserReleaseDate = getSupportBrowserReleaseDate(support);
const supportClassName = getCurrentSupportType(support, browser);
const status = getCurrentStatus(support, supportClassName, browser);
const supportType = getCurrentSupportType(support, browser);
const status = getCurrentStatus(support, supportType, browser);

let label: string | React.ReactNode;
let title = "";
Expand Down Expand Up @@ -256,9 +243,9 @@ const CellText = React.memo(
<span className="icon-wrap">
<abbr
className={`
bc-level-${supportClassName}
bc-level-${supportType}
icon
icon-${supportClassName}`}
icon-${supportType}`}
title={title}
>
<span className="bc-support-level">{title}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export interface SimpleSupportStatementExtended
version_last?: BCD.VersionValue;
}

export type SupportType =
| "no"
| "yes"
| "partial"
| "preview"
| "removed-partial"
| "unknown";

export type SupportStatementExtended =
| SimpleSupportStatementExtended
| SimpleSupportStatementExtended[];
Expand Down

0 comments on commit 8aca71d

Please sign in to comment.