summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-05-02 21:20:20 +0200
committerGitHub <noreply@github.com>2024-05-02 21:20:20 +0200
commit19602a0cee03afe954d3996b3cdcb7c3800e9b5d (patch)
tree8e8b627f29164a022cf929313f170050a870a040
parentdbd2bc7a666bc23fc47b940f188e386d83b210de (diff)
parente092adf213426f8855c1c08b99c2ec826306fbcc (diff)
Merge pull request #45096 from nextcloud/fix/files-types
fix(files): Add missing properties and fix Typescript errors in `FileEntryName`
-rw-r--r--apps/files/src/components/FileEntry/FileEntryName.vue54
-rw-r--r--dist/files-main.js4
-rw-r--r--dist/files-main.js.map2
3 files changed, 36 insertions, 24 deletions
diff --git a/apps/files/src/components/FileEntry/FileEntryName.vue b/apps/files/src/components/FileEntry/FileEntryName.vue
index c8de61cdfe8..f8689772db4 100644
--- a/apps/files/src/components/FileEntry/FileEntryName.vue
+++ b/apps/files/src/components/FileEntry/FileEntryName.vue
@@ -55,15 +55,17 @@
</template>
<script lang="ts">
+import type { Node, View } from '@nextcloud/files'
import type { PropType } from 'vue'
+import { showError, showSuccess } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { FileType, NodeStatus, Permission } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
-import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
-import Vue from 'vue'
+import { isAxiosError } from 'axios'
+import Vue, { defineComponent } from 'vue'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
@@ -72,7 +74,7 @@ import logger from '../../logger.js'
const forbiddenCharacters = loadState<string[]>('files', 'forbiddenCharacters', [])
-export default Vue.extend({
+export default defineComponent({
name: 'FileEntryName',
components: {
@@ -114,6 +116,10 @@ export default Vue.extend({
},
computed: {
+ currentView(): View {
+ return this.$navigation.active as View
+ },
+
isRenaming() {
return this.renamingStore.renamingNode === this.source
},
@@ -201,7 +207,7 @@ export default Vue.extend({
* input validity using browser's native validation.
* @param event the keyup event
*/
- checkInputValidity(event?: KeyboardEvent) {
+ checkInputValidity(event: KeyboardEvent) {
const input = event.target as HTMLInputElement
const newName = this.newName.trim?.() || ''
logger.debug('Checking input validity', { newName })
@@ -210,13 +216,18 @@ export default Vue.extend({
input.setCustomValidity('')
input.title = ''
} catch (e) {
- input.setCustomValidity(e.message)
- input.title = e.message
+ if (e instanceof Error) {
+ input.setCustomValidity(e.message)
+ input.title = e.message
+ } else {
+ input.setCustomValidity(t('files', 'Invalid file name'))
+ }
} finally {
input.reportValidity()
}
},
- isFileNameValid(name) {
+
+ isFileNameValid(name: string) {
const trimmedName = name.trim()
if (trimmedName === '.' || trimmedName === '..') {
throw new Error(t('files', '"{name}" is an invalid file name.', { name }))
@@ -224,7 +235,7 @@ export default Vue.extend({
throw new Error(t('files', 'File name cannot be empty.'))
} else if (trimmedName.indexOf('/') !== -1) {
throw new Error(t('files', '"/" is not allowed inside a file name.'))
- } else if (trimmedName.match(OC.config.blacklist_files_regex)) {
+ } else if (trimmedName.match(window.OC.config.blacklist_files_regex)) {
throw new Error(t('files', '"{name}" is not an allowed filetype.', { name }))
} else if (this.checkIfNodeExists(name)) {
throw new Error(t('files', '{newName} already exists.', { newName: name }))
@@ -237,7 +248,8 @@ export default Vue.extend({
return true
},
- checkIfNodeExists(name) {
+
+ checkIfNodeExists(name: string) {
return this.nodes.find(node => node.basename === name && node !== this.source)
},
@@ -289,7 +301,6 @@ export default Vue.extend({
}
// Set loading state
- this.loading = 'renaming'
Vue.set(this.source, 'status', NodeStatus.LOADING)
// Update node
@@ -314,26 +325,27 @@ export default Vue.extend({
// Reset the renaming store
this.stopRenaming()
this.$nextTick(() => {
- this.$refs.basename.focus()
+ this.$refs.basename?.focus()
})
} catch (error) {
logger.error('Error while renaming file', { error })
this.source.rename(oldName)
- this.$refs.renameInput.focus()
-
- // 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
+ this.$refs.renameInput?.focus()
+
+ 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?.