Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: record update events were not merged #1238

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ export class EventEmitterService {
return;
}

if (existingEvent.rawOpType === RawOpType.Create && event.name === Events.TABLE_RECORD_UPDATE) {
if (
[RawOpType.Create, RawOpType.Edit].includes(existingEvent.rawOpType) &&
event.name === Events.TABLE_RECORD_UPDATE
) {
const fields = this.getUpdateFieldsFromEvent(event as RecordUpdateEvent);
event = this.combineUpdateEvents(existingEvent as RecordCreateEvent, fields);
}
Expand Down
43 changes: 32 additions & 11 deletions apps/nestjs-backend/test/record-history.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { INestApplication } from '@nestjs/common';
import { FieldKeyType, FieldType, Relationship } from '@teable/core';
import { getRecordHistory, getRecordListHistory, recordHistoryVoSchema } from '@teable/openapi';
import type { IRecordHistoryVo, ITableFullVo } from '@teable/openapi';
import type { ITableFullVo } from '@teable/openapi';
import type { IBaseConfig } from '../src/configs/base.config';
import { baseConfig } from '../src/configs/base.config';
import { EventEmitterService } from '../src/event-emitter/event-emitter.service';
Expand Down Expand Up @@ -75,20 +75,41 @@ describe('Record history (e2e)', () => {
})
);

const { recordHistory, tableRecordHistory } = await new Promise<{
recordHistory: IRecordHistoryVo;
tableRecordHistory: IRecordHistoryVo;
}>((resolve) => {
setTimeout(async () => {
const { data: recordHistory } = await getRecordHistory(mainTable.id, recordId, {});
const { data: tableRecordHistory } = await getRecordListHistory(mainTable.id, {});
resolve({ recordHistory, tableRecordHistory });
}, 2000);
});
const { data: recordHistory } = await getRecordHistory(mainTable.id, recordId, {});
const { data: tableRecordHistory } = await getRecordListHistory(mainTable.id, {});

expect(recordHistory.historyList.length).toEqual(1);
expect(tableRecordHistory.historyList.length).toEqual(1);
});

it('should get record history of changes in the modified cell values is referenced by a formula', async () => {
const recordId = mainTable.records[0].id;
const textField = await createField(mainTable.id, {
type: FieldType.SingleLineText,
});
await createField(mainTable.id, {
type: FieldType.Formula,
options: {
expression: `{${textField.id}}`,
},
});

await awaitWithEvent(() =>
updateRecord(mainTable.id, recordId, {
record: {
fields: {
[textField.id]: 'test',
},
},
fieldKeyType: FieldKeyType.Id,
})
);

const { data: mainTableRecordHistory } = await getRecordHistory(mainTable.id, recordId, {});

expect(mainTableRecordHistory.historyList.length).toEqual(1);
});

it('should get record history of changes in the link field cell values', async () => {
const recordId = mainTable.records[0].id;
const foreignRecordId = foreignTable.records[0].id;
Expand Down
Loading