diff --git a/client/src/components/infoDrawer/infoFormat.tsx b/client/src/components/infoDrawer/infoFormat.tsx index b1a1d9562..e7f86ccb6 100644 --- a/client/src/components/infoDrawer/infoFormat.tsx +++ b/client/src/components/infoDrawer/infoFormat.tsx @@ -1,5 +1,6 @@ import { H3, H1, UL, HTMLTable, Classes } from "@blueprintjs/core"; import React from "react"; +import { checkValidVersion } from "../util/version"; // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. const renderContributors = (contributors: any, affiliations: any) => { @@ -184,11 +185,7 @@ const renderLinks = (projectLinks: any, aboutURL: any) => { const InfoFormat = React.memo( // @ts-expect-error ts-migrate(2339) FIXME: Property 'datasetTitle' does not exist on type '{ ... Remove this comment to see the full error message ({ datasetTitle, singleValueCategories, aboutURL, dataPortalProps = {} }) => { - if ( - ["1.0.0", "1.1.0"].indexOf( - dataPortalProps.version?.corpora_schema_version - ) === -1 - ) { + if (checkValidVersion(dataPortalProps)) { dataPortalProps = {}; } const { diff --git a/client/src/components/leftSidebar/topLeftLogoAndTitle.tsx b/client/src/components/leftSidebar/topLeftLogoAndTitle.tsx index e34f161ad..739c561f8 100644 --- a/client/src/components/leftSidebar/topLeftLogoAndTitle.tsx +++ b/client/src/components/leftSidebar/topLeftLogoAndTitle.tsx @@ -7,6 +7,7 @@ import Logo from "../framework/logo"; import Truncate from "../util/truncate"; import InfoDrawer from "../infoDrawer/infoDrawer"; import InformationMenu from "./infoMenu"; +import { checkValidVersion } from "../util/version"; const DATASET_TITLE_FONT_SIZE = 14; @@ -14,9 +15,7 @@ const DATASET_TITLE_FONT_SIZE = 14; @connect((state) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. const { corpora_props: corporaProps } = (state as any).config; - const correctVersion = - ["1.0.0", "1.1.0"].indexOf(corporaProps?.version?.corpora_schema_version) > - -1; + const isValidVersion = checkValidVersion(corporaProps); return { // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. datasetTitle: (state as any).config?.displayNames?.dataset ?? "", @@ -28,7 +27,7 @@ const DATASET_TITLE_FONT_SIZE = 14; tosURL: (state as any).config?.parameters?.about_legal_tos, // eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. privacyURL: (state as any).config?.parameters?.about_legal_privacy, - title: correctVersion ? corporaProps?.title : undefined, + title: isValidVersion ? corporaProps?.title : undefined, }; }) class LeftSideBar extends React.Component { diff --git a/client/src/components/util/version.ts b/client/src/components/util/version.ts new file mode 100644 index 000000000..7676b2baf --- /dev/null +++ b/client/src/components/util/version.ts @@ -0,0 +1,16 @@ +const VERSION_ONES = ["1.0.0", "1.1.0"]; +const VERSION_TWOS = ["2.0.0"]; + +export function checkValidVersion(corporaProps: any) { + if (!corporaProps) return false; + + // eslint-disable-next-line @typescript-eslint/naming-convention -- prop from BE + const { version, schema_version } = corporaProps; + + const isValidVersionOne = VERSION_ONES.includes( + version?.corpora_schema_version + ); + const isValidVersionTwo = VERSION_TWOS.includes(schema_version); + + return isValidVersionOne || isValidVersionTwo; +}