Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(files): trim names on new node creation #47147

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this expected behavior? I understand trimEnd because of mobile browsers that tend to add spaces on auto complete.
Having whitespace on the start is an edge case but is completely valid, meaning this will change names if you accidentally click rename on such a file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having whitespace on the start is an edge case but is completely valid

Having a white space at the end is also valid in many filesystems :)
I figured it's not about what is valid or not, but what makes most sense from a UX perspective.
And from my experience, I've yet to see someone willingly prepend or append a space in their file name 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, thats why I am asking. This PR only touches the new name handling so should be fine.

})

// 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.

Loading