Skip to content

Commit

Permalink
omit relations from csv exports
Browse files Browse the repository at this point in the history
  • Loading branch information
tatethurston committed Feb 28, 2024
1 parent b8b5fb4 commit d3a3864
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ describe('generateCsv', () => {
{ label: 'Foo', metadata: { fieldName: 'foo' } },
{ label: 'Empty', metadata: { fieldName: 'empty' } },
{ label: 'Nested', metadata: { fieldName: 'nested' } },
{
label: 'Relation',
metadata: { fieldName: 'relation', relationType: 'TO_ONE_OBJECT' },
},
] as ColumnDefinition<FieldMetadata>[];
const rows = [
{
foo: 'some field',
bar: 'another field',
empty: null,
foo: 'some field',
nested: { __typename: 'type', foo: 'foo', nested: 'nested' },
relation: 'a relation',
},
];
const csv = generateCsv({ columns, rows });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export const generateCsv: GenerateExport = ({
columns,
rows,
}: GenerateExportOptions): string => {
const keys = columns.flatMap((col) => {
const columnsWithoutRelations = columns.filter(
(col) => !('relationType' in col.metadata && col.metadata.relationType),
);

const keys = columnsWithoutRelations.flatMap((col) => {
const column = {
field: col.metadata.fieldName,
title: col.label,
Expand Down Expand Up @@ -118,7 +122,7 @@ export const useExportTableData = ({
useEffect(() => {
const MAXIMUM_REQUESTS = Math.min(maximumRequests, totalCount / pageSize);

const downloadCav = (rows: object[]) => {
const downloadCsv = (rows: object[]) => {
csvDownloader(filename, { rows, columns });
setIsDownloading(false);
setProgress(undefined);
Expand All @@ -138,7 +142,7 @@ export const useExportTableData = ({
}

if (!hasNextPage || pageCount >= MAXIMUM_REQUESTS) {
downloadCav(records);
downloadCsv(records);
} else {
fetchNextPage();
}
Expand Down

0 comments on commit d3a3864

Please sign in to comment.