-
-
Couldn't load subscription status.
- Fork 13
Added support for middleware in edit menu #31
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
Conversation
I think it would be useful to have async function support here!
Ex:
const promises = editMenuMiddlewares
.map(fn => fn({file: item, menuItems: items, isContextMenu}))
const appendItems = await Promise.all(promises)
const menuItems = [...editMenuItems, ...appendItems]
There are two problems:
First, the createEditMenu itself is not a async function. Can we make it async? How?
The second problem is that it doesn't support adding an item in a place other than the end of menu items (which is not very important for me).
To make it async, just place an async keyword here:
osjs-filemanager-application/index.js
Line 577 in d5319ee
Then await on this:
osjs-filemanager-application/index.js
Line 580 in d5319ee
And finally async keyword here
osjs-filemanager-application/index.js
Line 479 in d5319ee
Thanks for your help 😁
To make it possible for any application to add multiple items we need to assume that they will return an array, so appendedItems will be an array of arrays and we need a .reduce to make it a flat array. Right?
No problem!
To make it possible for any application to add multiple items we need to assume that they will return an array
Ah, yeah. These callbacks should probably only be able to return arrays.
To flatten it out simply do the following (as I'm not sure if the current babel setup does polyfills of .flatten and .flatMap)::
const promises = editMenuMiddlewares .map(fn => fn({file: item, menuItems: items, isContextMenu})) const appendItems = await Promise.all(promises) const menuItems = [...editMenuItems, ...([].concat(...appendItems))]
Maybe also sanitize it :)
const appendItems = (await Promise.all(promises))
.map(item => item instanceof Array)
Do you mean filter?
Ops. Yeah, filter 😊
You have confirmed that the latest changes and everything works with this ? 🤓
Now it's working 😁
I'd missed an await for menuItemsFromMiddleware.
Sweet! Then I'll merge and release this one as well :)
@osjs/filemanager-application@1.5.0 is now published with these changes.
Again, thank you very much for this!
I really enjoyed it, thank you too 😊
Uh oh!
There was an error while loading. Please reload this page.
It adds support for the dynamic edit menu in the application. Any other application can now use the
osjs/filemanager:contextmenu:editmiddleware group to change context/edit menu.Here is an example of how an application can use this feature:
middleware.jsfile at the root of your application.middleware.jsas a separate entry.{ "filename": "middleware.js", "type": "background" }to thefilesproperty in the metadata config.middleware.jsfile:Closes os-js/OS.js#752.