Skip to content

Commit

Permalink
Merge pull request #46690 from nextcloud/fix/files-displayname
Browse files Browse the repository at this point in the history
Update `@nextcloud/files` to 3.6.0 and fix display name handling of folders (breadcrumbs and filename)
  • Loading branch information
susnux authored Jul 25, 2024
2 parents ca5b746 + fe1aa83 commit d843d67
Show file tree
Hide file tree
Showing 50 changed files with 159 additions and 272 deletions.
2 changes: 1 addition & 1 deletion apps/files/src/actions/openFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const action = new FileAction({
id: 'open-folder',
displayName(files: Node[]) {
// Only works on single node
const displayName = files[0].attributes.displayname || files[0].basename
const displayName = files[0].displayname
return t('files', 'Open folder {displayName}', { displayName })
},
iconSvgInline: () => FolderSvg,
Expand Down
6 changes: 3 additions & 3 deletions apps/files/src/components/BreadCrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ export default defineComponent({
return this.$navigation?.active?.name || t('files', 'Home')
}
const source: FileSource | null = this.getFileSourceFromPath(path)
const node: Node | undefined = source ? this.getNodeFromSource(source) : undefined
return node?.attributes?.displayname || basename(path)
const source = this.getFileSourceFromPath(path)
const node = source ? this.getNodeFromSource(source) : undefined
return node?.displayname || basename(path)
},
onClick(to) {
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@click.native="execDefaultAction" />

<FileEntryName ref="name"
:display-name="displayName"
:basename="basename"
:extension="extension"
:files-list-width="filesListWidth"
:nodes="nodes"
Expand Down
14 changes: 10 additions & 4 deletions apps/files/src/components/FileEntry/FileEntryName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
v-bind="linkTo.params">
<!-- File name -->
<span class="files-list__row-name-text">
<!-- Keep the displayName stuck to the extension to avoid whitespace rendering issues-->
<span class="files-list__row-name-" v-text="displayName" />
<!-- Keep the filename stuck to the extension to avoid whitespace rendering issues-->
<span class="files-list__row-name-" v-text="basename" />
<span class="files-list__row-name-ext" v-text="extension" />
</span>
</component>
Expand Down Expand Up @@ -64,10 +64,16 @@ export default defineComponent({
},
props: {
displayName: {
/**
* The filename without extension
*/
basename: {
type: String,
required: true,
},
/**
* The extension of the filename
*/
extension: {
type: String,
required: true,
Expand Down Expand Up @@ -155,7 +161,7 @@ export default defineComponent({
params: {
download: this.source.basename,
href: this.source.source,
title: t('files', 'Download file {name}', { name: this.displayName }),
title: t('files', 'Download file {name}', { name: `${this.basename}${this.extension}` }),
tabindex: '0',
},
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/components/FileEntryGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@click.native="execDefaultAction" />

<FileEntryName ref="name"
:display-name="displayName"
:basename="basename"
:extension="extension"
:files-list-width="filesListWidth"
:grid-mode="true"
Expand Down
32 changes: 22 additions & 10 deletions apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,31 @@ export default defineComponent({
return this.source.status === NodeStatus.LOADING
},

extension() {
if (this.source.attributes?.displayname) {
return extname(this.source.attributes.displayname)
/**
* The display name of the current node
* Either the nodes filename or a custom display name (e.g. for shares)
*/
displayName() {
return this.source.displayname
},
/**
* The display name without extension
*/
basename() {
if (this.extension === '') {
return this.displayName
}
return this.source.extension || ''
return this.displayName.slice(0, 0 - this.extension.length)
},
displayName() {
const ext = this.extension
const name = String(this.source.attributes.displayname
|| this.source.basename)
/**
* The extension of the file
*/
extension() {
if (this.source.type === FileType.Folder) {
return ''
}

// Strip extension from name if defined
return !ext ? name : name.slice(0, 0 - ext.length)
return extname(this.displayName)
},

draggingFiles() {
Expand Down
9 changes: 8 additions & 1 deletion apps/files/src/services/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ import logger from '../logger.js'
* Slim wrapper over `@nextcloud/files` `davResultToNode` to allow using the function with `Array.map`
* @param node The node returned by the webdav library
*/
export const resultToNode = (node: FileStat): File | Folder => davResultToNode(node)
export const resultToNode = (node: FileStat): File | Folder => {
// TODO remove this hack with nextcloud-files v3.7
// just needed because of a bug in the webdav client
if (node.props?.displayname !== undefined) {
node.props.displayname = String(node.props.displayname)
}
return davResultToNode(node)
}

export const getContents = (path = '/'): CancelablePromise<ContentsWithRoot> => {
const controller = new AbortController()
Expand Down
100 changes: 0 additions & 100 deletions apps/files/src/services/SortingService.spec.ts

This file was deleted.

59 changes: 0 additions & 59 deletions apps/files/src/services/SortingService.ts

This file was deleted.

49 changes: 8 additions & 41 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import type { UserConfig } from '../types.ts'
import { getCapabilities } from '@nextcloud/capabilities'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { Folder, Node, Permission } from '@nextcloud/files'
import { Folder, Node, Permission, sortNodes } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { join, dirname, normalize } from 'path'
import { showError, showWarning } from '@nextcloud/dialogs'
Expand Down Expand Up @@ -148,7 +148,6 @@ import { useSelectionStore } from '../store/selection.ts'
import { useUploaderStore } from '../store/uploader.ts'
import { useUserConfigStore } from '../store/userconfig.ts'
import { useViewConfigStore } from '../store/viewConfig.ts'
import { orderBy } from '../services/SortingService.ts'
import BreadCrumbs from '../components/BreadCrumbs.vue'
import FilesListVirtual from '../components/FilesListVirtual.vue'
import filesListWidthMixin from '../mixins/filesListWidth.ts'
Expand Down Expand Up @@ -291,44 +290,10 @@ export default defineComponent({
return this.filesStore.getNode(source) as Folder
},
/**
* Directory content sorting parameters
* Provided by an extra computed property for caching
*/
sortingParameters() {
const identifiers = [
// 1: Sort favorites first if enabled
...(this.userConfig.sort_favorites_first ? [v => v.attributes?.favorite !== 1] : []),
// 2: Sort folders first if sorting by name
...(this.userConfig.sort_folders_first ? [v => v.type !== 'folder'] : []),
// 3: Use sorting mode if NOT basename (to be able to use displayName too)
...(this.sortingMode !== 'basename' ? [v => v[this.sortingMode]] : []),
// 4: Use displayname if available, fallback to name
v => v.attributes?.displayname || v.basename,
// 5: Finally, use basename if all previous sorting methods failed
v => v.basename,
]
const orders = [
// (for 1): always sort favorites before normal files
...(this.userConfig.sort_favorites_first ? ['asc'] : []),
// (for 2): always sort folders before files
...(this.userConfig.sort_folders_first ? ['asc'] : []),
// (for 3): Reverse if sorting by mtime as mtime higher means edited more recent -> lower
...(this.sortingMode === 'mtime' ? [this.isAscSorting ? 'desc' : 'asc'] : []),
// (also for 3 so make sure not to conflict with 2 and 3)
...(this.sortingMode !== 'mtime' && this.sortingMode !== 'basename' ? [this.isAscSorting ? 'asc' : 'desc'] : []),
// for 4: use configured sorting direction
this.isAscSorting ? 'asc' : 'desc',
// for 5: use configured sorting direction
this.isAscSorting ? 'asc' : 'desc',
] as ('asc'|'desc')[]
return [identifiers, orders] as const
},
/**
* The current directory contents.
*/
dirContentsSorted(): Node[] {
dirContentsSorted() {
if (!this.currentView) {
return []
}
Expand All @@ -351,10 +316,12 @@ export default defineComponent({
return this.isAscSorting ? results : results.reverse()
}
return orderBy(
filteredDirContent,
...this.sortingParameters,
)
return sortNodes(filteredDirContent, {
sortFavoritesFirst: this.userConfig.sort_favorites_first,
sortFoldersFirst: this.userConfig.sort_folders_first,
sortingMode: this.sortingMode,
sortingOrder: this.isAscSorting ? 'asc' : 'desc',
})
},
dirContents(): Node[] {
Expand Down
Loading

0 comments on commit d843d67

Please sign in to comment.