From e1b23ddcf00608945fc331bf1957f6dbc31a2690 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 28 Aug 2023 23:36:51 +0200 Subject: [PATCH] feat: Get files app config and use it for the file picker * Sort favorties first if configured * Use sorting order like the files app does * Show hidden files if configured * Crop file previews if configured Signed-off-by: Ferdinand Thiessen --- lib/components/FilePicker/FileList.spec.ts | 26 ++-- lib/components/FilePicker/FileList.vue | 116 +++++++++------- lib/components/FilePicker/FileListRow.spec.ts | 7 - lib/components/FilePicker/FilePicker.vue | 8 ++ lib/components/FilePicker/FilePreview.vue | 8 +- lib/composables/filesSettings.spec.ts | 68 ++++++++++ lib/composables/filesSettings.ts | 128 ++++++++++++++++++ lib/composables/filesViews.spec.ts | 90 ++++++++++++ package-lock.json | 2 + package.json | 6 +- 10 files changed, 391 insertions(+), 68 deletions(-) create mode 100644 lib/composables/filesSettings.spec.ts create mode 100644 lib/composables/filesSettings.ts create mode 100644 lib/composables/filesViews.spec.ts diff --git a/lib/components/FilePicker/FileList.spec.ts b/lib/components/FilePicker/FileList.spec.ts index ecac0c865..c550cbcf4 100644 --- a/lib/components/FilePicker/FileList.spec.ts +++ b/lib/components/FilePicker/FileList.spec.ts @@ -26,12 +26,10 @@ import { beforeAll, describe, expect, it, vi } from 'vitest' import FileList from './FileList.vue' import { File, Folder } from '@nextcloud/files' -// mock OC.MimeType -window.OC = { - MimeType: { - getIconUrl: (mime: string) => `icon/${mime}`, - }, -} as never +const axios = vi.hoisted(() => ({ + get: vi.fn(() => new Promise(() => {})), +})) +vi.mock('axios', () => axios) const exampleNodes = [ new File({ @@ -81,6 +79,7 @@ describe('FilePicker FileList', () => { const wrapper = mount(FileList, { propsData: { + currentView: 'files', multiselect: false, allowPickDirectory: false, loading: false, @@ -98,6 +97,7 @@ describe('FilePicker FileList', () => { it('header checkbox is not shown if multiselect is `false`', () => { const wrapper = mount(FileList, { propsData: { + currentView: 'files', multiselect: false, allowPickDirectory: false, loading: false, @@ -112,6 +112,7 @@ describe('FilePicker FileList', () => { it('header checkbox is shown if multiselect is `true`', () => { const wrapper = mount(FileList, { propsData: { + currentView: 'files', multiselect: true, allowPickDirectory: false, loading: false, @@ -132,6 +133,7 @@ describe('FilePicker FileList', () => { const nodes = [...exampleNodes] const wrapper = mount(FileList, { propsData: { + currentView: 'files', multiselect: true, allowPickDirectory: false, loading: false, @@ -150,6 +152,7 @@ describe('FilePicker FileList', () => { const nodes = [...exampleNodes] const wrapper = mount(FileList, { propsData: { + currentView: 'files', multiselect: true, allowPickDirectory: false, loading: false, @@ -164,16 +167,18 @@ describe('FilePicker FileList', () => { expect(rows.length).toBe(nodes.length) // folder are sorted first expect(rows.at(0).attributes('data-filename')).toBe('directory') + // by default favorites are sorted before other files + expect(rows.at(1).attributes('data-filename')).toBe('favorite.txt') // other files are ascending - expect(rows.at(1).attributes('data-filename')).toBe('a-file.txt') - expect(rows.at(2).attributes('data-filename')).toBe('b-file.txt') - expect(rows.at(3).attributes('data-filename')).toBe('favorite.txt') + expect(rows.at(2).attributes('data-filename')).toBe('a-file.txt') + expect(rows.at(3).attributes('data-filename')).toBe('b-file.txt') }) it('can sort descending by name', async () => { const nodes = [...exampleNodes] const wrapper = mount(FileList, { propsData: { + currentView: 'files', multiselect: true, allowPickDirectory: false, loading: false, @@ -190,8 +195,9 @@ describe('FilePicker FileList', () => { expect(rows.length).toBe(nodes.length) // folder are sorted first expect(rows.at(0).attributes('data-filename')).toBe('directory') - // other files are descending + // by default favorites are sorted before other files expect(rows.at(1).attributes('data-filename')).toBe('favorite.txt') + // other files are descending expect(rows.at(2).attributes('data-filename')).toBe('b-file.txt') expect(rows.at(3).attributes('data-filename')).toBe('a-file.txt') }) diff --git a/lib/components/FilePicker/FileList.vue b/lib/components/FilePicker/FileList.vue index 085cc1a22..928ff9c50 100644 --- a/lib/components/FilePicker/FileList.vue +++ b/lib/components/FilePicker/FileList.vue @@ -1,9 +1,9 @@