Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[full-ci] Remove contextRouteName from app params and add it to the query instead #6622

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 1 addition & 2 deletions packages/web-app-files/src/mixins/fileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ export default {
params: {
filePath,
fileId,
mode,
contextRouteName: this.$route.name
mode
},
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see the useRouteQuery composable? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see the useRouteQuery composable? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

})

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 || !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