Skip to content

Commit

Permalink
Hide columns hidden by users from the exported file
Browse files Browse the repository at this point in the history
  • Loading branch information
qu8n authored and ao508 committed Sep 13, 2024
1 parent dcf69f4 commit ddd86ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
12 changes: 8 additions & 4 deletions frontend/src/components/RecordsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function RecordsList({
const [rowCount, setRowCount] = useState<number>(0);
const [uniqueSampleCount, setUniqueSampleCount] = useState<number>(0);

const grid = useRef<AgGridReactType>(null);
const gridRef = useRef<AgGridReactType>(null);
const navigate = useNavigate();
const params = useParams();

Expand All @@ -114,7 +114,7 @@ export default function RecordsList({
const totalCountNodeName = `${dataName}Connection`;

const getSortModel = useCallback(() => {
const sortModel = grid.current?.columnApi
const sortModel = gridRef.current?.columnApi
?.getColumnState()
.filter(({ sort }) => sort)
.map(({ colId, sort }) => ({
Expand Down Expand Up @@ -211,7 +211,11 @@ export default function RecordsList({
agGridData = prepareDataForAgGrid(data, filterModel, sortModel);
}

return buildTsvString(agGridData[dataName], colDefs);
return buildTsvString(
agGridData[dataName],
colDefs,
gridRef.current?.columnApi?.getAllGridColumns()
);
}}
onComplete={() => setShowDownloadModal(false)}
exportFileName={`${dataName}.tsv`}
Expand Down Expand Up @@ -309,7 +313,7 @@ export default function RecordsList({
style={{ width: width }}
>
<AgGridReact
ref={grid}
ref={gridRef}
rowModelType={"serverSide"}
columnDefs={colDefs}
serverSideDatasource={datasource}
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/components/SamplesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,13 @@ export default function SamplesList({
<DownloadModal
loader={() => {
return sampleCount <= MAX_ROWS_TABLE
? Promise.resolve(buildTsvString(samples!, columnDefs))
? Promise.resolve(
buildTsvString(
samples!,
columnDefs,
gridRef.current?.columnApi?.getAllGridColumns()
)
)
: refetch({
options: {
limit: MAX_ROWS_EXPORT,
Expand Down
14 changes: 11 additions & 3 deletions frontend/src/utils/stringBuilders.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { ColDef } from "ag-grid-community";
import { ColDef, Column } from "ag-grid-community";

export function buildTsvString(
rows: any[],
colDefs: ColDef[],
cols?: Column[]
) {
const fieldsHiddenByUser =
cols?.filter((col) => !col.isVisible()).map((col) => col.getColId()) ?? [];

export function buildTsvString(rows: any[], colDefs: ColDef[]) {
const colDefsToExport = colDefs.filter(
(colDef) => colDef.headerName !== "View Samples" && colDef.hide !== true
({ field, hide }) =>
field && hide !== true && !fieldsHiddenByUser.includes(field)
);

const colHeadersAsTsvRow = colDefsToExport
Expand Down

0 comments on commit ddd86ad

Please sign in to comment.