eminiarts / nova-tabs

Laravel Nova Tabs Package
464 stars 139 forks source link

rendering the contents of a tab only if it's active #265

Closed vladcazacu closed 3 weeks ago

vladcazacu commented 1 year ago

Currently all relations of a resource are loaded on the Detail view, regardless of whether they're in the active tab or not. This leads to many unnecessary requests being made on the initial pageload. This PR addresses that issue.

mstaack commented 1 year ago

Nice!

gabrielesbaiz commented 1 year ago

Really nice, but probably it would be better to have an option to handle this situation. Sometimes it can be useful to have all relations loaded at the same time.

vladcazacu commented 1 year ago

Fair point, I've also added an option to the Tab class to allow conditional preloading.

Example usage:

Tabs::make('Some Title', [
    Tab::make('Balance', [
        Number::make('Balance', 'balance'),
        Number::make('Total', 'total'),
    ]),
    // This relation will load on initial pageload
    Tab::make('Invoices', [
        HasMany::make('Invoices'),
    ])
        ->preload(),
    // This relation will load only when the tab is activated
    Tab::make('Notes', [
        HasMany::make('Notes'),
    ]),
    Tab::make('Other Info', [
        Number::make('Paid To Date', 'paid_to_date')
    ]),
]),
chescos commented 1 year ago

Any chance to get this merged?

endze1t commented 1 year ago

Hey @marcfilipan could you maybe take a look at it?

mikkellindblom commented 11 months ago

Hey @marcfilipan , mind merging this?

LorenzoSapora commented 4 months ago

Has anyone managed to get this working locally? I see @karan-darji and @vladcazacu have been making commits towards fixing it, but pulling it in locally seems to make zero difference to the tabs. I have one specific resource that loads over 100 requests (some with queries ranging from 1-8 queries each), and limiting tabs would be incredible.