Skip to content

Commit 5b37db7

Browse files
committed
chore: support new spawnDialog format
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 84a3834 commit 5b37db7

File tree

5 files changed

+41
-29
lines changed

5 files changed

+41
-29
lines changed

lib/components/FilePicker/FileList.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ describe('FilePicker FileList', () => {
158158
// all nodes are shown
159159
expect(rows.length).toBe(nodes.length)
160160
// by default favorites are sorted before other files
161-
expect(rows.at(0).attributes('data-filename')).toBe('favorite.txt')
161+
expect(rows.at(0)!.attributes('data-filename')).toBe('favorite.txt')
162162
// folder are sorted first
163-
expect(rows.at(1).attributes('data-filename')).toBe('directory')
163+
expect(rows.at(1)!.attributes('data-filename')).toBe('directory')
164164
// other files are ascending
165-
expect(rows.at(2).attributes('data-filename')).toBe('a-file.txt')
166-
expect(rows.at(3).attributes('data-filename')).toBe('b-file.txt')
165+
expect(rows.at(2)!.attributes('data-filename')).toBe('a-file.txt')
166+
expect(rows.at(3)!.attributes('data-filename')).toBe('b-file.txt')
167167
})
168168

169169
it('can sort descending by name', async () => {
@@ -193,12 +193,12 @@ describe('FilePicker FileList', () => {
193193
// all nodes are shown
194194
expect(rows.length).toBe(nodes.length)
195195
// by default favorites are sorted before other files
196-
expect(rows.at(0).attributes('data-filename')).toBe('favorite.txt')
196+
expect(rows.at(0)!.attributes('data-filename')).toBe('favorite.txt')
197197
// folder are sorted first
198-
expect(rows.at(1).attributes('data-filename')).toBe('directory')
198+
expect(rows.at(1)!.attributes('data-filename')).toBe('directory')
199199
// other files are descending
200-
expect(rows.at(2).attributes('data-filename')).toBe('b-file.txt')
201-
expect(rows.at(3).attributes('data-filename')).toBe('a-file.txt')
200+
expect(rows.at(2)!.attributes('data-filename')).toBe('b-file.txt')
201+
expect(rows.at(3)!.attributes('data-filename')).toBe('a-file.txt')
202202
})
203203
})
204204
})

lib/components/FilePicker/FilePicker.vue

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
-->
55
<template>
66
<NcDialog v-model:open="isOpen"
7-
:container="container"
87
:buttons="dialogButtons"
98
:name="name"
109
size="large"
@@ -95,13 +94,7 @@ const props = withDefaults(defineProps<{
9594
/**
9695
* Is the navigation disabled
9796
*/
98-
disabledNavigation?: boolean
99-
100-
/**
101-
* Where to mount the dialog
102-
* @default 'body'
103-
*/
104-
container?: string
97+
disabledNavigation?: boolean
10598
10699
/**
107100
* Custom filter function used to filter pickable files
@@ -130,7 +123,6 @@ const props = withDefaults(defineProps<{
130123
}>(), {
131124
allowPickDirectory: false,
132125
disabledNavigation: false,
133-
container: 'body',
134126
filterFn: undefined,
135127
mimetypeFilter: () => [],
136128
multiselect: true,
@@ -175,7 +167,7 @@ const dialogButtons = computed(() => {
175167
let isHandlingCallback = false
176168
177169
const handleButtonClick = async (callback: IFilePickerButton['callback'], nodes: Node[]) => {
178-
callback(nodes)
170+
await callback(nodes)
179171
emit('close', nodes)
180172
// Unlock close
181173
isHandlingCallback = false

lib/components/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface IFilePickerButton extends Omit<IDialogButton, 'callback'> {
4747
*
4848
* @param nodes Array of `@nextcloud/files` Nodes that were selected
4949
*/
50-
callback: (nodes: Node[]) => void
50+
callback: (nodes: Node[]) => void | Promise<void>
5151
}
5252

5353
export type IFilePickerButtonFactory = (selectedNodes: Node[], currentPath: string, currentView: string) => IFilePickerButton[]

lib/composables/dav.spec.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { Ref } from 'vue'
6+
import type { ComponentPublicInstance, Ref } from 'vue'
77
import { describe, it, expect, vi, beforeEach } from 'vitest'
88
import { shallowMount } from '@vue/test-utils'
99
import { defineComponent, ref, toRef, nextTick, h } from 'vue'
@@ -20,9 +20,10 @@ const nextcloudFiles = vi.hoisted(() => ({
2020
}))
2121
vi.mock('@nextcloud/files', () => nextcloudFiles)
2222

23-
const waitLoaded = (vue: ReturnType<typeof shallowMount>) => new Promise((resolve) => {
23+
// eslint-disable-next-line @typescript-eslint/ban-types
24+
const waitLoaded = (vm: ComponentPublicInstance<{}, { isLoading: boolean }>) => new Promise((resolve) => {
2425
const w = () => {
25-
if (vue.vm.isLoading) window.setTimeout(w, 50)
26+
if (vm.isLoading) window.setTimeout(w, 50)
2627
else resolve(true)
2728
}
2829
w()
@@ -90,14 +91,15 @@ describe('dav composable', () => {
9091
})
9192

9293
// wait until files are loaded
93-
await waitLoaded(vue)
94+
await waitLoaded(vue.vm)
9495

9596
expect(vue.vm.files).toEqual(['node 1', 'node 2'])
9697
})
9798

9899
it('reloads on path change', async () => {
99100
const client = {
100-
getDirectoryContents: vi.fn(() => ({ data: [] })),
101+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
102+
getDirectoryContents: vi.fn((_path: string) => ({ data: [] })),
101103
}
102104
nextcloudFiles.davGetClient.mockImplementationOnce(() => client)
103105

@@ -110,21 +112,22 @@ describe('dav composable', () => {
110112
})
111113

112114
// wait until files are loaded
113-
await waitLoaded(vue)
115+
await waitLoaded(vue.vm)
114116

115117
expect(client.getDirectoryContents).toBeCalledTimes(1)
116118
expect(client.getDirectoryContents.mock.calls[0][0]).toBe(`${nextcloudFiles.davRootPath}/`)
117119

118120
vue.setProps({ currentPath: '/other' })
119-
await waitLoaded(vue)
121+
await waitLoaded(vue.vm)
120122

121123
expect(client.getDirectoryContents).toBeCalledTimes(2)
122124
expect(client.getDirectoryContents.mock.calls[1][0]).toBe(`${nextcloudFiles.davRootPath}/other`)
123125
})
124126

125127
it('reloads on view change', async () => {
126128
const client = {
127-
getDirectoryContents: vi.fn(() => ({ data: [] })),
129+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
130+
getDirectoryContents: vi.fn((_path: string) => ({ data: [] })),
128131
search: vi.fn(() => ({ data: { results: [], truncated: false } })),
129132
}
130133
nextcloudFiles.davGetClient.mockImplementationOnce(() => client)
@@ -138,14 +141,14 @@ describe('dav composable', () => {
138141
})
139142

140143
// wait until files are loaded
141-
await waitLoaded(vue)
144+
await waitLoaded(vue.vm)
142145

143146
expect(client.search).not.toBeCalled()
144147
expect(client.getDirectoryContents).toBeCalledTimes(1)
145148
expect(client.getDirectoryContents.mock.calls[0][0]).toBe(`${nextcloudFiles.davRootPath}/`)
146149

147150
vue.setProps({ currentView: 'recent' })
148-
await waitLoaded(vue)
151+
await waitLoaded(vue.vm)
149152

150153
// Uses search instead of getDirectoryContents
151154
expect(client.getDirectoryContents).toBeCalledTimes(1)

lib/vue-icons.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
declare module 'vue-material-design-icons/*.vue' {
6+
import type { DefineComponent } from 'vue'
7+
8+
const IconVue: DefineComponent<{
9+
/// `size` defaults to 24
10+
size?: number;
11+
/// `fillColor` defaults to 'currentColor'
12+
fillColor?: string;
13+
title?: string;
14+
}>
15+
16+
export default IconVue
17+
}

0 commit comments

Comments
 (0)