Skip to content

Commit

Permalink
Make typeahead and search limit/length configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Dec 17, 2021
1 parent 22279df commit 80bd1dc
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 54 deletions.
10 changes: 5 additions & 5 deletions core/js/dist/install.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions core/js/dist/login.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/login.js.map

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions core/js/dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/maintenance.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions core/js/dist/profile.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/profile.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions core/js/dist/recommendedapps.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/recommendedapps.js.map

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions core/js/dist/unified-search.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/unified-search.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion core/src/services/UnifiedSearchService.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'

export const defaultLimit = loadState('unified-search', 'limit-default')
export const minSearchLength = 2
export const minSearchLength = loadState('unified-search', 'min-search-length', 2)
export const typeAhead = loadState('unified-search', 'type-ahead', true)

export const regexFilterIn = /[^-]in:([a-z_-]+)/ig
export const regexFilterNot = /-in:([a-z_-]+)/ig

Expand Down
33 changes: 27 additions & 6 deletions core/src/views/UnifiedSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
class="unified-search__form-reset icon-close"
:aria-label="t('core','Reset search')"
value="">

<input v-if="!!query && !isLoading && !typeAhead"
type="submit"
class="unified-search__form-submit icon-confirm"
:aria-label="t('core','Start search')"
value="">
</form>

<!-- Search filters -->
Expand All @@ -76,7 +82,10 @@
<SearchResultPlaceholders v-if="isLoading" />

<EmptyContent v-else-if="isValidQuery" icon="icon-search">
<Highlight :text="t('core', 'No results for {query}', { query })" :search="query" />
<Highlight v-if="triggered" :text="t('core', 'No results for {query}', { query })" :search="query" />
<div v-else>
{{ t('core', 'Press enter to start searching') }}
</div>
</EmptyContent>

<EmptyContent v-else-if="!isLoading || isShortQuery" icon="icon-search">
Expand Down Expand Up @@ -124,7 +133,7 @@

<script>
import { emit } from '@nextcloud/event-bus'
import { minSearchLength, getTypes, search, defaultLimit, regexFilterIn, regexFilterNot } from '../services/UnifiedSearchService'
import { minSearchLength, getTypes, search, defaultLimit, regexFilterIn, regexFilterNot, typeAhead } from '../services/UnifiedSearchService'
import { showError } from '@nextcloud/dialogs'
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
Expand Down Expand Up @@ -175,9 +184,11 @@ export default {
query: '',
focused: null,
triggered: false,
defaultLimit,
minSearchLength,
typeAhead,
open: false,
}
Expand Down Expand Up @@ -345,6 +356,7 @@ export default {
this.reached = {}
this.results = {}
this.focused = null
this.triggered = false
await this.cancelPendingRequests()
},
Expand Down Expand Up @@ -413,6 +425,7 @@ export default {
// Reset search if the query changed
await this.resetState()
this.triggered = true
this.$set(this.loading, 'all', true)
this.logger.debug(`Searching ${query} in`, types)
Expand Down Expand Up @@ -472,9 +485,13 @@ export default {
this.loading = {}
})
},
onInputDebounced: debounce(function(e) {
this.onInput(e)
}, 500),
onInputDebounced: typeAhead
? debounce(function(e) {
this.onInput(e)
}, 500)
: function() {
this.triggered = false
},
/**
* Load more results for the provided type
Expand Down Expand Up @@ -711,7 +728,7 @@ $input-padding: 6px;
}
}
&-reset {
&-reset, &-submit {
position: absolute;
top: 0;
right: 0;
Expand All @@ -729,6 +746,10 @@ $input-padding: 6px;
opacity: 1;
}
}
&-submit {
right: 28px;
}
}
&__filters {
Expand Down
4 changes: 3 additions & 1 deletion lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public function __construct($renderAs, $appId = '') {
}

$this->initialState->provideInitialState('core', 'active-app', $this->navigationManager->getActiveEntry());
$this->initialState->provideInitialState('unified-search', 'limit-default', SearchQuery::LIMIT_DEFAULT);
$this->initialState->provideInitialState('unified-search', 'limit-default', (int)$this->config->getAppValue('core', 'unified-search.limit-default', (string)SearchQuery::LIMIT_DEFAULT));
$this->initialState->provideInitialState('unified-search', 'min-search-length', (int)$this->config->getAppValue('core', 'unified-search.min-search-length', (string)2));
$this->initialState->provideInitialState('unified-search', 'type-ahead', $this->config->getAppValue('core', 'unified-search.type-ahead', 'yes') === 'yes');
Util::addScript('core', 'dist/unified-search', 'core');

// Add navigation entry
Expand Down

0 comments on commit 80bd1dc

Please sign in to comment.