Skip to content

Commit

Permalink
Remove contextRouteName from app params and add it to the query instead
Browse files Browse the repository at this point in the history
  • Loading branch information
dschmidt committed Mar 18, 2022
1 parent 41f74ea commit a88e97a
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 16 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/change-context-route-name-in-query
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Change: App context route to query instead of params

We've moved app context information (where you get redirected
when you close an app) into the query instead of a regular
param. This relocates this information further to the back
of the url where it's less confusing for users.

https://github.com/owncloud/web/pull/6622
2 changes: 1 addition & 1 deletion packages/web-app-draw-io/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import App from './App.vue'
const routes = [
{
name: 'draw-io',
path: '/:contextRouteName/:filePath*',
path: '/:filePath*',
component: App,
meta: {
auth: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-external/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const appInfo = {
const routes = [
{
name: 'apps',
path: '/:contextRouteName/:fileId/:appName?',
path: '/:fileId/:appName?',
component: App,
meta: {
auth: false,
Expand Down
1 change: 0 additions & 1 deletion packages/web-app-files/src/mixins/fileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export default {
filePath,
fileId,
mode,
contextRouteName: this.$route.name
},
query: routeToContextQuery(route)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-markdown-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import translations from '../l10n/translations'

const routes = [
{
path: '/:contextRouteName/:filePath*',
path: '/:filePath*',
component: App,
name: 'markdown-editor',
meta: {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-media-viewer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function $gettext(msg) {

const routes = [
{
path: '/:contextRouteName/:filePath*',
path: '/:filePath*',
component: App,
name: 'media',
meta: {
Expand Down
22 changes: 14 additions & 8 deletions packages/web-pkg/src/composables/appDefaults/useAppDefaults.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { computed, unref, Ref } from '@vue/composition-api'
import { useRouter } from '../router'
import { useRouter, useRoute } from '../router'
import { useStore } from '../store'
import { ClientService, clientService as defaultClientService } from '../../services'

import { FileContext } from './types'
import {
useAppNavigation,
AppNavigationResult,
contextQueryToFileContextProps
contextQueryToFileContextProps,
contextRouteNameKey
} from './useAppNavigation'
import { useAppConfig, AppConfigResult } from './useAppConfig'
import { useAppFileHandling, AppFileHandlingResult } from './useAppFileHandling'
Expand All @@ -33,24 +34,29 @@ type AppDefaultsResult = AppConfigResult &
export function useAppDefaults(options: AppDefaultsOptions): AppDefaultsResult {
const router = useRouter()
const store = useStore()
const currentRoute = useRoute()
const clientService = options.clientService || defaultClientService

const currentRoute = computed(() => {
return router.currentRoute
})

const isPublicLinkContext = computed(() => {
return unref(currentRoute).params.contextRouteName === 'files-public-files'
return unref(currentRoute).query[contextRouteNameKey] === 'files-public-files'
})

const publicLinkPassword = computed(() => {
return store.getters['Files/publicLinkPassword']
})

const currentFileContext = computed((): FileContext => {
const queryItemAsString = (queryItem: string | string[]) => {
if (Array.isArray(queryItem)) {
return queryItem[0]
}

return queryItem
}

return {
path: `/${unref(currentRoute).params.filePath.split('/').filter(Boolean).join('/')}`,
routeName: unref(currentRoute).params.contextRouteName,
routeName: queryItemAsString(unref(currentRoute).query[contextRouteNameKey]),
...contextQueryToFileContextProps(unref(currentRoute).query)
}
})
Expand Down
13 changes: 12 additions & 1 deletion packages/web-pkg/src/composables/appDefaults/useAppNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface AppNavigationResult {
closeApp(): void
}

export const contextRouteNameKey = 'contextRouteName'
const contextRouteParamsKey = 'contextRouteParams'
const contextRouteQueryKey = 'contextRouteQuery'

Expand All @@ -36,19 +37,29 @@ export const routeToContextQuery = (location: Location): LocationQuery => {
}

return {
[contextRouteNameKey]: location.name,
[contextRouteParamsKey]: params,
[contextRouteQueryKey]: contextQuery
} as any
}
export const contextQueryToFileContextProps = (
query: LocationQuery
): { routeParams: LocationParams; routeQuery: LocationQuery } => {
): { routeName: string, routeParams: LocationParams; routeQuery: LocationQuery } => {
return {
routeName: queryItemAsString(query[contextRouteNameKey]),
routeParams: query[contextRouteParamsKey] as any,
routeQuery: query[contextRouteQueryKey] as any
}
}

const queryItemAsString = (queryItem: string | string[]) => {
if (Array.isArray(queryItem)) {
return queryItem[0]
}

return queryItem
}

export function useAppNavigation(options: AppNavigationOptions): AppNavigationResult {
const navigateToContext = (context: MaybeRef<FileContext>) => {
const router = options.router
Expand Down
5 changes: 3 additions & 2 deletions packages/web-runtime/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ const isAuthRequired = (router, to) => {
* The contextRouteName in routes is used to give applications additional context where the new route was triggered from.
* This means that the new route needs to fulfill both its own auth requirements and the auth requirements from the context route.
*/
if (!to.params?.contextRouteName) {
const contextRouteNameKey = 'contextRouteName'
if (!to.query?[contextRouteNameKey]) {
return false
}

const contextRoute = router.getRoutes().find((r) => r.name === to.params.contextRouteName)
const contextRoute = router.getRoutes().find((r) => r.name === to.query[contextRouteNameKey])
if (contextRoute) {
return contextRoute.meta?.auth !== false
}
Expand Down

0 comments on commit a88e97a

Please sign in to comment.