diff --git a/packages/twenty-front/src/modules/object-record/record-index/options/hooks/__tests__/useExportTableData.test.ts b/packages/twenty-front/src/modules/object-record/record-index/options/hooks/__tests__/useExportTableData.test.ts index f5d35d92bc..170260764e 100644 --- a/packages/twenty-front/src/modules/object-record/record-index/options/hooks/__tests__/useExportTableData.test.ts +++ b/packages/twenty-front/src/modules/object-record/record-index/options/hooks/__tests__/useExportTableData.test.ts @@ -40,6 +40,7 @@ describe('generateCsv', () => { ] as ColumnDefinition[]; const rows = [ { + id: '1', bar: 'another field', empty: null, foo: 'some field', @@ -48,8 +49,8 @@ describe('generateCsv', () => { }, ]; const csv = generateCsv({ columns, rows }); - expect(csv).toEqual(`Foo,Empty,Nested Foo,Nested Nested,Relation -some field,,foo,nested,a relation`); + expect(csv).toEqual(`id,Foo,Empty,Nested Foo,Nested Nested,Relation +1,some field,,foo,nested,a relation`); }); }); @@ -62,6 +63,7 @@ describe('csvDownloader', () => { { id: 2, name: 'Alice' }, ], columns: [], + objectNameSingular: '', }; const link = document.createElement('a'); diff --git a/packages/twenty-front/src/modules/object-record/record-index/options/hooks/useExportTableData.ts b/packages/twenty-front/src/modules/object-record/record-index/options/hooks/useExportTableData.ts index 785bb8f51d..72a2144c67 100644 --- a/packages/twenty-front/src/modules/object-record/record-index/options/hooks/useExportTableData.ts +++ b/packages/twenty-front/src/modules/object-record/record-index/options/hooks/useExportTableData.ts @@ -6,6 +6,7 @@ import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords'; import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata'; import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates'; import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition'; +import { FieldMetadataType } from '~/generated/graphql'; import { isDefined } from '~/utils/isDefined'; import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull'; import { sleep } from '~/utils/sleep'; @@ -45,14 +46,27 @@ export const generateCsv: GenerateExport = ({ col.metadata.relationType === 'TO_ONE_OBJECT', ); - const keys = columnsToExport.flatMap((col) => { + const objectIdColumn: ColumnDefinition = { + fieldMetadataId: '', + type: FieldMetadataType.Uuid, + iconName: '', + label: `Id`, + metadata: { + fieldName: 'id', + }, + position: 0, + size: 0, + }; + + const columnsToExportWithIdColumn = [objectIdColumn, ...columnsToExport]; + + const keys = columnsToExportWithIdColumn.flatMap((col) => { const column = { field: `${col.metadata.fieldName}${col.type === 'RELATION' ? 'Id' : ''}`, title: [col.label, col.type === 'RELATION' ? 'Id' : null] .filter(isDefined) .join(' '), }; - const fieldsWithSubFields = rows.find((row) => { const fieldValue = (row as any)[column.field]; const hasSubFields =