Skip to content

ui_bookmarks breaks column configuration #19

Description

@LBannenberg

Affected version: 0.7.0
Last good version: 0.6.4

If you define a getColumns() method in your ArrayProvider, it's called when the grid is rendered the first time. After that however, \Loki\AdminComponents\Component\Grid\GridViewModel::getAvailableColumns first tries to retrieve columns from the bookmarks and if that succeeds, skips the provider:

https://github.com/LokiExtensions/Loki_AdminComponents/blob/0.7.0/Component/Grid/GridViewModel.php#L198

public function getAvailableColumns(): array
    {
        $columns = $this->columnLoader->getColumnsFromNamespace($this->getNamespace());
        if (!empty($columns)) { // true the second time
            return $columns;
        }

        $providerHandler = $this->getRepository()->getProviderHandler();
        $provider = $this->getRepository()->getProvider();
        $columns = $providerHandler->getColumns($provider); // called the first time, skipped the second time

I noticed this because suddenly my cell templates and column labels were being ignored. For example:

https://github.com/LBannenberg/magento2-composer-dashboard/blob/main/src/Provider/InstalledPackagesArrayProvider.php#L22

public function getColumns(): array
    {
        return [
            $this->columnFactory->create([
                'code' => 'package',
                'label' => 'Package',
                'cell_template' => 'Corrivate_ComposerDashboard::grid/cell/package-name.phtml'
            ]),

When the column is created from the bookmark, it doesn't use the same data:

https://github.com/LokiExtensions/Loki_AdminComponents/blob/0.7.0/Grid/ColumnLoader.php#L85

            $columns[] = $this->columnFactory->create([
                'code' => $columnName,
                'visible' => $visible,
                'position' => (isset($positions[$columnName])) ? $positions[$columnName] : 99,
            ]);

Which visually looks like this on first load:

Image

And on reload:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions