mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge branch 'master' into fix-avatars-in-group-member-list
This commit is contained in:
commit
e1fe57c741
@ -223,8 +223,7 @@ export default {
|
||||
},
|
||||
searchResults: async (_parent, args, context, _resolveInfo) => {
|
||||
const { query, limit } = args
|
||||
let userId = null
|
||||
if (context.user) userId = context.user.id
|
||||
const userId = context.user?.id || null
|
||||
|
||||
const searchType = query.replace(/^([!@#&]?).*$/, '$1')
|
||||
const searchString = query.replace(/^([!@#&])/, '')
|
||||
|
||||
@ -33,7 +33,7 @@ const matchSomeWordsExactly = (str, boost = 2) => {
|
||||
const matchBeginningOfWords = (str) => {
|
||||
return str
|
||||
.split(' ')
|
||||
.filter((s) => s.length > 3)
|
||||
.filter((s) => s.length >= 2)
|
||||
.map((s) => s + '*')
|
||||
.join(' ')
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ describe('queryString', () => {
|
||||
|
||||
describe('globbing for longer words', () => {
|
||||
it('globs words with more than three characters', () => {
|
||||
expect(queryString('a couple of words')).toContain('couple* words*')
|
||||
expect(queryString('a couple of words')).toContain('couple* of* words*')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -63,13 +63,6 @@ describe('SearchableInput.vue', () => {
|
||||
expect(select.element.value).toBe('abcd')
|
||||
})
|
||||
|
||||
it('calls onDelete when the delete key is pressed', () => {
|
||||
const spy = jest.spyOn(wrapper.vm, 'onDelete')
|
||||
select.trigger('input')
|
||||
select.trigger('keyup.delete')
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
describe('navigating to resource', () => {
|
||||
beforeEach(() => {
|
||||
propsData = { options: searchResults }
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
<template>
|
||||
<div class="searchable-input" aria-label="search" role="search">
|
||||
<ds-select
|
||||
ref="select"
|
||||
type="search"
|
||||
icon="search"
|
||||
v-model="searchValue"
|
||||
v-model="value"
|
||||
:id="id"
|
||||
label-prop="id"
|
||||
:icon-right="null"
|
||||
@ -11,12 +12,11 @@
|
||||
:loading="loading"
|
||||
:filter="(item) => item"
|
||||
:no-options-available="emptyText"
|
||||
:auto-reset-search="!searchValue"
|
||||
:auto-reset-search="!value"
|
||||
:placeholder="$t('search.placeholder')"
|
||||
@focus.capture.native="onFocus"
|
||||
@input.native="handleInput"
|
||||
@input.native="onInput"
|
||||
@keyup.enter.native="onEnter"
|
||||
@keyup.delete.native="onDelete"
|
||||
@keyup.esc.native="clear"
|
||||
@blur.capture.native="onBlur"
|
||||
@input.exact="onSelect"
|
||||
@ -77,23 +77,29 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
searchValue: '',
|
||||
value: '',
|
||||
unprocessedSearchInput: '',
|
||||
searchProcess: null,
|
||||
previousSearchTerm: '',
|
||||
delay: 300,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
emptyText() {
|
||||
return this.isActive && !this.loading ? this.$t('search.failed') : this.$t('search.hint')
|
||||
return !this.loading && this.isSearchable()
|
||||
? this.$t('search.failed')
|
||||
: this.$t('search.hint')
|
||||
},
|
||||
isActive() {
|
||||
return !isEmpty(this.previousSearchTerm)
|
||||
return !isEmpty(this.value)
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
isSearchable() {
|
||||
return (
|
||||
!isEmpty(this.value) &&
|
||||
typeof this.value === 'string' &&
|
||||
this.value.replace(/\s+/g, '').length >= 3
|
||||
)
|
||||
},
|
||||
isFirstOfType(option) {
|
||||
return (
|
||||
this.options.findIndex((o) => o === option) ===
|
||||
@ -103,49 +109,36 @@ export default {
|
||||
onFocus(event) {
|
||||
clearTimeout(this.searchProcess)
|
||||
},
|
||||
handleInput(event) {
|
||||
onInput(event) {
|
||||
clearTimeout(this.searchProcess)
|
||||
this.value = event.target ? event.target.value.replace(/\s+/g, ' ').trim() : ''
|
||||
this.unprocessedSearchInput = this.value
|
||||
if (isEmpty(this.value) || this.value.replace(/\s+/g, '').length < 3) {
|
||||
if (!this.isSearchable()) {
|
||||
this.$emit('clearSearch')
|
||||
return
|
||||
}
|
||||
this.searchProcess = setTimeout(() => {
|
||||
this.previousSearchTerm = this.value
|
||||
this.$emit('query', this.value)
|
||||
}, this.delay)
|
||||
},
|
||||
onEnter(event) {
|
||||
this.$router.push({
|
||||
path: '/search/search-results',
|
||||
query: { search: this.unprocessedSearchInput },
|
||||
query: { search: this.value },
|
||||
})
|
||||
this.$emit('clearSearch')
|
||||
},
|
||||
onDelete(event) {
|
||||
clearTimeout(this.searchProcess)
|
||||
const value = event.target ? event.target.value.trim() : ''
|
||||
if (isEmpty(value)) {
|
||||
this.clear()
|
||||
} else {
|
||||
this.handleInput(event)
|
||||
}
|
||||
this.$refs.select.close()
|
||||
},
|
||||
clear() {
|
||||
this.unprocessedSearchInput = ''
|
||||
this.previousSearchTerm = ''
|
||||
this.searchValue = ''
|
||||
this.value = ''
|
||||
this.$emit('clearSearch')
|
||||
clearTimeout(this.searchProcess)
|
||||
},
|
||||
onBlur(event) {
|
||||
this.searchValue = this.previousSearchTerm
|
||||
clearTimeout(this.searchProcess)
|
||||
},
|
||||
onSelect(item) {
|
||||
this.goToResource(item)
|
||||
this.$nextTick(() => {
|
||||
this.searchValue = this.previousSearchTerm
|
||||
this.value = this.$refs.select.$data.searchString
|
||||
})
|
||||
},
|
||||
getRouteName(item) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user