Skip to content

Commit 80e1ddb

Browse files
authored
fix: group header rendering error related to date field (#1066)
* fix: duplicate record cannot be undo * fix: group header rendering error related to date field
1 parent ea7b2d2 commit 80e1ddb

7 files changed

Lines changed: 18 additions & 19 deletions

File tree

apps/nestjs-backend/src/features/record/open-api/record-open-api.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export class RecordOpenApiController {
143143

144144
@Permissions('record|create')
145145
@Post(':recordId')
146+
@EmitControllerEvent(Events.OPERATION_RECORDS_CREATE)
146147
async duplicateRecord(
147148
@Param('tableId') tableId: string,
148149
@Param('recordId') recordId: string,

apps/nestjs-backend/src/features/record/open-api/record-open-api.service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,6 @@ export class RecordOpenApiService {
582582
order,
583583
records: [records],
584584
};
585-
const createdRecords = await this.prismaService.$tx(async () =>
586-
this.createRecords(tableId, createRecordsRo)
587-
);
588-
return { id: createdRecords.records[0]?.id };
585+
return await this.prismaService.$tx(async () => this.createRecords(tableId, createRecordsRo));
589586
}
590587
}

apps/nestjs-backend/test/record.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe('OpenAPI RecordController (e2e)', () => {
303303
anchorId: addRecord.id,
304304
position: 'after',
305305
});
306-
const record = await getRecord(table.id, duplicateRes.id, undefined, 200);
306+
const record = await getRecord(table.id, duplicateRes.records[0].id, undefined, 200);
307307
expect(record.fields[table.fields[0].id]).toEqual(value1);
308308
});
309309
});

apps/nestjs-backend/test/utils/init-app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import type {
2626
ITableFullVo,
2727
ICreateSpaceRo,
2828
ICreateBaseRo,
29-
IDuplicateVo,
3029
IRecordInsertOrderRo,
3130
} from '@teable/openapi';
3231
import {
@@ -332,7 +331,7 @@ export async function duplicateRecord(
332331
if ((e as HttpError).status !== expectStatus) {
333332
throw e;
334333
}
335-
return {} as IDuplicateVo;
334+
return {} as ICreateRecordsVo;
336335
}
337336
}
338337

packages/core/src/models/field/cell-value-validation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ export const validateCellValue = (field: IFieldVo, cellValue: unknown) => {
6161
assertNever(type);
6262
}
6363
};
64+
65+
export const validateDateFieldValueLoose = (cellValue: unknown, isMultipleCellValue?: boolean) => {
66+
if (isMultipleCellValue) {
67+
return z.array(z.string()).nonempty().nullable().safeParse(cellValue);
68+
}
69+
return z.string().nullable().safeParse(cellValue);
70+
};

packages/openapi/src/record/duplicate.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { axios } from '../axios';
22
import { registerRoute, urlBuilder } from '../utils';
33
import { z } from '../zod';
4-
import type { IRecordInsertOrderRo } from './create';
5-
import { recordInsertOrderRoSchema } from './create';
4+
import type { ICreateRecordsVo, IRecordInsertOrderRo } from './create';
5+
import { createRecordsVoSchema, recordInsertOrderRoSchema } from './create';
66

77
export const DUPLICATE_URL = '/table/{tableId}/record/{recordId}';
88

9-
export const duplicateVoSchema = z.object({
10-
id: z.string(),
11-
});
12-
13-
export type IDuplicateVo = z.infer<typeof duplicateVoSchema>;
149
export const duplicateRoute = registerRoute({
1510
method: 'post',
1611
path: DUPLICATE_URL,
@@ -33,7 +28,7 @@ export const duplicateRoute = registerRoute({
3328
description: 'Successful duplicate',
3429
content: {
3530
'application/json': {
36-
schema: duplicateVoSchema,
31+
schema: createRecordsVoSchema,
3732
},
3833
},
3934
},
@@ -46,5 +41,5 @@ export const duplicateRecord = async (
4641
recordId: string,
4742
order: IRecordInsertOrderRo
4843
) => {
49-
return axios.post<IDuplicateVo>(urlBuilder(DUPLICATE_URL, { tableId, recordId }), order);
44+
return axios.post<ICreateRecordsVo>(urlBuilder(DUPLICATE_URL, { tableId, recordId }), order);
5045
};

packages/sdk/src/components/grid-enhancements/hooks/use-grid-group-collection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { IAttachmentCellValue, INumberShowAs, ISingleLineTextShowAs } from '@teable/core';
2-
import { CellValueType, ColorUtils, FieldType } from '@teable/core';
2+
import { CellValueType, ColorUtils, FieldType, validateDateFieldValueLoose } from '@teable/core';
33
import { LRUCache } from 'lru-cache';
44
import { useCallback, useMemo } from 'react';
55
import { useTranslation } from '../../../context/app/i18n/useTranslation';
66
import { useFields, useView } from '../../../hooks';
7-
import type { DateField, IFieldInstance } from '../../../model';
7+
import type { IFieldInstance } from '../../../model';
88
import { getFileCover, isSystemFileIcon } from '../../editor';
99
import { GRID_DEFAULT } from '../../grid/configs';
1010
import type { IGridColumn } from '../../grid/interface';
@@ -53,7 +53,7 @@ const useGenerateGroupCellFn = () => {
5353

5454
const validateCellValue =
5555
field.cellValueType === CellValueType.DateTime
56-
? (field as DateField).validateCellValueLoose(_cellValue)
56+
? validateDateFieldValueLoose(_cellValue)
5757
: field.validateCellValue(_cellValue);
5858
const cellValue = (
5959
validateCellValue.success ? validateCellValue.data : undefined

0 commit comments

Comments
 (0)