@vitessce/feature-list 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"FeatureList.d.ts","sourceRoot":"","sources":["../src/FeatureList.js"],"names":[],"mappings":"AAeA,6DA4FC"}
1
+ {"version":3,"file":"FeatureList.d.ts","sourceRoot":"","sources":["../src/FeatureList.js"],"names":[],"mappings":"AAeA,6DAgHC"}
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useEffect, useState } from 'react';
2
+ import React, { useEffect, useState, useMemo } from 'react';
3
3
  import { every } from 'lodash-es';
4
4
  import { makeStyles } from '@material-ui/core';
5
- import { capitalize } from '@vitessce/utils';
6
5
  import { SelectableTable } from './selectable-table/index.js';
6
+ import { ALT_COLNAME } from './constants.js';
7
7
  const useStyles = makeStyles(() => ({
8
8
  searchBar: {
9
9
  marginBottom: '4px',
@@ -13,10 +13,14 @@ const useStyles = makeStyles(() => ({
13
13
  },
14
14
  }));
15
15
  export default function FeatureList(props) {
16
- const { hasColorEncoding, geneList = [], featureLabelsMap, featureType, geneSelection = [], geneFilter = null, setGeneSelection, enableMultiSelect, showTable, sort, } = props;
16
+ const { hasColorEncoding, geneList = [], featureLabelsMap, geneSelection = [], geneFilter = null, setGeneSelection, enableMultiSelect, showFeatureTable, featureListSort, featureListSortKey, hasFeatureLabels, primaryColumnName, } = props;
17
17
  const classes = useStyles();
18
18
  const [searchTerm, setSearchTerm] = useState('');
19
19
  const [searchResults, setSearchResults] = useState(geneList);
20
+ // In FeatureListSubscriber, we think in terms of 'featureIndex' and 'featureLabels'.
21
+ // Here in FeatureList, we need to map these to 'key' or 'name' before
22
+ // passing to the SelectableTable component.
23
+ const selectableTableSortKey = (featureListSortKey === 'featureIndex' ? 'key' : 'name');
20
24
  useEffect(() => {
21
25
  const results = geneList
22
26
  .filter(gene => (gene.toLowerCase().includes(searchTerm.toLowerCase())
@@ -38,24 +42,35 @@ export default function FeatureList(props) {
38
42
  }
39
43
  }
40
44
  }
41
- let data = searchResults
42
- .filter(gene => (geneFilter ? geneFilter.includes(gene) : true))
43
- .map(gene => ({
44
- key: gene,
45
- name: featureLabelsMap?.get(gene) || gene,
46
- value: (geneSelection ? geneSelection.includes(gene) : false),
47
- }));
48
- if (sort === 'alphabetical') {
49
- data = data.sort((a, b) => a.name.localeCompare(b.name));
50
- }
45
+ const data = useMemo(() => {
46
+ const preSortedData = searchResults
47
+ .filter(gene => (geneFilter ? geneFilter.includes(gene) : true))
48
+ .map(gene => ({
49
+ key: gene,
50
+ name: featureLabelsMap?.get(gene) || gene,
51
+ value: (geneSelection ? geneSelection.includes(gene) : false),
52
+ }));
53
+ if (preSortedData && featureListSort === 'alphabetical' && preSortedData.length > 0) {
54
+ return preSortedData.sort((a, b) => a[selectableTableSortKey].localeCompare(b[selectableTableSortKey]));
55
+ }
56
+ return preSortedData;
57
+ }, [featureListSort, selectableTableSortKey, searchResults,
58
+ geneFilter, featureLabelsMap, geneSelection,
59
+ ]);
51
60
  const handleChange = (event) => {
52
61
  setSearchTerm(event.target.value);
53
62
  };
54
- const columns = ['name'];
55
- const columnLabels = [`${capitalize(featureType)} ID`];
56
- if (showTable) {
57
- columns.push('key');
58
- columnLabels.push('Alternate ID');
59
- }
63
+ const [columns, columnLabels] = useMemo(() => {
64
+ if (showFeatureTable && hasFeatureLabels) {
65
+ return [
66
+ ['name', 'key'],
67
+ [primaryColumnName, ALT_COLNAME],
68
+ ];
69
+ }
70
+ return [
71
+ ['name'],
72
+ [primaryColumnName],
73
+ ];
74
+ }, [showFeatureTable, primaryColumnName, hasFeatureLabels]);
60
75
  return (_jsxs(_Fragment, { children: [_jsx("input", { className: classes.searchBar, type: "text", placeholder: "Search", value: searchTerm, onChange: handleChange }), _jsx(SelectableTable, { columns: columns, columnLabels: columnLabels, data: data, hasColorEncoding: hasColorEncoding, idKey: "key", valueKey: "value", onChange: onChange, allowMultiple: enableMultiSelect, allowUncheck: enableMultiSelect, showTableHead: columnLabels.length > 1 })] }));
61
76
  }
@@ -0,0 +1,2 @@
1
+ export default function FeatureListOptions(props: any): JSX.Element;
2
+ //# sourceMappingURL=FeatureListOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FeatureListOptions.d.ts","sourceRoot":"","sources":["../src/FeatureListOptions.js"],"names":[],"mappings":"AAMA,oEA8FC"}
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { OptionsContainer, OptionSelect, usePlotOptionsStyles } from '@vitessce/vit-s';
4
+ import { TableCell, TableRow, Checkbox } from '@material-ui/core';
5
+ import { FEATURELIST_SORT_OPTIONS, ALT_COLNAME } from './constants.js';
6
+ export default function FeatureListOptions(props) {
7
+ const { children, featureListSort, setFeatureListSort, featureListSortKey, setFeatureListSortKey, showFeatureTable, setShowFeatureTable, hasFeatureLabels, primaryColumnName, } = props;
8
+ function handleFeatureListSortChange(event) {
9
+ setFeatureListSort(event.target.value);
10
+ }
11
+ function handleFeatureListSortKeyChange(event) {
12
+ setFeatureListSortKey(event.target.value);
13
+ }
14
+ function handleShowTableChange(event) {
15
+ setShowFeatureTable(event.target.checked);
16
+ }
17
+ const classes = usePlotOptionsStyles();
18
+ return (_jsxs(OptionsContainer, { children: [children, _jsxs(TableRow, { children: [_jsx(TableCell, { className: classes.labelCell, htmlFor: "feature-list-sort-option-select", children: "Sort Ordering" }), _jsx(TableCell, { children: _jsx(OptionSelect, { className: classes.select, value: featureListSort, onChange: handleFeatureListSortChange, inputProps: {
19
+ id: 'feature-list-sort-option-select',
20
+ }, children: FEATURELIST_SORT_OPTIONS.map(option => (_jsx("option", { value: option, children: option }, option))) }) })] }), hasFeatureLabels ? (_jsxs(_Fragment, { children: [_jsxs(TableRow, { children: [_jsx(TableCell, { className: classes.labelCell, htmlFor: "feature-list-sort-key-select", children: "Sort Key" }), _jsx(TableCell, { children: _jsx(OptionSelect, { className: classes.select, disabled: featureListSort === 'original', value: featureListSortKey, onChange: handleFeatureListSortKeyChange, inputProps: {
21
+ id: 'feature-list-sort-key-select',
22
+ }, children: hasFeatureLabels ? (_jsxs(_Fragment, { children: [_jsx("option", { value: "featureLabels", children: primaryColumnName }), _jsx("option", { value: "featureIndex", children: ALT_COLNAME })] })) : (_jsx("option", { value: "featureIndex", children: primaryColumnName })) }) })] }), _jsxs(TableRow, { children: [_jsx(TableCell, { className: classes.labelCell, children: "Show Alternate IDs" }), _jsx(TableCell, { className: classes.inputCell, children: _jsx(Checkbox, { className: classes.tableCheckbox, checked: showFeatureTable, onChange: handleShowTableChange, name: "feature-list-show-table", color: "default" }) })] })] })) : null] }));
23
+ }
@@ -14,9 +14,10 @@
14
14
  * @param {boolean} props.enableMultiSelect If true, allow
15
15
  * shift-clicking to select multiple genes.
16
16
  * @param {boolean} props.showTable If true, shows a table with the feature name and id.
17
- * @param {string} props.sort The sort order of the genes. If sort is defined and
17
+ * @param {'alphabetical'|'original'} props.sort The sort order of the genes. If sort is defined and
18
18
  * it is not equal to `alphabetical`, the genes will be displayed in the feature list in
19
19
  * the original order.
20
+ * @param {'featureIndex'|'featureLabels'|null} props.sortKey The information to use for sorting.
20
21
  */
21
22
  export function FeatureListSubscriber(props: {
22
23
  theme: string;
@@ -27,6 +28,7 @@ export function FeatureListSubscriber(props: {
27
28
  variablesPluralLabelOverride: string;
28
29
  enableMultiSelect: boolean;
29
30
  showTable: boolean;
30
- sort: string;
31
+ sort: 'alphabetical' | 'original';
32
+ sortKey: 'featureIndex' | 'featureLabels' | null;
31
33
  }): JSX.Element;
32
34
  //# sourceMappingURL=FeatureListSubscriber.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FeatureListSubscriber.d.ts","sourceRoot":"","sources":["../src/FeatureListSubscriber.js"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;;;GAmBG;AACH;IAjByB,KAAK,EAAnB,MAAM;IACQ,kBAAkB,EAAhC,MAAM;IAEU,mBAAmB;IAErB,KAAK,EAAnB,MAAM;IACQ,sBAAsB,EAApC,MAAM;IAEQ,4BAA4B,EAA1C,MAAM;IAES,iBAAiB,EAAhC,OAAO;IAEQ,SAAS,EAAxB,OAAO;IACO,IAAI,EAAlB,MAAM;gBAyFhB"}
1
+ {"version":3,"file":"FeatureListSubscriber.d.ts","sourceRoot":"","sources":["../src/FeatureListSubscriber.js"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH;IAlByB,KAAK,EAAnB,MAAM;IACQ,kBAAkB,EAAhC,MAAM;IAEU,mBAAmB;IAErB,KAAK,EAAnB,MAAM;IACQ,sBAAsB,EAApC,MAAM;IAEQ,4BAA4B,EAA1C,MAAM;IAES,iBAAiB,EAAhC,OAAO;IAEQ,SAAS,EAAxB,OAAO;IAC0B,IAAI,EAArC,cAAc,GAAC,UAAU;IAGkB,OAAO,EAAlD,cAAc,GAAC,eAAe,GAAC,IAAI;gBAgH7C"}
@@ -1,10 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from 'react';
2
+ import React, { useState } from 'react';
3
3
  import plur from 'plur';
4
4
  import { capitalize, commaNumber } from '@vitessce/utils';
5
5
  import { TitleInfo, useReady, useUrls, useFeatureLabelsData, useObsFeatureMatrixIndices, useCoordination, useLoaders, } from '@vitessce/vit-s';
6
6
  import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
7
7
  import FeatureList from './FeatureList.js';
8
+ import FeatureListOptions from './FeatureListOptions.js';
8
9
  /**
9
10
  * A subscriber component for a gene listing component.
10
11
  * @param {object} props
@@ -21,35 +22,45 @@ import FeatureList from './FeatureList.js';
21
22
  * @param {boolean} props.enableMultiSelect If true, allow
22
23
  * shift-clicking to select multiple genes.
23
24
  * @param {boolean} props.showTable If true, shows a table with the feature name and id.
24
- * @param {string} props.sort The sort order of the genes. If sort is defined and
25
+ * @param {'alphabetical'|'original'} props.sort The sort order of the genes. If sort is defined and
25
26
  * it is not equal to `alphabetical`, the genes will be displayed in the feature list in
26
27
  * the original order.
28
+ * @param {'featureIndex'|'featureLabels'|null} props.sortKey The information to use for sorting.
27
29
  */
28
30
  export function FeatureListSubscriber(props) {
29
- const { coordinationScopes, removeGridComponent, variablesLabelOverride, theme, title: titleOverride, enableMultiSelect = false, showTable = false, sort = 'alphabetical', } = props;
31
+ const { coordinationScopes, removeGridComponent, variablesLabelOverride, theme, title: titleOverride, enableMultiSelect = false, showTable = false, sort = 'alphabetical', sortKey = null, } = props;
30
32
  const loaders = useLoaders();
31
33
  // Get "props" from the coordination space.
32
34
  const [{ dataset, featureType, featureSelection: geneSelection, featureFilter: geneFilter, obsColorEncoding: cellColorEncoding, }, { setFeatureSelection: setGeneSelection, setFeatureFilter: setGeneFilter, setFeatureHighlight: setGeneHighlight, setObsColorEncoding: setCellColorEncoding, }] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.FEATURE_LIST], coordinationScopes);
33
35
  const variablesLabel = variablesLabelOverride || featureType;
34
36
  const title = titleOverride || `${capitalize(variablesLabel)} List`;
35
- const [urls, addUrl] = useUrls(loaders, dataset);
36
37
  // Get data from loaders using the data hooks.
37
38
  // TODO: support multiple feature labels using featureLabelsType coordination values.
38
- const [{ featureLabelsMap }, featureLabelsStatus] = useFeatureLabelsData(loaders, dataset, addUrl, false, {}, {}, { featureType });
39
- const [{ featureIndex }, matrixIndicesStatus] = useObsFeatureMatrixIndices(loaders, dataset, addUrl, true, { featureType });
39
+ const [{ featureLabelsMap }, featureLabelsStatus, featureLabelsUrls] = useFeatureLabelsData(loaders, dataset, false, {}, {}, { featureType });
40
+ const [{ featureIndex }, matrixIndicesStatus, obsFeatureMatrixUrls] = useObsFeatureMatrixIndices(loaders, dataset, true, { featureType });
40
41
  const isReady = useReady([
41
42
  featureLabelsStatus,
42
43
  matrixIndicesStatus,
43
44
  ]);
45
+ const urls = useUrls([
46
+ featureLabelsUrls,
47
+ obsFeatureMatrixUrls,
48
+ ]);
44
49
  const geneList = featureIndex || [];
45
50
  const numGenes = geneList.length;
51
+ const hasFeatureLabels = Boolean(featureLabelsMap);
46
52
  function setGeneSelectionAndColorEncoding(newSelection) {
47
53
  setGeneSelection(newSelection);
48
54
  setCellColorEncoding('geneSelection');
49
55
  }
56
+ const [showFeatureTable, setShowFeatureTable] = useState(showTable);
57
+ const [featureListSort, setFeatureListSort] = useState(sort);
58
+ const [featureListSortKey, setFeatureListSortKey] = useState(null);
59
+ const initialSortKey = sortKey || (hasFeatureLabels ? 'featureLabels' : 'featureIndex');
60
+ const primaryColumnName = `${capitalize(featureType)} ID`;
50
61
  return (_jsx(TitleInfo, { title: title, info: `${commaNumber(numGenes)} ${plur(variablesLabel, numGenes)}`, theme: theme,
51
62
  // Virtual scroll is used but this allows for the same styling as a scroll component
52
63
  // even though this no longer uses the TitleInfo component's
53
64
  // scroll css (SelectableTable is virtual scroll).
54
- isScroll: true, removeGridComponent: removeGridComponent, isReady: isReady, urls: urls, children: _jsx(FeatureList, { hasColorEncoding: cellColorEncoding === 'geneSelection', showTable: showTable, geneList: geneList, sort: sort, featureLabelsMap: featureLabelsMap, featureType: featureType, geneSelection: geneSelection, geneFilter: geneFilter, setGeneSelection: setGeneSelectionAndColorEncoding, setGeneFilter: setGeneFilter, setGeneHighlight: setGeneHighlight, enableMultiSelect: enableMultiSelect }) }));
65
+ isScroll: true, removeGridComponent: removeGridComponent, isReady: isReady, urls: urls, options: (_jsx(FeatureListOptions, { featureListSort: featureListSort, setFeatureListSort: setFeatureListSort, featureListSortKey: featureListSortKey || initialSortKey, setFeatureListSortKey: setFeatureListSortKey, showFeatureTable: showFeatureTable, setShowFeatureTable: setShowFeatureTable, hasFeatureLabels: Boolean(featureLabelsMap), primaryColumnName: primaryColumnName })), children: _jsx(FeatureList, { hasColorEncoding: cellColorEncoding === 'geneSelection', showFeatureTable: showFeatureTable, geneList: geneList, featureListSort: featureListSort, featureListSortKey: featureListSortKey || initialSortKey, featureLabelsMap: featureLabelsMap, featureType: featureType, geneSelection: geneSelection, geneFilter: geneFilter, setGeneSelection: setGeneSelectionAndColorEncoding, setGeneFilter: setGeneFilter, setGeneHighlight: setGeneHighlight, enableMultiSelect: enableMultiSelect, hasFeatureLabels: Boolean(featureLabelsMap), primaryColumnName: primaryColumnName }) }));
55
66
  }
@@ -0,0 +1,3 @@
1
+ export const FEATURELIST_SORT_OPTIONS: string[];
2
+ export const ALT_COLNAME: "Alternate ID";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.js"],"names":[],"mappings":"AAAA,gDAGE;AAEF,yCAA0C"}
@@ -0,0 +1,5 @@
1
+ export const FEATURELIST_SORT_OPTIONS = [
2
+ 'alphabetical',
3
+ 'original',
4
+ ];
5
+ export const ALT_COLNAME = 'Alternate ID';
@@ -129,7 +129,7 @@ export default function SelectableTable(props) {
129
129
  const inputUuid = uuidv4();
130
130
  const rowRenderer = ({ index, style }) => (
131
131
  // eslint-disable-next-line jsx-a11y/interactive-supports-focus
132
- _jsxs("div", { className: clsx(classes.tableItem, classes.tableRow, { 'row-checked': isSelected(data[index][idKey]) }), style: style, role: "button", onClick: () => onSelectRow(data[index][idKey], !isSelected(data[index][idKey]) || !hasColorEncoding), children: [_jsx("div", { className: clsx(classes.inputContainer, classes.tableCell, { [classes.hiddenInputColumn]: !showTableInputs }), children: _jsx("label", { htmlFor: `${inputUuid}_${data[index][idKey]}`, children: _jsx("input", { id: `${inputUuid}_${data[index][idKey]}`, type: "checkbox", className: clsx(classes.radioOrCheckbox, isCheckingMultiple ? classes.checkbox : classes.radio), name: inputUuid, value: data[index][idKey], onChange: handleInputChange, checked: isSelected(data[index][idKey]) }) }) }), columns.map(column => (_jsx("div", { className: classes.tableCell, children: data[index][column] }, column)))] }, data[index][idKey]));
132
+ _jsxs("div", { className: clsx(classes.tableItem, classes.tableRow, { 'row-checked': isSelected(data[index][idKey]) }), style: style, role: "button", onClick: () => onSelectRow(data[index][idKey], !isSelected(data[index][idKey]) || !hasColorEncoding), children: [_jsx("div", { className: clsx(classes.inputContainer, classes.tableCell, { [classes.hiddenInputColumn]: !showTableInputs }), children: _jsx("label", { htmlFor: `${inputUuid}_${data[index][idKey]}`, children: _jsx("input", { id: `${inputUuid}_${data[index][idKey]}`, type: "checkbox", className: clsx(classes.radioOrCheckbox, isCheckingMultiple ? classes.tableCheckbox : classes.tableRadio), name: inputUuid, value: data[index][idKey], onChange: handleInputChange, checked: isSelected(data[index][idKey]) }) }) }), columns.map(column => (_jsx("div", { className: classes.tableCell, children: data[index][column] }, column)))] }, data[index][idKey]));
133
133
  const headerRowRenderer = ({ style }) => (_jsx("div", { className: classes.tableRow, style: style, children: columnLabels.map(columnLabel => (_jsx("div", { className: classes.tableCell, style: { fontWeight: 'bold' }, children: columnLabel }, columnLabel))) }));
134
134
  return (_jsx("div", { className: classes.selectableTable, children: _jsx(AutoSizer, { children: ({ width, height }) => (_jsx(Table, { height: testHeight || height, gridStyle: { outline: 'none' }, rowCount: data.length,
135
135
  // 24 is 1 em + padding in either direction (see _selectable_table.scss).
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { describe, it, expect, afterEach } from 'vitest';
2
3
  import '@testing-library/jest-dom';
3
4
  import { cleanup, render, screen, } from '@testing-library/react';
4
5
  import userEvent from '@testing-library/user-event';
5
- import { afterEach } from 'vitest';
6
6
  import React from 'react';
7
7
  import SelectableTable from './SelectableTable.js';
8
8
  const user = userEvent.setup();
@@ -1,2 +1,2 @@
1
- export const useStyles: (props?: any) => import("@material-ui/core/styles/withStyles").ClassNameMap<"selectableTable" | "checkbox" | "radio" | "tableRow" | "tableItem" | "tableCell" | "inputContainer" | "hiddenInputColumn" | "radioOrCheckbox">;
1
+ export const useStyles: (props?: any) => import("@material-ui/core/styles/withStyles").ClassNameMap<"selectableTable" | "tableRow" | "tableItem" | "tableCell" | "inputContainer" | "hiddenInputColumn" | "radioOrCheckbox" | "tableRadio" | "tableCheckbox">;
2
2
  //# sourceMappingURL=styles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/selectable-table/styles.js"],"names":[],"mappings":"AAGA,oPAuEI"}
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/selectable-table/styles.js"],"names":[],"mappings":"AAGA,8PAuEI"}
@@ -64,10 +64,10 @@ export const useStyles = makeStyles(theme => ({
64
64
  backgroundClip: 'unset',
65
65
  },
66
66
  },
67
- radio: {
67
+ tableRadio: {
68
68
  borderRadius: '50%',
69
69
  },
70
- checkbox: {
70
+ tableCheckbox: {
71
71
  borderRadius: '2px',
72
72
  },
73
73
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/feature-list",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -22,24 +22,24 @@
22
22
  "plur": "^5.1.0",
23
23
  "react-virtualized": "^9.22.2",
24
24
  "uuid": "^9.0.0",
25
- "@vitessce/constants-internal": "3.0.0",
26
- "@vitessce/utils": "3.0.0",
27
- "@vitessce/vit-s": "3.0.0"
25
+ "@vitessce/constants-internal": "3.1.0",
26
+ "@vitessce/utils": "3.1.0",
27
+ "@vitessce/vit-s": "3.1.0"
28
28
  },
29
29
  "devDependencies": {
30
- "react": "^18.0.0",
31
- "vite": "^4.3.0",
32
- "vitest": "^0.23.4",
33
30
  "@testing-library/jest-dom": "^5.16.4",
34
31
  "@testing-library/react": "^13.3.0",
35
- "@testing-library/user-event": "^14.2.1"
32
+ "@testing-library/user-event": "^14.2.1",
33
+ "react": "^18.0.0",
34
+ "vite": "^4.3.0",
35
+ "vitest": "^0.32.2"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
39
39
  },
40
40
  "scripts": {
41
41
  "bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
42
- "test": "pnpm exec vitest --run -r ../../../ --dir ."
42
+ "test": "pnpm exec vitest --run"
43
43
  },
44
44
  "module": "dist/index.js",
45
45
  "exports": {
@@ -1,8 +1,8 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useEffect, useState, useMemo } from 'react';
2
2
  import { every } from 'lodash-es';
3
3
  import { makeStyles } from '@material-ui/core';
4
- import { capitalize } from '@vitessce/utils';
5
4
  import { SelectableTable } from './selectable-table/index.js';
5
+ import { ALT_COLNAME } from './constants.js';
6
6
 
7
7
  const useStyles = makeStyles(() => ({
8
8
  searchBar: {
@@ -18,13 +18,15 @@ export default function FeatureList(props) {
18
18
  hasColorEncoding,
19
19
  geneList = [],
20
20
  featureLabelsMap,
21
- featureType,
22
21
  geneSelection = [],
23
22
  geneFilter = null,
24
23
  setGeneSelection,
25
24
  enableMultiSelect,
26
- showTable,
27
- sort,
25
+ showFeatureTable,
26
+ featureListSort,
27
+ featureListSortKey,
28
+ hasFeatureLabels,
29
+ primaryColumnName,
28
30
  } = props;
29
31
 
30
32
  const classes = useStyles();
@@ -32,6 +34,11 @@ export default function FeatureList(props) {
32
34
  const [searchTerm, setSearchTerm] = useState('');
33
35
  const [searchResults, setSearchResults] = useState(geneList);
34
36
 
37
+ // In FeatureListSubscriber, we think in terms of 'featureIndex' and 'featureLabels'.
38
+ // Here in FeatureList, we need to map these to 'key' or 'name' before
39
+ // passing to the SelectableTable component.
40
+ const selectableTableSortKey = (featureListSortKey === 'featureIndex' ? 'key' : 'name');
41
+
35
42
 
36
43
  useEffect(() => {
37
44
  const results = geneList
@@ -56,31 +63,44 @@ export default function FeatureList(props) {
56
63
  }
57
64
  }
58
65
 
59
- let data = searchResults
60
- .filter(gene => (geneFilter ? geneFilter.includes(gene) : true))
61
- .map(
62
- gene => ({
63
- key: gene,
64
- name: featureLabelsMap?.get(gene) || gene,
65
- value: (geneSelection ? geneSelection.includes(gene) : false),
66
- }),
67
- );
66
+ const data = useMemo(() => {
67
+ const preSortedData = searchResults
68
+ .filter(gene => (geneFilter ? geneFilter.includes(gene) : true))
69
+ .map(
70
+ gene => ({
71
+ key: gene,
72
+ name: featureLabelsMap?.get(gene) || gene,
73
+ value: (geneSelection ? geneSelection.includes(gene) : false),
74
+ }),
75
+ );
68
76
 
69
- if (sort === 'alphabetical') {
70
- data = data.sort((a, b) => a.name.localeCompare(b.name));
71
- }
77
+ if (preSortedData && featureListSort === 'alphabetical' && preSortedData.length > 0) {
78
+ return preSortedData.sort(
79
+ (a, b) => a[selectableTableSortKey].localeCompare(b[selectableTableSortKey]),
80
+ );
81
+ }
82
+
83
+ return preSortedData;
84
+ }, [featureListSort, selectableTableSortKey, searchResults,
85
+ geneFilter, featureLabelsMap, geneSelection,
86
+ ]);
72
87
 
73
88
  const handleChange = (event) => {
74
89
  setSearchTerm(event.target.value);
75
90
  };
76
91
 
77
- const columns = ['name'];
78
- const columnLabels = [`${capitalize(featureType)} ID`];
79
-
80
- if (showTable) {
81
- columns.push('key');
82
- columnLabels.push('Alternate ID');
83
- }
92
+ const [columns, columnLabels] = useMemo(() => {
93
+ if (showFeatureTable && hasFeatureLabels) {
94
+ return [
95
+ ['name', 'key'],
96
+ [primaryColumnName, ALT_COLNAME],
97
+ ];
98
+ }
99
+ return [
100
+ ['name'],
101
+ [primaryColumnName],
102
+ ];
103
+ }, [showFeatureTable, primaryColumnName, hasFeatureLabels]);
84
104
 
85
105
  return (
86
106
  <>
@@ -0,0 +1,101 @@
1
+ import React from 'react';
2
+ import { OptionsContainer, OptionSelect, usePlotOptionsStyles } from '@vitessce/vit-s';
3
+ import { TableCell, TableRow, Checkbox } from '@material-ui/core';
4
+ import { FEATURELIST_SORT_OPTIONS, ALT_COLNAME } from './constants.js';
5
+
6
+
7
+ export default function FeatureListOptions(props) {
8
+ const {
9
+ children,
10
+ featureListSort,
11
+ setFeatureListSort,
12
+ featureListSortKey,
13
+ setFeatureListSortKey,
14
+ showFeatureTable,
15
+ setShowFeatureTable,
16
+ hasFeatureLabels,
17
+ primaryColumnName,
18
+ } = props;
19
+
20
+ function handleFeatureListSortChange(event) {
21
+ setFeatureListSort(event.target.value);
22
+ }
23
+
24
+ function handleFeatureListSortKeyChange(event) {
25
+ setFeatureListSortKey(event.target.value);
26
+ }
27
+
28
+ function handleShowTableChange(event) {
29
+ setShowFeatureTable(event.target.checked);
30
+ }
31
+
32
+ const classes = usePlotOptionsStyles();
33
+
34
+ return (
35
+ <OptionsContainer>
36
+ {children}
37
+ <TableRow>
38
+ <TableCell className={classes.labelCell} htmlFor="feature-list-sort-option-select">
39
+ Sort Ordering
40
+ </TableCell>
41
+ <TableCell>
42
+ <OptionSelect
43
+ className={classes.select}
44
+ value={featureListSort}
45
+ onChange={handleFeatureListSortChange}
46
+ inputProps={{
47
+ id: 'feature-list-sort-option-select',
48
+ }}
49
+ >
50
+ {FEATURELIST_SORT_OPTIONS.map(option => (
51
+ <option key={option} value={option}>{option}</option>
52
+ ))}
53
+ </OptionSelect>
54
+ </TableCell>
55
+ </TableRow>
56
+ {hasFeatureLabels ? (
57
+ <>
58
+ <TableRow>
59
+ <TableCell className={classes.labelCell} htmlFor="feature-list-sort-key-select">
60
+ Sort Key
61
+ </TableCell>
62
+ <TableCell>
63
+ <OptionSelect
64
+ className={classes.select}
65
+ disabled={featureListSort === 'original'}
66
+ value={featureListSortKey}
67
+ onChange={handleFeatureListSortKeyChange}
68
+ inputProps={{
69
+ id: 'feature-list-sort-key-select',
70
+ }}
71
+ >
72
+ {hasFeatureLabels ? (
73
+ <>
74
+ <option value="featureLabels">{primaryColumnName}</option>
75
+ <option value="featureIndex">{ALT_COLNAME}</option>
76
+ </>
77
+ ) : (
78
+ <option value="featureIndex">{primaryColumnName}</option>
79
+ )}
80
+ </OptionSelect>
81
+ </TableCell>
82
+ </TableRow>
83
+ <TableRow>
84
+ <TableCell className={classes.labelCell}>
85
+ Show Alternate IDs
86
+ </TableCell>
87
+ <TableCell className={classes.inputCell}>
88
+ <Checkbox
89
+ className={classes.tableCheckbox}
90
+ checked={showFeatureTable}
91
+ onChange={handleShowTableChange}
92
+ name="feature-list-show-table"
93
+ color="default"
94
+ />
95
+ </TableCell>
96
+ </TableRow>
97
+ </>
98
+ ) : null}
99
+ </OptionsContainer>
100
+ );
101
+ }
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import plur from 'plur';
3
3
  import { capitalize, commaNumber } from '@vitessce/utils';
4
4
  import {
@@ -9,6 +9,7 @@ import {
9
9
  } from '@vitessce/vit-s';
10
10
  import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
11
11
  import FeatureList from './FeatureList.js';
12
+ import FeatureListOptions from './FeatureListOptions.js';
12
13
 
13
14
 
14
15
  /**
@@ -27,9 +28,10 @@ import FeatureList from './FeatureList.js';
27
28
  * @param {boolean} props.enableMultiSelect If true, allow
28
29
  * shift-clicking to select multiple genes.
29
30
  * @param {boolean} props.showTable If true, shows a table with the feature name and id.
30
- * @param {string} props.sort The sort order of the genes. If sort is defined and
31
+ * @param {'alphabetical'|'original'} props.sort The sort order of the genes. If sort is defined and
31
32
  * it is not equal to `alphabetical`, the genes will be displayed in the feature list in
32
33
  * the original order.
34
+ * @param {'featureIndex'|'featureLabels'|null} props.sortKey The information to use for sorting.
33
35
  */
34
36
  export function FeatureListSubscriber(props) {
35
37
  const {
@@ -41,6 +43,7 @@ export function FeatureListSubscriber(props) {
41
43
  enableMultiSelect = false,
42
44
  showTable = false,
43
45
  sort = 'alphabetical',
46
+ sortKey = null,
44
47
  } = props;
45
48
 
46
49
  const loaders = useLoaders();
@@ -63,29 +66,38 @@ export function FeatureListSubscriber(props) {
63
66
 
64
67
  const title = titleOverride || `${capitalize(variablesLabel)} List`;
65
68
 
66
- const [urls, addUrl] = useUrls(loaders, dataset);
67
-
68
69
  // Get data from loaders using the data hooks.
69
70
  // TODO: support multiple feature labels using featureLabelsType coordination values.
70
- const [{ featureLabelsMap }, featureLabelsStatus] = useFeatureLabelsData(
71
- loaders, dataset, addUrl, false, {}, {},
71
+ const [{ featureLabelsMap }, featureLabelsStatus, featureLabelsUrls] = useFeatureLabelsData(
72
+ loaders, dataset, false, {}, {},
72
73
  { featureType },
73
74
  );
74
- const [{ featureIndex }, matrixIndicesStatus] = useObsFeatureMatrixIndices(
75
- loaders, dataset, addUrl, true,
75
+ const [{ featureIndex }, matrixIndicesStatus, obsFeatureMatrixUrls] = useObsFeatureMatrixIndices(
76
+ loaders, dataset, true,
76
77
  { featureType },
77
78
  );
78
79
  const isReady = useReady([
79
80
  featureLabelsStatus,
80
81
  matrixIndicesStatus,
81
82
  ]);
83
+ const urls = useUrls([
84
+ featureLabelsUrls,
85
+ obsFeatureMatrixUrls,
86
+ ]);
82
87
  const geneList = featureIndex || [];
83
88
  const numGenes = geneList.length;
89
+ const hasFeatureLabels = Boolean(featureLabelsMap);
84
90
 
85
91
  function setGeneSelectionAndColorEncoding(newSelection) {
86
92
  setGeneSelection(newSelection);
87
93
  setCellColorEncoding('geneSelection');
88
94
  }
95
+ const [showFeatureTable, setShowFeatureTable] = useState(showTable);
96
+ const [featureListSort, setFeatureListSort] = useState(sort);
97
+ const [featureListSortKey, setFeatureListSortKey] = useState(null);
98
+ const initialSortKey = sortKey || (hasFeatureLabels ? 'featureLabels' : 'featureIndex');
99
+
100
+ const primaryColumnName = `${capitalize(featureType)} ID`;
89
101
 
90
102
  return (
91
103
  <TitleInfo
@@ -99,12 +111,25 @@ export function FeatureListSubscriber(props) {
99
111
  removeGridComponent={removeGridComponent}
100
112
  isReady={isReady}
101
113
  urls={urls}
114
+ options={(
115
+ <FeatureListOptions
116
+ featureListSort={featureListSort}
117
+ setFeatureListSort={setFeatureListSort}
118
+ featureListSortKey={featureListSortKey || initialSortKey}
119
+ setFeatureListSortKey={setFeatureListSortKey}
120
+ showFeatureTable={showFeatureTable}
121
+ setShowFeatureTable={setShowFeatureTable}
122
+ hasFeatureLabels={Boolean(featureLabelsMap)}
123
+ primaryColumnName={primaryColumnName}
124
+ />
125
+ )}
102
126
  >
103
127
  <FeatureList
104
128
  hasColorEncoding={cellColorEncoding === 'geneSelection'}
105
- showTable={showTable}
129
+ showFeatureTable={showFeatureTable}
106
130
  geneList={geneList}
107
- sort={sort}
131
+ featureListSort={featureListSort}
132
+ featureListSortKey={featureListSortKey || initialSortKey}
108
133
  featureLabelsMap={featureLabelsMap}
109
134
  featureType={featureType}
110
135
  geneSelection={geneSelection}
@@ -113,6 +138,8 @@ export function FeatureListSubscriber(props) {
113
138
  setGeneFilter={setGeneFilter}
114
139
  setGeneHighlight={setGeneHighlight}
115
140
  enableMultiSelect={enableMultiSelect}
141
+ hasFeatureLabels={Boolean(featureLabelsMap)}
142
+ primaryColumnName={primaryColumnName}
116
143
  />
117
144
  </TitleInfo>
118
145
  );