Merge branch 'master' into fix-avatars-in-group-member-list

This commit is contained in:
Ulf Gebhardt 2023-04-25 15:17:16 +02:00 committed by GitHub
commit e1fe57c741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 40 deletions

View File

@ -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(/^([!@#&])/, '')

View File

@ -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(' ')
}

View File

@ -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*')
})
})
})

View File

@ -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 }

View File

@ -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) {