mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-03 03:28:11 +08:00
fix performance regression caused by excessive rendering (#1219)
This commit is contained in:
@@ -19,17 +19,33 @@ import LabelInput from "./labelInput";
|
|||||||
import { AnnotationsHelpers } from "../../util/stateManager";
|
import { AnnotationsHelpers } from "../../util/stateManager";
|
||||||
import { labelPrompt, isLabelErroneous } from "./labelUtil";
|
import { labelPrompt, isLabelErroneous } from "./labelUtil";
|
||||||
|
|
||||||
@connect(state => ({
|
/* this is defined outside of the class so we can use it in connect() */
|
||||||
categoricalSelection: state.categoricalSelection,
|
function _currentLabel(ownProps, categoricalSelection) {
|
||||||
annotations: state.annotations,
|
const { metadataField, categoryIndex } = ownProps;
|
||||||
colorScale: state.colors.scale,
|
return String(
|
||||||
colorAccessor: state.colors.colorAccessor,
|
categoricalSelection[metadataField].categoryValues[categoryIndex]
|
||||||
pointDilation: state.pointDilation,
|
).valueOf();
|
||||||
schema: state.world?.schema,
|
}
|
||||||
world: state.world,
|
|
||||||
crossfilter: state.crossfilter,
|
@connect((state, ownProps) => {
|
||||||
ontology: state.ontology
|
const { pointDilation, categoricalSelection } = state;
|
||||||
}))
|
const { metadataField, categoryField } = ownProps;
|
||||||
|
const isDilated =
|
||||||
|
pointDilation.metadataField === metadataField &&
|
||||||
|
pointDilation.categoryField ===
|
||||||
|
_currentLabel(ownProps, categoricalSelection);
|
||||||
|
return {
|
||||||
|
categoricalSelection,
|
||||||
|
annotations: state.annotations,
|
||||||
|
colorScale: state.colors.scale,
|
||||||
|
colorAccessor: state.colors.colorAccessor,
|
||||||
|
schema: state.world?.schema,
|
||||||
|
world: state.world,
|
||||||
|
crossfilter: state.crossfilter,
|
||||||
|
ontology: state.ontology,
|
||||||
|
isDilated
|
||||||
|
};
|
||||||
|
})
|
||||||
class CategoryValue extends React.Component {
|
class CategoryValue extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@@ -169,7 +185,7 @@ class CategoryValue extends React.Component {
|
|||||||
const crossfilterChange =
|
const crossfilterChange =
|
||||||
props.isUserAnno && props.crossfilter !== nextProps.crossfilter;
|
props.isUserAnno && props.crossfilter !== nextProps.crossfilter;
|
||||||
const editingLabel = state.editedLabelText !== nextState.editedLabelText;
|
const editingLabel = state.editedLabelText !== nextState.editedLabelText;
|
||||||
const dilationChange = props.pointDilation !== nextProps.pointDilation;
|
const dilationChange = props.isDilated !== nextProps.isDilated;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
valueSelectionChange ||
|
valueSelectionChange ||
|
||||||
@@ -227,10 +243,8 @@ class CategoryValue extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
currentLabel() {
|
currentLabel() {
|
||||||
const { categoricalSelection, metadataField, categoryIndex } = this.props;
|
const { categoricalSelection } = this.props;
|
||||||
return String(
|
return _currentLabel(this.props, categoricalSelection);
|
||||||
categoricalSelection[metadataField].categoryValues[categoryIndex]
|
|
||||||
).valueOf();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isAddCurrentSelectionDisabled(category, value) {
|
isAddCurrentSelectionDisabled(category, value) {
|
||||||
@@ -276,7 +290,7 @@ class CategoryValue extends React.Component {
|
|||||||
// flippedProps is potentially brittle, their docs want {...flippedProps} on our div,
|
// flippedProps is potentially brittle, their docs want {...flippedProps} on our div,
|
||||||
// our lint doesn't like jsx spread, we are version pinned to prevent api change on their part
|
// our lint doesn't like jsx spread, we are version pinned to prevent api change on their part
|
||||||
flippedProps,
|
flippedProps,
|
||||||
pointDilation
|
isDilated
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const ontologyEnabled = ontology?.enabled ?? false;
|
const ontologyEnabled = ontology?.enabled ?? false;
|
||||||
|
|
||||||
@@ -336,12 +350,7 @@ class CategoryValue extends React.Component {
|
|||||||
data-portal-key={flippedProps["data-portal-key"]}
|
data-portal-key={flippedProps["data-portal-key"]}
|
||||||
className={
|
className={
|
||||||
/* This code is to change the styles on centroid label hover is causing over-rendering */
|
/* This code is to change the styles on centroid label hover is causing over-rendering */
|
||||||
`${styles.value}${
|
`${styles.value}${isDilated ? ` ${styles.hover}` : ""}`
|
||||||
pointDilation.metadataField === metadataField &&
|
|
||||||
pointDilation.categoryField === displayString
|
|
||||||
? ` ${styles.hover}`
|
|
||||||
: ""
|
|
||||||
}`
|
|
||||||
}
|
}
|
||||||
data-testclass="categorical-row"
|
data-testclass="categorical-row"
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
Reference in New Issue
Block a user