From 5325495123f426f0e22f4949b8eab54281b79679 Mon Sep 17 00:00:00 2001 From: maniarathi Date: Mon, 12 Oct 2020 11:20:58 -0700 Subject: [PATCH] Speed up dataset drawer rendering (#1926) --- .../src/components/infoDrawer/infoDrawer.js | 98 ++++--------------- .../src/components/infoDrawer/infoFormat.js | 88 ++++++----------- 2 files changed, 53 insertions(+), 133 deletions(-) diff --git a/client/src/components/infoDrawer/infoDrawer.js b/client/src/components/infoDrawer/infoDrawer.js index 57bfd77b..9f41ef14 100644 --- a/client/src/components/infoDrawer/infoDrawer.js +++ b/client/src/components/infoDrawer/infoDrawer.js @@ -1,13 +1,9 @@ import React, { PureComponent } from "react"; -import { connect, shallowEqual } from "react-redux"; +import { connect } from "react-redux"; import { Drawer } from "@blueprintjs/core"; -import Async from "react-async"; import InfoFormat from "./infoFormat"; -import { - selectableCategoryNames, - createCategorySummaryFromDfCol, -} from "../../util/stateManager/controlsHelpers"; +import { selectableCategoryNames } from "../../util/stateManager/controlsHelpers"; @connect((state) => { return { @@ -20,44 +16,6 @@ import { }; }) class InfoDrawer extends PureComponent { - static watchAsync(props, prevProps) { - return !shallowEqual(props.watchProps, prevProps.watchProps); - } - - fetchAsyncProps = async (props) => { - const { schema } = props.watchProps; - const { annoMatrix } = this.props; - - const allCategoryNames = selectableCategoryNames(schema).sort(); - - const nonUserAnnoCategories = allCategoryNames.map((catName) => { - const isUserAnno = schema?.annotations?.obsByName[catName]?.writable; - if (!isUserAnno) return annoMatrix.fetch("obs", catName); - return null; - }); - const singleValueCategories = ( - await Promise.all(nonUserAnnoCategories) - ).reduce((acc, categoryData, i) => { - // Actually check to see if it is null(user anno) - if (!categoryData) return acc; - const catName = allCategoryNames[i]; - - const column = categoryData.icol(0); - const colSchema = schema.annotations.obsByName[catName]; - - const categorySummary = createCategorySummaryFromDfCol(column, colSchema); - - const { numCategoryValues } = categorySummary; - // Add to the array if the category has only one value - if (numCategoryValues === 1) { - acc.set(catName, categorySummary.allCategoryValues[0]); - } - return acc; - }, new Map()); - - return { singleValueCategories }; - }; - handleClose = () => { const { dispatch } = this.props; @@ -74,45 +32,31 @@ class InfoDrawer extends PureComponent { dataPortalProps, } = this.props; + const allCategoryNames = selectableCategoryNames(schema).sort(); + const singleValueCategories = new Map(); + + allCategoryNames.forEach((catName) => { + const isUserAnno = schema?.annotations?.obsByName[catName]?.writable; + const colSchema = schema.annotations.obsByName[catName]; + if (!isUserAnno && colSchema.categories?.length === 1) { + singleValueCategories.set(catName, colSchema.categories[0]); + } + }); + return ( - - - - - - {(error) => { - console.error(error); - return Failed to load info; - }} - - - {(asyncProps) => { - const { singleValueCategories } = asyncProps; - return ( - - ); - }} - - + ); } diff --git a/client/src/components/infoDrawer/infoFormat.js b/client/src/components/infoDrawer/infoFormat.js index eacaa406..880a5f7d 100644 --- a/client/src/components/infoDrawer/infoFormat.js +++ b/client/src/components/infoDrawer/infoFormat.js @@ -1,15 +1,15 @@ -import { H3, H1, UL, Classes } from "@blueprintjs/core"; +import { H3, H1, UL } from "@blueprintjs/core"; import React from "react"; import Truncate from "../util/truncate"; -const renderContributors = (contributors, affiliations, skeleton) => { +const renderContributors = (contributors, affiliations) => { // eslint-disable-next-line no-constant-condition -- Temp removed contributor section to avoid publishing PII if (!contributors || contributors.length === 0 || true) return null; return ( <> -

Contributors

-

+

Contributors

+

{contributors.map((contributor) => { const { email, name, institution } = contributor; @@ -22,7 +22,7 @@ const renderContributors = (contributors, affiliations, skeleton) => { ); })}

- {renderAffiliations(affiliations, skeleton)} + {renderAffiliations(affiliations)} ); }; @@ -39,14 +39,14 @@ const buildAffiliations = (contributors = []) => { return affiliations; }; -const renderAffiliations = (affiliations, skeleton) => { +const renderAffiliations = (affiliations) => { if (affiliations.length === 0) return null; return ( <> -

Affiliations

+

Affiliations