@vitessce/feature-list 2.0.3 → 3.0.1
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} +21949 -13431
- package/dist-tsc/FeatureList.d.ts +2 -0
- package/dist-tsc/FeatureList.d.ts.map +1 -0
- package/dist-tsc/FeatureList.js +76 -0
- package/dist-tsc/FeatureListOptions.d.ts +2 -0
- package/dist-tsc/FeatureListOptions.d.ts.map +1 -0
- package/dist-tsc/FeatureListOptions.js +23 -0
- package/dist-tsc/FeatureListSubscriber.d.ts +34 -0
- package/dist-tsc/FeatureListSubscriber.d.ts.map +1 -0
- package/dist-tsc/FeatureListSubscriber.js +66 -0
- package/dist-tsc/constants.d.ts +3 -0
- package/dist-tsc/constants.d.ts.map +1 -0
- package/dist-tsc/constants.js +5 -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 +23 -11
- package/src/FeatureList.js +53 -16
- package/src/FeatureListOptions.js +101 -0
- package/src/FeatureListSubscriber.js +44 -17
- package/src/constants.js +6 -0
- package/src/index.js +2 -2
- package/src/selectable-table/SelectableTable.js +14 -12
- package/src/selectable-table/SelectableTable.test.jsx +47 -7
- package/src/selectable-table/index.js +1 -1
- package/src/selectable-table/styles.js +8 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/feature-list",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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
|
-
"
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/index.js",
|
|
12
13
|
"files": [
|
|
14
|
+
"src",
|
|
13
15
|
"dist",
|
|
14
|
-
"
|
|
16
|
+
"dist-tsc"
|
|
15
17
|
],
|
|
16
18
|
"dependencies": {
|
|
17
19
|
"@material-ui/core": "~4.12.3",
|
|
18
20
|
"clsx": "^1.1.1",
|
|
19
|
-
"lodash": "^4.17.21",
|
|
21
|
+
"lodash-es": "^4.17.21",
|
|
20
22
|
"plur": "^5.1.0",
|
|
21
23
|
"react-virtualized": "^9.22.2",
|
|
22
|
-
"uuid": "^
|
|
23
|
-
"@vitessce/constants-internal": "
|
|
24
|
-
"@vitessce/utils": "
|
|
25
|
-
"@vitessce/vit-s": "
|
|
24
|
+
"uuid": "^9.0.0",
|
|
25
|
+
"@vitessce/constants-internal": "3.0.1",
|
|
26
|
+
"@vitessce/utils": "3.0.1",
|
|
27
|
+
"@vitessce/vit-s": "3.0.1"
|
|
26
28
|
},
|
|
27
29
|
"devDependencies": {
|
|
30
|
+
"@testing-library/jest-dom": "^5.16.4",
|
|
31
|
+
"@testing-library/react": "^13.3.0",
|
|
32
|
+
"@testing-library/user-event": "^14.2.1",
|
|
28
33
|
"react": "^18.0.0",
|
|
29
|
-
"vite": "^3.0
|
|
30
|
-
"vitest": "^0.
|
|
34
|
+
"vite": "^4.3.0",
|
|
35
|
+
"vitest": "^0.32.2"
|
|
31
36
|
},
|
|
32
37
|
"peerDependencies": {
|
|
33
38
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
34
39
|
},
|
|
35
40
|
"scripts": {
|
|
36
41
|
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
|
|
37
|
-
"test": "pnpm exec vitest --run
|
|
42
|
+
"test": "pnpm exec vitest --run"
|
|
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
|
}
|
package/src/FeatureList.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import every from 'lodash
|
|
3
|
-
import { makeStyles } from '@material-ui/core
|
|
4
|
-
import { SelectableTable } from './selectable-table/index';
|
|
1
|
+
import React, { useEffect, useState, useMemo } from 'react';
|
|
2
|
+
import { every } from 'lodash-es';
|
|
3
|
+
import { makeStyles } from '@material-ui/core';
|
|
4
|
+
import { SelectableTable } from './selectable-table/index.js';
|
|
5
|
+
import { ALT_COLNAME } from './constants.js';
|
|
5
6
|
|
|
6
7
|
const useStyles = makeStyles(() => ({
|
|
7
8
|
searchBar: {
|
|
@@ -21,6 +22,11 @@ export default function FeatureList(props) {
|
|
|
21
22
|
geneFilter = null,
|
|
22
23
|
setGeneSelection,
|
|
23
24
|
enableMultiSelect,
|
|
25
|
+
showFeatureTable,
|
|
26
|
+
featureListSort,
|
|
27
|
+
featureListSortKey,
|
|
28
|
+
hasFeatureLabels,
|
|
29
|
+
primaryColumnName,
|
|
24
30
|
} = props;
|
|
25
31
|
|
|
26
32
|
const classes = useStyles();
|
|
@@ -28,6 +34,12 @@ export default function FeatureList(props) {
|
|
|
28
34
|
const [searchTerm, setSearchTerm] = useState('');
|
|
29
35
|
const [searchResults, setSearchResults] = useState(geneList);
|
|
30
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
|
+
|
|
42
|
+
|
|
31
43
|
useEffect(() => {
|
|
32
44
|
const results = geneList
|
|
33
45
|
.filter(gene => (
|
|
@@ -51,21 +63,45 @@ export default function FeatureList(props) {
|
|
|
51
63
|
}
|
|
52
64
|
}
|
|
53
65
|
|
|
54
|
-
const data =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
+
);
|
|
76
|
+
|
|
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
|
+
]);
|
|
64
87
|
|
|
65
88
|
const handleChange = (event) => {
|
|
66
89
|
setSearchTerm(event.target.value);
|
|
67
90
|
};
|
|
68
91
|
|
|
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]);
|
|
104
|
+
|
|
69
105
|
return (
|
|
70
106
|
<>
|
|
71
107
|
<input
|
|
@@ -76,7 +112,8 @@ export default function FeatureList(props) {
|
|
|
76
112
|
onChange={handleChange}
|
|
77
113
|
/>
|
|
78
114
|
<SelectableTable
|
|
79
|
-
columns={
|
|
115
|
+
columns={columns}
|
|
116
|
+
columnLabels={columnLabels}
|
|
80
117
|
data={data}
|
|
81
118
|
hasColorEncoding={hasColorEncoding}
|
|
82
119
|
idKey="key"
|
|
@@ -84,7 +121,7 @@ export default function FeatureList(props) {
|
|
|
84
121
|
onChange={onChange}
|
|
85
122
|
allowMultiple={enableMultiSelect}
|
|
86
123
|
allowUncheck={enableMultiSelect}
|
|
87
|
-
showTableHead={
|
|
124
|
+
showTableHead={columnLabels.length > 1}
|
|
88
125
|
/>
|
|
89
126
|
</>
|
|
90
127
|
);
|
|
@@ -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 {
|
|
@@ -6,10 +6,10 @@ 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';
|
|
12
|
+
import FeatureListOptions from './FeatureListOptions.js';
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -27,6 +27,11 @@ import FeatureList from './FeatureList';
|
|
|
27
27
|
* form of the name of the variable.
|
|
28
28
|
* @param {boolean} props.enableMultiSelect If true, allow
|
|
29
29
|
* shift-clicking to select multiple genes.
|
|
30
|
+
* @param {boolean} props.showTable If true, shows a table with the feature name and id.
|
|
31
|
+
* @param {'alphabetical'|'original'} props.sort The sort order of the genes. If sort is defined and
|
|
32
|
+
* it is not equal to `alphabetical`, the genes will be displayed in the feature list in
|
|
33
|
+
* the original order.
|
|
34
|
+
* @param {'featureIndex'|'featureLabels'|null} props.sortKey The information to use for sorting.
|
|
30
35
|
*/
|
|
31
36
|
export function FeatureListSubscriber(props) {
|
|
32
37
|
const {
|
|
@@ -36,6 +41,9 @@ export function FeatureListSubscriber(props) {
|
|
|
36
41
|
theme,
|
|
37
42
|
title: titleOverride,
|
|
38
43
|
enableMultiSelect = false,
|
|
44
|
+
showTable = false,
|
|
45
|
+
sort = 'alphabetical',
|
|
46
|
+
sortKey = null,
|
|
39
47
|
} = props;
|
|
40
48
|
|
|
41
49
|
const loaders = useLoaders();
|
|
@@ -58,29 +66,38 @@ export function FeatureListSubscriber(props) {
|
|
|
58
66
|
|
|
59
67
|
const title = titleOverride || `${capitalize(variablesLabel)} List`;
|
|
60
68
|
|
|
61
|
-
const [urls, addUrl] = useUrls(loaders, dataset);
|
|
62
|
-
|
|
63
69
|
// Get data from loaders using the data hooks.
|
|
64
70
|
// TODO: support multiple feature labels using featureLabelsType coordination values.
|
|
65
|
-
const [{ featureLabelsMap }, featureLabelsStatus] = useFeatureLabelsData(
|
|
66
|
-
loaders, dataset,
|
|
71
|
+
const [{ featureLabelsMap }, featureLabelsStatus, featureLabelsUrls] = useFeatureLabelsData(
|
|
72
|
+
loaders, dataset, false, {}, {},
|
|
67
73
|
{ featureType },
|
|
68
74
|
);
|
|
69
|
-
const [{ featureIndex }, matrixIndicesStatus] = useObsFeatureMatrixIndices(
|
|
70
|
-
loaders, dataset,
|
|
75
|
+
const [{ featureIndex }, matrixIndicesStatus, obsFeatureMatrixUrls] = useObsFeatureMatrixIndices(
|
|
76
|
+
loaders, dataset, true,
|
|
71
77
|
{ featureType },
|
|
72
78
|
);
|
|
73
79
|
const isReady = useReady([
|
|
74
80
|
featureLabelsStatus,
|
|
75
81
|
matrixIndicesStatus,
|
|
76
82
|
]);
|
|
83
|
+
const urls = useUrls([
|
|
84
|
+
featureLabelsUrls,
|
|
85
|
+
obsFeatureMatrixUrls,
|
|
86
|
+
]);
|
|
77
87
|
const geneList = featureIndex || [];
|
|
78
88
|
const numGenes = geneList.length;
|
|
89
|
+
const hasFeatureLabels = Boolean(featureLabelsMap);
|
|
79
90
|
|
|
80
91
|
function setGeneSelectionAndColorEncoding(newSelection) {
|
|
81
92
|
setGeneSelection(newSelection);
|
|
82
93
|
setCellColorEncoding('geneSelection');
|
|
83
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`;
|
|
84
101
|
|
|
85
102
|
return (
|
|
86
103
|
<TitleInfo
|
|
@@ -94,26 +111,36 @@ export function FeatureListSubscriber(props) {
|
|
|
94
111
|
removeGridComponent={removeGridComponent}
|
|
95
112
|
isReady={isReady}
|
|
96
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
|
+
)}
|
|
97
126
|
>
|
|
98
127
|
<FeatureList
|
|
99
128
|
hasColorEncoding={cellColorEncoding === 'geneSelection'}
|
|
129
|
+
showFeatureTable={showFeatureTable}
|
|
100
130
|
geneList={geneList}
|
|
131
|
+
featureListSort={featureListSort}
|
|
132
|
+
featureListSortKey={featureListSortKey || initialSortKey}
|
|
101
133
|
featureLabelsMap={featureLabelsMap}
|
|
134
|
+
featureType={featureType}
|
|
102
135
|
geneSelection={geneSelection}
|
|
103
136
|
geneFilter={geneFilter}
|
|
104
137
|
setGeneSelection={setGeneSelectionAndColorEncoding}
|
|
105
138
|
setGeneFilter={setGeneFilter}
|
|
106
139
|
setGeneHighlight={setGeneHighlight}
|
|
107
140
|
enableMultiSelect={enableMultiSelect}
|
|
141
|
+
hasFeatureLabels={Boolean(featureLabelsMap)}
|
|
142
|
+
primaryColumnName={primaryColumnName}
|
|
108
143
|
/>
|
|
109
144
|
</TitleInfo>
|
|
110
145
|
);
|
|
111
146
|
}
|
|
112
|
-
|
|
113
|
-
export function register() {
|
|
114
|
-
registerPluginViewType(
|
|
115
|
-
ViewType.FEATURE_LIST,
|
|
116
|
-
FeatureListSubscriber,
|
|
117
|
-
COMPONENT_COORDINATION_TYPES[ViewType.FEATURE_LIST],
|
|
118
|
-
);
|
|
119
|
-
}
|
package/src/constants.js
ADDED
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',
|
|
@@ -169,7 +173,7 @@ export default function SelectableTable(props) {
|
|
|
169
173
|
<input
|
|
170
174
|
id={`${inputUuid}_${data[index][idKey]}`}
|
|
171
175
|
type="checkbox"
|
|
172
|
-
className={clsx(classes.radioOrCheckbox, isCheckingMultiple ? classes.
|
|
176
|
+
className={clsx(classes.radioOrCheckbox, isCheckingMultiple ? classes.tableCheckbox : classes.tableRadio)}
|
|
173
177
|
name={inputUuid}
|
|
174
178
|
value={data[index][idKey]}
|
|
175
179
|
onChange={handleInputChange}
|
|
@@ -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
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
1
2
|
import '@testing-library/jest-dom';
|
|
2
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
cleanup, render, screen,
|
|
5
|
+
} from '@testing-library/react';
|
|
3
6
|
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import
|
|
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',
|
|
@@ -62,10 +66,10 @@ export const useStyles = makeStyles(theme => ({
|
|
|
62
66
|
backgroundClip: 'unset',
|
|
63
67
|
},
|
|
64
68
|
},
|
|
65
|
-
|
|
69
|
+
tableRadio: {
|
|
66
70
|
borderRadius: '50%',
|
|
67
71
|
},
|
|
68
|
-
|
|
72
|
+
tableCheckbox: {
|
|
69
73
|
borderRadius: '2px',
|
|
70
74
|
},
|
|
71
75
|
}));
|