Skip to content

Commit

Permalink
Update record field query fields selection to limit filter out unquer…
Browse files Browse the repository at this point in the history
…yable fields, and replace it with c-input-select
  • Loading branch information
Fajfa committed May 21, 2024
1 parent 91070bc commit d04c433
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@
:label="$t('kind.record.queryFieldsLabel')"
label-class="text-primary"
>
<b-form-select
<c-input-select
v-model="f.options.queryFields"
:options="queryFieldOptions"
label="text"
:reduce="field => field.value"
:placeholder="$t('kind.record.queryFieldsPlaceholder')"
multiple
/>
</b-form-group>
Expand Down Expand Up @@ -116,6 +119,7 @@
<script>
import { mapGetters } from 'vuex'
import { NoID } from '@cortezaproject/corteza-js'
import { nonQueryableFieldKinds } from 'corteza-webapp-compose/src/lib/record-filter'
import base from './base'
export default {
Expand Down Expand Up @@ -167,15 +171,17 @@ export default {
fieldOptions () {
const fields = this.selectedModule
? this.selectedModule.fields
.map(({ label, name }) => { return { value: name, text: label || name } })
.map(({ label, name, kind }) => {
return { value: name, text: label || name, kind }
})
: []
return [
...fields.sort((a, b) => a.text.localeCompare(b.text)),
]
},
queryFieldOptions () {
return this.fieldOptions.slice(1)
return this.fieldOptions.filter(({ kind }) => !nonQueryableFieldKinds.includes(kind))
},
labelField () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ import base from './base'
import { debounce } from 'lodash'
import { compose, NoID } from '@cortezaproject/corteza-js'
import { mapActions, mapGetters } from 'vuex'
import { evaluatePrefilter, isFieldInFilter } from 'corteza-webapp-compose/src/lib/record-filter'
import { queryToFilter, evaluatePrefilter, isFieldInFilter } from 'corteza-webapp-compose/src/lib/record-filter'
import Pagination from '../Common/Pagination.vue'
export default {
Expand Down Expand Up @@ -371,10 +371,8 @@ export default {
}
if (query.length > 0) {
// Construct query
query = qf.map(qf => {
return `${qf} LIKE '%${query}%'`
}).join(' OR ')
const fields = qf.map(f => this.module.fields.find(({ name }) => name === f))
query = queryToFilter(query, '', fields)
}
this.fetchPrefiltered({ namespaceID, moduleID, query, sort: this.sortString(), limit, pageCursor })
Expand Down
6 changes: 3 additions & 3 deletions client/web/compose/src/lib/record-filter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import moment from 'moment'

const noneQueryableFieldNames = ['recordID']
const noneQueryableFieldKinds = ['Number', 'Record', 'User', 'Bool', 'DateTime', 'File', 'Geometry']
export const nonQueryableFieldNames = ['recordID']
export const nonQueryableFieldKinds = ['Number', 'Record', 'User', 'Bool', 'DateTime', 'File', 'Geometry']

// Generate record list sql query string based on filter object input

Expand Down Expand Up @@ -171,7 +171,7 @@ export function queryToFilter (searchQuery = '', prefilter = '', fields = [], re
// Create query for search string
if (searchQuery || searchQuery === 0) {
searchQuery = fields
.filter(f => !noneQueryableFieldNames.includes(f.name) && !noneQueryableFieldKinds.includes(f.kind))
.filter(f => !nonQueryableFieldNames.includes(f.name) && !nonQueryableFieldKinds.includes(f.kind))
.map(f => getFieldFilter(f.name, f.kind, searchQuery, 'LIKE'))
.filter(q => !!q)
.join(' OR ')
Expand Down
1 change: 1 addition & 0 deletions locale/en/corteza-webapp-compose/field.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ kind:
moduleLabel: Module
modulePlaceholder: Pick module
queryFieldsLabel: Query fields on search
queryFieldsPlaceholder: If no fields are picked the Label field will be used
moduleField: Label field
variantField: Variant field
fieldFromModuleField: Label field from related module field
Expand Down

0 comments on commit d04c433

Please sign in to comment.