fix(files): Add missing directory variable to error message

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2024-07-26 01:43:52 +02:00
parent 4ebea3db3a
commit ad8aa23fba
No known key found for this signature in database
GPG key ID: 45FAE7268762B400
2 changed files with 62 additions and 7 deletions

View file

@ -69,6 +69,7 @@ import Vue, { 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 logger from '../../logger.js'
@ -116,6 +117,7 @@ export default Vue.extend({
setup() {
const { currentView } = useNavigation()
const { directory } = useRouteParameters()
const renamingStore = useRenamingStore()
const defaultFileAction = inject<FileAction | undefined>('defaultFileAction')
@ -123,6 +125,7 @@ export default Vue.extend({
return {
currentView,
defaultFileAction,
directory,
renamingStore,
}
@ -326,13 +329,15 @@ export default Vue.extend({
// 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

View file

@ -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,
}
}