Skip to content
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

Relationship collapsed state not stored anymore #6726

Closed
rderks88 opened this issue Feb 7, 2025 · 3 comments
Closed

Relationship collapsed state not stored anymore #6726

rderks88 opened this issue Feb 7, 2025 · 3 comments

Comments

@rderks88
Copy link

rderks88 commented Feb 7, 2025

  • Laravel Version: 10.48.27
  • Nova Version: 5.2.1
  • PHP Version: 8.2

Description:

Laravel nova 4 used to remember the "collapse-state" of the relationships of entities.
After upgrading to Laravel nova 5, it does not do that anymore.

Detailed steps to reproduce the issue on a fresh Nova installation:

  • Create an entity with a hasMany / belongsToMany relationship.
  • Populate both entities
  • Go to the detail page of the "parent" entity.
  • Collapse the relationship view
  • Refresh the page
  • The relationship opens non-collapsed

Extra info

  • I removed all my local storage and cookies before testing.
  • It DOES create a new local storage entry with the collapsed state, e.g. "nova.resources.ingredients.ingredients.collapsed", it doesn't "listen" to this local storage entry though.
  • A collapsed Panel field DOES still maintain it's state after a page refresh (on the contrary to a relationship)
    • As do nav items and so on
@crynobone
Copy link
Member

Image

Did you explicitly set the relationship field as collapsable(), without specifically setting the option Nova 5 now will not remember the state after page change/refresh.

@crynobone crynobone added the needs more info More information is required label Feb 7, 2025
@rderks88
Copy link
Author

rderks88 commented Feb 7, 2025

Perfect, that must be the case then. That behaviour changed from Nova 4 if I'm not mistaken. We never needed to define Collapsable for that.
I can confirm that WHEN defined as collapsable, it DOES listen to the local storage defined state.
Thank you for clarifying.

@rderks88 rderks88 closed this as completed Feb 7, 2025
@rderks88
Copy link
Author

rderks88 commented Feb 7, 2025

Anyone, who prefers the default "collapsable" behaviour.
We have a "baseResource" abstract class, that every Nova resource of ours extends.
We just added this method there. A bit of overhead, but saves us a LOT of ->collapsable() repetition.

@crynobone Don't take this the wrong way. We completely understand that the default behaviour is non-collapsable.
We just really like the collapsable functionality and we don't see any downside to it for our usecase.

/**
 * We prefer the default behaviour to be that everything is collapsable.
 * Therefore, we override each field to be collapsable by default if that is available.
 */
public function availableFields(NovaRequest $request): FieldCollection
{
    $availableFields = parent::availableFields($request);
    
    $availableFields->each(function ($field) {
        if (method_exists($field, 'collapsable')) {
            $field->collapsable();
        }
    });

    return $availableFields;
}

❤ Loving Nova and the major 5 update ❤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants