@vitessce/feature-list 2.0.3 → 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.
- package/dist/{index.mjs → index.js} +16488 -10354
- package/dist-tsc/FeatureList.d.ts +2 -0
- package/dist-tsc/FeatureList.d.ts.map +1 -0
- package/dist-tsc/FeatureList.js +61 -0
- package/dist-tsc/FeatureListSubscriber.d.ts +32 -0
- package/dist-tsc/FeatureListSubscriber.d.ts.map +1 -0
- package/dist-tsc/FeatureListSubscriber.js +55 -0
- package/dist-tsc/index.d.ts +3 -0
- package/dist-tsc/index.d.ts.map +1 -0
- package/dist-tsc/index.js +2 -2
- package/dist-tsc/selectable-table/SelectableTable.d.ts +21 -0
- package/dist-tsc/selectable-table/SelectableTable.d.ts.map +1 -0
- package/dist-tsc/selectable-table/SelectableTable.js +137 -0
- package/dist-tsc/selectable-table/SelectableTable.test.d.ts +2 -0
- package/dist-tsc/selectable-table/SelectableTable.test.d.ts.map +1 -0
- package/dist-tsc/selectable-table/SelectableTable.test.js +94 -0
- package/dist-tsc/selectable-table/index.d.ts +2 -0
- package/dist-tsc/selectable-table/index.d.ts.map +1 -0
- package/dist-tsc/selectable-table/index.js +1 -0
- package/dist-tsc/selectable-table/styles.d.ts +2 -0
- package/dist-tsc/selectable-table/styles.d.ts.map +1 -0
- package/dist-tsc/selectable-table/styles.js +73 -0
- package/package.json +22 -10
- package/src/FeatureList.js +25 -8
- package/src/FeatureListSubscriber.js +10 -10
- package/src/index.js +2 -2
- package/src/selectable-table/SelectableTable.js +13 -11
- package/src/selectable-table/SelectableTable.test.jsx +47 -7
- package/src/selectable-table/index.js +1 -1
- package/src/selectable-table/styles.js +6 -2
package/src/FeatureList.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import every from 'lodash
|
|
3
|
-
import { makeStyles } from '@material-ui/core
|
|
4
|
-
import {
|
|
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';
|
|
5
6
|
|
|
6
7
|
const useStyles = makeStyles(() => ({
|
|
7
8
|
searchBar: {
|
|
@@ -17,10 +18,13 @@ export default function FeatureList(props) {
|
|
|
17
18
|
hasColorEncoding,
|
|
18
19
|
geneList = [],
|
|
19
20
|
featureLabelsMap,
|
|
21
|
+
featureType,
|
|
20
22
|
geneSelection = [],
|
|
21
23
|
geneFilter = null,
|
|
22
24
|
setGeneSelection,
|
|
23
25
|
enableMultiSelect,
|
|
26
|
+
showTable,
|
|
27
|
+
sort,
|
|
24
28
|
} = props;
|
|
25
29
|
|
|
26
30
|
const classes = useStyles();
|
|
@@ -28,6 +32,7 @@ export default function FeatureList(props) {
|
|
|
28
32
|
const [searchTerm, setSearchTerm] = useState('');
|
|
29
33
|
const [searchResults, setSearchResults] = useState(geneList);
|
|
30
34
|
|
|
35
|
+
|
|
31
36
|
useEffect(() => {
|
|
32
37
|
const results = geneList
|
|
33
38
|
.filter(gene => (
|
|
@@ -51,7 +56,7 @@ export default function FeatureList(props) {
|
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
|
|
59
|
+
let data = searchResults
|
|
55
60
|
.filter(gene => (geneFilter ? geneFilter.includes(gene) : true))
|
|
56
61
|
.map(
|
|
57
62
|
gene => ({
|
|
@@ -59,13 +64,24 @@ export default function FeatureList(props) {
|
|
|
59
64
|
name: featureLabelsMap?.get(gene) || gene,
|
|
60
65
|
value: (geneSelection ? geneSelection.includes(gene) : false),
|
|
61
66
|
}),
|
|
62
|
-
)
|
|
63
|
-
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (sort === 'alphabetical') {
|
|
70
|
+
data = data.sort((a, b) => a.name.localeCompare(b.name));
|
|
71
|
+
}
|
|
64
72
|
|
|
65
73
|
const handleChange = (event) => {
|
|
66
74
|
setSearchTerm(event.target.value);
|
|
67
75
|
};
|
|
68
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
|
+
|
|
69
85
|
return (
|
|
70
86
|
<>
|
|
71
87
|
<input
|
|
@@ -76,7 +92,8 @@ export default function FeatureList(props) {
|
|
|
76
92
|
onChange={handleChange}
|
|
77
93
|
/>
|
|
78
94
|
<SelectableTable
|
|
79
|
-
columns={
|
|
95
|
+
columns={columns}
|
|
96
|
+
columnLabels={columnLabels}
|
|
80
97
|
data={data}
|
|
81
98
|
hasColorEncoding={hasColorEncoding}
|
|
82
99
|
idKey="key"
|
|
@@ -84,7 +101,7 @@ export default function FeatureList(props) {
|
|
|
84
101
|
onChange={onChange}
|
|
85
102
|
allowMultiple={enableMultiSelect}
|
|
86
103
|
allowUncheck={enableMultiSelect}
|
|
87
|
-
showTableHead={
|
|
104
|
+
showTableHead={columnLabels.length > 1}
|
|
88
105
|
/>
|
|
89
106
|
</>
|
|
90
107
|
);
|
|
@@ -6,10 +6,9 @@ import {
|
|
|
6
6
|
useReady, useUrls,
|
|
7
7
|
useFeatureLabelsData, useObsFeatureMatrixIndices,
|
|
8
8
|
useCoordination, useLoaders,
|
|
9
|
-
registerPluginViewType,
|
|
10
9
|
} from '@vitessce/vit-s';
|
|
11
10
|
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
|
12
|
-
import FeatureList from './FeatureList';
|
|
11
|
+
import FeatureList from './FeatureList.js';
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
/**
|
|
@@ -27,6 +26,10 @@ import FeatureList from './FeatureList';
|
|
|
27
26
|
* form of the name of the variable.
|
|
28
27
|
* @param {boolean} props.enableMultiSelect If true, allow
|
|
29
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.
|
|
30
33
|
*/
|
|
31
34
|
export function FeatureListSubscriber(props) {
|
|
32
35
|
const {
|
|
@@ -36,6 +39,8 @@ export function FeatureListSubscriber(props) {
|
|
|
36
39
|
theme,
|
|
37
40
|
title: titleOverride,
|
|
38
41
|
enableMultiSelect = false,
|
|
42
|
+
showTable = false,
|
|
43
|
+
sort = 'alphabetical',
|
|
39
44
|
} = props;
|
|
40
45
|
|
|
41
46
|
const loaders = useLoaders();
|
|
@@ -97,8 +102,11 @@ export function FeatureListSubscriber(props) {
|
|
|
97
102
|
>
|
|
98
103
|
<FeatureList
|
|
99
104
|
hasColorEncoding={cellColorEncoding === 'geneSelection'}
|
|
105
|
+
showTable={showTable}
|
|
100
106
|
geneList={geneList}
|
|
107
|
+
sort={sort}
|
|
101
108
|
featureLabelsMap={featureLabelsMap}
|
|
109
|
+
featureType={featureType}
|
|
102
110
|
geneSelection={geneSelection}
|
|
103
111
|
geneFilter={geneFilter}
|
|
104
112
|
setGeneSelection={setGeneSelectionAndColorEncoding}
|
|
@@ -109,11 +117,3 @@ export function FeatureListSubscriber(props) {
|
|
|
109
117
|
</TitleInfo>
|
|
110
118
|
);
|
|
111
119
|
}
|
|
112
|
-
|
|
113
|
-
export function register() {
|
|
114
|
-
registerPluginViewType(
|
|
115
|
-
ViewType.FEATURE_LIST,
|
|
116
|
-
FeatureListSubscriber,
|
|
117
|
-
COMPONENT_COORDINATION_TYPES[ViewType.FEATURE_LIST],
|
|
118
|
-
);
|
|
119
|
-
}
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { FeatureListSubscriber
|
|
2
|
-
export { default as FeatureList } from './FeatureList';
|
|
1
|
+
export { FeatureListSubscriber } from './FeatureListSubscriber.js';
|
|
2
|
+
export { default as FeatureList } from './FeatureList.js';
|
|
@@ -2,20 +2,23 @@
|
|
|
2
2
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
3
3
|
/* eslint-disable max-len */
|
|
4
4
|
import React, { useEffect, useCallback, useState } from 'react';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
5
|
+
// The CommonJS imports for react-virtualized are needed
|
|
6
|
+
// because the ESM version is broken.
|
|
7
|
+
// Reference: https://github.com/bvaughn/react-virtualized/issues/1632
|
|
8
|
+
import { AutoSizer } from 'react-virtualized/dist/commonjs/AutoSizer/index.js';
|
|
9
|
+
import { Table } from 'react-virtualized/dist/commonjs/Table/index.js';
|
|
10
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
11
|
+
import { union, difference, isEqual } from 'lodash-es';
|
|
11
12
|
import clsx from 'clsx';
|
|
12
|
-
import { useStyles } from './styles';
|
|
13
|
+
import { useStyles } from './styles.js';
|
|
13
14
|
|
|
14
15
|
const SHIFT_KEYCODE = 16;
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* A table with "selectable" rows.
|
|
18
19
|
* @prop {string[]} columns An array of column names, corresponding to data object properties.
|
|
20
|
+
* @prop {string[]} columnLabels An array of labels to be used for the columns, corresponding to `columns`.
|
|
21
|
+
* columnLabels.length must be equal to columns.length.
|
|
19
22
|
* @prop {object[]} data An array of data objects used to populate table rows.
|
|
20
23
|
* @prop {function} onChange Callback function,
|
|
21
24
|
* passed a selection object when `allowMultiple` is false (and `null` if `allowUncheck` is true),
|
|
@@ -34,6 +37,7 @@ export default function SelectableTable(props) {
|
|
|
34
37
|
const {
|
|
35
38
|
hasColorEncoding,
|
|
36
39
|
columns,
|
|
40
|
+
columnLabels,
|
|
37
41
|
data,
|
|
38
42
|
onChange,
|
|
39
43
|
idKey = 'id',
|
|
@@ -189,10 +193,8 @@ export default function SelectableTable(props) {
|
|
|
189
193
|
);
|
|
190
194
|
|
|
191
195
|
const headerRowRenderer = ({ style }) => (
|
|
192
|
-
<div className={
|
|
193
|
-
{
|
|
194
|
-
<div key={column}>{column}</div>
|
|
195
|
-
))}
|
|
196
|
+
<div className={classes.tableRow} style={style}>
|
|
197
|
+
{columnLabels.map(columnLabel => (<div key={columnLabel} className={classes.tableCell} style={{ fontWeight: 'bold' }}>{columnLabel}</div>))}
|
|
196
198
|
</div>
|
|
197
199
|
);
|
|
198
200
|
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import '@testing-library/jest-dom';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
cleanup, render, screen,
|
|
4
|
+
} from '@testing-library/react';
|
|
3
5
|
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { afterEach } from 'vitest'
|
|
6
|
+
import { afterEach } from 'vitest';
|
|
7
|
+
import React from 'react';
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
import SelectableTable from './SelectableTable.js';
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
const user = userEvent.setup();
|
|
9
12
|
|
|
10
13
|
afterEach(() => {
|
|
11
|
-
cleanup()
|
|
14
|
+
cleanup();
|
|
12
15
|
});
|
|
13
16
|
|
|
14
17
|
const tableData = [
|
|
@@ -34,6 +37,7 @@ const tableColumns = [
|
|
|
34
37
|
'Y',
|
|
35
38
|
'Name',
|
|
36
39
|
];
|
|
40
|
+
const columnLabels = ['Label 1', 'Label 2', 'Name'];
|
|
37
41
|
|
|
38
42
|
describe('SelectableTable.js', () => {
|
|
39
43
|
describe('<SelectableTable />', () => {
|
|
@@ -42,11 +46,14 @@ describe('SelectableTable.js', () => {
|
|
|
42
46
|
<SelectableTable
|
|
43
47
|
data={tableData}
|
|
44
48
|
columns={tableColumns}
|
|
49
|
+
columnLabels={columnLabels}
|
|
45
50
|
idKey={tableIdKey}
|
|
46
51
|
testHeight={500}
|
|
47
52
|
testWidth={500}
|
|
48
53
|
/>,
|
|
49
54
|
);
|
|
55
|
+
expect(await screen.findByText('Label 1'));
|
|
56
|
+
expect(await screen.findByText('Label 2'));
|
|
50
57
|
expect(await screen.findByText('Name'));
|
|
51
58
|
// Since the button (although hidden) is also a table-cell, it has a blank string.
|
|
52
59
|
expect(await screen.findAllByText('X1'));
|
|
@@ -55,11 +62,12 @@ describe('SelectableTable.js', () => {
|
|
|
55
62
|
});
|
|
56
63
|
|
|
57
64
|
it('emits single selected object when allowMultiple is false', async () => {
|
|
58
|
-
const p = new Promise((resolve
|
|
65
|
+
const p = new Promise((resolve) => {
|
|
59
66
|
render(
|
|
60
67
|
<SelectableTable
|
|
61
68
|
data={tableData}
|
|
62
69
|
columns={tableColumns}
|
|
70
|
+
columnLabels={columnLabels}
|
|
63
71
|
idKey={tableIdKey}
|
|
64
72
|
onChange={(selection) => {
|
|
65
73
|
expect(Array.isArray(selection)).toBe(false);
|
|
@@ -78,11 +86,12 @@ describe('SelectableTable.js', () => {
|
|
|
78
86
|
});
|
|
79
87
|
|
|
80
88
|
it('emits an array of selected objects when allowMultiple is true', async () => {
|
|
81
|
-
const p = new Promise((resolve
|
|
89
|
+
const p = new Promise((resolve) => {
|
|
82
90
|
render(
|
|
83
91
|
<SelectableTable
|
|
84
92
|
data={tableData}
|
|
85
93
|
columns={tableColumns}
|
|
94
|
+
columnLabels={columnLabels}
|
|
86
95
|
idKey={tableIdKey}
|
|
87
96
|
allowMultiple
|
|
88
97
|
onChange={(selection) => {
|
|
@@ -101,5 +110,36 @@ describe('SelectableTable.js', () => {
|
|
|
101
110
|
});
|
|
102
111
|
await p;
|
|
103
112
|
});
|
|
113
|
+
|
|
114
|
+
it('renders single column values', async () => {
|
|
115
|
+
const customTableColumns = [
|
|
116
|
+
'Name',
|
|
117
|
+
];
|
|
118
|
+
const customColumnLabels = ['Name'];
|
|
119
|
+
|
|
120
|
+
render(
|
|
121
|
+
<SelectableTable
|
|
122
|
+
data={tableData}
|
|
123
|
+
columns={customTableColumns}
|
|
124
|
+
columnLabels={customColumnLabels}
|
|
125
|
+
idKey={tableIdKey}
|
|
126
|
+
testHeight={500}
|
|
127
|
+
testWidth={500}
|
|
128
|
+
/>,
|
|
129
|
+
);
|
|
130
|
+
// write an expect statement to check that Label 1 is not rendered
|
|
131
|
+
const label1 = screen.queryByText('Label 1');
|
|
132
|
+
const label2 = screen.queryByText('Label 2');
|
|
133
|
+
const X1 = screen.queryByText('X1');
|
|
134
|
+
const Y2 = screen.queryByText('Y2');
|
|
135
|
+
|
|
136
|
+
expect(label1).toBeNull();
|
|
137
|
+
expect(label2).toBeNull();
|
|
138
|
+
expect(X1).toBeNull();
|
|
139
|
+
expect(Y2).toBeNull();
|
|
140
|
+
|
|
141
|
+
expect(await screen.findByText('Tile 3'));
|
|
142
|
+
expect(await screen.findByText('Name'));
|
|
143
|
+
});
|
|
104
144
|
});
|
|
105
145
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as SelectableTable } from './SelectableTable';
|
|
1
|
+
export { default as SelectableTable } from './SelectableTable.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
|
-
import { makeStyles } from '@material-ui/core
|
|
2
|
+
import { makeStyles } from '@material-ui/core';
|
|
3
3
|
|
|
4
4
|
export const useStyles = makeStyles(theme => ({
|
|
5
5
|
selectableTable: {
|
|
@@ -29,7 +29,11 @@ export const useStyles = makeStyles(theme => ({
|
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
tableCell: {
|
|
32
|
-
|
|
32
|
+
textAlign: 'left',
|
|
33
|
+
flexBasis: 0,
|
|
34
|
+
flexGrow: 1,
|
|
35
|
+
textOverflow: 'ellipsis',
|
|
36
|
+
whiteSpace: 'nowrap',
|
|
33
37
|
},
|
|
34
38
|
inputContainer: {
|
|
35
39
|
width: '1em',
|