]> source.dussan.org Git - nextcloud-server.git/commitdiff
chore(deps): Update `@nextcloud/files` to v3.6.0
authorFerdinand Thiessen <opensource@fthiessen.de>
Mon, 22 Jul 2024 15:54:20 +0000 (17:54 +0200)
committerskjnldsv <skjnldsv@protonmail.com>
Fri, 2 Aug 2024 08:03:03 +0000 (10:03 +0200)
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
apps/files/src/actions/openFolderAction.ts
apps/files/src/components/BreadCrumbs.vue
apps/files/src/services/SortingService.spec.ts [deleted file]
apps/files/src/services/SortingService.ts [deleted file]
apps/files/src/views/FilesList.vue
package.json

index f575bdde7e8f98c027edd0385ff243e981352977..090b1093d9ea94b81e039dd2605bb35469288ca0 100644 (file)
@@ -27,7 +27,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,
index df7931a4a5bd5e2cf46ee0ffdf3b6901e507272c..1c7994e4111a3ad007c7ec7df8ee845e7309bf9f 100644 (file)
@@ -175,9 +175,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) {
diff --git a/apps/files/src/services/SortingService.spec.ts b/apps/files/src/services/SortingService.spec.ts
deleted file mode 100644 (file)
index 5d20c43..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-import { describe, expect } from '@jest/globals'
-import { orderBy } from './SortingService'
-
-describe('SortingService', () => {
-       test('By default the identify and ascending order is used', () => {
-               const array = ['a', 'z', 'b']
-               expect(orderBy(array)).toEqual(['a', 'b', 'z'])
-       })
-
-       test('Use identifiy but descending', () => {
-               const array = ['a', 'z', 'b']
-               expect(orderBy(array, undefined, ['desc'])).toEqual(['z', 'b', 'a'])
-       })
-
-       test('Can set identifier function', () => {
-               const array = [
-                       { text: 'a', order: 2 },
-                       { text: 'z', order: 1 },
-                       { text: 'b', order: 3 },
-               ] as const
-               expect(orderBy(array, [(v) => v.order]).map((v) => v.text)).toEqual(['z', 'a', 'b'])
-       })
-
-       test('Can set multiple identifier functions', () => {
-               const array = [
-                       { text: 'a', order: 2, secondOrder: 2 },
-                       { text: 'z', order: 1, secondOrder: 3 },
-                       { text: 'b', order: 2, secondOrder: 1 },
-               ] as const
-               expect(orderBy(array, [(v) => v.order, (v) => v.secondOrder]).map((v) => v.text)).toEqual(['z', 'b', 'a'])
-       })
-
-       test('Can set order partially', () => {
-               const array = [
-                       { text: 'a', order: 2, secondOrder: 2 },
-                       { text: 'z', order: 1, secondOrder: 3 },
-                       { text: 'b', order: 2, secondOrder: 1 },
-               ] as const
-
-               expect(
-                       orderBy(
-                               array,
-                               [(v) => v.order, (v) => v.secondOrder],
-                               ['desc'],
-                       ).map((v) => v.text),
-               ).toEqual(['b', 'a', 'z'])
-       })
-
-       test('Can set order array', () => {
-               const array = [
-                       { text: 'a', order: 2, secondOrder: 2 },
-                       { text: 'z', order: 1, secondOrder: 3 },
-                       { text: 'b', order: 2, secondOrder: 1 },
-               ] as const
-
-               expect(
-                       orderBy(
-                               array,
-                               [(v) => v.order, (v) => v.secondOrder],
-                               ['desc', 'desc'],
-                       ).map((v) => v.text),
-               ).toEqual(['a', 'b', 'z'])
-       })
-
-       test('Numbers are handled correctly', () => {
-               const array = [
-                       { text: '2.3' },
-                       { text: '2.10' },
-                       { text: '2.0' },
-                       { text: '2.2' },
-               ] as const
-
-               expect(
-                       orderBy(
-                               array,
-                               [(v) => v.text],
-                       ).map((v) => v.text),
-               ).toEqual(['2.0', '2.2', '2.3', '2.10'])
-       })
-
-       test('Numbers with suffixes are handled correctly', () => {
-               const array = [
-                       { text: '2024-01-05' },
-                       { text: '2024-05-01' },
-                       { text: '2024-01-10' },
-                       { text: '2024-01-05 Foo' },
-               ] as const
-
-               expect(
-                       orderBy(
-                               array,
-                               [(v) => v.text],
-                       ).map((v) => v.text),
-               ).toEqual(['2024-01-05', '2024-01-05 Foo', '2024-01-10', '2024-05-01'])
-       })
-})
diff --git a/apps/files/src/services/SortingService.ts b/apps/files/src/services/SortingService.ts
deleted file mode 100644 (file)
index 392f35e..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-import { getCanonicalLocale, getLanguage } from '@nextcloud/l10n'
-
-type IdentifierFn<T> = (v: T) => unknown
-type SortingOrder = 'asc'|'desc'
-
-/**
- * Helper to create string representation
- * @param value Value to stringify
- */
-function stringify(value: unknown) {
-       // The default representation of Date is not sortable because of the weekday names in front of it
-       if (value instanceof Date) {
-               return value.toISOString()
-       }
-       return String(value)
-}
-
-/**
- * Natural order a collection
- * You can define identifiers as callback functions, that get the element and return the value to sort.
- *
- * @param collection The collection to order
- * @param identifiers An array of identifiers to use, by default the identity of the element is used
- * @param orders Array of orders, by default all identifiers are sorted ascening
- */
-export function orderBy<T>(collection: readonly T[], identifiers?: IdentifierFn<T>[], orders?: SortingOrder[]): T[] {
-       // If not identifiers are set we use the identity of the value
-       identifiers = identifiers ?? [(value) => value]
-       // By default sort the collection ascending
-       orders = orders ?? []
-       const sorting = identifiers.map((_, index) => (orders[index] ?? 'asc') === 'asc' ? 1 : -1)
-
-       const collator = Intl.Collator(
-               [getLanguage(), getCanonicalLocale()],
-               {
-                       // handle 10 as ten and not as one-zero
-                       numeric: true,
-                       usage: 'sort',
-               },
-       )
-
-       return [...collection].sort((a, b) => {
-               for (const [index, identifier] of identifiers.entries()) {
-                       // Get the local compare of stringified value a and b
-                       const value = collator.compare(stringify(identifier(a)), stringify(identifier(b)))
-                       // If they do not match return the order
-                       if (value !== 0) {
-                               return value * sorting[index]
-                       }
-                       // If they match we need to continue with the next identifier
-               }
-               // If all are equal we need to return equality
-               return 0
-       })
-}
index f992ed3cd364e361e064599f3878b7ca3ea9962c..9f8ae294f9cb72c08e9b1818ff72975a4a7f218b 100644 (file)
@@ -154,7 +154,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'
@@ -310,7 +309,7 @@ export default defineComponent({
                /**
                 * The current directory contents.
                 */
-               dirContentsSorted(): Node[] {
+               dirContentsSorted() {
                        if (!this.currentView) {
                                return []
                        }
@@ -333,10 +332,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[] {
index a9377885738feae162d65c3f9711c3e72c7c8563..2c50f0d341652844ab1a372c2bf6e34f1dc21a49 100644 (file)
@@ -47,7 +47,7 @@
     "@nextcloud/capabilities": "^1.2.0",
     "@nextcloud/dialogs": "^5.3.5",
     "@nextcloud/event-bus": "^3.3.1",
-    "@nextcloud/files": "^3.5.1",
+    "@nextcloud/files": "^3.6.0",
     "@nextcloud/initial-state": "^2.2.0",
     "@nextcloud/l10n": "^3.1.0",
     "@nextcloud/logger": "^2.5.0",