Skip to content

Commit 1e39c92

Browse files
authored
Merge pull request #212 from BimberLab/23.3_fb_columnSelectorPersist
Persist user-hidden columns across rerenders
2 parents 24b2f3c + 2a5d2d3 commit 1e39c92

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

jbrowse/src/client/JBrowse/VariantSearch/components/ArrowPagination.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ArrowPagination: React.FC<ArrowPaginationProps> = ({ offset, onOffsetChang
2424
<IconButton onClick={handleLeftClick}>
2525
<ArrowBackIosIcon />
2626
</IconButton>
27-
<span style={{marginTop: "4px"}}><strong>Results {offset*100}-{(offset+1)*100}</strong></span>
27+
<span style={{marginTop: "4px"}}><strong>Page {offset+1}</strong></span>
2828
<IconButton onClick={handleRightClick}>
2929
<ArrowForwardIosIcon />
3030
</IconButton>

jbrowse/src/client/JBrowse/VariantSearch/components/FilterForm.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,17 @@ const FilterForm = (props: FilterFormProps ) => {
106106
};
107107

108108
const handleRemoveFilter = (index) => {
109+
// If it's the last filter, just reset its values to default empty values
110+
if (filters.length === 1) {
111+
localSetFilters([{ field: "", operator: "", value: "" }]);
112+
} else {
113+
// Otherwise, remove the filter normally
109114
localSetFilters(
110115
filters.filter((filter, i) => {
111116
return i !== index;
112117
})
113118
);
114-
};
119+
}};
115120

116121
const handleFilterChange = (index, key, value) => {
117122
const newFilters = filters.map((filter, i) => {
@@ -129,29 +134,30 @@ const handleSubmit = (event) => {
129134
const highlightedInputs = {};
130135

131136
filters.forEach((filter, index) => {
132-
highlightedInputs[index] = { field: false, operator: false, value: false };
137+
highlightedInputs[index] = { field: false, operator: false, value: false };
133138

134-
if (filter.field === '') {
135-
highlightedInputs[index].field = true;
136-
}
139+
if (filter.field === '') {
140+
highlightedInputs[index].field = true;
141+
}
137142

138-
if (filter.operator === '') {
139-
highlightedInputs[index].operator = true;
140-
}
143+
if (filter.operator === '') {
144+
highlightedInputs[index].operator = true;
145+
}
141146

142-
if (filter.value === '') {
143-
highlightedInputs[index].value = true;
144-
}
145-
});
147+
if (filter.value === '') {
148+
highlightedInputs[index].value = true;
149+
}
150+
});
146151

147-
setHighlightedInputs(highlightedInputs);
152+
const isSingleEmptyFilter = filters.length === 1 && !filters[0].field && !filters[0].operator && !filters[0].value;
148153

149-
if (!Object.values(highlightedInputs).some(v => (v as any).field || (v as any).operator || (v as any).value)) {
150-
handleQuery(filters);
151-
setFilters(filters);
152-
handleClose();
153-
}
154-
};
154+
setHighlightedInputs(highlightedInputs);
155+
if (isSingleEmptyFilter || !Object.values(highlightedInputs).some(v => (v as any).field || (v as any).operator || (v as any).value)) {
156+
handleQuery(filters);
157+
setFilters(filters);
158+
handleClose();
159+
}
160+
};
155161

156162
return (
157163
<Card className={classes.card} elevation={0}>
@@ -260,15 +266,13 @@ const handleSubmit = (event) => {
260266
/>
261267
)}
262268

263-
{filters.length > 1 && (
264269
<Button
265270
variant="contained"
266271
color="primary"
267272
onClick={() => handleRemoveFilter(index)}
268273
>
269274
Remove Filter
270275
</Button>
271-
)}
272276
</div>
273277
))}
274278
</div>

jbrowse/src/client/JBrowse/VariantSearch/components/VariantTableWidget.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
GridToolbarExport
1111
} from '@mui/x-data-grid';
1212
import ScopedCssBaseline from '@material-ui/core/ScopedCssBaseline';
13-
import FilterListIcon from '@material-ui/icons/FilterList';
13+
import SearchIcon from '@material-ui/icons/Search';
1414
import React, { useEffect, useState } from 'react';
1515
import { getConf } from '@jbrowse/core/configuration';
1616
import { AppBar, Box, Button, Dialog, Paper, Popover, Toolbar, Tooltip, Typography } from '@material-ui/core';
@@ -174,12 +174,12 @@ const VariantTableWidget = observer(props => {
174174
<GridToolbarContainer>
175175
<GridToolbarColumnsButton />
176176
<Button
177-
startIcon={<FilterListIcon />}
177+
startIcon={<SearchIcon />}
178178
size="small"
179179
color="primary"
180180
onClick={() => setFilterModalOpen(true)}
181181
>
182-
Filter
182+
Search
183183
</Button>
184184
<GridToolbarDensitySelector />
185185
<GridToolbarExport />
@@ -216,6 +216,7 @@ const VariantTableWidget = observer(props => {
216216
const [filterModalOpen, setFilterModalOpen] = useState(false);
217217
const [filters, setFilters] = useState([]);
218218
const [fieldTypeInfo, setFieldTypeInfo] = useState<FieldModel[]>([]);
219+
const [hiddenColumns, setHiddenColumns] = useState([]);
219220

220221
const [adapter, setAdapter] = useState<EVAdapterClass | undefined>(undefined)
221222

@@ -358,15 +359,27 @@ const VariantTableWidget = observer(props => {
358359
}
359360
}
360361

362+
const columnsWithLocalHideState = columns.map(col => ({
363+
...col,
364+
hide: hiddenColumns.includes(col.field),
365+
}));
366+
361367
const gridElement = (
362368
<DataGrid
363-
columns={[...columns, actionsCol]}
369+
columns={[...columnsWithLocalHideState, actionsCol]}
364370
rows={features}
365371
components={{ Toolbar: ToolbarWithProps }}
366372
rowsPerPageOptions={[10,25,50,100]}
367373
pageSize={pageSize}
368374
density="comfortable"
369375
onPageSizeChange={(newPageSize) => setPageSize(newPageSize)}
376+
onColumnVisibilityChange={(params) => {
377+
if (params.isVisible) {
378+
setHiddenColumns(prev => prev.filter(field => field !== params.field));
379+
} else {
380+
setHiddenColumns(prev => [...prev, params.field]);
381+
}
382+
}}
370383
/>
371384
)
372385

0 commit comments

Comments
 (0)