mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-26 13:31:45 +03:00
add object id column to csv export (#5971)
closes: #5893 --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
parent
bc8c895b0e
commit
59b9ce689d
@ -40,6 +40,7 @@ describe('generateCsv', () => {
|
|||||||
] as ColumnDefinition<FieldMetadata>[];
|
] as ColumnDefinition<FieldMetadata>[];
|
||||||
const rows = [
|
const rows = [
|
||||||
{
|
{
|
||||||
|
id: '1',
|
||||||
bar: 'another field',
|
bar: 'another field',
|
||||||
empty: null,
|
empty: null,
|
||||||
foo: 'some field',
|
foo: 'some field',
|
||||||
@ -48,8 +49,8 @@ describe('generateCsv', () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
const csv = generateCsv({ columns, rows });
|
const csv = generateCsv({ columns, rows });
|
||||||
expect(csv).toEqual(`Foo,Empty,Nested Foo,Nested Nested,Relation
|
expect(csv).toEqual(`id,Foo,Empty,Nested Foo,Nested Nested,Relation
|
||||||
some field,,foo,nested,a relation`);
|
1,some field,,foo,nested,a relation`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ describe('csvDownloader', () => {
|
|||||||
{ id: 2, name: 'Alice' },
|
{ id: 2, name: 'Alice' },
|
||||||
],
|
],
|
||||||
columns: [],
|
columns: [],
|
||||||
|
objectNameSingular: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
|
@ -6,6 +6,7 @@ import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
|
|||||||
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
|
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
|
||||||
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
|
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
|
||||||
import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition';
|
import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition';
|
||||||
|
import { FieldMetadataType } from '~/generated/graphql';
|
||||||
import { isDefined } from '~/utils/isDefined';
|
import { isDefined } from '~/utils/isDefined';
|
||||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||||
import { sleep } from '~/utils/sleep';
|
import { sleep } from '~/utils/sleep';
|
||||||
@ -45,14 +46,27 @@ export const generateCsv: GenerateExport = ({
|
|||||||
col.metadata.relationType === 'TO_ONE_OBJECT',
|
col.metadata.relationType === 'TO_ONE_OBJECT',
|
||||||
);
|
);
|
||||||
|
|
||||||
const keys = columnsToExport.flatMap((col) => {
|
const objectIdColumn: ColumnDefinition<FieldMetadata> = {
|
||||||
|
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 = {
|
const column = {
|
||||||
field: `${col.metadata.fieldName}${col.type === 'RELATION' ? 'Id' : ''}`,
|
field: `${col.metadata.fieldName}${col.type === 'RELATION' ? 'Id' : ''}`,
|
||||||
title: [col.label, col.type === 'RELATION' ? 'Id' : null]
|
title: [col.label, col.type === 'RELATION' ? 'Id' : null]
|
||||||
.filter(isDefined)
|
.filter(isDefined)
|
||||||
.join(' '),
|
.join(' '),
|
||||||
};
|
};
|
||||||
|
|
||||||
const fieldsWithSubFields = rows.find((row) => {
|
const fieldsWithSubFields = rows.find((row) => {
|
||||||
const fieldValue = (row as any)[column.field];
|
const fieldValue = (row as any)[column.field];
|
||||||
const hasSubFields =
|
const hasSubFields =
|
||||||
|
Loading…
Reference in New Issue
Block a user