Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to disable file picker navigation #1261

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/components/FilePicker/FilePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<template #navigation="{ isCollapsed }">
<FilePickerNavigation :is-collapsed="isCollapsed"
:current-view.sync="currentView"
:filter-string.sync="filterString" />
:filter-string.sync="filterString"
:disabled-navigation="disabledNavigation" />
</template>

<div class="file-picker__main">
Expand Down Expand Up @@ -89,6 +90,11 @@ const props = withDefaults(defineProps<{
*/
allowPickDirectory?: boolean

/**
* Is the navigation disabled
*/
disabledNavigation?: boolean

/**
* Where to mount the dialog
* @default 'body'
Expand Down Expand Up @@ -121,6 +127,7 @@ const props = withDefaults(defineProps<{
path?: string
}>(), {
allowPickDirectory: false,
disabledNavigation: false,
container: 'body',
filterFn: undefined,
mimetypeFilter: () => [],
Expand Down
5 changes: 3 additions & 2 deletions lib/components/FilePicker/FilePickerNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<IconClose :size="16" />
</template>
</NcTextField>
<template v-if="availableViews.length > 1">
<template v-if="availableViews.length > 1 && !disabledNavigation">
<!-- On non collapsed dialogs show the tablist, otherwise a dropdown is shown -->
<ul v-if="!isCollapsed"
class="file-picker__side">
Expand Down Expand Up @@ -52,7 +52,8 @@ import { useViews } from '../../composables/views'
const props = defineProps<{
currentView: 'files' | 'recent' | 'favorites',
filterString: string,
isCollapsed: boolean
isCollapsed: boolean,
disabledNavigation: boolean,
}>()

interface INavigationEvents {
Expand Down
20 changes: 19 additions & 1 deletion lib/filepicker-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class FilePicker<IsMultiSelect extends boolean> {
private path?: string
private filter?: IFilePickerFilter
private container?: string
private disabledNavigation: boolean

public constructor(title: string,
multiSelect: IsMultiSelect,
Expand All @@ -64,7 +65,9 @@ export class FilePicker<IsMultiSelect extends boolean> {
buttons: IFilePickerButton[] | IFilePickerButtonFactory,
path?: string,
filter?: IFilePickerFilter,
container?: string) {
container?: string,
disabledNavigation = false,
) {
this.title = title
this.multiSelect = multiSelect
this.mimeTypeFilter = mimeTypeFilter
Expand All @@ -73,6 +76,7 @@ export class FilePicker<IsMultiSelect extends boolean> {
this.filter = filter
this.buttons = buttons
this.container = container
this.disabledNavigation = disabledNavigation
}

/**
Expand All @@ -93,6 +97,7 @@ export class FilePicker<IsMultiSelect extends boolean> {
mimetypeFilter: this.mimeTypeFilter,
multiselect: this.multiSelect,
filterFn: this.filter,
disabledNavigation: this.disabledNavigation,
}, (...rest: unknown[]) => {
const [nodes] = rest as [nodes: Node[]]
if (!Array.isArray(nodes) || nodes.length === 0) {
Expand Down Expand Up @@ -120,6 +125,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
private filter?: IFilePickerFilter
private buttons: IFilePickerButton[] | IFilePickerButtonFactory = []
private container?: string
private disabledNavigation = false

/**
* Construct a new FilePicker
Expand Down Expand Up @@ -273,6 +279,16 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
return this
}

/**
* Allow to pick directories besides files
*
* @param allow True to allow picking directories
*/
public disableNavigation() {
this.disabledNavigation = true
return this
}

/**
* Construct the configured FilePicker
*/
Expand All @@ -285,6 +301,8 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
this.buttons,
this.path,
this.filter,
this.container,
this.disabledNavigation,
)
}

Expand Down
126 changes: 44 additions & 82 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@
"dist"
],
"peerDependencies": {
"@nextcloud/vue": "^8.2.0",
"@nextcloud/vue": "^8.9.1",
"vue": "^2.7.16"
},
"dependencies": {
"@mdi/js": "^7.4.47",
"@nextcloud/auth": "^2.2.1",
"@nextcloud/axios": "^2.4.0",
"@nextcloud/event-bus": "^3.1.0",
"@nextcloud/files": "^3.1.0",
Expand Down