Skip to content

Commit 46c00da

Browse files
authored
fix: add select field option clear filter unexpectedly (#1289)
* fix: add select field option clear filter unexpectedly * test: rename field-view-sync e2e and add a test for add select field option
1 parent 984b5b4 commit 46c00da

2 files changed

Lines changed: 64 additions & 3 deletions

File tree

apps/nestjs-backend/src/features/field/field-calculate/field-view-sync.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class FieldViewSyncService {
259259
});
260260
const deleteOptions = differenceBy(oldOptions, newOptions, 'id');
261261
if (!deleteOptions?.length && !updateNameOptions?.length) {
262-
return;
262+
return filter;
263263
}
264264

265265
return this.getFilterBySelectTypeChanges(filter, fieldId, updateNameOptions, deleteOptions);

apps/nestjs-backend/test/field-update-delete-view-relative.e2e-spec.ts renamed to apps/nestjs-backend/test/field-view-sync.e2e-spec.ts

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import type { INestApplication } from '@nestjs/common';
2-
import type { IFieldVo, ISelectFieldOptions } from '@teable/core';
3-
import { FieldType, ViewType, SortFunc } from '@teable/core';
2+
import { Optional } from '@prisma/client/runtime/library';
3+
import type {
4+
IConvertFieldRo,
5+
IFieldVo,
6+
ISelectFieldChoice,
7+
ISelectFieldOptions,
8+
IUpdateFieldRo,
9+
} from '@teable/core';
10+
import { FieldType, ViewType, SortFunc, Colors } from '@teable/core';
411
import {
512
createTable,
613
createView,
@@ -232,4 +239,58 @@ describe('OpenAPI FieldController (e2e)', () => {
232239
},
233240
});
234241
});
242+
243+
it('should still intact for filter condition when add select option', async () => {
244+
const numberField = fields.find(({ type }) => type === FieldType.Number) as IFieldVo;
245+
const selectField = fields.find(({ type }) => type === FieldType.SingleSelect) as IFieldVo;
246+
247+
// create all views with some view conditions
248+
const gridView = await createView(tableId, {
249+
type: ViewType.Grid,
250+
filter: {
251+
conjunction: 'and',
252+
filterSet: [
253+
{ fieldId: numberField.id, operator: 'isGreater', value: 1 },
254+
{
255+
fieldId: selectField.id,
256+
operator: 'is',
257+
value: (selectField.options as ISelectFieldOptions)?.choices[0].name,
258+
},
259+
],
260+
},
261+
});
262+
263+
const newChoices = [
264+
...(selectField.options as ISelectFieldOptions).choices,
265+
] as Partial<ISelectFieldChoice>[];
266+
267+
newChoices.push({ name: 'test-add-choice', color: Colors.YellowLight2 });
268+
269+
// number field convert to text field
270+
await convertField(tableId, selectField.id, {
271+
name: selectField.name,
272+
dbFieldName: selectField.dbFieldName,
273+
type: FieldType.SingleSelect,
274+
options: {
275+
...selectField.options,
276+
choices: newChoices,
277+
},
278+
});
279+
280+
const views = await getViews(tableId);
281+
282+
const gridViewAfterChange = views.find(({ id }) => id === gridView.id);
283+
284+
expect(gridViewAfterChange?.filter).toEqual({
285+
conjunction: 'and',
286+
filterSet: [
287+
{ fieldId: numberField.id, operator: 'isGreater', value: 1 },
288+
{
289+
fieldId: selectField.id,
290+
operator: 'is',
291+
value: (selectField.options as ISelectFieldOptions)?.choices[0].name,
292+
},
293+
],
294+
});
295+
});
235296
});

0 commit comments

Comments
 (0)