Skip to content

Commit 3dbbb70

Browse files
authored
fix: filter empty text (#1942)
* fix: empty string should be empty when filter * fix: should not call the database connection api without permission
1 parent 4186ff0 commit 3dbbb70

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎apps/nestjs-backend/src/db-provider/filter-query/cell-value-filter.abstract.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,20 @@ export abstract class AbstractCellValueFilter implements ICellValueFilterInterfa
216216
_operator: IFilterOperator,
217217
_value: IFilterValue
218218
): Knex.QueryBuilder {
219-
builderClient.whereNull(this.tableColumnRef);
219+
const tableColumnRef = this.tableColumnRef;
220+
const { cellValueType, isStructuredCellValue, isMultipleCellValue } = this.field;
221+
222+
builderClient.where(function () {
223+
this.whereNull(tableColumnRef);
224+
225+
if (
226+
cellValueType === CellValueType.String &&
227+
!isStructuredCellValue &&
228+
!isMultipleCellValue
229+
) {
230+
this.orWhere(tableColumnRef, '=', '');
231+
}
232+
});
220233
return builderClient;
221234
}
222235

@@ -225,7 +238,13 @@ export abstract class AbstractCellValueFilter implements ICellValueFilterInterfa
225238
_operator: IFilterOperator,
226239
_value: IFilterValue
227240
): Knex.QueryBuilder {
241+
const { cellValueType, isStructuredCellValue, isMultipleCellValue } = this.field;
242+
228243
builderClient.whereNotNull(this.tableColumnRef);
244+
245+
if (cellValueType === CellValueType.String && !isStructuredCellValue && !isMultipleCellValue) {
246+
builderClient.where(this.tableColumnRef, '!=', '');
247+
}
229248
return builderClient;
230249
}
231250

‎apps/nestjs-backend/test/data-helpers/20x.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export const x_20 = {
135135
// actual number of items: 23
136136
records: [
137137
{
138-
fields: {},
138+
fields: {
139+
[textField.name]: '',
140+
},
139141
},
140142
{
141143
fields: {

‎apps/nextjs-app/src/features/app/blocks/db-connection/hooks/useDbConnection.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import { useQuery } from '@tanstack/react-query';
2-
import { getDbConnection } from '@teable/openapi';
3-
import { useBaseId } from '@teable/sdk/hooks';
2+
import { BillingProductLevel, getDbConnection } from '@teable/openapi';
3+
import { useBaseId, useBasePermission } from '@teable/sdk/hooks';
4+
import { useBaseUsage } from '@/features/app/hooks/useBaseUsage';
5+
import { useIsCloud } from '@/features/app/hooks/useIsCloud';
46

57
export const useDbConnection = () => {
68
const baseId = useBaseId() as string;
9+
const permissions = useBasePermission();
10+
const hasPermission = permissions?.['base|db_connection'];
11+
const isCloud = useIsCloud();
12+
const usage = useBaseUsage();
13+
const isUnavailable = isCloud && usage?.level !== BillingProductLevel.Enterprise;
714

815
const { data, isLoading } = useQuery({
916
queryKey: ['connection', baseId],
1017
queryFn: ({ queryKey }) => getDbConnection(queryKey[1]).then((data) => data.data),
18+
enabled: hasPermission && !isUnavailable,
1119
});
1220

1321
const dataArray = data?.dsn

0 commit comments

Comments
 (0)