Skip to content

Commit

Permalink
refactor(bcd): extract getCurrentStatus()
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Oct 24, 2024
1 parent a06721c commit 057446e
Showing 1 changed file with 46 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,51 @@ function versionLabelFromSupport(
);
}

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

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;
};
switch (added) {
case null:
status = { isSupported: "unknown" };
break;
case true:
status = { isSupported: lastVersion ? "no" : "yes" };
break;
case false:
status = { isSupported: "no" };
break;
case "preview":
status = { isSupported: "preview" };
break;
default:
status = {
isSupported: supportClassName,
label: versionLabelFromSupport(added, lastVersion, browser),
};
break;
}
return status;
}

const CellText = React.memo(
({
support,
Expand All @@ -133,40 +178,9 @@ const CellText = React.memo(
browser: BCD.BrowserStatement;
timeline?: boolean;
}) => {
const currentSupport = getCurrentSupport(support);

const added = currentSupport?.version_added ?? null;
const lastVersion = currentSupport?.version_last ?? null;

const browserReleaseDate = getSupportBrowserReleaseDate(support);
const supportClassName = getSupportClassName(support, browser);

let status:
| { isSupported: "unknown" }
| {
isSupported: "no" | "yes" | "partial" | "preview" | "removed-partial";
label?: React.ReactNode;
};
switch (added) {
case null:
status = { isSupported: "unknown" };
break;
case true:
status = { isSupported: lastVersion ? "no" : "yes" };
break;
case false:
status = { isSupported: "no" };
break;
case "preview":
status = { isSupported: "preview" };
break;
default:
status = {
isSupported: supportClassName,
label: versionLabelFromSupport(added, lastVersion, browser),
};
break;
}
const status = getCurrentStatus(support, supportClassName, browser);

let label: string | React.ReactNode;
let title = "";
Expand Down

0 comments on commit 057446e

Please sign in to comment.