Skip to content

Commit

Permalink
chore: Add types for rrecognized version commit (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
tihuan authored Sep 23, 2021
1 parent 6536f05 commit e807dca
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
19 changes: 19 additions & 0 deletions client/src/common/types/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,22 @@
export interface GCHints {
isHot: boolean;
}

export interface DataPortalProps {
version: {
corpora_schema_version: string;
corpora_encoding_version: string;
};
title: string;
contributors: { name: string; institution: string }[];
layer_descriptions: { X: string };
organism: string;
organism_ontology_term_id: string;
project_name: string;
project_description: string;
project_links: { link_name: string; link_type: string; link_url: string }[];
default_embedding: string;
preprint_doi: string;
publication_doi: string;
schema_version: string;
}
7 changes: 3 additions & 4 deletions client/src/components/infoDrawer/infoDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { PureComponent } from "react";
import { connect } from "react-redux";
import { Drawer } from "@blueprintjs/core";

import InfoFormat from "./infoFormat";
import InfoFormat, { SingleValueCategories } from "./infoFormat";
import { selectableCategoryNames } from "../../util/stateManager/controlsHelpers";

// @ts-expect-error ts-migrate(1238) FIXME: Unable to resolve signature of class decorator whe... Remove this comment to see the full error message
Expand Down Expand Up @@ -45,10 +45,9 @@ class InfoDrawer extends PureComponent {
} = this.props;

const allCategoryNames = selectableCategoryNames(schema).sort();
const singleValueCategories = new Map();
const singleValueCategories: SingleValueCategories = new Map();

// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
allCategoryNames.forEach((catName: any) => {
allCategoryNames.forEach((catName) => {
const isUserAnno = schema?.annotations?.obsByName[catName]?.writable;
const colSchema = schema.annotations.obsByName[catName];
if (!isUserAnno && colSchema.categories?.length === 1) {
Expand Down
56 changes: 36 additions & 20 deletions client/src/components/infoDrawer/infoFormat.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { H3, H1, UL, HTMLTable, Classes } from "@blueprintjs/core";
import React from "react";
import { DataPortalProps } from "../../common/types/entities";
import Category from "../categorical/category";
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) => {
const renderContributors = (
contributors: DataPortalProps["contributors"],
affiliations: string[]
) => {
// eslint-disable-next-line no-constant-condition -- Temp removed contributor section to avoid publishing PII
if (!contributors || contributors.length === 0 || true) return null;

return (
<>
<H3>Contributors</H3>
Expand All @@ -29,27 +34,28 @@ const renderContributors = (contributors: any, affiliations: any) => {
};

// generates a list of unique institutions by order of appearance in contributors
const buildAffiliations = (contributors = []) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
const affiliations: any = [];
const buildAffiliations = (
contributors: { name: string; institution: string }[] = []
) => {
const affiliations: string[] = [];

contributors.forEach((contributor) => {
const { institution } = contributor;
if (affiliations.indexOf(institution) === -1) {
affiliations.push(institution);
}
});

return affiliations;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
const renderAffiliations = (affiliations: any) => {
const renderAffiliations = (affiliations: string[]) => {
if (affiliations.length === 0) return null;
return (
<>
<H3>Affiliations</H3>
<UL>
{/* eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. */}
{affiliations.map((item: any, index: any) => (
{affiliations.map((item, index) => (
<div key={item}>
<sup>{index + 1}</sup>
{" "}
Expand All @@ -61,9 +67,9 @@ const renderAffiliations = (affiliations: any) => {
);
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
const renderDOILink = (type: any, doi: any) => {
const renderDOILink = (type: string, doi: string) => {
if (!doi) return null;

return (
<>
<H3>{type}</H3>
Expand All @@ -79,10 +85,8 @@ const renderDOILink = (type: any, doi: any) => {
const ONTOLOGY_KEY = "ontology_term_id";
// Render list of metadata attributes found in categorical field
const renderDatasetMetadata = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
singleValueCategories: any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
corporaMetadata: any
singleValueCategories: SingleValueCategories,
corporaMetadata: Partial<DataPortalProps>
) => {
if (singleValueCategories.size === 0) return null;
return (
Expand All @@ -104,13 +108,11 @@ const renderDatasetMetadata = (
{Object.entries(corporaMetadata).map(([key, value]) => (
<tr {...{ key }}>
<td>{`${key}:`}</td>
{/* @ts-expect-error ts-migrate(2322) FIXME: Type 'unknown' is not assignable to type 'ReactNod... Remove this comment to see the full error message */}
<td>{value}</td>
<td />
</tr>
))}
{Array.from(singleValueCategories).reduce((elems, pair) => {
// @ts-expect-error ts-migrate(2488) FIXME: Type 'unknown' must have a '[Symbol.iterator]()' m... Remove this comment to see the full error message
const [category, value] = pair;
// If the value is empty skip it
if (!value) return elems;
Expand Down Expand Up @@ -182,12 +184,26 @@ const renderLinks = (projectLinks: any, aboutURL: any) => {
);
};

export type SingleValueCategories = Map<string, Category>;

interface Props {
datasetTitle: string;
singleValueCategories: SingleValueCategories;
aboutURL: string;
dataPortalProps: DataPortalProps;
}

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 = {} }) => {
({
datasetTitle,
singleValueCategories,
aboutURL,
dataPortalProps = {} as DataPortalProps,
}: Props) => {
if (checkValidVersion(dataPortalProps)) {
dataPortalProps = {};
dataPortalProps = {} as DataPortalProps;
}

const {
title,
publication_doi: doi,
Expand Down
9 changes: 5 additions & 4 deletions client/src/components/util/version.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { DataPortalProps } from "../../common/types/entities";

const VERSION_ONES = ["1.0.0", "1.1.0"];
const VERSION_TWOS = ["2.0.0"];

export function checkValidVersion(corporaProps: any) {
export function checkValidVersion(corporaProps: DataPortalProps): boolean {
if (!corporaProps) return false;

// eslint-disable-next-line @typescript-eslint/naming-convention -- prop from BE
const { version, schema_version } = corporaProps;
const { version, schema_version: schemaVersion } = corporaProps;

const isValidVersionOne = VERSION_ONES.includes(
version?.corpora_schema_version
);
const isValidVersionTwo = VERSION_TWOS.includes(schema_version);
const isValidVersionTwo = VERSION_TWOS.includes(schemaVersion);

return isValidVersionOne || isValidVersionTwo;
}

0 comments on commit e807dca

Please sign in to comment.