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: better match empty text fields #1181

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
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
@@ -1,4 +1,4 @@
import type { IFilterOperator, ILiteralValue } from '@teable/core';
import type { IFilterOperator, IFilterValue, ILiteralValue } from '@teable/core';
import type { Knex } from 'knex';
import { CellValueFilterPostgres } from '../cell-value-filter.postgres';

Expand Down Expand Up @@ -34,4 +34,26 @@ export class StringCellValueFilterAdapter extends CellValueFilterPostgres {
): Knex.QueryBuilder {
return super.doesNotContainOperatorHandler(builderClient, operator, value);
}

isEmptyOperatorHandler(
builderClient: Knex.QueryBuilder,
_operator: IFilterOperator,
_value: IFilterValue
): Knex.QueryBuilder {
builderClient.where((builder) => {
builder.whereNull(this.tableColumnRef).orWhere(this.tableColumnRef, '');
});
return builderClient;
}

isNotEmptyOperatorHandler(
builderClient: Knex.QueryBuilder,
_operator: IFilterOperator,
_value: IFilterValue
): Knex.QueryBuilder {
builderClient.where((builder) => {
builder.whereNotNull(this.tableColumnRef).andWhereNot(this.tableColumnRef, '');
});
return builderClient;
}
}
2 changes: 1 addition & 1 deletion apps/nestjs-backend/test/data-helpers/20x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export const x_20 = {
},
{
fields: {
[textField.name]: 'Text Field 20',
[textField.name]: '',
[numberField.name]: 20,
[checkboxField.name]: true,
[dateField.name]: new DateUtil('Asia/Singapore', true).date().toISOString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ export const TEXT_FIELD_CASES = [
fieldIndex: 0,
aggFunc: StatisticsFunc.Count,
expectValue: 23,
expectGroupedCount: 22,
expectGroupedCount: 21,
},
{
fieldIndex: 0,
aggFunc: StatisticsFunc.Empty,
expectValue: 1,
expectGroupedCount: 22,
expectValue: 2,
expectGroupedCount: 21,
},
{
fieldIndex: 0,
aggFunc: StatisticsFunc.Filled,
expectValue: 22,
expectGroupedCount: 22,
expectValue: 21,
expectGroupedCount: 21,
},
{
fieldIndex: 0,
aggFunc: StatisticsFunc.Unique,
expectValue: 21,
expectGroupedCount: 22,
expectValue: 20,
expectGroupedCount: 21,
},
{
fieldIndex: 0,
aggFunc: StatisticsFunc.PercentEmpty,
expectValue: 4.347826,
expectGroupedCount: 22,
expectValue: 8.695652,
expectGroupedCount: 21,
},
{
fieldIndex: 0,
aggFunc: StatisticsFunc.PercentFilled,
expectValue: 95.652173,
expectGroupedCount: 22,
expectValue: 91.304347,
expectGroupedCount: 21,
},
{
fieldIndex: 0,
aggFunc: StatisticsFunc.PercentUnique,
expectValue: 91.304347,
expectGroupedCount: 22,
expectValue: 86.956521,
expectGroupedCount: 21,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ export const TEXT_FIELD_CASES = [
fieldIndex: 0,
operator: isEmpty.value,
queryValue: null,
expectResultLength: 1,
expectResultLength: 2,
expectMoreResults: false,
},
{
fieldIndex: 0,
operator: isNotEmpty.value,
queryValue: null,
expectResultLength: 22,
expectResultLength: 21,
expectMoreResults: false,
},
{
Expand All @@ -33,14 +33,14 @@ export const TEXT_FIELD_CASES = [
fieldIndex: 0,
operator: contains.value,
queryValue: 'Text',
expectResultLength: 22,
expectResultLength: 21,
expectMoreResults: true,
},
{
fieldIndex: 0,
operator: doesNotContain.value,
queryValue: 'Text',
expectResultLength: 1,
expectResultLength: 2,
expectMoreResults: false,
},
];
Expand Down
Loading