From ae854d4c38cbd1677d207b4a3b3bd33597b6e7d7 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 14 Jan 2023 13:25:48 +0100 Subject: [PATCH 01/18] Vue 3: Fix OcTooltip for Vue 3 components --- .../design-system/src/directives/OcTooltip.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/design-system/src/directives/OcTooltip.ts b/packages/design-system/src/directives/OcTooltip.ts index ddce940f63a..affe7394e1b 100644 --- a/packages/design-system/src/directives/OcTooltip.ts +++ b/packages/design-system/src/directives/OcTooltip.ts @@ -47,14 +47,14 @@ export const destroy = (_tippy) => { } } -const initOrUpdate = (el, { value = {} }: any, { elm }) => { +const initOrUpdate = (el, { value = {} }: any) => { if (Object.prototype.toString.call(value) !== '[object Object]') { value = { content: value } } - if (value.content !== 0 && !value.content) { - destroy(elm.tooltip) - elm.tooltip = null + if ((value.content !== 0 && !value.content) || value.content === '') { + destroy(el.tooltip) + el.tooltip = null return } @@ -69,20 +69,20 @@ const initOrUpdate = (el, { value = {} }: any, { elm }) => { value ]) - if (!elm.tooltip) { - elm.tooltip = tippy(el, { + if (!el.tooltip) { + el.tooltip = tippy(el, { ...props, plugins: [hideOnEsc, ariaHidden] }) return } - elm.tooltip.setProps(props) + el.tooltip.setProps(props) } export default { name: 'OcTooltip', beforeMount: initOrUpdate, updated: initOrUpdate, - unmounted: (el, binding, { elm }) => destroy(elm.tooltip) + unmounted: (el, binding) => destroy(el.tooltip) } From 49726056cebee562df414f2052e4cb4075320959 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 14 Jan 2023 13:26:43 +0100 Subject: [PATCH 02/18] Bump vue-router --- packages/web-app-files/package.json | 2 +- packages/web-pkg/package.json | 2 +- packages/web-runtime/package.json | 2 +- packages/web-runtime/src/defaults/vue.js | 2 - packages/web-runtime/src/index.ts | 6 +- packages/web-runtime/src/router/index.ts | 11 +-- packages/web-test-helpers/package.json | 2 +- pnpm-lock.yaml | 93 ++++++++---------------- 8 files changed, 41 insertions(+), 79 deletions(-) diff --git a/packages/web-app-files/package.json b/packages/web-app-files/package.json index fa83f2c058a..2889a059a8d 100644 --- a/packages/web-app-files/package.json +++ b/packages/web-app-files/package.json @@ -25,7 +25,7 @@ "uuid": "^9.0.0", "vue-concurrency": "4.0.0", "vue-gettext": "2.1.12", - "vue-router": "3.6.5", + "vue-router": "4.1.6", "vuex": "4.1.0", "web-app-files": "workspace:*", "web-app-search": "workspace:*", diff --git a/packages/web-pkg/package.json b/packages/web-pkg/package.json index 4ffbc41df72..9f4a774f5cc 100644 --- a/packages/web-pkg/package.json +++ b/packages/web-pkg/package.json @@ -12,7 +12,7 @@ "popper-max-size-modifier": "^0.2.0", "qs": "^6.10.3", "uuid": "^9.0.0", - "vue-router": "3.6.5", + "vue-router": "4.1.6", "vuex": "4.1.0", "web-client": "npm:@ownclouders/web-client", "web-pkg": "npm:@ownclouders/web-pkg", diff --git a/packages/web-runtime/package.json b/packages/web-runtime/package.json index e701607c9d5..075da732af0 100644 --- a/packages/web-runtime/package.json +++ b/packages/web-runtime/package.json @@ -43,7 +43,7 @@ "vue-concurrency": "4.0.0", "vue-gettext": "2.1.12", "vue-inline-svg": "3.1.0", - "vue-router": "3.6.5", + "vue-router": "4.1.6", "vue-select": "4.0.0-beta.6", "vuex": "4.1.0", "vuex-router-sync": "^5.0.0", diff --git a/packages/web-runtime/src/defaults/vue.js b/packages/web-runtime/src/defaults/vue.js index b98d935c9d6..eb4c240e204 100644 --- a/packages/web-runtime/src/defaults/vue.js +++ b/packages/web-runtime/src/defaults/vue.js @@ -3,11 +3,9 @@ import WebPlugin from '../plugins/web' import Avatar from '../components/Avatar.vue' import focusMixin from '../mixins/focusMixin' import lifecycleMixin from '../mixins/lifecycleMixin' -import VueRouter from 'vue-router' import Vuex from 'vuex' Vue.use(Vuex) -Vue.use(VueRouter) Vue.use(WebPlugin) Vue.component('AvatarImage', Avatar) diff --git a/packages/web-runtime/src/index.ts b/packages/web-runtime/src/index.ts index 8393bd6d5b0..546b8bb582f 100644 --- a/packages/web-runtime/src/index.ts +++ b/packages/web-runtime/src/index.ts @@ -65,13 +65,12 @@ export const bootstrap = async (configurationPath: string): Promise => { announceDefaults({ store, router }) } -export const renderSuccess = (): void => { +export const renderSuccess = async (): Promise => { Vue.prototype.$store = store const applications = Array.from(applicationStore.values()) const instance = createApp({ store, - router, render() { return h(pages.success) } @@ -86,6 +85,9 @@ export const renderSuccess = (): void => { // @vueuse/head instance.use(createHead()) + // install router + instance.use(router) + // mount App instance.mount('#owncloud') applications.forEach((application) => application.mounted(instance)) diff --git a/packages/web-runtime/src/router/index.ts b/packages/web-runtime/src/router/index.ts index 5a9b27997c9..7cdef5375cc 100644 --- a/packages/web-runtime/src/router/index.ts +++ b/packages/web-runtime/src/router/index.ts @@ -8,7 +8,7 @@ import ResolvePublicLinkPage from '../pages/resolvePublicLink.vue' import ResolvePrivateLinkPage from '../pages/resolvePrivateLink.vue' import { setupAuthGuard } from './setupAuthGuard' import { patchRouter } from './patchCleanPath' -import VueRouter from 'vue-router' +import { createRouter as _createRouter, createWebHashHistory, createWebHistory, RouterOptions } from 'vue-router' export * from './helpers' @@ -17,8 +17,8 @@ function $gettext(msg) { return msg } -export const createRouter = (options?: any) => { - ;(window as any).__HACK__router = new VueRouter(options) +export const createRouter = (options?: RouterOptions) => { + ;(window as any).__HACK__router = _createRouter(options) return (window as any).__HACK__router } @@ -36,10 +36,7 @@ export const router = patchRouter( addQueryPrefix: true }) }, - ...(base && { - mode: 'history', - base: new URL(base.href).pathname - }), + history: base && createWebHistory(new URL(base.href).pathname) || createWebHashHistory(), routes: [ { path: '/login', diff --git a/packages/web-test-helpers/package.json b/packages/web-test-helpers/package.json index b2c86eb8b32..385c5204e50 100644 --- a/packages/web-test-helpers/package.json +++ b/packages/web-test-helpers/package.json @@ -5,7 +5,7 @@ "peerDependencies": { "axios": "0.27.2", "vue-gettext": "2.1.12", - "vue-router": "3.6.5", + "vue-router": "4.1.6", "vuex": "4.1.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 708748f9e1f..2772b943006 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,12 +6,12 @@ patchedDependencies: '@adobe/leonardo-contrast-colors@1.0.0-alpha.16': hash: uknaqjiop66j4kgrr7nmysu5gi path: patches/@adobe__leonardo-contrast-colors@1.0.0-alpha.16.patch - jest-serializer-vue-tjw@3.19.0: - hash: n3ezndisi6xx2kbxcsk5pv4dxy - path: patches/jest-serializer-vue-tjw@3.19.0.patch vue-gettext@2.1.12: hash: 6c2crj3kpnhb2sofrku4e7jhce path: patches/vue-gettext@2.1.12.patch + jest-serializer-vue-tjw@3.19.0: + hash: n3ezndisi6xx2kbxcsk5pv4dxy + path: patches/jest-serializer-vue-tjw@3.19.0.patch keycode@2.2.1: hash: nmisee7m676ph5sqah5fka5ueu path: patches/keycode@2.2.1.patch @@ -477,7 +477,7 @@ importers: uuid: ^9.0.0 vue-concurrency: 4.0.0 vue-gettext: 2.1.12 - vue-router: 3.6.5 + vue-router: 4.1.6 vuex: 4.1.0 web-app-files: workspace:* web-app-search: workspace:* @@ -496,10 +496,10 @@ importers: sanitize-html: 2.7.0 semver: 7.3.8 uuid: 9.0.0 - vue-concurrency: 4.0.0 + vue-concurrency: 4.0.0_vue@3.2.45 vue-gettext: 2.1.12_6c2crj3kpnhb2sofrku4e7jhce - vue-router: 3.6.5 - vuex: 4.1.0 + vue-router: 4.1.6_vue@3.2.45 + vuex: 4.1.0_vue@3.2.45 web-app-files: 'link:' web-app-search: link:../web-app-search web-client: link:../web-client @@ -507,7 +507,7 @@ importers: web-runtime: link:../web-runtime devDependencies: '@jest/globals': 29.3.1 - '@vueuse/core': 9.8.2 + '@vueuse/core': 9.8.2_vue@3.2.45 packages/web-app-pdf-viewer: specifiers: @@ -593,7 +593,7 @@ importers: qs: ^6.10.3 uuid: ^9.0.0 vue-concurrency: 4.0.0 - vue-router: 3.6.5 + vue-router: 4.1.6 vuex: 4.1.0 web-client: npm:@ownclouders/web-client web-pkg: npm:@ownclouders/web-pkg @@ -605,9 +605,9 @@ importers: popper-max-size-modifier: 0.2.0_@popperjs+core@2.11.5 qs: 6.10.3 uuid: 9.0.0 - vue-concurrency: 4.0.0 - vue-router: 3.6.5 - vuex: 4.1.0 + vue-concurrency: 4.0.0_vue@3.2.45 + vue-router: 4.1.6_vue@3.2.45 + vuex: 4.1.0_vue@3.2.45 web-client: link:../web-client web-pkg: 'link:' @@ -654,7 +654,7 @@ importers: vue-concurrency: 4.0.0 vue-gettext: 2.1.12 vue-inline-svg: 3.1.0 - vue-router: 3.6.5 + vue-router: 4.1.6 vue-select: 4.0.0-beta.6 vuex: 4.1.0 vuex-router-sync: ^5.0.0 @@ -703,10 +703,10 @@ importers: vue-concurrency: 4.0.0_vue@3.2.45 vue-gettext: 2.1.12_6c2crj3kpnhb2sofrku4e7jhce vue-inline-svg: 3.1.0_agvlx64p3fh52dmj7mriww4tnm_vue@3.2.45 - vue-router: 3.6.5_vue@3.2.45 + vue-router: 4.1.6_vue@3.2.45 vue-select: 4.0.0-beta.6_vue@3.2.45 vuex: 4.1.0_vue@3.2.45 - vuex-router-sync: 5.0.0_6x7cybbl2jmitybnyifyjha3eu + vuex-router-sync: 5.0.0_mhkwdqbz43jpnlolybzfmh5sqi web-client: link:../web-client web-pkg: link:../web-pkg web-runtime: 'link:' @@ -722,13 +722,13 @@ importers: specifiers: axios: 0.27.2 vue-gettext: 2.1.12 - vue-router: 3.6.5 + vue-router: 4.1.6 vuex: 4.1.0 dependencies: axios: 0.27.2 vue-gettext: 2.1.12_6c2crj3kpnhb2sofrku4e7jhce - vue-router: 3.6.5 - vuex: 4.1.0 + vue-router: 4.1.6_vue@3.2.45 + vuex: 4.1.0_vue@3.2.45 tests/acceptance: specifiers: @@ -6575,13 +6575,13 @@ packages: - supports-color dev: true - /@vueuse/core/9.8.2: + /@vueuse/core/9.8.2_vue@3.2.45: resolution: {integrity: sha512-aWiCmcYIpPt7xjuqYiceODEMHchDYthrJ4AqI+FXPZrR23PZOqdiktbUVyQl2kGlR3H4i9UJ/uimQrwhz9UouQ==} dependencies: '@types/web-bluetooth': 0.0.16 '@vueuse/metadata': 9.8.2 - '@vueuse/shared': 9.8.2 - vue-demi: 0.13.11 + '@vueuse/shared': 9.8.2_vue@3.2.45 + vue-demi: 0.13.11_vue@3.2.45 transitivePeerDependencies: - '@vue/composition-api' - vue @@ -6603,10 +6603,10 @@ packages: resolution: {integrity: sha512-N4E/BKS+9VsUeD4WLVRU1J2kCOLh+iikBcMtipFcTyL204132vDYHs27zLAVabJYGnhC0dIVGdhg9pbOZiY2TQ==} dev: true - /@vueuse/shared/9.8.2: + /@vueuse/shared/9.8.2_vue@3.2.45: resolution: {integrity: sha512-ACjrPQzowd5dnabNJt9EoGVobco9/ENiA5qP53vjiuxndlJYuc/UegwhXC7KdQbPX4F45a50+45K3g1wNqOzmA==} dependencies: - vue-demi: 0.13.11 + vue-demi: 0.13.11_vue@3.2.45 transitivePeerDependencies: - '@vue/composition-api' - vue @@ -22099,14 +22099,6 @@ packages: resolution: {integrity: sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==} engines: {node: '>=0.10.0'} - /vue-concurrency/4.0.0: - resolution: {integrity: sha512-YOLrHang8w15bMOpftw6iPsoqlZT/u5zsblnT+CrVvc2HZ0eP76hjj77sgepHxB6FRcN3dlFXDNBMQ6iZzpiNw==} - peerDependencies: - vue: ^3.2.20 || ^2.7.0 - dependencies: - caf: 15.0.1 - dev: false - /vue-concurrency/4.0.0_vue@3.2.45: resolution: {integrity: sha512-YOLrHang8w15bMOpftw6iPsoqlZT/u5zsblnT+CrVvc2HZ0eP76hjj77sgepHxB6FRcN3dlFXDNBMQ6iZzpiNw==} peerDependencies: @@ -22116,19 +22108,6 @@ packages: vue: 3.2.45 dev: false - /vue-demi/0.13.11: - resolution: {integrity: sha512-IR8HoEEGM65YY3ZJYAjMlKygDQn25D5ajNFNoKh9RSDMQtlzCxtfQjdQgv9jjK+m3377SsJXY8ysq8kLCZL25A==} - engines: {node: '>=12'} - hasBin: true - requiresBuild: true - peerDependencies: - '@vue/composition-api': ^1.0.0-rc.1 - vue: ^3.0.0-0 || ^2.6.0 - peerDependenciesMeta: - '@vue/composition-api': - optional: true - dev: true - /vue-demi/0.13.11_vue@3.2.45: resolution: {integrity: sha512-IR8HoEEGM65YY3ZJYAjMlKygDQn25D5ajNFNoKh9RSDMQtlzCxtfQjdQgv9jjK+m3377SsJXY8ysq8kLCZL25A==} engines: {node: '>=12'} @@ -22142,7 +22121,6 @@ packages: optional: true dependencies: vue: 3.2.45 - dev: false /vue-docgen-api/4.56.0_vue@3.2.45: resolution: {integrity: sha512-ab/Scb0DCjm4YVLf+AFa/R7XMFl8TVwUsvh26fFT5iaURih1m2hdd5Y8NveA7NQDcycpWavkFZj9eVbQdp2VGQ==} @@ -22359,17 +22337,12 @@ packages: - whiskers dev: true - /vue-router/3.6.5: - resolution: {integrity: sha512-VYXZQLtjuvKxxcshuRAwjHnciqZVoXAjTjcqBTz4rKc8qih9g9pI3hbDjmqXaHdgL3v8pV6P8Z335XvHzESxLQ==} + /vue-router/4.1.6_vue@3.2.45: + resolution: {integrity: sha512-DYWYwsG6xNPmLq/FmZn8Ip+qrhFEzA14EI12MsMgVxvHFDYvlr4NXpVF5hrRH1wVcDP8fGi5F4rxuJSl8/r+EQ==} peerDependencies: - vue: ^2 - dev: false - - /vue-router/3.6.5_vue@3.2.45: - resolution: {integrity: sha512-VYXZQLtjuvKxxcshuRAwjHnciqZVoXAjTjcqBTz4rKc8qih9g9pI3hbDjmqXaHdgL3v8pV6P8Z335XvHzESxLQ==} - peerDependencies: - vue: ^2 + vue: ^3.2.0 dependencies: + '@vue/devtools-api': 6.4.5 vue: 3.2.45 dev: false @@ -22519,24 +22492,16 @@ packages: '@vue/server-renderer': 3.2.45_vue@3.2.45 '@vue/shared': 3.2.45 - /vuex-router-sync/5.0.0_6x7cybbl2jmitybnyifyjha3eu: + /vuex-router-sync/5.0.0_mhkwdqbz43jpnlolybzfmh5sqi: resolution: {integrity: sha512-Mry2sO4kiAG64714X1CFpTA/shUH1DmkZ26DFDtwoM/yyx6OtMrc+MxrU+7vvbNLO9LSpgwkiJ8W+rlmRtsM+w==} peerDependencies: vue-router: ^3.0.0 vuex: ^3.0.0 dependencies: - vue-router: 3.6.5_vue@3.2.45 + vue-router: 4.1.6_vue@3.2.45 vuex: 4.1.0_vue@3.2.45 dev: false - /vuex/4.1.0: - resolution: {integrity: sha512-hmV6UerDrPcgbSy9ORAtNXDr9M4wlNP4pEFKye4ujJF8oqgFFuxDCdOLS3eNoRTtq5O3hoBDh9Doj1bQMYHRbQ==} - peerDependencies: - vue: ^3.2.0 - dependencies: - '@vue/devtools-api': 6.4.5 - dev: false - /vuex/4.1.0_vue@3.2.45: resolution: {integrity: sha512-hmV6UerDrPcgbSy9ORAtNXDr9M4wlNP4pEFKye4ujJF8oqgFFuxDCdOLS3eNoRTtq5O3hoBDh9Doj1bQMYHRbQ==} peerDependencies: From 21964da8abda173f5f3aba11a92b7a9d22c3f811 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 14 Jan 2023 13:30:23 +0100 Subject: [PATCH 03/18] Adjust driveAliasAndItem to make it a string and optional. With just * we receive an array in route.params, which is not what we want/need/expect. The question mark makes it optional, we need that to be able to redirect or do any sort of other fallback handling. --- packages/web-app-draw-io/src/index.js | 2 +- packages/web-app-external/src/index.js | 2 +- packages/web-app-files/src/router/public.ts | 2 +- packages/web-app-files/src/router/spaces.ts | 2 +- packages/web-app-files/src/router/trash.ts | 2 +- packages/web-app-pdf-viewer/src/index.js | 2 +- packages/web-app-preview/src/index.js | 2 +- packages/web-app-text-editor/src/index.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/web-app-draw-io/src/index.js b/packages/web-app-draw-io/src/index.js index 0312bbe70e1..25b1a682f40 100644 --- a/packages/web-app-draw-io/src/index.js +++ b/packages/web-app-draw-io/src/index.js @@ -4,7 +4,7 @@ import App from './App.vue' const routes = [ { name: 'draw-io', - path: '/:driveAliasAndItem*', + path: '/:driveAliasAndItem(.*)?', component: App, meta: { authContext: 'hybrid', diff --git a/packages/web-app-external/src/index.js b/packages/web-app-external/src/index.js index 92c6449d552..f8e7c287e83 100644 --- a/packages/web-app-external/src/index.js +++ b/packages/web-app-external/src/index.js @@ -10,7 +10,7 @@ const appInfo = { const routes = [ { name: 'apps', - path: '/:driveAliasAndItem*', + path: '/:driveAliasAndItem(.*)?', component: App, meta: { authContext: 'hybrid', diff --git a/packages/web-app-files/src/router/public.ts b/packages/web-app-files/src/router/public.ts index 706ee7a3d2c..5e6e76f13d9 100644 --- a/packages/web-app-files/src/router/public.ts +++ b/packages/web-app-files/src/router/public.ts @@ -25,7 +25,7 @@ export const buildRoutes = (components: RouteComponents): RouteConfig[] => [ children: [ { name: locationPublicLink.name, - path: ':driveAliasAndItem*', + path: ':driveAliasAndItem(.*)?', component: components.Spaces.DriveResolver, meta: { authContext: 'publicLink', diff --git a/packages/web-app-files/src/router/spaces.ts b/packages/web-app-files/src/router/spaces.ts index f3d5eb5bde0..cc2acc7f7ae 100644 --- a/packages/web-app-files/src/router/spaces.ts +++ b/packages/web-app-files/src/router/spaces.ts @@ -32,7 +32,7 @@ export const buildRoutes = (components: RouteComponents): RouteConfig[] => [ } }, { - path: ':driveAliasAndItem*', + path: ':driveAliasAndItem(.*)?', name: locationSpacesGeneric.name, component: components.Spaces.DriveResolver, meta: { diff --git a/packages/web-app-files/src/router/trash.ts b/packages/web-app-files/src/router/trash.ts index b770f33ce39..aad4c61c007 100644 --- a/packages/web-app-files/src/router/trash.ts +++ b/packages/web-app-files/src/router/trash.ts @@ -18,7 +18,7 @@ export const buildRoutes = (components: RouteComponents): RouteConfig[] => [ children: [ { name: locationTrashGeneric.name, - path: ':driveAliasAndItem*', + path: ':driveAliasAndItem(.*)?', component: components.Spaces.DriveResolver, meta: { authContext: 'user', diff --git a/packages/web-app-pdf-viewer/src/index.js b/packages/web-app-pdf-viewer/src/index.js index ec17da753c6..86a8a5523a3 100644 --- a/packages/web-app-pdf-viewer/src/index.js +++ b/packages/web-app-pdf-viewer/src/index.js @@ -8,7 +8,7 @@ function $gettext(msg) { const routes = [ { - path: '/:driveAliasAndItem*', + path: '/:driveAliasAndItem(.*)?', component: App, name: 'pdf-viewer', meta: { diff --git a/packages/web-app-preview/src/index.js b/packages/web-app-preview/src/index.js index ccb25d87853..15d35f68ef4 100644 --- a/packages/web-app-preview/src/index.js +++ b/packages/web-app-preview/src/index.js @@ -8,7 +8,7 @@ function $gettext(msg) { const routes = [ { - path: '/:driveAliasAndItem*', + path: '/:driveAliasAndItem(.*)?', component: App, name: 'media', meta: { diff --git a/packages/web-app-text-editor/src/index.js b/packages/web-app-text-editor/src/index.js index f495d6470ea..1777c528dcf 100644 --- a/packages/web-app-text-editor/src/index.js +++ b/packages/web-app-text-editor/src/index.js @@ -10,7 +10,7 @@ const appId = 'text-editor' const routes = [ { - path: '/:driveAliasAndItem*', + path: '/:driveAliasAndItem(.*)?', component: App, name: 'text-editor', meta: { From e99554c52e53148cb4eaaf0cfce80f31d3f59a3b Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 14 Jan 2023 13:52:39 +0100 Subject: [PATCH 04/18] Fix Router type --- packages/web-app-files/src/fileSideBars.ts | 2 +- .../web-app-files/src/router/deprecated.ts | 4 +-- packages/web-app-files/src/router/utils.ts | 9 ++--- .../web-app-files/src/search/sdk/index.ts | 6 ++-- .../web-app-files/src/search/sdk/preview.ts | 6 ++-- .../src/services/folder/loaderSpace.ts | 2 +- .../src/services/folder/loaderTrashbin.ts | 2 +- .../tests/unit/components/Search/List.spec.ts | 2 -- .../tests/unit/router/utils.spec.ts | 33 +++++++++---------- .../tests/unit/search/sdk.spec.ts | 19 ++++++----- .../appDefaults/useAppNavigation.ts | 4 +-- .../src/composables/router/useActiveApp.ts | 3 +- .../src/composables/router/useRouter.ts | 4 +-- .../unit/composables/router/useRouter.spec.ts | 7 ++-- packages/web-runtime/src/container/api.ts | 10 +++--- .../src/container/application/classic.ts | 4 +-- .../src/container/application/index.ts | 4 +-- .../web-runtime/src/container/bootstrap.ts | 8 ++--- packages/web-runtime/src/container/types.ts | 4 +-- packages/web-runtime/src/router/helpers.ts | 2 +- packages/web-runtime/src/router/index.ts | 9 +++-- .../web-runtime/src/router/patchCleanPath.ts | 2 +- .../src/services/auth/authService.ts | 6 ++-- 23 files changed, 79 insertions(+), 73 deletions(-) diff --git a/packages/web-app-files/src/fileSideBars.ts b/packages/web-app-files/src/fileSideBars.ts index d536993b3e7..5060f07b539 100644 --- a/packages/web-app-files/src/fileSideBars.ts +++ b/packages/web-app-files/src/fileSideBars.ts @@ -18,7 +18,7 @@ import { spaceRoleEditor, spaceRoleManager } from 'web-client/src/helpers/share' import { Panel } from '../../web-pkg/src/components/sideBar' import { Resource, User } from 'web-client' -import Router from 'vue-router' +import { Router } from 'vue-router' function $gettext(msg: string): string { return msg diff --git a/packages/web-app-files/src/router/deprecated.ts b/packages/web-app-files/src/router/deprecated.ts index 96a50c20b76..8c7761f7856 100644 --- a/packages/web-app-files/src/router/deprecated.ts +++ b/packages/web-app-files/src/router/deprecated.ts @@ -1,4 +1,4 @@ -import VueRouter, { RouteConfig, Route, Location, RouteMeta } from 'vue-router' +import { RouteConfig, Route, Location, RouteMeta, Router } from 'vue-router' import { createLocationSpaces } from './spaces' import { createLocationShares } from './shares' import { createLocationCommon } from './common' @@ -100,7 +100,7 @@ export const buildRoutes = (): RouteConfig[] => * @param comparatives */ export const isLocationActive = ( - router: VueRouter, + router: Router, ...comparatives: [Location, ...Location[]] ): boolean => { const [first, ...rest] = comparatives.map((c) => { diff --git a/packages/web-app-files/src/router/utils.ts b/packages/web-app-files/src/router/utils.ts index fb05096d6fc..5ec59f08711 100644 --- a/packages/web-app-files/src/router/utils.ts +++ b/packages/web-app-files/src/router/utils.ts @@ -1,8 +1,9 @@ -import VueRouter, { Location } from 'vue-router' +import { Location } from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import merge from 'lodash-es/merge' export interface ActiveRouteDirectorFunc { - (router: VueRouter, ...comparatives: T[]): boolean + (router: Router, ...comparatives: T[]): boolean } /** @@ -13,7 +14,7 @@ export interface ActiveRouteDirectorFunc { * @param comparatives */ export const isLocationActive = ( - router: VueRouter, + router: Router, ...comparatives: [Location, ...Location[]] ): boolean => { const { href: currentHref } = router.resolve(router.currentRoute) @@ -47,7 +48,7 @@ export const isLocationActive = ( export const isLocationActiveDirector = ( ...defaultComparatives: [Location, ...Location[]] ): ActiveRouteDirectorFunc => { - return (router: VueRouter, ...comparatives: T[]): boolean => { + return (router: Router, ...comparatives: T[]): boolean => { if (!comparatives.length) { return isLocationActive(router, ...defaultComparatives) } diff --git a/packages/web-app-files/src/search/sdk/index.ts b/packages/web-app-files/src/search/sdk/index.ts index 14efc43f8a3..7ce144b9106 100644 --- a/packages/web-app-files/src/search/sdk/index.ts +++ b/packages/web-app-files/src/search/sdk/index.ts @@ -3,7 +3,7 @@ import Preview from './preview' import List from './list' import { EventBus } from 'web-pkg/src/services/eventBus' import { Store } from 'vuex' -import VueRouter from 'vue-router' +import { Router } from 'vue-router' function $gettext(msg) { return msg @@ -14,9 +14,9 @@ export default class Provider extends EventBus implements SearchProvider { public readonly previewSearch: SearchPreview public readonly listSearch: SearchList private readonly store: Store - private readonly router: VueRouter + private readonly router: Router - constructor(store: Store, router: VueRouter) { + constructor(store: Store, router: Router) { super() this.id = 'files.sdk' diff --git a/packages/web-app-files/src/search/sdk/preview.ts b/packages/web-app-files/src/search/sdk/preview.ts index 5ebbffa6c33..009fc05edeb 100644 --- a/packages/web-app-files/src/search/sdk/preview.ts +++ b/packages/web-app-files/src/search/sdk/preview.ts @@ -4,7 +4,7 @@ import { clientService } from 'web-pkg/src/services' import { buildResource } from 'web-client/src/helpers' import { Cache } from 'web-pkg/src/helpers/cache' import { Component } from 'vue' -import VueRouter from 'vue-router' +import { Router } from 'vue-router' import { DavProperties } from 'web-client/src/webdav/constants' import { Store } from 'vuex' @@ -13,10 +13,10 @@ export const previewSearchLimit = 8 export default class Preview implements SearchPreview { public readonly component: Component private readonly cache: Cache - private readonly router: VueRouter + private readonly router: Router private readonly store: Store - constructor(store: Store, router: VueRouter) { + constructor(store: Store, router: Router) { this.component = PreviewComponent this.router = router this.store = store diff --git a/packages/web-app-files/src/services/folder/loaderSpace.ts b/packages/web-app-files/src/services/folder/loaderSpace.ts index 662c888e396..b9024d50f70 100644 --- a/packages/web-app-files/src/services/folder/loaderSpace.ts +++ b/packages/web-app-files/src/services/folder/loaderSpace.ts @@ -1,5 +1,5 @@ import { FolderLoader, FolderLoaderTask, TaskContext } from '../folder' -import Router from 'vue-router' +import { Router } from 'vue-router' import { useTask } from 'vue-concurrency' import { isLocationPublicActive, isLocationSpacesActive } from '../../router' import { diff --git a/packages/web-app-files/src/services/folder/loaderTrashbin.ts b/packages/web-app-files/src/services/folder/loaderTrashbin.ts index ffbf52924cd..41ac93ed445 100644 --- a/packages/web-app-files/src/services/folder/loaderTrashbin.ts +++ b/packages/web-app-files/src/services/folder/loaderTrashbin.ts @@ -1,5 +1,5 @@ import { FolderLoader, FolderLoaderTask, TaskContext } from '../folder' -import Router from 'vue-router' +import { Router } from 'vue-router' import { useTask } from 'vue-concurrency' import { DavProperties } from 'web-client/src/webdav/constants' import { isLocationTrashActive } from '../../router' diff --git a/packages/web-app-files/tests/unit/components/Search/List.spec.ts b/packages/web-app-files/tests/unit/components/Search/List.spec.ts index fa77aefca12..0b167d11d51 100644 --- a/packages/web-app-files/tests/unit/components/Search/List.spec.ts +++ b/packages/web-app-files/tests/unit/components/Search/List.spec.ts @@ -1,5 +1,4 @@ import { describe } from '@jest/globals' -// import VueRouter from 'vue-router' // import List from 'web-app-files/src/components/Search/List.vue' // // const stubs = { @@ -98,7 +97,6 @@ describe('List component', () => { // } // }, // store: createStore(files), -// router: new VueRouter(), // stubs, // mock: { // webdav: { diff --git a/packages/web-app-files/tests/unit/router/utils.spec.ts b/packages/web-app-files/tests/unit/router/utils.spec.ts index 234a8449d16..f7eb919a555 100644 --- a/packages/web-app-files/tests/unit/router/utils.spec.ts +++ b/packages/web-app-files/tests/unit/router/utils.spec.ts @@ -3,18 +3,19 @@ import { isLocationActiveDirector, createLocation } from '../../../src/router/utils' -import VueRouter from 'vue-router' +import { Router } from 'vue-router' +import { mock } from 'jest-mock-extended' describe('utils', () => { describe('isLocationActive', () => { it('returns true if one location is active', () => { - const fakeRouter = { + const fakeRouter = mock({ currentRoute: { name: 'foo' }, resolve: (r) => ({ href: r.name }) - } + }) - expect(isLocationActive(fakeRouter as VueRouter, { name: 'foo' })).toBe(true) - expect(isLocationActive(fakeRouter as VueRouter, { name: 'foo' }, { name: 'bar' })).toBe(true) + expect(isLocationActive(fakeRouter, { name: 'foo' })).toBe(true) + expect(isLocationActive(fakeRouter, { name: 'foo' }, { name: 'bar' })).toBe(true) }) it('returns false if all locations inactive', () => { @@ -23,41 +24,39 @@ describe('utils', () => { resolve: (r) => ({ href: r.name }) } - expect(isLocationActive(fakeRouter as VueRouter, { name: 'bar' })).toBe(false) - expect(isLocationActive(fakeRouter as VueRouter, { name: 'bar' }, { name: 'baz' })).toBe( - false - ) + expect(isLocationActive(fakeRouter, { name: 'bar' })).toBe(false) + expect(isLocationActive(fakeRouter, { name: 'bar' }, { name: 'baz' })).toBe(false) }) }) describe('isLocationActiveDirector', () => { test('director can be created and be used to check active locations', () => { - const fakeRouter = { + const fakeRouter = mock({ currentRoute: { name: 'unknown' }, resolve: (r) => ({ href: r.name }) - } + }) const isFilesLocationActive = isLocationActiveDirector( { name: 'foo' }, { name: 'bar' }, { name: 'baz' } ) - expect(isFilesLocationActive(fakeRouter as VueRouter)).toBe(false) + expect(isFilesLocationActive(fakeRouter)).toBe(false) fakeRouter.currentRoute.name = 'bar' - expect(isFilesLocationActive(fakeRouter as VueRouter)).toBe(true) - expect(isFilesLocationActive(fakeRouter as VueRouter, 'foo', 'bar')).toBe(true) + expect(isFilesLocationActive(fakeRouter)).toBe(true) + expect(isFilesLocationActive(fakeRouter, 'foo', 'bar')).toBe(true) }) test('director closure only allows to check known locations and throws if unknown', () => { - const fakeRouter = { + const fakeRouter = mock({ currentRoute: { name: 'baz' }, resolve: (r) => ({ href: r.name }) - } + }) const isFilesLocationActive = isLocationActiveDirector({ name: 'foo' }, { name: 'bar' }) - expect(() => isFilesLocationActive(fakeRouter as VueRouter, 'unknown')).toThrow() + expect(() => isFilesLocationActive(fakeRouter, 'unknown')).toThrow() }) }) 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 ac0ee5f9a08..184d1aa26fa 100644 --- a/packages/web-app-files/tests/unit/search/sdk.spec.ts +++ b/packages/web-app-files/tests/unit/search/sdk.spec.ts @@ -1,8 +1,8 @@ import { SDKSearch } from '../../../src/search' import { clientService } from 'web-pkg/src/services' import { Store } from 'vuex' -import VueRouter from 'vue-router' -import { mockDeep } from 'jest-mock-extended' +import { Router } from 'vue-router' +import { mock, mockDeep } from 'jest-mock-extended' const searchMock = jest.fn() jest.spyOn(clientService, 'owncloudSdk', 'get').mockImplementation( @@ -35,7 +35,7 @@ const storeWithoutFileSearch = mockDeep>({ describe('SDKProvider', () => { it('is only available if announced via capabilities', () => { - const search = new SDKSearch(storeWithoutFileSearch, {} as unknown as VueRouter) + const search = new SDKSearch(storeWithoutFileSearch, mock()) expect(search.available).toBe(false) }) @@ -46,16 +46,19 @@ describe('SDKProvider', () => { { route: 'search-provider-list' }, { route: 'bar', available: true } ].forEach((v) => { - const search = new SDKSearch(store, { - currentRoute: { name: v.route } - } as unknown as VueRouter) + const search = new SDKSearch( + store, + mock({ + currentRoute: { name: v.route } + }) + ) expect(!!search.previewSearch.available).toBe(!!v.available) }) }) it('can search', async () => { - const search = new SDKSearch(store, jest.fn() as unknown as VueRouter) + const search = new SDKSearch(store, mock()) const files = [ { id: 'foo', name: 'foo' }, { id: 'bar', name: 'bar' }, @@ -75,7 +78,7 @@ describe('SDKProvider', () => { }) describe('SDKProvider listSearch', () => { it('can search', async () => { - const search = new SDKSearch(store, jest.fn() as unknown as VueRouter) + const search = new SDKSearch(store, mock()) const files = [ { id: 'foo', name: 'foo' }, { id: 'bar', name: 'bar' }, diff --git a/packages/web-pkg/src/composables/appDefaults/useAppNavigation.ts b/packages/web-pkg/src/composables/appDefaults/useAppNavigation.ts index 1bfd72ec3de..9ef1104b3d4 100644 --- a/packages/web-pkg/src/composables/appDefaults/useAppNavigation.ts +++ b/packages/web-pkg/src/composables/appDefaults/useAppNavigation.ts @@ -1,5 +1,5 @@ import { unref } from 'vue' -import VueRouter, { Location } from 'vue-router' +import { Location, Router } from 'vue-router' import { MaybeRef } from '../../utils' import { FileContext } from './types' @@ -8,7 +8,7 @@ import { Resource } from 'web-client' import { useFileRouteReplace } from '../router/useFileRouteReplace' interface AppNavigationOptions { - router: VueRouter + router: Router currentFileContext: MaybeRef } diff --git a/packages/web-pkg/src/composables/router/useActiveApp.ts b/packages/web-pkg/src/composables/router/useActiveApp.ts index 4b3fbff4b59..4f35b7f82c7 100644 --- a/packages/web-pkg/src/composables/router/useActiveApp.ts +++ b/packages/web-pkg/src/composables/router/useActiveApp.ts @@ -1,6 +1,5 @@ import { computed, ComputedRef, unref } from 'vue' -import { useRoute } from './useRoute' -import { Route } from 'vue-router' +import { useRoute } from 'vue-router' export const activeApp = (route: Route): string => { return route.path.split('/')[1] diff --git a/packages/web-pkg/src/composables/router/useRouter.ts b/packages/web-pkg/src/composables/router/useRouter.ts index 83aff6d30a5..c8f15df78cd 100644 --- a/packages/web-pkg/src/composables/router/useRouter.ts +++ b/packages/web-pkg/src/composables/router/useRouter.ts @@ -1,7 +1,7 @@ -import VueRouter from 'vue-router' +import { Router } from 'vue-router' import { useService } from '../service' -export const useRouter = (): VueRouter => { +export const useRouter = (): Router => { const hack = (window as any).__HACK__router if (hack) { return hack diff --git a/packages/web-pkg/tests/unit/composables/router/useRouter.spec.ts b/packages/web-pkg/tests/unit/composables/router/useRouter.spec.ts index 7c743d4a511..cf5616ccc91 100644 --- a/packages/web-pkg/tests/unit/composables/router/useRouter.spec.ts +++ b/packages/web-pkg/tests/unit/composables/router/useRouter.spec.ts @@ -1,8 +1,7 @@ import { useRouter } from 'web-pkg/src/composables' -import VueRouter from 'vue-router' import { createRouter, getComposableWrapper } from 'web-test-helpers' -describe('useRouter', () => { +describe.skip('useRouter', () => { // FIXME it.skip('should be valid', () => { expect(useRouter).toBeDefined() @@ -10,7 +9,9 @@ describe('useRouter', () => { const mocks = { $router: router } getComposableWrapper( () => { - expect(useRouter()).toBeInstanceOf(VueRouter) + // FIXME: Router is just a type, so we can't do a runtime check + // hopefully we can just get rid of our own useRouter composable + // expect(useRouter()).toBeInstanceOf(Router) }, { mocks } ) diff --git a/packages/web-runtime/src/container/api.ts b/packages/web-runtime/src/container/api.ts index b12384d703d..59b39e0eb37 100644 --- a/packages/web-runtime/src/container/api.ts +++ b/packages/web-runtime/src/container/api.ts @@ -1,4 +1,4 @@ -import VueRouter, { RouteConfig } from 'vue-router' +import { RouteConfig, Router } from 'vue-router' import clone from 'lodash-es/clone' import { RuntimeApi, @@ -18,7 +18,7 @@ import { App, Component, h } from 'vue' * @param router * @param routes */ -const announceRoutes = (applicationId: string, router: VueRouter, routes: RouteConfig[]): void => { +const announceRoutes = (applicationId: string, router: Router, routes: RouteConfig[]): void => { if (!isArray(routes)) { throw new ApiError("routes can't be blank") } @@ -205,7 +205,7 @@ const requestStore = (store: Store): Store => { * * @param router */ -const requestRouter = (router: VueRouter): VueRouter => { +const requestRouter = (router: Router): Router => { if (isEqual(process.env.NODE_ENV, 'development')) { console.warn('requestRouter // router api is deprecated, use with caution') } @@ -238,7 +238,7 @@ export const buildRuntimeApi = ({ applicationId: string store: Store translations: unknown - router: VueRouter + router: Router supportedLanguages: { [key: string]: string } }): RuntimeApi => { if (!applicationName) { @@ -262,7 +262,7 @@ export const buildRuntimeApi = ({ announceExtension: (extension: { [key: string]: unknown }): void => announceExtension(applicationId, store, extension), requestStore: (): Store => requestStore(store), - requestRouter: (): VueRouter => requestRouter(router), + requestRouter: (): Router => requestRouter(router), openPortal: ( instance: App, toApp: string, diff --git a/packages/web-runtime/src/container/application/classic.ts b/packages/web-runtime/src/container/application/classic.ts index 4f8e18da68c..49104267204 100644 --- a/packages/web-runtime/src/container/application/classic.ts +++ b/packages/web-runtime/src/container/application/classic.ts @@ -4,7 +4,7 @@ import Vue, { App } from 'vue' import { isFunction, isObject } from 'lodash-es' import { NextApplication } from './next' import { Store } from 'vuex' -import VueRouter from 'vue-router' +import { Router } from 'vue-router' import { RuntimeError } from '../error' type VueConstructor = typeof Vue @@ -78,7 +78,7 @@ export const convertClassicApplication = async ({ }: { applicationScript: ClassicApplicationScript store: Store - router: VueRouter + router: Router translations: unknown supportedLanguages: { [key: string]: string } }): Promise => { diff --git a/packages/web-runtime/src/container/application/index.ts b/packages/web-runtime/src/container/application/index.ts index 9afc1e9842a..ab2c2648894 100644 --- a/packages/web-runtime/src/container/application/index.ts +++ b/packages/web-runtime/src/container/application/index.ts @@ -1,5 +1,5 @@ import { Store } from 'vuex' -import VueRouter from 'vue-router' +import { Router } from 'vue-router' import { NextApplication } from './next' import { convertClassicApplication } from './classic' import { ClassicApplicationScript } from '../types' @@ -54,7 +54,7 @@ export const buildApplication = async ({ }: { applicationPath: string store: Store - router: VueRouter + router: Router translations: unknown supportedLanguages: { [key: string]: string } configurationManager: ConfigurationManager diff --git a/packages/web-runtime/src/container/bootstrap.ts b/packages/web-runtime/src/container/bootstrap.ts index 544bee7438c..46914aa2a9c 100644 --- a/packages/web-runtime/src/container/bootstrap.ts +++ b/packages/web-runtime/src/container/bootstrap.ts @@ -2,7 +2,7 @@ import { registerClient } from '../services/clientRegistration' import { RuntimeConfiguration } from './types' import { buildApplication, NextApplication } from './application' import { Store } from 'vuex' -import VueRouter from 'vue-router' +import { Router } from 'vue-router' import Vue from 'vue' import { loadTheme } from '../helpers/theme' import OwnCloud from 'owncloud-sdk' @@ -121,7 +121,7 @@ export const initializeApplications = async ({ runtimeConfiguration: RuntimeConfiguration configurationManager: ConfigurationManager store: Store - router: VueRouter + router: Router translations: unknown supportedLanguages: { [key: string]: string } }): Promise => { @@ -325,7 +325,7 @@ export const announceAuthService = ({ vue: VueConstructor configurationManager: ConfigurationManager store: Store - router: VueRouter + router: Router }): void => { authService.initialize(configurationManager, clientService, store, router) vue.prototype.$authService = authService @@ -344,7 +344,7 @@ export const announceDefaults = ({ router }: { store: Store - router: VueRouter + router: Router }): void => { // set home route const appIds = store.getters.appIds diff --git a/packages/web-runtime/src/container/types.ts b/packages/web-runtime/src/container/types.ts index 6f5dd86ca39..594fe6e5ccc 100644 --- a/packages/web-runtime/src/container/types.ts +++ b/packages/web-runtime/src/container/types.ts @@ -1,5 +1,5 @@ import { Store } from 'vuex' -import VueRouter, { RouteConfig } from 'vue-router' +import { RouteConfig, Router } from 'vue-router' import { App, Component } from 'vue' /** shim configuration for now, should be typed in a later step */ @@ -83,7 +83,7 @@ export interface RuntimeApi { announceStore: (applicationStore: Store) => void announceExtension: (extension: { [key: string]: unknown }) => void requestStore: () => Store - requestRouter: () => VueRouter + requestRouter: () => Router openPortal: ( instance: App, toApp: string, diff --git a/packages/web-runtime/src/router/helpers.ts b/packages/web-runtime/src/router/helpers.ts index e010208bbca..eae077c09be 100644 --- a/packages/web-runtime/src/router/helpers.ts +++ b/packages/web-runtime/src/router/helpers.ts @@ -1,5 +1,5 @@ import { base, router } from './index' -import Router, { Route, RouteRecordPublic } from 'vue-router' +import { Route, Router, RouteRecordPublic } from 'vue-router' import { authContextValues, contextQueryToFileContextProps, diff --git a/packages/web-runtime/src/router/index.ts b/packages/web-runtime/src/router/index.ts index 7cdef5375cc..0ddc6b95673 100644 --- a/packages/web-runtime/src/router/index.ts +++ b/packages/web-runtime/src/router/index.ts @@ -8,7 +8,12 @@ import ResolvePublicLinkPage from '../pages/resolvePublicLink.vue' import ResolvePrivateLinkPage from '../pages/resolvePrivateLink.vue' import { setupAuthGuard } from './setupAuthGuard' import { patchRouter } from './patchCleanPath' -import { createRouter as _createRouter, createWebHashHistory, createWebHistory, RouterOptions } from 'vue-router' +import { + createRouter as _createRouter, + createWebHashHistory, + createWebHistory, + RouterOptions +} from 'vue-router' export * from './helpers' @@ -36,7 +41,7 @@ export const router = patchRouter( addQueryPrefix: true }) }, - history: base && createWebHistory(new URL(base.href).pathname) || createWebHashHistory(), + history: (base && createWebHistory(new URL(base.href).pathname)) || createWebHashHistory(), routes: [ { path: '/login', diff --git a/packages/web-runtime/src/router/patchCleanPath.ts b/packages/web-runtime/src/router/patchCleanPath.ts index a7995fcd7da..50db87f9b65 100644 --- a/packages/web-runtime/src/router/patchCleanPath.ts +++ b/packages/web-runtime/src/router/patchCleanPath.ts @@ -1,4 +1,4 @@ -import Router from 'vue-router' +import { RouteLocation, RouteLocationNormalizedLoaded, RouteLocationRaw, Router } from 'vue-router' import get from 'lodash-es/get' // type: patch diff --git a/packages/web-runtime/src/services/auth/authService.ts b/packages/web-runtime/src/services/auth/authService.ts index 64c917b40e9..4be1cee442b 100644 --- a/packages/web-runtime/src/services/auth/authService.ts +++ b/packages/web-runtime/src/services/auth/authService.ts @@ -3,14 +3,14 @@ import { PublicLinkManager } from './publicLinkManager' import { Store } from 'vuex' import { ClientService } from 'web-pkg/src/services' import { ConfigurationManager } from 'web-pkg/src/configuration' -import VueRouter, { Route } from 'vue-router' +import { Route, Router } from 'vue-router' import { extractPublicLinkToken, isPublicLinkContext, isUserContext } from '../../router' export class AuthService { private clientService: ClientService private configurationManager: ConfigurationManager private store: Store - private router: VueRouter + private router: Router private userManager: UserManager private publicLinkManager: PublicLinkManager @@ -18,7 +18,7 @@ export class AuthService { configurationManager: ConfigurationManager, clientService: ClientService, store: Store, - router: VueRouter + router: Router ): void { this.configurationManager = configurationManager this.clientService = clientService From c123c1839ab38cdae83c640161c0d401ca5d2160 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 14 Jan 2023 14:41:45 +0100 Subject: [PATCH 05/18] Fix currentRoute usage --- packages/web-app-files/src/router/utils.ts | 4 ++- .../web-app-files/src/search/sdk/preview.ts | 4 +-- .../src/services/folder/loaderSpace.ts | 2 +- .../web-app-files/src/views/FilesDrop.vue | 4 +-- .../tests/unit/router/utils.spec.ts | 25 ++++++------- .../src/components/Spaces/QuotaModal.vue | 4 +-- .../composables/router/useFileRouteReplace.ts | 3 +- .../src/composables/router/useRoute.ts | 12 +++---- .../src/composables/router/useRouteMeta.ts | 2 +- .../src/composables/router/useRouteParam.ts | 35 ++++++++----------- .../src/composables/router/useRouteQuery.ts | 34 ++++++++---------- packages/web-pkg/src/mixins/spaces/delete.ts | 3 +- packages/web-pkg/src/mixins/spaces/disable.ts | 8 +++-- .../src/mixins/spaces/editDescription.ts | 3 +- .../web-pkg/src/mixins/spaces/navigate.ts | 4 ++- packages/web-pkg/src/mixins/spaces/rename.ts | 3 +- packages/web-pkg/src/mixins/spaces/restore.ts | 3 +- .../web-pkg/src/mixins/spaces/setReadme.ts | 3 +- .../composables/router/useRouteQuery.spec.ts | 4 +-- .../web-runtime/src/layouts/Application.vue | 4 +-- .../src/services/auth/authService.ts | 15 ++++---- 21 files changed, 90 insertions(+), 89 deletions(-) diff --git a/packages/web-app-files/src/router/utils.ts b/packages/web-app-files/src/router/utils.ts index 5ec59f08711..98764e13dba 100644 --- a/packages/web-app-files/src/router/utils.ts +++ b/packages/web-app-files/src/router/utils.ts @@ -1,6 +1,7 @@ import { Location } from 'vue-router' import { Router } from 'web-pkg/src/types/router' import merge from 'lodash-es/merge' +import { unref } from 'vue' export interface ActiveRouteDirectorFunc { (router: Router, ...comparatives: T[]): boolean @@ -17,13 +18,14 @@ export const isLocationActive = ( router: Router, ...comparatives: [Location, ...Location[]] ): boolean => { - const { href: currentHref } = router.resolve(router.currentRoute) + const { href: currentHref } = router.resolve(unref(router.currentRoute)) return comparatives .map((comparative) => { const { href: comparativeHref } = router.resolve({ ...comparative // ...(comparative.name && { name: resolveRouteName(comparative.name) }) }) + /** * Href might be '/' or '#/' if router is not able to resolve the proper path. * This happens if the we don't pass a param which is defined in the route configuration, for example: diff --git a/packages/web-app-files/src/search/sdk/preview.ts b/packages/web-app-files/src/search/sdk/preview.ts index 009fc05edeb..9a256001456 100644 --- a/packages/web-app-files/src/search/sdk/preview.ts +++ b/packages/web-app-files/src/search/sdk/preview.ts @@ -3,7 +3,7 @@ import PreviewComponent from '../../components/Search/Preview.vue' import { clientService } from 'web-pkg/src/services' import { buildResource } from 'web-client/src/helpers' import { Cache } from 'web-pkg/src/helpers/cache' -import { Component } from 'vue' +import { Component, unref } from 'vue' import { Router } from 'vue-router' import { DavProperties } from 'web-client/src/webdav/constants' import { Store } from 'vuex' @@ -63,6 +63,6 @@ export default class Preview implements SearchPreview { } public get available(): boolean { - return this.router.currentRoute.name !== 'search-provider-list' + return unref(this.router.currentRoute).name !== 'search-provider-list' } } diff --git a/packages/web-app-files/src/services/folder/loaderSpace.ts b/packages/web-app-files/src/services/folder/loaderSpace.ts index b9024d50f70..fd5a3fa7815 100644 --- a/packages/web-app-files/src/services/folder/loaderSpace.ts +++ b/packages/web-app-files/src/services/folder/loaderSpace.ts @@ -97,7 +97,7 @@ export class FolderLoaderSpace implements FolderLoader { console.error(error) if (error.statusCode === 401) { - return authService.handleAuthError(router.currentRoute) + return authService.handleAuthError(unref(router.currentRoute)) } } }).restartable() diff --git a/packages/web-app-files/src/views/FilesDrop.vue b/packages/web-app-files/src/views/FilesDrop.vue index 44f0711c877..24e7937ab53 100644 --- a/packages/web-app-files/src/views/FilesDrop.vue +++ b/packages/web-app-files/src/views/FilesDrop.vue @@ -40,7 +40,7 @@ import { DavProperties, DavProperty } from 'web-client/src/webdav/constants' import { createLocationPublic } from '../router' import ResourceUpload from '../components/AppBar/Upload/ResourceUpload.vue' -import { defineComponent, getCurrentInstance, onMounted } from 'vue' +import { defineComponent, getCurrentInstance, onMounted, unref } from 'vue' import { useUpload } from 'web-runtime/src/composables/upload' import * as uuid from 'uuid' import { usePublicLinkPassword, useStore } from 'web-pkg/src/composables' @@ -152,7 +152,7 @@ export default defineComponent({ .catch((error) => { // likely missing password, redirect to public link password prompt if (error.statusCode === 401) { - return this.$authService.handleAuthError(this.$router.currentRoute) + return this.$authService.handleAuthError(unref(this.$router.currentRoute)) } console.error(error) this.errorMessage = error diff --git a/packages/web-app-files/tests/unit/router/utils.spec.ts b/packages/web-app-files/tests/unit/router/utils.spec.ts index f7eb919a555..a77159bff82 100644 --- a/packages/web-app-files/tests/unit/router/utils.spec.ts +++ b/packages/web-app-files/tests/unit/router/utils.spec.ts @@ -3,15 +3,16 @@ import { isLocationActiveDirector, createLocation } from '../../../src/router/utils' -import { Router } from 'vue-router' +import { RouteLocation, Router } from 'vue-router' import { mock } from 'jest-mock-extended' +import { ref } from 'vue' describe('utils', () => { describe('isLocationActive', () => { it('returns true if one location is active', () => { const fakeRouter = mock({ - currentRoute: { name: 'foo' }, - resolve: (r) => ({ href: r.name }) + currentRoute: ref({ name: 'foo' }), + resolve: (r: any) => mock({ href: r.name }) }) expect(isLocationActive(fakeRouter, { name: 'foo' })).toBe(true) @@ -19,10 +20,10 @@ describe('utils', () => { }) it('returns false if all locations inactive', () => { - const fakeRouter = { - currentRoute: { name: 'foo' }, - resolve: (r) => ({ href: r.name }) - } + const fakeRouter = mock({ + currentRoute: ref({ name: 'foo' }), + resolve: (r: any) => mock({ href: r.name }) + }) expect(isLocationActive(fakeRouter, { name: 'bar' })).toBe(false) expect(isLocationActive(fakeRouter, { name: 'bar' }, { name: 'baz' })).toBe(false) @@ -32,8 +33,8 @@ describe('utils', () => { describe('isLocationActiveDirector', () => { test('director can be created and be used to check active locations', () => { const fakeRouter = mock({ - currentRoute: { name: 'unknown' }, - resolve: (r) => ({ href: r.name }) + currentRoute: ref({ name: 'unknown' }), + resolve: (r: any) => mock({ href: r.name }) }) const isFilesLocationActive = isLocationActiveDirector( @@ -43,7 +44,7 @@ describe('utils', () => { ) expect(isFilesLocationActive(fakeRouter)).toBe(false) - fakeRouter.currentRoute.name = 'bar' + fakeRouter.currentRoute.value.name = 'bar' expect(isFilesLocationActive(fakeRouter)).toBe(true) expect(isFilesLocationActive(fakeRouter, 'foo', 'bar')).toBe(true) @@ -51,8 +52,8 @@ describe('utils', () => { test('director closure only allows to check known locations and throws if unknown', () => { const fakeRouter = mock({ - currentRoute: { name: 'baz' }, - resolve: (r) => ({ href: r.name }) + currentRoute: ref({ name: 'baz' }), + resolve: (r: any) => mock({ href: r.name }) }) const isFilesLocationActive = isLocationActiveDirector({ name: 'foo' }, { name: 'bar' }) diff --git a/packages/web-pkg/src/components/Spaces/QuotaModal.vue b/packages/web-pkg/src/components/Spaces/QuotaModal.vue index 7a19385d9e7..3627175209f 100644 --- a/packages/web-pkg/src/components/Spaces/QuotaModal.vue +++ b/packages/web-pkg/src/components/Spaces/QuotaModal.vue @@ -20,7 +20,7 @@