mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-03 15:08:11 +08:00
mock reducer
This commit is contained in:
@@ -4,34 +4,32 @@
|
||||
import React from "react";
|
||||
import _ from "lodash";
|
||||
import { connect } from "react-redux";
|
||||
import HistogramBrush from "../brushableHistogram";
|
||||
import { Icon } from "@blueprintjs/core";
|
||||
import * as globals from "../../globals";
|
||||
import actions from "../../actions";
|
||||
import Gene from "./gene";
|
||||
import { Button, ButtonGroup, Tooltip } from "@blueprintjs/core";
|
||||
import {
|
||||
postUserErrorToast,
|
||||
keepAroundErrorToast
|
||||
} from "../framework/toasters";
|
||||
import { memoize } from "../../util/dataframe/util";
|
||||
import Truncate from "../util/truncate";
|
||||
|
||||
@connect(state => {
|
||||
@connect((state) => {
|
||||
return {
|
||||
world: state.world,
|
||||
userDefinedGenes: state.controls.userDefinedGenes,
|
||||
userDefinedGenesLoading: state.controls.userDefinedGenesLoading
|
||||
userDefinedGenesLoading: state.controls.userDefinedGenesLoading,
|
||||
};
|
||||
})
|
||||
class GeneSet extends React.Component {
|
||||
_memoGenesToUpper = memoize(this._genesToUpper, (arr) => arr);
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
isOpen: false,
|
||||
haveFetched: false
|
||||
haveFetched: false,
|
||||
};
|
||||
}
|
||||
|
||||
_genesToUpper = listGenes => {
|
||||
_genesToUpper = (listGenes) => {
|
||||
// Has to be a Map to preserve index
|
||||
const upperGenes = new Map();
|
||||
for (let i = 0, { length } = listGenes; i < length; i += 1) {
|
||||
@@ -41,23 +39,19 @@ class GeneSet extends React.Component {
|
||||
return upperGenes;
|
||||
};
|
||||
|
||||
_memoGenesToUpper = memoize(this._genesToUpper, arr => arr);
|
||||
|
||||
fetchGenes = () => {
|
||||
const { world, dispatch, userDefinedGenes, setGenes } = this.props;
|
||||
const { world, dispatch, setGenes } = this.props;
|
||||
const varIndexName = world.schema.annotations.var.index;
|
||||
const { haveFetched } = this.state;
|
||||
|
||||
const worldGenes = world.varAnnotations.col(varIndexName).asArray();
|
||||
|
||||
const upperGenes = this._genesToUpper(setGenes);
|
||||
const upperUserDefinedGenes = this._genesToUpper(userDefinedGenes);
|
||||
const upperWorldGenes = this._memoGenesToUpper(worldGenes);
|
||||
|
||||
dispatch({ type: "bulk user defined gene start" });
|
||||
|
||||
Promise.all(
|
||||
[...upperGenes.keys()].map(upperGene => {
|
||||
[...upperGenes.keys()].map((upperGene) => {
|
||||
/* Unlike bulk add... with gene sets this test needs to be within the set... */
|
||||
// if (upperUserDefinedGenes.get(upperGene) !== undefined) {
|
||||
// return keepAroundErrorToast(`${upperGene} already exists`);
|
||||
@@ -87,25 +81,54 @@ class GeneSet extends React.Component {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
onGenesetMenuClick = () => {
|
||||
const { isOpen, haveFetched } = this.state;
|
||||
this.setState({ isOpen: !isOpen });
|
||||
if (!haveFetched) {
|
||||
// this.fetchGenes(); TODO
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { setName, setGenes } = this.props;
|
||||
const { haveFetched, isOpen } = this.state;
|
||||
const { isOpen } = this.state;
|
||||
// console.log("geneSet setGenes variable: ", setGenes);
|
||||
return (
|
||||
<div>
|
||||
<Button
|
||||
minimal
|
||||
onClick={() => {
|
||||
this.setState({ isOpen: !isOpen });
|
||||
if (!haveFetched) {
|
||||
this.fetchGenes();
|
||||
}
|
||||
<span
|
||||
role="menuitem"
|
||||
tabIndex="0"
|
||||
data-testclass="geneset-expand"
|
||||
data-testid={`${setName}:geneset-expand`}
|
||||
onKeyPress={/* todo */ () => {}}
|
||||
style={{
|
||||
cursor: "pointer",
|
||||
}}
|
||||
onClick={this.onGenesetMenuClick}
|
||||
>
|
||||
{setName}
|
||||
</Button>
|
||||
<Truncate>
|
||||
<span
|
||||
style={{
|
||||
maxWidth: globals.leftSidebarWidth - 150,
|
||||
}}
|
||||
data-testid={`${setName}:geneset-label`}
|
||||
>
|
||||
{setName}
|
||||
</span>
|
||||
</Truncate>
|
||||
<Icon
|
||||
data-testclass={
|
||||
isOpen
|
||||
? "geneset-expand-is-expanded"
|
||||
: "geneset-expand-is-not-expanded"
|
||||
}
|
||||
icon={isOpen ? "caret-down" : "caret-right"}
|
||||
iconSize={14}
|
||||
/>
|
||||
</span>
|
||||
|
||||
{isOpen
|
||||
? _.map(setGenes, gene => {
|
||||
? _.map(setGenes, (gene) => {
|
||||
return <Gene key={gene} gene={gene} />;
|
||||
})
|
||||
: null}
|
||||
|
||||
Reference in New Issue
Block a user