Skip to content

Add OCA.Files.Settings for Files navigation settings - #18556

Merged
rullzer merged 1 commit into
masterfrom
enh/16602/files-app-settings
Mar 22, 2020
Merged

Add OCA.Files.Settings for Files navigation settings#18556
rullzer merged 1 commit into
masterfrom
enh/16602/files-app-settings

Conversation

@gary-kim

@gary-kimgary-kim commented Dec 23, 2019

Copy link
Copy Markdown
Member

Resolves#16602

Most of this is taken from #15719 so thank you @skjnldsv!

cc @ChristophWurst for Recommendations app
Example use here: nextcloud/recommendations#168 (Can be tested with this)
Also for Text: nextcloud/text#708

window.addEventListener('DOMContentLoaded',()=>{if(OCA.Files&&OCA.Files.Settings){OCA.Files.Settings.register(newOCA.Files.Settings.Setting('recommendations',{el: ()=>{// return an unmounted element.returndocument.createElement('a');},open: ()=>{// Callback called when settings is opened},close: ()=>{// Callback called when settings is closed}}))}})

Signed-off-by: Gary Kim gary@garykim.dev

@kesselb

Copy link
Copy Markdown
Contributor

Cool 👍 Is the text app still able to inject or is a update required?

@skjnldsv

skjnldsv commented Dec 23, 2019

Copy link
Copy Markdown
Member

You're welcome :)
Please not that we don't know what will be planned for 19, so it might conflict with some other tasks ;)

@skjnldsv whistle files to vue 😁
(a man can dream)

@skjnldsvskjnldsv changed the title Add OCA.Files.Settings for Files Sidebar SettingsAdd OCA.Files.Settings for Files navigation settingsDec 23, 2019
@gary-kim

gary-kim commented Dec 23, 2019

Copy link
Copy Markdown
MemberAuthor

whistle files to vue grin

YES 😃!!!
In any case, this change is already using Vue so it shouldn't be much of a conflict.

Cool +1 Is the text app still able to inject or is a update required?

The Text app would need an update to use the new API.

@gary-kim
gary-kimforce-pushed the enh/16602/files-app-settings branch 5 times, most recently from 2e00c62 to 637d434CompareDecember 23, 2019 16:36
@gary-kimgary-kim self-assigned this Dec 23, 2019
@ChristophWurst

Copy link
Copy Markdown
Member

Thanks for looking into this!

As with the sidebar, my gut feeling tells we we shouldn't make this a Vue-specific API but one that works with any framework. Yes, right now Vue is our main tool, but so was jQuery and Backbone and now we have to deal with legacy APIs that are bound to these libraries. There is no perfect API that works forever, but we can try to make it as flexible as possible.

Thus I would like to propose that we make this framework-agnostic and don't reply on a component passed. One thing that I had in mind with the sidebar as well is that if you register X (sidebar, settings, whatever) you get a mounted DOM element back. And then you simply render your UI into this element.

So, as someone who wants to adds a custom settings to files, I do something like

constel=OCA.Files.Settings.register('recommendations')constview=Vue.extend(...).mount(el)

^ that should work with most frameworks and isn't much less convenient to use. It even has the advantage that creating the component is done by your app and not the server Vue instance, hence you get $store or whatever you have registered globally. @skjnldsv ran into such an issue recently with the Talk sidebar.

Hope this makes sense. I won't be around much the next few days, but I'll happily discuss this next year :)

@skjnldsv

skjnldsv commented Dec 23, 2019

Copy link
Copy Markdown
Member
constel=OCA.Files.Settings.register('recommendations')

With this you leave the mount mechanism to the app's management, but the app might not know the current settings status.
Did we changed the view of the files app, did we changed another thing (like the sidebar, you can change the file, but the sidebar doesn't change everything, they just reload the tabs and data)

I could therefore do it differently,

OCA.Files.Settings.register('recommendations',function(){returnnewVue({...}).$el})

And then every time the Settings would change it can generate the whole data itself by requesting a new instance of the registered Settings?
That's how I plan to upgrade the sidebar, but I definitely have no fixed mind on this, so I could be totally wrong ;)

@ChristophWurst

Copy link
Copy Markdown
Member

lol, yes, that was the simplified version. I had pretty much the same in mind for cases where you need more context information. Maybe with an object, though

OCA.Files.Settings.register('recommendations',{open: ()=>{...},close: ()=>{...},})

^ allows separation of different events. A single callback would either have a single purpose for which it's called or you need to pass in this information as parameter. If you use the object style then in server you even know which callbacks are provided, should you need that information.

I'm not sure if we should return a new element every time a callback is invoked.

@gary-kim

gary-kim commented Dec 24, 2019

Copy link
Copy Markdown
MemberAuthor

Alright, let's go with a more framework agnostic one!

For the sidebar, it definitely would make sense to have different events but I don't think that's necessary for the settings for which it's usually a mount then done thing. Could just make it so that, at least for settings, only el exists but it is till an object to make the API somewhat consistent, so for recommendations, it would be something like this:

OCA.Files.Settings.register('recommendations',{el: ()=>{new(Vue.extend(Settings)).$mount(document.createElement('div')).$el}});

Also, cc @juliushaertl for Text app rich workspace enabled setting.

EDIT: Just thinking, it may also make sense to have a dirChange callback for Settings. Maybe the recommendations settings should only be visible in the root directory?

@juliusknorr

Copy link
Copy Markdown
Member

EDIT: Just thinking, it may also make sense to have a dirChange callback for Settings. Maybe the recommendations settings should only be visible in the root directory?

Let's keep the settings independent from the current directory. Otherwise it would be confusing if they are sometimes there and sometimes not. 😉

@skjnldsv

Copy link
Copy Markdown
Member
	el: ()=>{new(Vue.extend(Settings)).$mount(document.createElement('div')).$el}

No, you don't need to mount or do anything, this is exactly what @ChristophWurst suggested :)
With the open/close. As long as the open return an unmounted dom it's fine :)

The close would just be unmounting stuff, and we could possibly need this as we might have different settings for different files views? (sharing, deleted files...)
If so, we still need to unmount the elements so they're not stacking and creating a memory leak.

Now that I think of it, why are you all using Vue.extend instead of creating a new Vue instance? I feel like I'm missing something :)

@gary-kim

Copy link
Copy Markdown
MemberAuthor

As long as the open return an unmounted dom it's fine

Oh wait,

new(Vue.extend(Settings)).$mount().$el

also works doesn't it. 🙈

The close would just be unmounting stuff, and we could possibly need this as we might have different settings for different files views?

Oh, that makes sense, although it should be possible to unmount without needing that to be handled for most cases? Still can't hurt to have it available.

It may make sense to have options el, open, close. So el should return a unmounted dom and open and close get called when first mounting and unmounting respectively.

Sorry if I'm misunderstanding something.

@skjnldsv

skjnldsv commented Dec 24, 2019

Copy link
Copy Markdown
Member

It may make sense to have options el, open, close. So el should return a unmounted dom and open and close get called when first mounting and unmounting respectively.

seems about right :)
It's then just a matter of choosing the right keywords for us then, we can also use skjnldsv but not sure I'll get a consensus on this!

Oh wait,

new(Vue.extend(Settings)).$mount().$el

also works doesn't it.

Can you? I never seen the Vue.extend used in those cases.


I just found this: https://forum.vuejs.org/t/what-is-the-relation-or-difference-between-vue-instance-and-vue-component-instance/12439/2
So as I now understand, in the end it's basically the same.

The difference is than from 1.x to vue 2.x, they removed the option to use el in a Vue.extend

Comment threadapps/files/src/components/Settings.vue Outdated
Comment threadapps/files/src/components/Settings.vue Outdated
Comment threadapps/files/src/files-app-settings.js Outdated
@gary-kim
gary-kimforce-pushed the enh/16602/files-app-settings branch 3 times, most recently from 9212bc4 to b45e22eCompareDecember 27, 2019 10:07
Comment threadapps/files/src/services/Settings.js
Comment threadapps/files/src/components/Settings.vue Outdated
Comment threadapps/files/src/components/Settings.vue Outdated
@gary-kim
gary-kimforce-pushed the enh/16602/files-app-settings branch from cb96515 to 27b6aa1CompareJanuary 17, 2020 15:43
@gary-kim
gary-kimforce-pushed the enh/16602/files-app-settings branch from 27b6aa1 to 05e43c3CompareJanuary 17, 2020 15:52
@gary-kimgary-kim added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jan 17, 2020
@gary-kim
gary-kimforce-pushed the enh/16602/files-app-settings branch 2 times, most recently from 0434a25 to 1639a16CompareFebruary 5, 2020 13:05
@gary-kim
gary-kimforce-pushed the enh/16602/files-app-settings branch from 1639a16 to 6ef0fb4CompareFebruary 25, 2020 12:41
Comment threadapps/files/src/components/Settings.vue Outdated
@gary-kim
gary-kimforce-pushed the enh/16602/files-app-settings branch from 6ef0fb4 to 3371ad8CompareFebruary 26, 2020 15:23

@ChristophWurstChristophWurst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@jancborchardtjancborchardt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works instantly, really nice! :)

Just suggested a slight wording change over in the Recommendations pull request: nextcloud/recommendations#168

And only a small request here: Is it possible to change the order so that "Show hidden files" is last? Then it is:

  • Show rich workspaces
  • Show recommendations
  • Show hidden files

And it corresponds to the order these elements show in the actual files view.

@gary-kim
gary-kimforce-pushed the enh/16602/files-app-settings branch 2 times, most recently from ae4f521 to d2b833dCompareMarch 15, 2020 05:49
@ChristophWurstChristophWurst added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Mar 20, 2020
@rullzer
rullzerforce-pushed the enh/16602/files-app-settings branch from d2b833d to 7cc9a53CompareMarch 22, 2020 13:25
@rullzer

Copy link
Copy Markdown
Member

/compile amend /

@npmbuildbot-nextcloud
npmbuildbot-nextcloudBotforce-pushed the enh/16602/files-app-settings branch from 7cc9a53 to 884bb45CompareMarch 22, 2020 13:34
Signed-off-by: Gary Kim <gary@garykim.dev>
@gary-kim
gary-kimforce-pushed the enh/16602/files-app-settings branch from 884bb45 to 98eeb57CompareMarch 22, 2020 14:35
@rullzer
rullzer merged commit 3b92af9 into masterMar 22, 2020
@rullzer
rullzer deleted the enh/16602/files-app-settings branch March 22, 2020 18:41
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4. to releaseReady to be released and/or waiting for tests to finishenhancementfeature: files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow custom app settings in bottom left of Files app

7 participants

@gary-kim@kesselb@skjnldsv@ChristophWurst@juliusknorr@rullzer@jancborchardt