-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
165 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 21 additions & 51 deletions
72
client/src/components/MenuBar/components/DiffExpButtons/DiffExpButtons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 31 additions & 44 deletions
75
...c/components/MenuBar/components/DiffExpButtons/components/CellSetButton/CellSetButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,42 @@ | ||
import React from "react"; | ||
import { AnchorButton, Tooltip } from "@blueprintjs/core"; | ||
import { connect } from "react-redux"; | ||
import actions from "actions"; | ||
import { track } from "analytics"; | ||
import { EVENTS } from "analytics/events"; | ||
import { tooltipHoverOpenDelay } from "~/globals"; | ||
import { | ||
CellSetButtonProps, | ||
mapDispatchToProps, | ||
mapStateToProps, | ||
} from "./types"; | ||
import { useConnect } from "./connect"; | ||
|
||
// @ts-expect-error ts-migrate(1238) FIXME: Unable to resolve signature of class decorator whe... Remove this comment to see the full error message | ||
@connect((state) => ({ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. | ||
differential: (state as any).differential, | ||
})) | ||
class CellSetButton extends React.PureComponent { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS. | ||
set() { | ||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'dispatch' does not exist on type 'Readon... Remove this comment to see the full error message | ||
const { dispatch, eitherCellSetOneOrTwo } = this.props; | ||
dispatch(actions.setCellSetFromSelection(eitherCellSetOneOrTwo)); | ||
} | ||
function CellSetButton(props: CellSetButtonProps) { | ||
const { set, cellsSelected } = useConnect(props); | ||
const { eitherCellSetOneOrTwo } = props; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS. | ||
render() { | ||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'differential' does not exist on type 'Re... Remove this comment to see the full error message | ||
const { differential, eitherCellSetOneOrTwo } = this.props; | ||
const cellListName = `celllist${eitherCellSetOneOrTwo}`; | ||
const cellsSelected = differential[cellListName] | ||
? differential[cellListName].length | ||
: 0; | ||
return ( | ||
<Tooltip | ||
content="Save current selection for differential expression computation" | ||
position="bottom" | ||
hoverOpenDelay={tooltipHoverOpenDelay} | ||
> | ||
<AnchorButton | ||
type="button" | ||
onClick={() => { | ||
track(EVENTS.EXPLORER_CELLSET_BUTTON_CLICKED); | ||
return ( | ||
<Tooltip | ||
content="Save current selection for differential expression computation" | ||
position="bottom" | ||
hoverOpenDelay={tooltipHoverOpenDelay} | ||
> | ||
<AnchorButton | ||
type="button" | ||
onClick={() => { | ||
track(EVENTS.EXPLORER_CELLSET_BUTTON_CLICKED); | ||
|
||
this.set(); | ||
}} | ||
data-testid={`cellset-button-${eitherCellSetOneOrTwo}`} | ||
> | ||
<span data-testid={`cellset-count-${eitherCellSetOneOrTwo}`}> | ||
{cellsSelected} | ||
</span> | ||
{" cells"} | ||
</AnchorButton> | ||
</Tooltip> | ||
); | ||
} | ||
set(); | ||
}} | ||
data-testid={`cellset-button-${eitherCellSetOneOrTwo}`} | ||
> | ||
<span data-testid={`cellset-count-${eitherCellSetOneOrTwo}`}> | ||
{cellsSelected} | ||
</span> | ||
{" cells"} | ||
</AnchorButton> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
export default CellSetButton; | ||
export default connect(mapStateToProps, mapDispatchToProps)(CellSetButton); |
22 changes: 22 additions & 0 deletions
22
client/src/components/MenuBar/components/DiffExpButtons/components/CellSetButton/connect.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import actions from "actions"; | ||
import { DifferentialState } from "reducers/differential"; | ||
import { CellSetButtonProps } from "./types"; | ||
|
||
export function useConnect({ | ||
dispatch, | ||
differential, | ||
eitherCellSetOneOrTwo, | ||
}: CellSetButtonProps) { | ||
function set() { | ||
dispatch(actions.setCellSetFromSelection(eitherCellSetOneOrTwo)); | ||
} | ||
|
||
const cellListName: keyof DifferentialState = `celllist${eitherCellSetOneOrTwo}`; | ||
|
||
const cellsSelected = differential[cellListName]?.length ?? 0; | ||
|
||
return { | ||
set, | ||
cellsSelected, | ||
}; | ||
} |
16 changes: 16 additions & 0 deletions
16
client/src/components/MenuBar/components/DiffExpButtons/components/CellSetButton/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { AppDispatch, RootState } from "reducers"; | ||
import { DifferentialState } from "reducers/differential"; | ||
|
||
export interface CellSetButtonProps { | ||
differential: DifferentialState; | ||
eitherCellSetOneOrTwo: 1 | 2; | ||
dispatch: AppDispatch; | ||
} | ||
|
||
export const mapStateToProps = (state: RootState) => ({ | ||
differential: state.differential, | ||
}); | ||
|
||
export const mapDispatchToProps = (dispatch: AppDispatch) => ({ | ||
dispatch, | ||
}); |
48 changes: 48 additions & 0 deletions
48
client/src/components/MenuBar/components/DiffExpButtons/connect.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import actions from "actions"; | ||
import { DiffexpButtonsProps } from "./types"; | ||
import { | ||
DIFFEXP_SLOW_MSG, | ||
genTipMessageWarn, | ||
genTipMessage, | ||
} from "./constants"; | ||
|
||
export function useConnect({ | ||
dispatch, | ||
differential, | ||
diffexpMayBeSlow, | ||
diffexpCellcountMax, | ||
}: DiffexpButtonsProps) { | ||
function computeDiffExp() { | ||
if (differential.celllist1 && differential.celllist2) { | ||
dispatch( | ||
actions.requestDifferentialExpression( | ||
differential.celllist1, | ||
differential.celllist2 | ||
) | ||
).catch((error) => { | ||
console.error("Failed to request differential expression:", error); | ||
}); | ||
} | ||
} | ||
|
||
const haveBothCellSets = !!differential.celllist1 && !!differential.celllist2; | ||
const haveEitherCellSet = | ||
!!differential.celllist1 || !!differential.celllist2; | ||
const slowMsg = diffexpMayBeSlow ? DIFFEXP_SLOW_MSG : ""; | ||
const tipMessage = genTipMessage(slowMsg); | ||
const tipMessageWarn = genTipMessageWarn(diffexpCellcountMax); | ||
const warnMaxSizeExceeded = | ||
haveEitherCellSet && | ||
!!diffexpCellcountMax && | ||
(differential.celllist1?.length ?? 0) + | ||
(differential.celllist2?.length ?? 0) > | ||
diffexpCellcountMax; | ||
|
||
return { | ||
computeDiffExp, | ||
haveBothCellSets, | ||
warnMaxSizeExceeded, | ||
tipMessage, | ||
tipMessageWarn, | ||
}; | ||
} |
6 changes: 6 additions & 0 deletions
6
client/src/components/MenuBar/components/DiffExpButtons/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const DIFFEXP_SLOW_MSG = | ||
"(CAUTION: large dataset - may take longer or fail)"; | ||
export const genTipMessage = (slowMsg: string) => | ||
`See top differentially expressed genes${slowMsg}`; | ||
export const genTipMessageWarn = (cellCountMax: number) => | ||
`The total number of cells for differential expression computation may not exceed ${cellCountMax}. Try reselecting new cell sets.`; |
19 changes: 19 additions & 0 deletions
19
client/src/components/MenuBar/components/DiffExpButtons/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AppDispatch, RootState } from "reducers"; | ||
import { DifferentialState } from "reducers/differential"; | ||
|
||
export interface DiffexpButtonsProps { | ||
differential: DifferentialState; | ||
diffexpMayBeSlow: boolean; | ||
diffexpCellcountMax: number; | ||
dispatch: AppDispatch; | ||
} | ||
|
||
export const mapStateToProps = (state: RootState) => ({ | ||
differential: state.differential, | ||
diffexpMayBeSlow: state.config?.parameters?.["diffexp-may-be-slow"] ?? false, | ||
diffexpCellcountMax: state.config?.limits?.diffexp_cellcount_max ?? 0, | ||
}); | ||
|
||
export const mapDispatchToProps = (dispatch: AppDispatch) => ({ | ||
dispatch, | ||
}); |