Skip to content

Commit

Permalink
Merge pull request #1261 from nextcloud-libraries/feat/enabledNavigation
Browse files Browse the repository at this point in the history
feat: allow to disable file picker navigation
  • Loading branch information
skjnldsv authored Mar 6, 2024
2 parents ee7729a + 6fae34f commit f8ee08f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 87 deletions.
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

0 comments on commit f8ee08f

Please sign in to comment.