SAP / luigi

Micro frontend framework
https://luigi-project.io
Apache License 2.0
830 stars 171 forks source link

`userSettings` with `viewUrl` should allow setting `clientPermissions` #3997

Open silvester-pari opened 1 week ago

silvester-pari commented 1 week ago

Description

By setting the viewUrl property inside a userSettingGroup it is possible to load a micro frontend as editor. But, if developing a e.g. custom language switcher, it is not possible to set clientPermissions.changeCurrentLocale, necessary for allowing the micro frontend to switch the locale.

This is because the createIframe function is called with only the viewUrl and microFrontendType, the rest being undefined. It looks like clientPermissions would be expected to be passed as part of the third argument (currentNode).

Reasons

When offering the usage of custom editors for userSettings, it would be great to have all the (necessary) functionalities present in the node creation process; especially the language switching use case demonstrates this. Other functionality could be e.g. also passing a context.

hardl commented 1 week ago

Hi @silvester-pari, the userSettings custom editor functionality was initially meant to make changes to the userSettingsData object only and giving the core the chance to execute custom code when the user clicks 'Save' (e.g. if certain values have changed, like locale, theme, etc., do the necessary updates via Luigi Core API). I assume you want to have more like an "instant/live" effect for changed values, but i'm afraid that just adding the clientPermissions mechanism to userSettings MFE's wouldn't be sufficient, since it rather would mean a change of the whole flow. E.g. the "Save" button is probably obsolete in such a scenario, instead you would need a "rollback" action on cancel... or maybe even no cancel button at all(?)... storeUserSettings probably needs to be called on each change. etc. So I guess we have 3 options now (in order of complexity and thus time to be available):

  1. you implement your user settings locale switcher editor mfe in the "traditional" way, living with the "transactional"-like UX (there is an example for switching theme on https://fiddle.luigi-project.io/, with a declarative settings UI though, but should be the same for a custom mfe using the example code here: https://docs.luigi-project.io/docs/user-settings?section=write-a-custom-editor
  2. we add clientPermissions functionality to userSettings editor MFE's (and maybe additional things) as stated in this ticket, knowing that it has the potential to induce follow-up tickets due to the described shortcomings
  3. we provide an option in luigi core config to use "instant-change"-flavour for userSettings and implement all the things necessary to make it a nice developer and user experience.