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

Panel collapsable / collapsedByDefault local storage key is not unique to the resource #6011

Closed
dmason30 opened this issue Oct 31, 2023 · 2 comments
Labels
fix incoming A fix is in review

Comments

@dmason30
Copy link

dmason30 commented Oct 31, 2023

  • Nova Version: 4.28

Description:

Say you have these two resources with collapsable panels:

class ExampleA extends Resource {
  public function fields(NovaRequest $request) {
        return [
             Panel::make('Settings', [
                  Text::make('Some field', 'some_field'),
             ])->collapsable(),
        ];
  }
}
class ExampleB extends Resource {
  public function fields(NovaRequest $request) {
        return [
             Panel::make('Settings', [
                  Text::make('Another field', 'another_field'),
             ])->collapsable(),
        ];
  }
}

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

  1. If you navigate to Example A resource details screen and collapse the Settings panel
  2. nova.panels.Settings.collapsed is written to local storage with a value of true
  3. Navigate to Example B resource details screen and the Settings panel will be collapsed
  4. This is because it ends up using the same nova.panels.Settings.collapsed key

Proposed solution

The resource uriKey should be included in the localStorage key?


Additional request

Another issue is if we are on a multi language application where the panel label is translated.

For a simple example:

  • English: Settings
  • Other: Sëttïngs

Then because the key is being generated using the translated panel name if a user switches language they are going to lose all their collapsed panels because the key is changed between languages.

  • English key: nova.panels.Settings.collapsed
  • Other: nova.panels.Sëttïngs.collapsed

It would be helpful, if you allowed us to provide an attribute like we do for all other fields to the Panel which when it is provided will prefer to use that in the local storage key rather than the panel name. For example:

class ExampleA extends Resource {
  public function fields(NovaRequest $request) {
        return [
             Panel::make(
                 __('Settings'), 
                 [
                     Text::make('Another field', 'some_field'),
                 ],
                'some-attribute', // <--- new attribute argument
             )->collapsable(), 
        ];
  }
}
@crynobone crynobone added the pending Issues that are pending triage label Nov 1, 2023
@davidhemphill
Copy link
Contributor

Panels already have a slug property, but you're right, we do currently use the name in the localStorage key. Changing this would technically be a breaking change, but seems harmless enough that we could do it in a patch release.

@davidhemphill davidhemphill added fix incoming A fix is in review and removed pending Issues that are pending triage labels Nov 10, 2023
@dmason30
Copy link
Author

@davidhemphill thanks for looking at this. Would be nice DX if you could make it possible to set the attribute via a fluent method too? Happy if you disagree though 😜

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

No branches or pull requests

3 participants