Skip to content

Commit

Permalink
fix: rename link results in illegal data (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
tea-artist committed Mar 14, 2024
1 parent aa7b944 commit 28238a4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

4 changes: 2 additions & 2 deletions apps/nestjs-backend/src/configs/threshold.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { registerAs } from '@nestjs/config';

export const thresholdConfig = registerAs('threshold', () => ({
maxCopyCells: Number(process.env.MAX_COPY_CELLS ?? 50_000),
maxResetCells: Number(process.env.MAX_RESET_CELLS ?? 10_000),
maxPasteCells: Number(process.env.MAX_PASTE_CELLS ?? 10_000),
maxResetCells: Number(process.env.MAX_RESET_CELLS ?? 50_000),
maxPasteCells: Number(process.env.MAX_PASTE_CELLS ?? 50_000),
maxReadRows: Number(process.env.MAX_READ_ROWS ?? 10_000),
maxDeleteRows: Number(process.env.MAX_DELETE_ROWS ?? 1_000),
maxSyncUpdateCells: Number(process.env.MAX_SYNC_UPDATE_CELLS ?? 10_000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,13 @@ export class FieldSupplementService {
private async prepareUpdateLinkField(tableId: string, fieldRo: IFieldRo, oldFieldVo: IFieldVo) {
const newOptionsRo = fieldRo.options as ILinkFieldOptionsRo;
const oldOptions = oldFieldVo.options as ILinkFieldOptions;
// isOneWay may be undefined or false, so we should convert it to boolean
const oldIsOneWay = Boolean(oldOptions.isOneWay);
const newIsOneWay = Boolean(newOptionsRo.isOneWay);
if (
oldOptions.foreignTableId === newOptionsRo.foreignTableId &&
oldOptions.relationship === newOptionsRo.relationship
oldOptions.relationship === newOptionsRo.relationship &&
oldIsOneWay !== newIsOneWay
) {
return {
...oldFieldVo,
Expand Down
20 changes: 19 additions & 1 deletion apps/nestjs-backend/test/field-converting.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,26 @@ describe('OpenAPI Freely perform column transformations (e2e)', () => {
},
};

const { newField } = await expectUpdate(table1, linkFieldRo, linkFieldRo2);
const linkField = await createField(table1.id, linkFieldRo);
await updateRecordByApi(table1.id, table1.records[0].id, linkField.id, {
id: table2.records[0].id,
});

const newField = await convertField(table1.id, linkField.id, linkFieldRo2);

expect(newField.name).toEqual('other name');

const { name: _, ...newFieldOthers } = newField;
const { name: _0, ...oldFieldOthers } = linkField;

expect(newFieldOthers).toEqual(oldFieldOthers);

const table2Records = await getRecords(table2.id, { fieldKeyType: FieldKeyType.Id });
expect(
table2Records.records[0].fields[
(linkField.options as ILinkFieldOptions).symmetricFieldId as string
]
).toMatchObject([{ id: table1.records[0].id }]);
});

it('should modify rollup field name', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/openapi/src/field/update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RouteConfig } from '@asteasolutions/zod-to-openapi';
import type { IFieldVo, IUpdateFieldRo } from '@teable/core';
import type { IUpdateFieldRo } from '@teable/core';
import { updateFieldRoSchema } from '@teable/core';
import { axios } from '../axios';
import { registerRoute, urlBuilder } from '../utils';
Expand Down Expand Up @@ -35,7 +35,7 @@ export const UpdateFieldRoute: RouteConfig = registerRoute({
});

export const updateField = async (tableId: string, fieldId: string, fieldRo: IUpdateFieldRo) => {
return axios.patch<IFieldVo>(
return axios.patch(
urlBuilder(UPDATE_FIELD, {
tableId,
fieldId,
Expand Down

0 comments on commit 28238a4

Please sign in to comment.