Skip to content

Commit

Permalink
fix(files): trim names on new node creation
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <[email protected]>
Signed-off-by: nextcloud-command <[email protected]>
  • Loading branch information
skjnldsv authored and nextcloud-command committed Aug 9, 2024
1 parent 81b01c2 commit e4e12a3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions apps/files/src/components/NewNodeDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ function submit() {
// Reset local name on props change
watch(() => props.defaultName, () => {
localDefaultName.value = getUniqueName(props.defaultName, props.otherNames)
localDefaultName.value = getUniqueName(props.defaultName, props.otherNames).trim()
})
// Validate the local name
watchEffect(() => {
if (props.otherNames.includes(localDefaultName.value)) {
if (props.otherNames.includes(localDefaultName.value.trim())) {
validity.value = t('files', 'This name is already in use.')
} else {
validity.value = getFilenameValidity(localDefaultName.value)
validity.value = getFilenameValidity(localDefaultName.value.trim())
}
const input = nameInput.value?.$el.querySelector('input')
if (input) {
Expand All @@ -144,7 +144,7 @@ watch(() => props.open, () => {
onMounted(() => {
// on mounted lets use the unique name
localDefaultName.value = getUniqueName(localDefaultName.value, props.otherNames)
localDefaultName.value = getUniqueName(localDefaultName.value, props.otherNames).trim()
nextTick(() => focusInput())
})
</script>
Expand Down
8 changes: 6 additions & 2 deletions apps/files/src/newMenu/newFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const entry = {
async handler(context: Folder, content: Node[]) {
const name = await newNodeName(t('files', 'New folder'), content)
if (name !== null) {
const { fileid, source } = await createNewFolder(context, name)
const { fileid, source } = await createNewFolder(context, name.trim())

// Create the folder in the store
const folder = new Folder({
source,
Expand All @@ -65,9 +66,12 @@ export const entry = {
},
})

// Show success
emit('files:node:created', folder)
showSuccess(t('files', 'Created new folder "{name}"', { name: basename(source) }))
logger.debug('Created new folder', { folder, source })
emit('files:node:created', folder)

// Navigate to the new folder
window.OCP.Files.Router.goToRoute(
null, // use default route
{ view: 'files', fileid: folder.fileid },
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/newMenu/newFromTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function registerTemplateEntries() {
if (name !== null) {
// Create the file
const picker = await templatePicker
picker.open(name, provider)
picker.open(name.trim(), provider)
}
},
} as Entry)
Expand Down
4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

0 comments on commit e4e12a3

Please sign in to comment.