diff --git a/client/src/components/embedding/index.js b/client/src/components/embedding/index.js
index 586218d8..337843ab 100644
--- a/client/src/components/embedding/index.js
+++ b/client/src/components/embedding/index.js
@@ -1,6 +1,6 @@
import React from "react";
import { connect } from "react-redux";
-import Async from "react-async";
+import { useAsync } from "react-async";
import {
ButtonGroup,
Popover,
@@ -84,18 +84,11 @@ class Embedding extends React.PureComponent {
There are {schema?.dataframe?.nObs} cells in the entire dataset.
-
- {layoutChoice.available.map((name) => (
-
- ))}
-
+ annoMatrix={annoMatrix}
+ layoutChoice={layoutChoice}
+ />
}
/>
@@ -106,40 +99,58 @@ class Embedding extends React.PureComponent {
export default Embedding;
-const loadEmbeddingCounts = async ({ annoMatrix, layoutName }) => {
- const embedding = await annoMatrix.fetch("emb", layoutName);
- const discreteCellIndex = getDiscreteCellEmbeddingRowIndex(embedding);
- return { embedding, discreteCellIndex };
+const loadAllEmbeddingCounts = async ({ annoMatrix, available }) => {
+ const embeddings = await Promise.all(
+ available.map((name) => annoMatrix.fetch("emb", name))
+ );
+ return available.map((name, idx) => ({
+ embeddingName: name,
+ embedding: embeddings[idx],
+ discreteCellIndex: getDiscreteCellEmbeddingRowIndex(embeddings[idx]),
+ }));
};
-const LayoutChoice = ({ annoMatrix, layoutName }) => {
- return (
-
- {({ data, error, isPending }) => {
- if (error) {
- /* log, as this is unexpected */
- console.error(error);
- }
- if (error || isPending) {
- /* still loading, or errored out - just omit counts (TODO: spinner?) */
- return ;
- }
- if (data) {
- const { embedding, discreteCellIndex } = data;
+const EmbeddingChoices = ({ onChange, annoMatrix, layoutChoice }) => {
+ const { available } = layoutChoice;
+ const { data, error, isPending } = useAsync({
+ promiseFn: loadAllEmbeddingCounts,
+ annoMatrix,
+ available,
+ });
+
+ if (error) {
+ /* log, as this is unexpected */
+ console.error(error);
+ }
+ if (error || isPending) {
+ /* still loading, or errored out - just omit counts (TODO: spinner?) */
+ return (
+
+ {layoutChoice.available.map((name) => (
+
+ ))}
+
+ );
+ }
+ if (data) {
+ return (
+
+ {data.map((summary) => {
+ const { discreteCellIndex, embedding, embeddingName } = summary;
const isAllCells = discreteCellIndex.size() === embedding.length;
const sizeHint = `${discreteCellIndex.size()} ${
isAllCells ? "(all) " : ""
}cells`;
return (
-
+
);
- }
- return null;
- }}
-
- );
+ })}
+
+ );
+ }
+ return null;
};