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

Fix Sidebar enabled check #18449

Merged
merged 1 commit into from
Dec 19, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions apps/files/js/dist/sidebar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files/js/dist/sidebar.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3650,8 +3650,9 @@
registerTabView: function(tabView) {
console.warn('registerTabView is deprecated! It will be removed in nextcloud 20.');
const name = tabView.getLabel()
const enabled = tabView.canDisplay || undefined
if (name) {
OCA.Files.Sidebar.registerTab(new OCA.Files.Sidebar.Tab(name, tabView, true))
OCA.Files.Sidebar.registerTab(new OCA.Files.Sidebar.Tab(name, tabView, enabled, true))
}
},

Expand Down
19 changes: 15 additions & 4 deletions apps/files/src/models/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,27 @@

export default class Tab {

#component;
#legacy;
#name;
#component
#legacy
#name
#enabled

/**
* Create a new tab instance
*
* @param {string} name the name of this tab
* @param {Object} component the vue component
* @param {Function} [enabled] function that returns if the tab should be shown or not
* @param {boolean} [legacy] is this a legacy tab
*/
constructor(name, component, legacy) {
constructor(name, component, enabled = () => true, legacy) {
if (typeof enabled !== 'function') {
throw new Error('The enabled argument should be a function')
}

this.#name = name
this.#component = component
this.#enabled = enabled
this.#legacy = legacy === true

if (this.#legacy) {
Expand All @@ -52,6 +59,10 @@ export default class Tab {
return this.#component
}

get isEnabled() {
return this.#enabled
}

get isLegacyTab() {
return this.#legacy === true
}
Expand Down
6 changes: 1 addition & 5 deletions apps/files/src/views/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,7 @@ export default {
* @returns {boolean}
*/
canDisplay(tab) {
if (tab.isLegacyTab) {
return this.fileInfo && tab.component.canDisplay && tab.component.canDisplay(this.fileInfo)
}
// if the tab does not have an enabled method, we assume it's always available
return tab.enabled ? tab.enabled(this.fileInfo) : true
return tab.isEnabled(this.fileInfo)
},
onClose() {
this.resetData()
Expand Down