admin icon indicating copy to clipboard operation
admin copied to clipboard

Using serialization group for LIST, but not for SHOW results in empty columns instead of non existent columns

Open diimpp opened this issue 7 years ago • 3 comments
trafficstars

Hi,

When I'm using serialization groups for collectionOperations/get, I'm expecting those fields not to appear in the view, instead I'm getting this fields with empty values.

Screenshot should illustrate the issue, empty columns are not really empty, but filtered with serialization group. screen shot 2018-08-04 at 11 18 57

my resource configuration

 App\Entity\Restaurant:
     collectionOperations:
         get:
             filters: ['restaurant.search_filter']
             normalization_context:
                 groups: ['restaurant:list']
             denormalization_context:
                 groups: ['restaurant:list']
         post: ~
     attributes:
         normalization_context:
             groups: ['restaurant']
         denormalization_context:
             groups: ['restaurant']

Serialization configuration

 App\Entity\Restaurant:
     attributes:
         owner:
             groups: ['restaurant', 'restaurant:list']
         city:
             groups: ['restaurant', 'restaurant:list']
         specialities:
             groups: ['restaurant']
...
 
         name:
             groups: ['restaurant']
...

If I will change entity global normalization_context to restaurant:list, then I will get only owner and city everywhere and it's not possible to extend list of fields per operation with restaurant group.

Is it bug or misconfiguration? What can be done to render only specific fields at resources listing page?

diimpp avatar Aug 04 '18 04:08 diimpp

Likely override the List view and use only specific list items. Maybe:

<Datagrid>
    <TextField source="only-this-field" />
    <TextField source="only-this-field-2" />
    <TextField source="only-this-field-3" />
</Datagrid>

?

krcrawford avatar Nov 02 '18 17:11 krcrawford

@krcrawford Yes, it's a possible way, but in this case I will lose advantage of auto-generation with admin/List module. In my opinion, admin/List should catch up, if some of data is not provided and therefore not render those columns.

I'm out of the loop with react-admin and api-platform/admin these days, so I cannot offer any other information about it. Maybe whole idea is irrelevant and there are other ways to render custom columns at List view.

diimpp avatar Nov 02 '18 19:11 diimpp

I think that it is not possible to have informations about serialization configurations used by groups and operations into hydra contexts. In this case, the admin can't know the availables properties for read/write and by write operations (PUT, POST).

For admin overrides, you can see new simply solution: https://github.com/api-platform/admin/pull/130

comxd avatar Feb 18 '19 20:02 comxd