Skip to content

Commit cf06861

Browse files
add object id column to export as csv
1 parent bc8c895 commit cf06861

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

packages/twenty-front/src/modules/object-record/record-index/options/hooks/__tests__/useExportTableData.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('generateCsv', () => {
4040
] as ColumnDefinition<FieldMetadata>[];
4141
const rows = [
4242
{
43+
id: '1',
4344
bar: 'another field',
4445
empty: null,
4546
foo: 'some field',
@@ -48,8 +49,8 @@ describe('generateCsv', () => {
4849
},
4950
];
5051
const csv = generateCsv({ columns, rows });
51-
expect(csv).toEqual(`Foo,Empty,Nested Foo,Nested Nested,Relation
52-
some field,,foo,nested,a relation`);
52+
expect(csv).toEqual(`id,Foo,Empty,Nested Foo,Nested Nested,Relation
53+
1,some field,,foo,nested,a relation`);
5354
});
5455
});
5556

@@ -62,6 +63,7 @@ describe('csvDownloader', () => {
6263
{ id: 2, name: 'Alice' },
6364
],
6465
columns: [],
66+
objectNameSingular: '',
6567
};
6668

6769
const link = document.createElement('a');

packages/twenty-front/src/modules/object-record/record-index/options/hooks/useExportTableData.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
66
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
77
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
88
import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition';
9+
import { FieldMetadataType } from '~/generated/graphql';
910
import { isDefined } from '~/utils/isDefined';
1011
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
1112
import { sleep } from '~/utils/sleep';
@@ -45,14 +46,27 @@ export const generateCsv: GenerateExport = ({
4546
col.metadata.relationType === 'TO_ONE_OBJECT',
4647
);
4748

48-
const keys = columnsToExport.flatMap((col) => {
49+
const objectIdColumn: ColumnDefinition<FieldMetadata> = {
50+
fieldMetadataId: '',
51+
type: FieldMetadataType.Uuid,
52+
iconName: '',
53+
label: `id`,
54+
metadata: {
55+
fieldName: 'id',
56+
},
57+
position: 0,
58+
size: 0,
59+
};
60+
61+
const columnsToExportWithIdColumn = [objectIdColumn, ...columnsToExport];
62+
63+
const keys = columnsToExportWithIdColumn.flatMap((col) => {
4964
const column = {
5065
field: `${col.metadata.fieldName}${col.type === 'RELATION' ? 'Id' : ''}`,
5166
title: [col.label, col.type === 'RELATION' ? 'Id' : null]
5267
.filter(isDefined)
5368
.join(' '),
5469
};
55-
5670
const fieldsWithSubFields = rows.find((row) => {
5771
const fieldValue = (row as any)[column.field];
5872
const hasSubFields =

0 commit comments

Comments
 (0)