@@ -56,10 +82,12 @@ export default function PacksReadme() {
setCustomReadme(null);
}
};
- importComponent();
+ importComponent().catch((e) => {
+ console.error("Error importing custom readme component for pack. Additional information follows: \n", e);
+ });
}, []);
- const packData = useMemo(() => {
+ const packData: PackData = useMemo(() => {
const pack = packs.find((pack) => pack.name === packName);
if (pack) {
const packDataInfo: PackReadmeProps = {
@@ -91,24 +119,20 @@ export default function PacksReadme() {
latestVersion: "",
};
}, [packName]);
+
useEffect(() => {
const searchParams = window ? new URLSearchParams(window.location.search) : null;
const urlParamVersion = searchParams?.get("version");
const version = urlParamVersion || packData?.latestVersion || packData?.versions[0]?.title || "";
- let parentVersionObj: any;
if (version && !version.endsWith(".x")) {
- parentVersionObj = getParentVersion(version);
- const packDataObj = parentVersionObj?.children.find((child: any) => child.title === version);
- setSelectedPackUid(packDataObj?.packUid || "");
- setSelectedVersion(version);
+ const parentVersionObj = getParentVersion(version);
+ const packDataObj = parentVersionObj?.children.find((child) => child.title === version);
+ if (packDataObj) {
+ setSelectedPackUid(packDataObj.packUid);
+ setSelectedVersion(version);
+ }
}
}, [packData]);
- let warningContent;
- if (packData.disabled) {
- warningContent = "This pack is disabled. Upgrade to a newer version to take advantage of new features.";
- } else if (selectedPackUid && packData.packUidMap[selectedPackUid]?.deprecated) {
- warningContent = "This pack is deprecated. Upgrade to a newer version to take advantage of new features.";
- }
function versionChange(item: string) {
const [version, packUid] = item.split("===");
@@ -119,32 +143,28 @@ export default function PacksReadme() {
}
function getParentVersion(version: string) {
- return packData.versions.find((tagVersion) => tagVersion.children.find((child: any) => child.title === version));
+ return packData.versions.find((tagVersion) => tagVersion.children.find((child) => child.title === version));
}
function renderVersionOptions() {
- return packData.versions.map((tagVersion) => {
- return {
- value: tagVersion.title,
- title: tagVersion.title,
- selectable: false,
- children: tagVersion.children.map((child: any) => {
- return {
- value: `${child.title}===${child.packUid}`,
- title:
{child.title},
- };
- }),
- };
- });
+ return packData.versions.map((tagVersion) => ({
+ value: tagVersion.title,
+ title: tagVersion.title,
+ selectable: false,
+ children: tagVersion.children.map((child) => ({
+ value: `${child.title}===${child.packUid}`,
+ title:
{child.title},
+ })),
+ }));
}
function renderTabs() {
- let readme = selectedPackUid ? packData.packUidMap[selectedPackUid]?.readme : "";
+ const readme = selectedPackUid ? packData.packUidMap[selectedPackUid]?.readme : "";
const tabs = [
readme && {
label: `README`,
key: "1",
- children:
,
+ children:
{readme},
},
customReadme && {
label: `Additional Details`,
@@ -156,13 +176,11 @@ export default function PacksReadme() {
if (tabs.length > 1) {
return (
- {tabs.map((item) => {
- return (
-
- {item.children}
-
- );
- })}
+ {tabs.map((item) => (
+
+ {item.children}
+
+ ))}
);
}
@@ -195,12 +213,14 @@ export default function PacksReadme() {
.map((provider) => cloudDisplayNames[provider as keyof typeof cloudDisplayNames] || provider)
.join(", ");
}
+
function getRegistries() {
if (selectedVersion && !selectedVersion.endsWith(".x")) {
- const registerUid = packData.packUidMap[selectedPackUid]?.registryUid || "";
- return packData.selectedRepositories.find((registry) => registry.uid === registerUid)?.name || "";
+ const registryUid = packData.packUidMap[selectedPackUid]?.registryUid || "";
+ const registry = packData.selectedRepositories.find((registry) => registry.uid === registryUid);
+ return registry ? registry.name : "";
}
- const consolidatedRegistries = packData.registries.reduce((accumulator: string[], registry) => {
+ const consolidatedRegistries = packData.registries.reduce
((accumulator, registry) => {
const regObj = packData.selectedRepositories.find((repo) => repo.uid === registry);
if (regObj) {
accumulator.push(regObj.name);
@@ -210,6 +230,8 @@ export default function PacksReadme() {
return consolidatedRegistries.join(", ");
}
+ console.log("packData", packData);
+
return (
@@ -230,23 +252,27 @@ export default function PacksReadme() {
dropdownStyle={{ maxHeight: 400, overflow: "auto" }}
placeholder="Search"
treeDefaultExpandAll
- onChange={(item) => versionChange(item as string)}
+ onChange={(item) => versionChange(item)}
treeData={renderVersionOptions()}
/>
-
- {`Type: ${packTypeNames[packData.type as keyof typeof packTypeNames]}`}
-
+
{`Type: ${packTypeNames[packData.type]}`}
{`Cloud Providers: ${getProviders()}`}
{`Registry: ${getRegistries()}`}