diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-07-26 01:43:52 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-08-08 17:20:54 +0200 |
commit | 081219a535649ba279ae7c466e773cfc7400d26f (patch) | |
tree | d06937d9f155d5b3b8a7ee7bf383a983fdba68f1 /apps | |
parent | adacfa8e9b353cdb5788c5fe6c429d59debcc635 (diff) | |
download | nextcloud-server-081219a535649ba279ae7c466e773cfc7400d26f.tar.gz nextcloud-server-081219a535649ba279ae7c466e773cfc7400d26f.zip |
fix(files): Add missing directory variable to error message
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/src/components/FileEntry/FileEntryName.vue | 19 | ||||
-rw-r--r-- | apps/files/src/composables/useRouteParameters.ts | 50 |
2 files changed, 62 insertions, 7 deletions
diff --git a/apps/files/src/components/FileEntry/FileEntryName.vue b/apps/files/src/components/FileEntry/FileEntryName.vue index f3f97ee259f..abc3baeaf16 100644 --- a/apps/files/src/components/FileEntry/FileEntryName.vue +++ b/apps/files/src/components/FileEntry/FileEntryName.vue @@ -67,6 +67,7 @@ import { defineComponent, inject } from 'vue' import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js' import { useNavigation } from '../../composables/useNavigation' +import { useRouteParameters } from '../../composables/useRouteParameters.ts' import { useRenamingStore } from '../../store/renaming.ts' import { getFilenameValidity } from '../../utils/filenameValidity.ts' import logger from '../../logger.js' @@ -113,6 +114,7 @@ export default defineComponent({ setup() { const { currentView } = useNavigation() + const { directory } = useRouteParameters() const renamingStore = useRenamingStore() const defaultFileAction = inject<FileAction | undefined>('defaultFileAction') @@ -120,6 +122,7 @@ export default defineComponent({ return { currentView, defaultFileAction, + directory, renamingStore, } @@ -299,13 +302,15 @@ export default defineComponent({ // And ensure we reset to the renaming state this.startRenaming() - // TODO: 409 means current folder does not exist, redirect ? - if (error?.response?.status === 404) { - showError(t('files', 'Could not rename "{oldName}", it does not exist any more', { oldName })) - return - } else if (error?.response?.status === 412) { - showError(t('files', 'The name "{newName}" is already used in the folder "{dir}". Please choose a different name.', { newName, dir: this.currentDir })) - return + if (isAxiosError(error)) { + // TODO: 409 means current folder does not exist, redirect ? + if (error?.response?.status === 404) { + showError(t('files', 'Could not rename "{oldName}", it does not exist any more', { oldName })) + return + } else if (error?.response?.status === 412) { + showError(t('files', 'The name "{newName}" is already used in the folder "{dir}". Please choose a different name.', { newName, dir: this.directory })) + return + } } // Unknown error diff --git a/apps/files/src/composables/useRouteParameters.ts b/apps/files/src/composables/useRouteParameters.ts new file mode 100644 index 00000000000..abf14614fb7 --- /dev/null +++ b/apps/files/src/composables/useRouteParameters.ts @@ -0,0 +1,50 @@ +/*! + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { computed } from 'vue' +import { useRoute } from 'vue-router/composables' + +/** + * Get information about the current route + */ +export function useRouteParameters() { + + const route = useRoute() + + /** + * Get the path of the current active directory + */ + const directory = computed<string>( + () => String(route.query.dir || '/') + // Remove any trailing slash but leave root slash + .replace(/^(.+)\/$/, '$1'), + ) + + /** + * Get the current fileId used on the route + */ + const fileId = computed<number | null>(() => { + const fileId = Number.parseInt(route.params.fileid ?? '0') || null + return Number.isNaN(fileId) ? null : fileId + }) + + /** + * State of `openFile` route param + */ + const openFile = computed<boolean>( + // if `openfile` is set it is considered truthy, but allow to explicitly set it to 'false' + () => 'openfile' in route.query && (typeof route.query.openfile !== 'string' || route.query.openfile.toLocaleLowerCase() !== 'false'), + ) + + return { + /** Path of currently open directory */ + directory, + + /** Current active fileId */ + fileId, + + /** Should the active node should be opened (`openFile` route param) */ + openFile, + } +} |