Skip to content

Commit

Permalink
fix(files): Add missing directory variable to error message
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Aug 20, 2024
1 parent 4ebea3d commit ad8aa23
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
19 changes: 12 additions & 7 deletions apps/files/src/components/FileEntry/FileEntryName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -116,13 +117,15 @@ export default Vue.extend({
setup() {
const { currentView } = useNavigation()
const { directory } = useRouteParameters()
const renamingStore = useRenamingStore()
const defaultFileAction = inject<FileAction | undefined>('defaultFileAction')
return {
currentView,
defaultFileAction,
directory,
renamingStore,
}
Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions apps/files/src/composables/useRouteParameters.ts
Original file line number Diff line number Diff line change
@@ -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,
}
}

0 comments on commit ad8aa23

Please sign in to comment.