silverstripe / silverstripe-versioned-snapshot-admin

An administrative UI for the versioned-snapshots module
BSD 3-Clause "New" or "Revised" License
5 stars 10 forks source link

Pagination breaks history viewer #104

Open mfendeksilverstripe opened 2 months ago

mfendeksilverstripe commented 2 months ago

Module version(s) affected

3.x-dev

Description

History viewer will break as long as the versions list has more than 30 items.

How to reproduce

Expected behaviour:

I want to see the history list the same way as I see this list when I have 30 or less items.

Screenshot 2024-09-02 at 11 08 02 AM

Actual behaviour:

I don't see the history viewer at all.

Screenshot 2024-09-02 at 11 15 38 AM

Error observed:

Screenshot 2024-09-02 at 11 14 31 AM

Possible Solution

Likely caused by a regression on how pagination is handled during CMS 5 upgrade. Temporary workaround can be applied by limiting the number of items to 30.

<?php

namespace App\Snapshots\Extensions;

use SilverStripe\Core\Extension;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\Snapshots\SnapshotPublishable;

/**
 * TODO remove this once module issue is resolved
 * https://github.com/silverstripe/silverstripe-versioned-snapshot-admin/issues/104
 *
 * @method DataObject getOwner()
 */
class PaginationWorkaroundExtension extends Extension
{
    /**
     * Extension point in @see SnapshotPublishable::getRelevantSnapshots()
     *
     * @param DataList $result
     * @return void
     */
    public function updateRelevantSnapshots(DataList &$result): void
    {
        $owner = $this->getOwner();

        // Not relevant for this model
        if (!$owner->hasExtension(SnapshotPublishable::class)) {
            return;
        }

        // Limit the number of items in the history viewer to work around the pagination issue
        // https://github.com/silverstripe/silverstripe-versioned-snapshot-admin/issues/104
        $result = $result->limit(30);
    }
}

Additional Context

No response

Validations

Jianbinzhu commented 2 months ago

@mfendeksilverstripe the pagination is broken by the upgrade of react-griddle library, the old GridPagination vs the new Pagination has a completely different structure.

https://github.com/silverstripe/silverstripe-versioned-snapshot-admin/blob/master/client/src/components/HistoryViewer/HistoryViewer.js#L314 will need to be updated to use the new structure of the component.