dcasia / column-toggler

A Laravel Nova package that allows you to hide/show columns in the index view.
MIT License
40 stars 5 forks source link

Bug that automatically hides all columns for relationships that are not also in the owner model #4

Closed AndrewMast closed 11 months ago

AndrewMast commented 11 months ago

First off, I'm glad that you created this package! Being able to hide columns (and by default!) is amazing.

The package works as expected on index pages, but on any relationship, most of the columns are hidden by default. Take a look at this gif: column-toggler

You can see when I refresh the page, I see all of my columns for an instant and then it starts hiding them until I am left with columns that are both in the parent model and the relationship's model. I was able to track down this error to the ColumnTogglerTrait.php file on lines 43-45 where the fields are filtered by the columnToggler request array. This array contains a list of the parent model's enabled columns, not the relationship's columns. Because I only have the ID and UID columns in common between most of my relationships, I can only see those two columns. I have been able to see additional columns (ie "languages") when both the main model and the model of its relation have that column.

Due to this bug, I won't be able to use this package, but when this gets fixed, I will definitely give it another try!

milewski commented 11 months ago

Hi, I'm unable to reproduce this, can you tell me what other packages you have installed? what type of relationship it is?

AndrewMast commented 11 months ago

The bug happens with both native nova fields and fields from packages. I have even removed all package-based fields with the same results. Edit: It's a normal HasMany relationship.

milewski commented 11 months ago

This is how I'm testing, I have a table Users and Articles User Has Many Articles, on the user details page I show the articles' relationship and it is working:

image

AndrewMast commented 11 months ago

It works when I go in and actually toggle a column. When I leave everything enabled by default, it then messes up.

milewski commented 11 months ago

What happens when you clear your localstorage cache, then refresh the page?

Can you send a screenshot of how you localstorage looks like after the refresh:

image

AndrewMast commented 11 months ago

Localstorage does nothing. Ah! Have you tried it when you have multiple relationships?

AndrewMast commented 11 months ago

When having two relationships, the first relationship (in order from top to bottom) has all of the fields when it first loads, and then narrows down to only show the fields that are also in the second relationship. When having even more relationships, the fields for all above relationships are filtered as well.

AndrewMast commented 11 months ago

I have uninstalled all nova packages, and nothing changes anything. I am only able to properly use the column-toggler package when I only have one relationship on a model.

AndrewMast commented 11 months ago

image By commenting out what columns the nova resource for model 2 has, I am able to remove columns from model 1. Checking and unchecking any column from the toggle menu shows the expected result.

image

milewski commented 11 months ago

Okay got it, working on a fix now

AndrewMast commented 11 months ago

Thank you! I'm glad you were able to reproduce it.

milewski commented 11 months ago

Fixed here: https://github.com/dcasia/column-toggler/pull/5