Skip to content

Commit

Permalink
Apply selection range without extension to new file dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Apr 8, 2022
1 parent cd2b088 commit 2ac0620
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
5 changes: 3 additions & 2 deletions changelog/unreleased/enhancement-add-rename-selection-range
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Enhancement: Add rename selection range
Enhancement: Add filename selection range

We've added a selection range for the rename modal
We've added a selection range for the rename modal and the new file modal
to intially select the resource name without extension.

https://github.com/owncloud/web/issues/6729
https://github.com/owncloud/web/pull/6736
https://github.com/owncloud/web/pull/6760
16 changes: 13 additions & 3 deletions packages/web-app-files/src/components/AppBar/CreateAndUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
</div>
</template>

<script>
<script lang="ts">
import { mapActions, mapGetters, mapMutations } from 'vuex'
import pathUtil from 'path'
Expand All @@ -131,14 +131,16 @@ import MixinFileActions, { EDITOR_MODE_CREATE } from '../../mixins/fileActions'
import { buildResource, buildWebDavFilesPath, buildWebDavSpacesPath } from '../../helpers/resources'
import { isLocationPublicActive, isLocationSpacesActive } from '../../router'
import { useActiveLocation } from '../../composables'
import { defineComponent } from '@vue/composition-api'
import { extractNameWithoutExtension, Resource } from '../../helpers/resource'
import { DavProperties, DavProperty } from 'web-pkg/src/constants'
import FileDrop from './Upload/FileDrop.vue'
import FileUpload from './Upload/FileUpload.vue'
import FolderUpload from './Upload/FolderUpload.vue'
export default {
export default defineComponent({
components: {
FileDrop,
FileUpload,
Expand Down Expand Up @@ -349,6 +351,7 @@ export default {
confirmText: this.$gettext('Create'),
hasInput: true,
inputValue: defaultName,
inputSelectionRange: null,
inputLabel: isFolder ? this.$gettext('Folder name') : this.$gettext('File name'),
inputError: isFolder
? this.checkNewFolderName(defaultName)
Expand All @@ -362,6 +365,13 @@ export default {
onInput: checkInputValue
}
if (!isFolder) {
const nameWithoutExtension = extractNameWithoutExtension({
name: defaultName
} as Resource)
modal.inputSelectionRange = [0, nameWithoutExtension.length]
}
this.createModal(modal)
},
Expand Down Expand Up @@ -629,7 +639,7 @@ export default {
return null
}
}
}
})
</script>
<style lang="scss" scoped>
#create-list {
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-files/src/helpers/resource/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const extractStorageId = (id?: string): string => {
return id.indexOf('!') >= 0 ? id.split('!')[0] : ''
}

export const extractNameWithoutExtension = (resource?: Resource): string => {
const extension = resource.extension || ''
export const extractNameWithoutExtension = (resource: Resource): string => {
const extension = extractExtensionFromFile(resource)
const name = resource.name || ''
if (!extension.length) return name
const extensionIndexInName = name.lastIndexOf(`.${extension}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,16 @@ import {
Resource
} from '../../../../src/helpers/resource'

const resourceWithoutExtension = {
name: 'file'
}
const resourceNameWithExtension = {
name: 'file.txt',
extension: 'txt'
}
const resourceNameWithExtensionAndDots = {
name: 'file.dot.txt',
extension: 'txt'
}

describe('filterResources', () => {
describe('extractNameWithoutExtension', () => {
it('should return resource name when there is no extension', () => {
expect(extractNameWithoutExtension(resourceWithoutExtension as Resource)).toEqual(
resourceWithoutExtension.name
)
expect(extractNameWithoutExtension({ name: 'file' } as Resource)).toEqual('file')
})
it('should return resource name without extension when there is an extension', () => {
expect(extractNameWithoutExtension(resourceNameWithExtension as Resource)).toEqual('file')
expect(extractNameWithoutExtension({ name: 'file.txt' } as Resource)).toEqual('file')
})
it('should return resource name with dots without extension when there is an extension', () => {
expect(extractNameWithoutExtension(resourceNameWithExtensionAndDots as Resource)).toEqual(
'file.dot'
)
expect(extractNameWithoutExtension({ name: 'file.dot.txt' } as Resource)).toEqual('file.dot')
})
})
describe('extractExtensionFromFile', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ localVue.use(Vuex)

const currentFolder = {
id: 1,
name: 'folder',
path: '/folder',
webDavPath: '/files/admin/folder'
}
Expand Down

0 comments on commit 2ac0620

Please sign in to comment.