Browse Source

fix: show checkbox for boolean field in filter component

re #953,#947

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/988/head
Pranav C 3 years ago
parent
commit
1760c7cedf
  1. 31
      packages/nc-gui/components/project/spreadsheet/components/columnFilter.vue
  2. 4
      packages/nc-gui/components/project/spreadsheet/components/columnFilterMenu.vue
  3. 1
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  4. 2
      packages/nc-gui/components/project/tableTabs/webhooks.vue
  5. 12
      packages/nocodb/src/lib/dataMapper/lib/sql/CustomKnex.ts
  6. 13
      packages/nocodb/src/lib/noco/common/BaseModel.ts

31
packages/nc-gui/components/project/spreadsheet/components/columnFilter.vue

@ -93,6 +93,13 @@
</template> </template>
</v-select> </v-select>
<span v-if="['is null', 'is not null'].includes(filter.op)" :key="'span' + i" /> <span v-if="['is null', 'is not null'].includes(filter.op)" :key="'span' + i" />
<v-checkbox
v-else-if="types[filter.field] === 'boolean'"
:key="i + '_7'"
v-model="filter.value"
dense
:disabled="filter.readOnly"
/>
<v-text-field <v-text-field
v-else v-else
:key="i + '_7'" :key="i + '_7'"
@ -126,9 +133,11 @@
</template> </template>
<script> <script>
import { UITypes } from '~/components/project/spreadsheet/helpers/uiTypes'
export default { export default {
name: 'ColumnFilter', name: 'ColumnFilter',
props: ['fieldList', 'value'], props: ['fieldList', 'value', 'meta'],
data: () => ({ data: () => ({
filters: [], filters: [],
opList: [ opList: [
@ -141,6 +150,26 @@ export default {
'<=' '<='
] ]
}), }),
computed: {
types() {
if (!this.meta || !this.meta.columns || !this.meta.columns.length) { return {} }
return this.meta.columns.reduce((obj, col) => {
switch (col.uidt) {
case UITypes.Number:
case UITypes.Decimal:
obj[col._cn] = obj[col.cn] = 'number'
break
case UITypes.Checkbox:
obj[col._cn] = obj[col.cn] = 'boolean'
break
default:
break
}
return obj
}, {})
}
},
watch: { watch: {
filters: { filters: {
handler(v) { handler(v) {

4
packages/nc-gui/components/project/spreadsheet/components/columnFilterMenu.vue

@ -26,7 +26,7 @@
</v-btn> </v-btn>
</v-badge> </v-badge>
</template> </template>
<column-filter v-model="filters" :field-list="fieldList"> <column-filter v-model="filters" :field-list="fieldList" :meta="meta">
<div class="d-flex align-center mx-2" @click.stop> <div class="d-flex align-center mx-2" @click.stop>
<v-checkbox <v-checkbox
id="col-filter-checkbox" id="col-filter-checkbox"
@ -58,7 +58,7 @@ import ColumnFilter from '@/components/project/spreadsheet/components/columnFilt
export default { export default {
name: 'ColumnFilterMenu', name: 'ColumnFilterMenu',
components: { ColumnFilter }, components: { ColumnFilter },
props: ['fieldList', 'isLocked', 'value'], props: ['fieldList', 'isLocked', 'value', 'meta'],
data: () => ({ data: () => ({
filters: [] filters: []
}), }),

1
packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue

@ -88,6 +88,7 @@
<column-filter <column-filter
v-if="!isForm" v-if="!isForm"
v-model="filters" v-model="filters"
:meta="meta"
:is-locked="isLocked" :is-locked="isLocked"
:field-list="[...realFieldList, ...formulaFieldList]" :field-list="[...realFieldList, ...formulaFieldList]"
dense dense

2
packages/nc-gui/components/project/tableTabs/webhooks.vue

@ -202,6 +202,7 @@
<column-filter <column-filter
v-if="enableCondition && _isEE" v-if="enableCondition && _isEE"
v-model="hook.condition" v-model="hook.condition"
:meta="meta"
:field-list="fieldList" :field-list="fieldList"
dense dense
style="max-width: 100%" style="max-width: 100%"
@ -374,6 +375,7 @@ export default {
enableCondition: false, enableCondition: false,
hooks: null, hooks: null,
valid: false, valid: false,
meta: null,
loading: false, loading: false,
notificationList: [ notificationList: [
'Email', 'Email',

12
packages/nocodb/src/lib/dataMapper/lib/sql/CustomKnex.ts

@ -138,7 +138,7 @@ const appendWhereCondition = function(
break; break;
} }
} else if (typeof condition === 'string') { } else if (typeof condition === 'string') {
const matches = condition.match( const matches: any[] = condition.match(
/^(?:~(\w+))?\(([\w ]+),(\w+),(.*?)\)(?:~(?:or|and|not))?$/ /^(?:~(\w+))?\(([\w ]+),(\w+),(.*?)\)(?:~(?:or|and|not))?$/
); );
@ -385,6 +385,14 @@ const appendWhereCondition = function(
default: default:
if (!(matches[3] in opMapping)) if (!(matches[3] in opMapping))
throw new Error(`${matches[3]} : Invalid comparison operator`); throw new Error(`${matches[3]} : Invalid comparison operator`);
if (
opMapping[matches[3]] === '=' &&
['true', 'false'].includes(matches[4])
) {
matches[4] = matches[4] === 'true';
}
switch (matches[1] || '') { switch (matches[1] || '') {
case 'or': case 'or':
knexRef[`or${camKey}`]( knexRef[`or${camKey}`](
@ -438,6 +446,8 @@ const appendWhereCondition = function(
throw new Error('appendWhereCondition : grammar error ' + conditions); throw new Error('appendWhereCondition : grammar error ' + conditions);
} }
}); });
console.log(knexRef.toQuery());
return knexRef; return knexRef;
}; };

13
packages/nocodb/src/lib/noco/common/BaseModel.ts

@ -393,12 +393,21 @@ class BaseModel<T extends BaseApiBuilder<any>> extends BaseModelSql {
const isValid = condition.reduce((valid, con) => { const isValid = condition.reduce((valid, con) => {
let res; let res;
const field = this.columnToAlias[con.field] ?? con.field; const field = this.columnToAlias[con.field] ?? con.field;
let val = data[field];
switch (typeof con.value) {
case 'boolean':
val = !!data[field];
break;
case 'number':
val = !!data[field];
break;
}
switch (con.op as string) { switch (con.op as string) {
case 'is equal': case 'is equal':
res = data[field] === con.value; res = val === con.value;
break; break;
case 'is not equal': case 'is not equal':
res = data[field] !== con.value; res = val !== con.value;
break; break;
case 'is like': case 'is like':
res = res =

Loading…
Cancel
Save