Browse Source

feat(gui): add checked and notchecked option in filter

re #2014
pull/4861/head
Pranav C 2 years ago
parent
commit
9792a3a0ad
  1. 16
      packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
  2. 21
      packages/nc-gui/utils/filterUtils.ts
  3. 19
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts
  4. 6
      packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts
  5. 2
      packages/nocodb/src/lib/models/Filter.ts
  6. 1
      packages/nocodb/src/lib/utils/projectAcl.ts

16
packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue

@ -100,11 +100,6 @@ watch(
},
)
const getApplicableFilters = (id?: string) => {
const colType = (meta.value?.columnsById as Record<string, ColumnType>)?.[id ?? '']?.uidt
return comparisonOpList.filter((op) => !op.types || op.types.includes(colType))
}
const applyChanges = async (hookId?: string, _nested = false) => {
await sync(hookId, _nested)
@ -218,18 +213,15 @@ defineExpose({
dropdown-class-name="nc-dropdown-filter-comp-op"
@change="filterUpdateCondition(filter, i)"
>
<a-select-option
v-for="compOp in getApplicableFilters(filter.fk_column_id)"
:key="compOp.value"
:value="compOp.value"
class=""
>
<template v-for="compOp in comparisonOpList" :key="compOp.value">
<a-select-option :value="compOp.value" v-if=" !compOp.allowedTypes || (filter.fk_column_id && compOp.allowedTypes.includes(types[filter.fk_column_id]))" >
{{ compOp.text }}
</a-select-option>
</template>
</a-select>
<span
v-if="filter.comparison_op && ['null', 'notnull', 'empty', 'notempty'].includes(filter.comparison_op)"
v-if="filter.comparison_op && ['null', 'notnull','checked', 'notchecked', 'empty', 'notempty'].includes(filter.comparison_op)"
:key="`span${i}`"
/>

21
packages/nc-gui/utils/filterUtils.ts

@ -1,4 +1,11 @@
export const comparisonOpList = [
import { UITypes } from 'nocodb-sdk'
export const comparisonOpList: {
text: string
value: string
ignoreVal?: boolean
allowedTypes?: string[]
}[] = [
{
text: 'is equal',
value: 'eq',
@ -35,6 +42,18 @@ export const comparisonOpList = [
value: 'notnull',
ignoreVal: true,
},
{
text: 'is checked',
value: 'checked',
ignoreVal: true,
allowedTypes: ['boolean'],
},
{
text: 'is not checked',
value: 'notchecked',
ignoreVal: true,
allowedTypes: ['boolean'],
},
{
text: 'contains all of',
value: 'allof',

19
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

@ -9,7 +9,6 @@ import RollupColumn from '../../../../models/RollupColumn';
import formulaQueryBuilderv2 from './formulav2/formulaQueryBuilderv2';
import FormulaColumn from '../../../../models/FormulaColumn';
import { RelationTypes, UITypes } from 'nocodb-sdk';
// import LookupColumn from '../../../models/LookupColumn';
import { sanitize } from './helpers/sanitize';
export default async function conditionV2(
@ -368,6 +367,10 @@ const parseConditionV2 = async (
qb = qb.where(customWhereClause || field, '');
else if (filter.value === 'notempty')
qb = qb.whereNot(customWhereClause || field, '');
else if (filter.value === 'true')
qb = qb.where(customWhereClause || field, true);
else if (filter.value === 'false')
qb = qb.where(customWhereClause || field, false);
break;
case 'isnot':
if (filter.value === 'null')
@ -378,6 +381,10 @@ const parseConditionV2 = async (
qb = qb.whereNot(customWhereClause || field, '');
else if (filter.value === 'notempty')
qb = qb.where(customWhereClause || field, '');
else if (filter.value === 'true')
qb = qb.whereNot(customWhereClause || field, true);
else if (filter.value === 'false')
qb = qb.whereNot(customWhereClause || field, false);
break;
case 'lt':
qb = qb.where(field, customWhereClause ? '>' : '<', val);
@ -405,6 +412,16 @@ const parseConditionV2 = async (
case 'notnull':
qb = qb.whereNotNull(customWhereClause || field);
break;
case 'checked':
qb = qb.where(customWhereClause || field, true);
break;
case 'notchecked':
qb = qb.where((grpdQb) => {
grpdQb
.whereNull(customWhereClause || field)
.orWhere(customWhereClause || field, false);
});
break;
case 'btw':
qb = qb.whereBetween(field, val.split(','));
break;

6
packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts

@ -66,6 +66,12 @@ export async function validateCondition(filters: Filter[], data: any) {
data[field] === undefined
);
break;
case 'checked':
res = !!data[field];
break;
case 'notchecked':
res = !data[field];
break;
case 'null':
res = res = data[field] === null;
break;

2
packages/nocodb/src/lib/models/Filter.ts

@ -32,6 +32,8 @@ export default class Filter {
| 'notempty'
| 'null'
| 'notnull'
| 'checked'
| 'notchecked'
| 'allof'
| 'anyof'
| 'nallof'

1
packages/nocodb/src/lib/utils/projectAcl.ts

@ -17,6 +17,7 @@ export default {
pluginRead: true,
pluginUpdate: true,
isPluginActive: true,
projectDelete: true,
},
},
guest: {},

Loading…
Cancel
Save