@vitessce/feature-list 2.0.3-beta.0 → 3.0.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.
Files changed (32) hide show
  1. package/dist/index.js +26866 -2
  2. package/dist-tsc/FeatureList.d.ts +2 -0
  3. package/dist-tsc/FeatureList.d.ts.map +1 -0
  4. package/{dist → dist-tsc}/FeatureList.js +17 -8
  5. package/dist-tsc/FeatureListSubscriber.d.ts +32 -0
  6. package/dist-tsc/FeatureListSubscriber.d.ts.map +1 -0
  7. package/{dist → dist-tsc}/FeatureListSubscriber.js +8 -7
  8. package/dist-tsc/index.d.ts +3 -0
  9. package/dist-tsc/index.d.ts.map +1 -0
  10. package/dist-tsc/index.js +2 -0
  11. package/dist-tsc/selectable-table/SelectableTable.d.ts +21 -0
  12. package/dist-tsc/selectable-table/SelectableTable.d.ts.map +1 -0
  13. package/{dist → dist-tsc}/selectable-table/SelectableTable.js +12 -9
  14. package/dist-tsc/selectable-table/SelectableTable.test.d.ts +2 -0
  15. package/dist-tsc/selectable-table/SelectableTable.test.d.ts.map +1 -0
  16. package/{dist → dist-tsc}/selectable-table/SelectableTable.test.js +29 -7
  17. package/dist-tsc/selectable-table/index.d.ts +2 -0
  18. package/dist-tsc/selectable-table/index.d.ts.map +1 -0
  19. package/dist-tsc/selectable-table/index.js +1 -0
  20. package/dist-tsc/selectable-table/styles.d.ts +2 -0
  21. package/dist-tsc/selectable-table/styles.d.ts.map +1 -0
  22. package/{dist → dist-tsc}/selectable-table/styles.js +6 -2
  23. package/package.json +23 -11
  24. package/src/FeatureList.js +108 -0
  25. package/src/FeatureListSubscriber.js +119 -0
  26. package/src/index.js +2 -0
  27. package/src/selectable-table/SelectableTable.js +221 -0
  28. package/src/selectable-table/SelectableTable.test.jsx +145 -0
  29. package/src/selectable-table/index.js +1 -0
  30. package/src/selectable-table/styles.js +75 -0
  31. package/dist/selectable-table/index.js +0 -1
  32. package/dist/selectable-table/style.js +0 -1
@@ -0,0 +1,2 @@
1
+ export default function FeatureList(props: any): JSX.Element;
2
+ //# sourceMappingURL=FeatureList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FeatureList.d.ts","sourceRoot":"","sources":["../src/FeatureList.js"],"names":[],"mappings":"AAeA,6DA4FC"}
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React, { useEffect, useState } from 'react';
3
- import every from 'lodash/every';
4
- import { makeStyles } from '@material-ui/core/styles';
5
- import { SelectableTable } from './selectable-table/index';
3
+ import { every } from 'lodash-es';
4
+ import { makeStyles } from '@material-ui/core';
5
+ import { capitalize } from '@vitessce/utils';
6
+ import { SelectableTable } from './selectable-table/index.js';
6
7
  const useStyles = makeStyles(() => ({
7
8
  searchBar: {
8
9
  marginBottom: '4px',
@@ -12,7 +13,7 @@ const useStyles = makeStyles(() => ({
12
13
  },
13
14
  }));
14
15
  export default function FeatureList(props) {
15
- const { hasColorEncoding, geneList = [], featureLabelsMap, geneSelection = [], geneFilter = null, setGeneSelection, enableMultiSelect, } = props;
16
+ const { hasColorEncoding, geneList = [], featureLabelsMap, featureType, geneSelection = [], geneFilter = null, setGeneSelection, enableMultiSelect, showTable, sort, } = props;
16
17
  const classes = useStyles();
17
18
  const [searchTerm, setSearchTerm] = useState('');
18
19
  const [searchResults, setSearchResults] = useState(geneList);
@@ -37,16 +38,24 @@ export default function FeatureList(props) {
37
38
  }
38
39
  }
39
40
  }
40
- const data = searchResults
41
+ let data = searchResults
41
42
  .filter(gene => (geneFilter ? geneFilter.includes(gene) : true))
42
43
  .map(gene => ({
43
44
  key: gene,
44
45
  name: featureLabelsMap?.get(gene) || gene,
45
46
  value: (geneSelection ? geneSelection.includes(gene) : false),
46
- }))
47
- .sort((a, b) => a.name.localeCompare(b.name));
47
+ }));
48
+ if (sort === 'alphabetical') {
49
+ data = data.sort((a, b) => a.name.localeCompare(b.name));
50
+ }
48
51
  const handleChange = (event) => {
49
52
  setSearchTerm(event.target.value);
50
53
  };
51
- return (_jsxs(_Fragment, { children: [_jsx("input", { className: classes.searchBar, type: "text", placeholder: "Search", value: searchTerm, onChange: handleChange }), _jsx(SelectableTable, { columns: ['name'], data: data, hasColorEncoding: hasColorEncoding, idKey: "key", valueKey: "value", onChange: onChange, allowMultiple: enableMultiSelect, allowUncheck: enableMultiSelect, showTableHead: false })] }));
54
+ const columns = ['name'];
55
+ const columnLabels = [`${capitalize(featureType)} ID`];
56
+ if (showTable) {
57
+ columns.push('key');
58
+ columnLabels.push('Alternate ID');
59
+ }
60
+ 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 })] }));
52
61
  }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * A subscriber component for a gene listing component.
3
+ * @param {object} props
4
+ * @param {string} props.theme The current theme name.
5
+ * @param {object} props.coordinationScopes The mapping from coordination types to coordination
6
+ * scopes.
7
+ * @param {function} props.removeGridComponent The callback function to pass to TitleInfo,
8
+ * to call when the component has been removed from the grid.
9
+ * @param {string} props.title The component title.
10
+ * @param {string} props.variablesLabelOverride The singular form
11
+ * of the name of the variable.
12
+ * @param {string} props.variablesPluralLabelOverride The plural
13
+ * form of the name of the variable.
14
+ * @param {boolean} props.enableMultiSelect If true, allow
15
+ * shift-clicking to select multiple genes.
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
18
+ * it is not equal to `alphabetical`, the genes will be displayed in the feature list in
19
+ * the original order.
20
+ */
21
+ export function FeatureListSubscriber(props: {
22
+ theme: string;
23
+ coordinationScopes: object;
24
+ removeGridComponent: Function;
25
+ title: string;
26
+ variablesLabelOverride: string;
27
+ variablesPluralLabelOverride: string;
28
+ enableMultiSelect: boolean;
29
+ showTable: boolean;
30
+ sort: string;
31
+ }): JSX.Element;
32
+ //# sourceMappingURL=FeatureListSubscriber.d.ts.map
@@ -0,0 +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"}
@@ -2,9 +2,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from 'react';
3
3
  import plur from 'plur';
4
4
  import { capitalize, commaNumber } from '@vitessce/utils';
5
- import { TitleInfo, useReady, useUrls, useFeatureLabelsData, useObsFeatureMatrixIndices, useCoordination, useLoaders, registerPluginViewType, } from '@vitessce/vit-s';
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
- import FeatureList from './FeatureList';
7
+ import FeatureList from './FeatureList.js';
8
8
  /**
9
9
  * A subscriber component for a gene listing component.
10
10
  * @param {object} props
@@ -20,9 +20,13 @@ import FeatureList from './FeatureList';
20
20
  * form of the name of the variable.
21
21
  * @param {boolean} props.enableMultiSelect If true, allow
22
22
  * shift-clicking to select multiple genes.
23
+ * @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
+ * it is not equal to `alphabetical`, the genes will be displayed in the feature list in
26
+ * the original order.
23
27
  */
24
28
  export function FeatureListSubscriber(props) {
25
- const { coordinationScopes, removeGridComponent, variablesLabelOverride, theme, title: titleOverride, enableMultiSelect = false, } = props;
29
+ const { coordinationScopes, removeGridComponent, variablesLabelOverride, theme, title: titleOverride, enableMultiSelect = false, showTable = false, sort = 'alphabetical', } = props;
26
30
  const loaders = useLoaders();
27
31
  // Get "props" from the coordination space.
28
32
  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);
@@ -47,8 +51,5 @@ export function FeatureListSubscriber(props) {
47
51
  // Virtual scroll is used but this allows for the same styling as a scroll component
48
52
  // even though this no longer uses the TitleInfo component's
49
53
  // scroll css (SelectableTable is virtual scroll).
50
- isScroll: true, removeGridComponent: removeGridComponent, isReady: isReady, urls: urls, children: _jsx(FeatureList, { hasColorEncoding: cellColorEncoding === 'geneSelection', geneList: geneList, featureLabelsMap: featureLabelsMap, geneSelection: geneSelection, geneFilter: geneFilter, setGeneSelection: setGeneSelectionAndColorEncoding, setGeneFilter: setGeneFilter, setGeneHighlight: setGeneHighlight, enableMultiSelect: enableMultiSelect }) }));
51
- }
52
- export function register() {
53
- registerPluginViewType(ViewType.FEATURE_LIST, FeatureListSubscriber, COMPONENT_COORDINATION_TYPES[ViewType.FEATURE_LIST]);
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 }) }));
54
55
  }
@@ -0,0 +1,3 @@
1
+ export { FeatureListSubscriber } from "./FeatureListSubscriber.js";
2
+ export { default as FeatureList } from "./FeatureList.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { FeatureListSubscriber } from './FeatureListSubscriber.js';
2
+ export { default as FeatureList } from './FeatureList.js';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A table with "selectable" rows.
3
+ * @prop {string[]} columns An array of column names, corresponding to data object properties.
4
+ * @prop {string[]} columnLabels An array of labels to be used for the columns, corresponding to `columns`.
5
+ * columnLabels.length must be equal to columns.length.
6
+ * @prop {object[]} data An array of data objects used to populate table rows.
7
+ * @prop {function} onChange Callback function,
8
+ * passed a selection object when `allowMultiple` is false (and `null` if `allowUncheck` is true),
9
+ * or passed an array of selection objects when `allowMultiple` is true.
10
+ * @prop {string} idKey The key for a unique identifier property of `data` objects.
11
+ * @prop {string} valueKey If initially-selected rows are required,
12
+ * this key specifies a boolean property of the `data` objects
13
+ * indicating those rows that should be initially selected.
14
+ * @prop {boolean} allowMultiple Whether to allow multiple rows to be selected.
15
+ * @prop {boolean} allowUncheck Whether to allow selected rows to be un-checked. By default, false.
16
+ * @prop {boolean} showTableHead Whether to show the table header element. By default, true.
17
+ * @prop {boolean} showTableInputs Whether to show the table input elements for each row.
18
+ * By default, false.
19
+ */
20
+ export default function SelectableTable(props: any): JSX.Element;
21
+ //# sourceMappingURL=SelectableTable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectableTable.d.ts","sourceRoot":"","sources":["../../src/selectable-table/SelectableTable.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,iEAyLC"}
@@ -3,18 +3,21 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  /* eslint-disable jsx-a11y/click-events-have-key-events */
4
4
  /* eslint-disable max-len */
5
5
  import React, { useEffect, useCallback, useState } from 'react';
6
- import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
7
- import Table from 'react-virtualized/dist/commonjs/Table';
8
- import uuidv4 from 'uuid/v4';
9
- import union from 'lodash/union';
10
- import difference from 'lodash/difference';
11
- import isEqual from 'lodash/isEqual';
6
+ // The CommonJS imports for react-virtualized are needed
7
+ // because the ESM version is broken.
8
+ // Reference: https://github.com/bvaughn/react-virtualized/issues/1632
9
+ import { AutoSizer } from 'react-virtualized/dist/commonjs/AutoSizer/index.js';
10
+ import { Table } from 'react-virtualized/dist/commonjs/Table/index.js';
11
+ import { v4 as uuidv4 } from 'uuid';
12
+ import { union, difference, isEqual } from 'lodash-es';
12
13
  import clsx from 'clsx';
13
- import { useStyles } from './styles';
14
+ import { useStyles } from './styles.js';
14
15
  const SHIFT_KEYCODE = 16;
15
16
  /**
16
17
  * A table with "selectable" rows.
17
18
  * @prop {string[]} columns An array of column names, corresponding to data object properties.
19
+ * @prop {string[]} columnLabels An array of labels to be used for the columns, corresponding to `columns`.
20
+ * columnLabels.length must be equal to columns.length.
18
21
  * @prop {object[]} data An array of data objects used to populate table rows.
19
22
  * @prop {function} onChange Callback function,
20
23
  * passed a selection object when `allowMultiple` is false (and `null` if `allowUncheck` is true),
@@ -30,7 +33,7 @@ const SHIFT_KEYCODE = 16;
30
33
  * By default, false.
31
34
  */
32
35
  export default function SelectableTable(props) {
33
- const { hasColorEncoding, columns, data, onChange, idKey = 'id', valueKey = 'value', allowMultiple = false, allowUncheck = false, showTableHead = true, showTableInputs = false, testHeight = undefined, testWidth = undefined, } = props;
36
+ const { hasColorEncoding, columns, columnLabels, data, onChange, idKey = 'id', valueKey = 'value', allowMultiple = false, allowUncheck = false, showTableHead = true, showTableInputs = false, testHeight = undefined, testWidth = undefined, } = props;
34
37
  const [selectedRows, setSelectedRows] = useState(null);
35
38
  const [isCheckingMultiple, setIsCheckingMultiple] = useState(false);
36
39
  // Enable selecting multiple rows while the shift key is down.
@@ -127,7 +130,7 @@ export default function SelectableTable(props) {
127
130
  const rowRenderer = ({ index, style }) => (
128
131
  // eslint-disable-next-line jsx-a11y/interactive-supports-focus
129
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]));
130
- const headerRowRenderer = ({ style }) => (_jsx("div", { className: clsx({ [classes.hiddenInputColumn]: !showTableInputs }, classes.tableRow), style: style, children: columns.map(column => (_jsx("div", { children: column }, column))) }));
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))) }));
131
134
  return (_jsx("div", { className: classes.selectableTable, children: _jsx(AutoSizer, { children: ({ width, height }) => (_jsx(Table, { height: testHeight || height, gridStyle: { outline: 'none' }, rowCount: data.length,
132
135
  // 24 is 1 em + padding in either direction (see _selectable_table.scss).
133
136
  rowHeight: 24, headerHeight: showTableHead ? 24 : undefined, rowRenderer: rowRenderer, width: testWidth || width, headerRowRenderer: showTableHead ? headerRowRenderer : undefined, rowGetter: ({ index }) => data[index] })) }) }));
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=SelectableTable.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectableTable.test.d.ts","sourceRoot":"","sources":["../../src/selectable-table/SelectableTable.test.jsx"],"names":[],"mappings":""}
@@ -1,10 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import '@testing-library/jest-dom';
3
- import { cleanup, render, screen } from '@testing-library/react';
3
+ import { cleanup, render, screen, } from '@testing-library/react';
4
4
  import userEvent from '@testing-library/user-event';
5
5
  import { afterEach } from 'vitest';
6
+ import React from 'react';
7
+ import SelectableTable from './SelectableTable.js';
6
8
  const user = userEvent.setup();
7
- import SelectableTable from './SelectableTable';
8
9
  afterEach(() => {
9
10
  cleanup();
10
11
  });
@@ -31,10 +32,13 @@ const tableColumns = [
31
32
  'Y',
32
33
  'Name',
33
34
  ];
35
+ const columnLabels = ['Label 1', 'Label 2', 'Name'];
34
36
  describe('SelectableTable.js', () => {
35
37
  describe('<SelectableTable />', () => {
36
38
  it('renders column values', async () => {
37
- render(_jsx(SelectableTable, { data: tableData, columns: tableColumns, idKey: tableIdKey, testHeight: 500, testWidth: 500 }));
39
+ render(_jsx(SelectableTable, { data: tableData, columns: tableColumns, columnLabels: columnLabels, idKey: tableIdKey, testHeight: 500, testWidth: 500 }));
40
+ expect(await screen.findByText('Label 1'));
41
+ expect(await screen.findByText('Label 2'));
38
42
  expect(await screen.findByText('Name'));
39
43
  // Since the button (although hidden) is also a table-cell, it has a blank string.
40
44
  expect(await screen.findAllByText('X1'));
@@ -42,8 +46,8 @@ describe('SelectableTable.js', () => {
42
46
  expect(await screen.findByText('Tile 3'));
43
47
  });
44
48
  it('emits single selected object when allowMultiple is false', async () => {
45
- const p = new Promise((resolve, reject) => {
46
- render(_jsx(SelectableTable, { data: tableData, columns: tableColumns, idKey: tableIdKey, onChange: (selection) => {
49
+ const p = new Promise((resolve) => {
50
+ render(_jsx(SelectableTable, { data: tableData, columns: tableColumns, columnLabels: columnLabels, idKey: tableIdKey, onChange: (selection) => {
47
51
  expect(Array.isArray(selection)).toBe(false);
48
52
  expect(selection.Name).toEqual('Tile 1');
49
53
  resolve();
@@ -55,8 +59,8 @@ describe('SelectableTable.js', () => {
55
59
  await p;
56
60
  });
57
61
  it('emits an array of selected objects when allowMultiple is true', async () => {
58
- const p = new Promise((resolve, reject) => {
59
- render(_jsx(SelectableTable, { data: tableData, columns: tableColumns, idKey: tableIdKey, allowMultiple: true, onChange: (selection) => {
62
+ const p = new Promise((resolve) => {
63
+ render(_jsx(SelectableTable, { data: tableData, columns: tableColumns, columnLabels: columnLabels, idKey: tableIdKey, allowMultiple: true, onChange: (selection) => {
60
64
  expect(Array.isArray(selection)).toBe(true);
61
65
  expect(selection.length).toEqual(1);
62
66
  expect(selection[0].Name).toEqual('Tile 2');
@@ -68,5 +72,23 @@ describe('SelectableTable.js', () => {
68
72
  });
69
73
  await p;
70
74
  });
75
+ it('renders single column values', async () => {
76
+ const customTableColumns = [
77
+ 'Name',
78
+ ];
79
+ const customColumnLabels = ['Name'];
80
+ render(_jsx(SelectableTable, { data: tableData, columns: customTableColumns, columnLabels: customColumnLabels, idKey: tableIdKey, testHeight: 500, testWidth: 500 }));
81
+ // write an expect statement to check that Label 1 is not rendered
82
+ const label1 = screen.queryByText('Label 1');
83
+ const label2 = screen.queryByText('Label 2');
84
+ const X1 = screen.queryByText('X1');
85
+ const Y2 = screen.queryByText('Y2');
86
+ expect(label1).toBeNull();
87
+ expect(label2).toBeNull();
88
+ expect(X1).toBeNull();
89
+ expect(Y2).toBeNull();
90
+ expect(await screen.findByText('Tile 3'));
91
+ expect(await screen.findByText('Name'));
92
+ });
71
93
  });
72
94
  });
@@ -0,0 +1,2 @@
1
+ export { default as SelectableTable } from "./SelectableTable.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/selectable-table/index.js"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export { default as SelectableTable } from './SelectableTable.js';
@@ -0,0 +1,2 @@
1
+ export const useStyles: (props?: any) => import("@material-ui/core/styles/withStyles").ClassNameMap<"selectableTable" | "checkbox" | "radio" | "tableRow" | "tableItem" | "tableCell" | "inputContainer" | "hiddenInputColumn" | "radioOrCheckbox">;
2
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/selectable-table/styles.js"],"names":[],"mappings":"AAGA,oPAuEI"}
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable max-len */
2
- import { makeStyles } from '@material-ui/core/styles';
2
+ import { makeStyles } from '@material-ui/core';
3
3
  export const useStyles = makeStyles(theme => ({
4
4
  selectableTable: {
5
5
  flex: '1 1 auto',
@@ -27,7 +27,11 @@ export const useStyles = makeStyles(theme => ({
27
27
  },
28
28
  },
29
29
  tableCell: {
30
- padding: '0 4px',
30
+ textAlign: 'left',
31
+ flexBasis: 0,
32
+ flexGrow: 1,
33
+ textOverflow: 'ellipsis',
34
+ whiteSpace: 'nowrap',
31
35
  },
32
36
  inputContainer: {
33
37
  width: '1em',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitessce/feature-list",
3
- "version": "2.0.3-beta.0",
3
+ "version": "3.0.0",
4
4
  "author": "Gehlenborg Lab",
5
5
  "homepage": "http://vitessce.io",
6
6
  "repository": {
@@ -8,32 +8,44 @@
8
8
  "url": "git+https://github.com/vitessce/vitessce.git"
9
9
  },
10
10
  "license": "MIT",
11
+ "type": "module",
11
12
  "main": "dist/index.js",
12
13
  "files": [
13
- "dist"
14
+ "src",
15
+ "dist",
16
+ "dist-tsc"
14
17
  ],
15
18
  "dependencies": {
16
19
  "@material-ui/core": "~4.12.3",
17
20
  "clsx": "^1.1.1",
18
- "lodash": "^4.17.21",
21
+ "lodash-es": "^4.17.21",
19
22
  "plur": "^5.1.0",
20
23
  "react-virtualized": "^9.22.2",
21
- "uuid": "^3.3.2",
22
- "@vitessce/constants-internal": "2.0.3-beta.0",
23
- "@vitessce/vit-s": "2.0.3-beta.0",
24
- "@vitessce/utils": "2.0.3-beta.0"
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
28
  },
26
29
  "devDependencies": {
27
30
  "react": "^18.0.0",
28
- "vite": "^3.0.0",
29
- "vitest": "^0.23.4"
31
+ "vite": "^4.3.0",
32
+ "vitest": "^0.23.4",
33
+ "@testing-library/jest-dom": "^5.16.4",
34
+ "@testing-library/react": "^13.3.0",
35
+ "@testing-library/user-event": "^14.2.1"
30
36
  },
31
37
  "peerDependencies": {
32
38
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
33
39
  },
34
40
  "scripts": {
35
- "start": "tsc --watch",
36
- "build": "tsc",
41
+ "bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
37
42
  "test": "pnpm exec vitest --run -r ../../../ --dir ."
43
+ },
44
+ "module": "dist/index.js",
45
+ "exports": {
46
+ ".": {
47
+ "types": "./dist-tsc/index.d.ts",
48
+ "import": "./dist/index.js"
49
+ }
38
50
  }
39
51
  }
@@ -0,0 +1,108 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { every } from 'lodash-es';
3
+ import { makeStyles } from '@material-ui/core';
4
+ import { capitalize } from '@vitessce/utils';
5
+ import { SelectableTable } from './selectable-table/index.js';
6
+
7
+ const useStyles = makeStyles(() => ({
8
+ searchBar: {
9
+ marginBottom: '4px',
10
+ border: '0',
11
+ padding: '2px',
12
+ borderRadius: '2px',
13
+ },
14
+ }));
15
+
16
+ export default function FeatureList(props) {
17
+ const {
18
+ hasColorEncoding,
19
+ geneList = [],
20
+ featureLabelsMap,
21
+ featureType,
22
+ geneSelection = [],
23
+ geneFilter = null,
24
+ setGeneSelection,
25
+ enableMultiSelect,
26
+ showTable,
27
+ sort,
28
+ } = props;
29
+
30
+ const classes = useStyles();
31
+
32
+ const [searchTerm, setSearchTerm] = useState('');
33
+ const [searchResults, setSearchResults] = useState(geneList);
34
+
35
+
36
+ useEffect(() => {
37
+ const results = geneList
38
+ .filter(gene => (
39
+ gene.toLowerCase().includes(searchTerm.toLowerCase())
40
+ || featureLabelsMap?.get(gene)?.toLowerCase().includes(searchTerm.toLowerCase())
41
+ ));
42
+ setSearchResults(results);
43
+ }, [searchTerm, geneList, featureLabelsMap]);
44
+
45
+ function onChange(selection) {
46
+ if (setGeneSelection && selection) {
47
+ if (Array.isArray(selection)) {
48
+ if (selection.length > 0 && every(selection, s => s.key)) {
49
+ setGeneSelection(selection.map(s => s.key));
50
+ } else {
51
+ setGeneSelection(null);
52
+ }
53
+ } else if (selection.key) {
54
+ setGeneSelection([selection.key]);
55
+ }
56
+ }
57
+ }
58
+
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
+ );
68
+
69
+ if (sort === 'alphabetical') {
70
+ data = data.sort((a, b) => a.name.localeCompare(b.name));
71
+ }
72
+
73
+ const handleChange = (event) => {
74
+ setSearchTerm(event.target.value);
75
+ };
76
+
77
+ const columns = ['name'];
78
+ const columnLabels = [`${capitalize(featureType)} ID`];
79
+
80
+ if (showTable) {
81
+ columns.push('key');
82
+ columnLabels.push('Alternate ID');
83
+ }
84
+
85
+ return (
86
+ <>
87
+ <input
88
+ className={classes.searchBar}
89
+ type="text"
90
+ placeholder="Search"
91
+ value={searchTerm}
92
+ onChange={handleChange}
93
+ />
94
+ <SelectableTable
95
+ columns={columns}
96
+ columnLabels={columnLabels}
97
+ data={data}
98
+ hasColorEncoding={hasColorEncoding}
99
+ idKey="key"
100
+ valueKey="value"
101
+ onChange={onChange}
102
+ allowMultiple={enableMultiSelect}
103
+ allowUncheck={enableMultiSelect}
104
+ showTableHead={columnLabels.length > 1}
105
+ />
106
+ </>
107
+ );
108
+ }
@@ -0,0 +1,119 @@
1
+ import React from 'react';
2
+ import plur from 'plur';
3
+ import { capitalize, commaNumber } from '@vitessce/utils';
4
+ import {
5
+ TitleInfo,
6
+ useReady, useUrls,
7
+ useFeatureLabelsData, useObsFeatureMatrixIndices,
8
+ useCoordination, useLoaders,
9
+ } from '@vitessce/vit-s';
10
+ import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
11
+ import FeatureList from './FeatureList.js';
12
+
13
+
14
+ /**
15
+ * A subscriber component for a gene listing component.
16
+ * @param {object} props
17
+ * @param {string} props.theme The current theme name.
18
+ * @param {object} props.coordinationScopes The mapping from coordination types to coordination
19
+ * scopes.
20
+ * @param {function} props.removeGridComponent The callback function to pass to TitleInfo,
21
+ * to call when the component has been removed from the grid.
22
+ * @param {string} props.title The component title.
23
+ * @param {string} props.variablesLabelOverride The singular form
24
+ * of the name of the variable.
25
+ * @param {string} props.variablesPluralLabelOverride The plural
26
+ * form of the name of the variable.
27
+ * @param {boolean} props.enableMultiSelect If true, allow
28
+ * shift-clicking to select multiple genes.
29
+ * @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
+ * it is not equal to `alphabetical`, the genes will be displayed in the feature list in
32
+ * the original order.
33
+ */
34
+ export function FeatureListSubscriber(props) {
35
+ const {
36
+ coordinationScopes,
37
+ removeGridComponent,
38
+ variablesLabelOverride,
39
+ theme,
40
+ title: titleOverride,
41
+ enableMultiSelect = false,
42
+ showTable = false,
43
+ sort = 'alphabetical',
44
+ } = props;
45
+
46
+ const loaders = useLoaders();
47
+
48
+ // Get "props" from the coordination space.
49
+ const [{
50
+ dataset,
51
+ featureType,
52
+ featureSelection: geneSelection,
53
+ featureFilter: geneFilter,
54
+ obsColorEncoding: cellColorEncoding,
55
+ }, {
56
+ setFeatureSelection: setGeneSelection,
57
+ setFeatureFilter: setGeneFilter,
58
+ setFeatureHighlight: setGeneHighlight,
59
+ setObsColorEncoding: setCellColorEncoding,
60
+ }] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.FEATURE_LIST], coordinationScopes);
61
+
62
+ const variablesLabel = variablesLabelOverride || featureType;
63
+
64
+ const title = titleOverride || `${capitalize(variablesLabel)} List`;
65
+
66
+ const [urls, addUrl] = useUrls(loaders, dataset);
67
+
68
+ // Get data from loaders using the data hooks.
69
+ // TODO: support multiple feature labels using featureLabelsType coordination values.
70
+ const [{ featureLabelsMap }, featureLabelsStatus] = useFeatureLabelsData(
71
+ loaders, dataset, addUrl, false, {}, {},
72
+ { featureType },
73
+ );
74
+ const [{ featureIndex }, matrixIndicesStatus] = useObsFeatureMatrixIndices(
75
+ loaders, dataset, addUrl, true,
76
+ { featureType },
77
+ );
78
+ const isReady = useReady([
79
+ featureLabelsStatus,
80
+ matrixIndicesStatus,
81
+ ]);
82
+ const geneList = featureIndex || [];
83
+ const numGenes = geneList.length;
84
+
85
+ function setGeneSelectionAndColorEncoding(newSelection) {
86
+ setGeneSelection(newSelection);
87
+ setCellColorEncoding('geneSelection');
88
+ }
89
+
90
+ return (
91
+ <TitleInfo
92
+ title={title}
93
+ info={`${commaNumber(numGenes)} ${plur(variablesLabel, numGenes)}`}
94
+ theme={theme}
95
+ // Virtual scroll is used but this allows for the same styling as a scroll component
96
+ // even though this no longer uses the TitleInfo component's
97
+ // scroll css (SelectableTable is virtual scroll).
98
+ isScroll
99
+ removeGridComponent={removeGridComponent}
100
+ isReady={isReady}
101
+ urls={urls}
102
+ >
103
+ <FeatureList
104
+ hasColorEncoding={cellColorEncoding === 'geneSelection'}
105
+ showTable={showTable}
106
+ geneList={geneList}
107
+ sort={sort}
108
+ featureLabelsMap={featureLabelsMap}
109
+ featureType={featureType}
110
+ geneSelection={geneSelection}
111
+ geneFilter={geneFilter}
112
+ setGeneSelection={setGeneSelectionAndColorEncoding}
113
+ setGeneFilter={setGeneFilter}
114
+ setGeneHighlight={setGeneHighlight}
115
+ enableMultiSelect={enableMultiSelect}
116
+ />
117
+ </TitleInfo>
118
+ );
119
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { FeatureListSubscriber } from './FeatureListSubscriber.js';
2
+ export { default as FeatureList } from './FeatureList.js';