sharp icon indicating copy to clipboard operation
sharp copied to clipboard

feat: add collapsable on entity list section

Open hichxm opened this issue 3 years ago • 1 comments

When I use Sharp framework, sometimes I need to collapse a section on the entity show page.

For example, I have this following code to show tags relation between servers and tags.

With PHP 8 and arrow function is okay, but with PHP version older than 8, the code can be really more, more, more, long.

class ServerEntityShow extends SharpShow
{
    protected function buildShowFields(FieldsContainer $showFields): void
    {
        $showFields
            ->addField(
                SharpShowEntityListField::make('tags', 'tag')
                    ->setLabel('Tags')
            );
    }
    
    protected function buildShowLayout(ShowLayout $showLayout): void
    {
        $showLayout

            // On current sharp version 
            ->addEntityListSection('tags', function(ShowLayoutSection $section) { 
                $section->setCollapsable()
            })

            // With the pull request
            // The third parameter as default "false", it represent $collapsable boolean
            ->addEntityListSection('tags', null, true);
    }
    
}

hichxm avatar Jan 26 '22 17:01 hichxm

I think you made a point here: maybe we should go further, and remove the closure (2nd param) of addEntityListSection, since we can't add an extra column, or change the section title in an EmbeddedEntityList case. In fact, the signature might be: addEntityListSection(string $entityListKey, bool $collapsable = false);

I'll think about this (it's a BC to change a signature)

dvlpp avatar Jan 27 '22 08:01 dvlpp

Hi @hichxm, and sorry for the delay. We are close to release a solution to this, allowing to write it like this:

protected function buildShowLayout(ShowLayout $showLayout): void
{
    $showLayout->addEntityListSection('posts', true);
}

For legacy compatibility, le 2nd arg could be either a bool or a Closure.

dvlpp avatar Aug 30 '22 09:08 dvlpp