kongulov / nova-tab-translatable

This package contains a NovaTabTranslatable class you can use to make any Nova field type translatable with tabs.
MIT License
79 stars 17 forks source link

Keep lang selected between reloads #12

Closed mgralikowski closed 2 years ago

mgralikowski commented 2 years ago

At this moment, when we click "save and back", we will return to default/first language. It is annoying for end-users, especially when a specific person is responsible for one, the specific language of translations (I mean translators using CMS panel). My proposal is to preserve the last clicked tab globally for the plugin, but of course, it is easy to make resource-specific by prefixing session variable names.

mgralikowski commented 2 years ago

I forked 1.0.12 version not intentionally (I forked from my local project). I will fix it if general idea will be accepted.

kongulov commented 2 years ago

@mgralikowski https://github.com/kongulov/nova-tab-translatable/commit/64f0986cf029be0f91c4511eef93f3dae5f1ee28

Not everyone may want such a change, so I added a method with which you can save languages You can use it by adding the code ->saveLastSelectedLang()

public function fields(Request $request)
{
    return [
        NovaTabTranslatable::make([
            Trix::make('text'),
        ])->saveLastSelectedLang(),
    ];
}
mgralikowski commented 2 years ago

It works like a charm.

Making optional this functionality was also my intention, I was thinking about config + inline: ->saveLastSelectedLang(bool|callback);

kongulov commented 2 years ago

@mgralikowski config is a good idea, so as not to constantly add a method, but to register it once in the config for the entire project. Now I will make changes

mgralikowski commented 2 years ago

Yes, and by allowing passing bool or callback it will be possible to adjust behaviour for specific resources (exclude). It is similar to other nova's features like disabled(true);.