laravel / nova-issues

554 stars 34 forks source link

Empty filter dropdown on SoftDeletes and withoutTrashed() #2781

Closed rasmuscnielsen closed 4 years ago

rasmuscnielsen commented 4 years ago

Description:

When having a HasMany relation to a model that SoftDeletes with the withoutTrashed() argument it displays an empty filter dropdown.

Screenshot 2020-08-04 at 13 25 39

I believe the issue occurs as a result of the following if-statements in FilterMenu.vue:

FilterMenu.vue:2

  <dropdown
    v-if="filters.length > 0 || softDeletes || !viaResource"
    dusk="filter-selector"
  >

and

FilterMenu.vue:44

<!-- Soft Deletes -->
<div v-if="softDeletes && showTrashedOption">

Suggested solution:

FilterMenu.vue:2

  <dropdown
    v-if="filters.length > 0 || (softDeletes && showTrashedOption) || !viaResource"
    dusk="filter-selector"
  >

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

Create a model+ nova resource ie. "User".

Create a HasMany relation ie. "Servers" that SoftDeletes and apply the withoutTrashed option on the field configuration.

Now there should be a filter button with no items.

nickshontz-ych commented 4 years ago

@davidhemphill any thoughts on this?

preliot commented 4 years ago

I'm seeing very similar behaviour, but with different code:

Fields\HasOne::make('Customer shop',  'shop', Shop::class);

I have only one filter (trashed) available. First the filter works as expected. When i try to filter on trashed only, i get the same result:

image

HTML output:

<div class="select-none overflow-hidden bg-white border border-60 shadow rounded-lg" direction="rtl" dark="true" style="width: 290px;">
<div class="scroll-wrap overflow-x-hidden overflow-y-auto" style="max-height: 350px;">
<!---->  
<!----> 
<!---->
</div>
</div>
temp1029 commented 4 years ago

Also seeing this (or at least something similar) in Nova 3.9.1 with Laravel 7.28.1, but on both HasMany and MorphMany relationships.

Nova Relationship Code MorphMany::make('Custom Values', 'field_values', 'App\Nova\CustomFieldValue')

Model Relationship Code public function field_values(){ return $this->morphMany('App\CustomFieldValue', 'owner'); }

If I remove the 'SoftDeletes' trait the filter icon and dropdown go away. I don't remember if filtering on MorphMany relationships was possible before in Nova. I am also not using withoutTrashed anywhere.

image

preliot commented 4 years ago

I'm seeing very similar behaviour, but with different code:

Fields\HasOne::make('Customer shop',  'shop', Shop::class);

I have only one filter (trashed) available. First the filter works as expected. When i try to filter on trashed only, i get the same result:

image

HTML output:

<div class="select-none overflow-hidden bg-white border border-60 shadow rounded-lg" direction="rtl" dark="true" style="width: 290px;">
<div class="scroll-wrap overflow-x-hidden overflow-y-auto" style="max-height: 350px;">
<!---->  
<!----> 
<!---->
</div>
</div>

My issue is gone in nova 3.13.0.

crynobone commented 4 years ago

Unable to recreate the issue on latest Laravel Nova.

preliot commented 4 years ago

Recently there was a fix for trashed filter not appearing; i think that fix also fixed this one.