diff --git a/changelog/unreleased/enhancement-capability-based-searchbar b/changelog/unreleased/enhancement-capability-based-searchbar new file mode 100644 index 00000000000..4c3bbde4efe --- /dev/null +++ b/changelog/unreleased/enhancement-capability-based-searchbar @@ -0,0 +1,7 @@ +Enhancement: Capability-based searchbar rendering + +We have removed the `hideSearchBar` configuration option and now always render a searchbar +if the backend announces the availability of search functionality using its capabilities. + +https://github.com/owncloud/web/pull/6856 +https://github.com/owncloud/web/issues/6806 diff --git a/dev/docker/ocis.web.config.json b/dev/docker/ocis.web.config.json index 7e4b2f6fb2b..1ec9b4d0de7 100644 --- a/dev/docker/ocis.web.config.json +++ b/dev/docker/ocis.web.config.json @@ -10,7 +10,6 @@ "scope": "openid profile email" }, "options": { - "hideSearchBar": true, "disablePreviews": true, "displayResourcesLazy": false }, diff --git a/docs/getting-started.md b/docs/getting-started.md index 37f01e0c1cb..82e2034ba34 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -41,7 +41,6 @@ Please refer to the [build documentation for Web]({{< ref "./building.md" >}}). Depending on the backend you are using, there are sample config files provided in the [config folder](https://github.com/owncloud/web/tree/master/config) of the ownCloud Web git repository. See below for available backends. Also, find some of the configuration details below. #### Options -- `options.hideSearchBar` Lets you hide the search bar at the top of the screen for all users. - `options.homeFolder` You can specify a folder that is used when the user navigates `home`. Navigating home gets triggered by clicking on the `All files` menu item. The user will not be jailed in that directory. It simply serves as a default location. You can either provide a static location, or you can use variables of the user object to come up with a user specific home path. This uses twig template variable style and allows you to pick a value or a diff --git a/packages/web-app-files/src/search/sdk/index.ts b/packages/web-app-files/src/search/sdk/index.ts index 65dc6a7b0e1..8f44b1d9a41 100644 --- a/packages/web-app-files/src/search/sdk/index.ts +++ b/packages/web-app-files/src/search/sdk/index.ts @@ -4,7 +4,6 @@ import List from './list' import { EventBus } from 'web-pkg/src/event' import { Store } from 'vuex' import VueRouter from 'vue-router' -import get from 'lodash-es/get' function $gettext(msg) { return msg @@ -54,8 +53,6 @@ export default class Provider extends EventBus implements SearchProvider { } public get available(): boolean { - const { hideSearchBar } = this.store.getters['Search/options'] - - return !get(this.store, 'state.config.options.hideSearchBar', hideSearchBar) + return this.store.getters.capabilities.dav.reports.includes('search-files') } } diff --git a/packages/web-app-files/tests/unit/search/sdk.spec.ts b/packages/web-app-files/tests/unit/search/sdk.spec.ts index 4156e13007e..a0ce055f903 100644 --- a/packages/web-app-files/tests/unit/search/sdk.spec.ts +++ b/packages/web-app-files/tests/unit/search/sdk.spec.ts @@ -19,25 +19,18 @@ const localVue = createLocalVue() localVue.use(Vuex) const store = new Vuex.Store({ - modules: { - Search: { - state: { - options: { - hideSearchBar: false - } - }, - getters: { - options: (state) => { - return state.options - } - }, - mutations: { - updateOptions(state, v) { - state.options = { ...state.options, hideSearchBar: v } - } - }, - namespaced: true - } + getters: { + capabilities: jest.fn(() => ({ + dav: { + reports: ['search-files'] + } + })) + } +}) + +const storeWithoutFileSearch = new Vuex.Store({ + getters: { + capabilities: jest.fn(() => ({ dav: { reports: [] } })) } }) @@ -72,12 +65,9 @@ describe('SDKProvider', () => { expect('not-implemented').toBe('not-implemented') }) - it('is only available if enabled in options', () => { - const search = new SDKSearch(store, {} as unknown as VueRouter) - ;[false, true, false].forEach((v) => { - store.commit('Search/updateOptions', v) - expect(search.available).toBe(!v) - }) + it('is only available if announced via capabilities', () => { + const search = new SDKSearch(storeWithoutFileSearch, {} as unknown as VueRouter) + expect(search.available).toBe(false) }) describe('SDKProvider previewSearch', () => { diff --git a/packages/web-app-search/src/index.ts b/packages/web-app-search/src/index.ts index b309c543b1a..177fe8a64bc 100644 --- a/packages/web-app-search/src/index.ts +++ b/packages/web-app-search/src/index.ts @@ -1,6 +1,5 @@ import SearchBar from './portals/SearchBar.vue' import App from './App.vue' -import store from './store' import List from './views/List.vue' import { providerStore } from './service' import { bus } from 'web-pkg/src/instance' @@ -25,7 +24,6 @@ export default { id: 'search', icon: 'folder' }, - store, routes: [ { name: 'search', diff --git a/packages/web-app-search/src/store/index.ts b/packages/web-app-search/src/store/index.ts deleted file mode 100644 index bf15dda9279..00000000000 --- a/packages/web-app-search/src/store/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -/* istanbul ignore file */ - -import merge from 'lodash-es/merge' -import options from './options' - -export default merge({ namespaced: true }, options) diff --git a/packages/web-app-search/src/store/options.ts b/packages/web-app-search/src/store/options.ts deleted file mode 100644 index 28153b53192..00000000000 --- a/packages/web-app-search/src/store/options.ts +++ /dev/null @@ -1,16 +0,0 @@ -const optionsState = { - options: { - hideSearchBar: false - } -} - -const getters = { - options: (state: typeof optionsState): unknown => { - return state.options - } -} - -export default { - state: optionsState, - getters -} diff --git a/packages/web-app-search/tests/unit/store/options.spec.ts b/packages/web-app-search/tests/unit/store/options.spec.ts deleted file mode 100644 index 794cdc00f19..00000000000 --- a/packages/web-app-search/tests/unit/store/options.spec.ts +++ /dev/null @@ -1,9 +0,0 @@ -import optionsStore from '../../../src/store/options' - -describe('search options store', () => { - test('by default the search is visible', () => { - const { state, getters } = optionsStore - const { hideSearchBar } = getters.options(state) as any - expect(hideSearchBar).toBe(false) - }) -})