Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: download all data columns in tsv export (#194) #195

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/components/Table/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
GridTrackSize,
} from "../../../config/entities";
import { EXPLORE_MODE, ExploreMode } from "../../../hooks/useExploreMode";
import { ACCESSOR_KEYS } from "../../TableCreator/common/constants";
import { CheckboxMenuListItem } from "../components/CheckboxMenu/checkboxMenu";

/**
Expand Down Expand Up @@ -146,8 +147,8 @@ export function generateDownloadBlob<T extends RowData>(
if (rows.length === 0) {
return;
}
const tableHeaders = getVisibleHeadersTableData(rows);
const tableData = getVisibleRowsTableData(rows);
const tableHeaders = getHeadersTableData(rows);
const tableData = getRowsTableData(rows);
const tsv = formatDataToTSV([tableHeaders, ...tableData]);
return new Blob([tsv], { type: "text/tab-separated-values" });
}
Expand Down Expand Up @@ -338,28 +339,29 @@ export function getTableStatePagination(
}

/**
* Returns the list of visible table headers.
* Returns the list of table headers, excluding "select" column.
* @param rows - Table rows.
* @returns list of visible headers.
* @returns list of headers.
*/
function getVisibleHeadersTableData<T extends RowData>(
rows: Row<T>[]
): TableData[] {
function getHeadersTableData<T extends RowData>(rows: Row<T>[]): TableData[] {
console.log(rows[0].getAllCells());
return rows[0]
.getVisibleCells()
.getAllCells()
.filter((cell) => cell.column.id !== ACCESSOR_KEYS.SELECT)
.map((cell) => cell.column.columnDef.header as TableData);
}

/**
* Returns the list of visible table data.
* Returns the list of table data, excluding "select" column.
* @param rows - Table rows.
* @returns list of visible data.
* @returns list of data.
*/
function getVisibleRowsTableData<T extends RowData>(
rows: Row<T>[]
): TableData[][] {
function getRowsTableData<T extends RowData>(rows: Row<T>[]): TableData[][] {
return rows.map((row) =>
row.getVisibleCells().map((cell) => cell.getValue() as TableData)
row
.getAllCells()
.filter((cell) => cell.column.id !== ACCESSOR_KEYS.SELECT)
.map((cell) => cell.getValue() as TableData)
);
}

Expand Down
Loading