eminiarts / nova-tabs

Laravel Nova Tabs Package
466 stars 139 forks source link

How to maintain tab #27

Closed iiDestiny closed 4 years ago

iiDestiny commented 5 years ago

Version Information

problem

When I set up multiple tabs, how can I maintain this tab after the success of "relation create"?

image

thanks

HenriqueSPin commented 5 years ago

Need this too.

morphsteve commented 5 years ago

Perhaps store the tab name in localStorage (possibly namespaced by request path) then add a check after the query parameter check here? https://github.com/eminiarts/nova-tabs/blob/d07c52c6d20d3713671030cdfb1429dc20d4d7f2/resources/js/components/DetailTabs.vue#L101

wize-wiz commented 5 years ago

I came to the same conclusion, here is the most simplest working version to keep track of selected tabs. I'm testing it now to see how much work it still needs and if, at all, it is viable.

https://github.com/wize-wiz/nova-tabs/commit/4c0691a55351b57ba8b410872c9f1500bdd91fa5

morphsteve commented 5 years ago

As a workaround for OP's issue, it is possible to configure Nova to redirect to a different URL after create/update, and the active tab can be set with a query string parameter.

Example assuming a Parent resource with a set of Child resources:

class Child extends Resource
{
    public static function redirectAfterCreate(NovaRequest $request, $resource)
    {
        return '/resources/' . Parent::uriKey() . '/' . $resource->parent_id . '?tab=Children';
    }
}
wize-wiz commented 5 years ago

@morphsteve sure, that could work when an API call was made, though reloading the page or viewing a related resource (browser back-button) will not help a bit maintaining the position of the selected tab.

bernhardh commented 4 years ago

With my pull request https://github.com/eminiarts/nova-tabs/pull/86 this should be fixed.

@wize-wiz I had a look at your code and you are asking yourself

// where the heck is `this.$route.query.tab` coming from?
this.$route.query.tab = this.getTabState();

I think, eminiarts had already tried to solve it by a query string, but it just not worked. My solution is very similar, but working, without localStorage.

wize-wiz commented 4 years ago

@bernhardh Yea I figured that out after I pushed the commit. The fork I made was less than 5 minutes of work, it's absolutely and can be improved in a lot of ways.

RVxLab commented 4 years ago

In light of #86 almost being ready to be merged I'll be closing this. Expect this functionality in 1.3.0.