fix(files): trim names on new node creation

Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
This commit is contained in:
skjnldsv 2024-08-09 09:12:32 +02:00 committed by nextcloud-command
parent 81b01c26c5
commit e4e12a35f5
5 changed files with 14 additions and 10 deletions

View file

@ -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) {
@ -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>

View file

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

View file

@ -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)

4
dist/files-init.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long