Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Fix error when deleting collections #10908

Merged
merged 11 commits into from
Oct 11, 2024

Conversation

duncanmcclean
Copy link
Member

@duncanmcclean duncanmcclean commented Oct 7, 2024

This pull request fixes an issue where you'd see a console error when attempting to delete collections.

This issue was caused by the rename of rows to items in #10471. This PR fixes it by doing away with the <resource-deleter> component, in favour of the Delete action we use elsewhere.

This PR also fixes a bug with the context passed to collection actions on the "collection show", where view was wrongly list instead of form.

@duncanmcclean duncanmcclean marked this pull request as ready for review October 7, 2024 12:17
Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure how we got ourselves into a situation where we sometimes have this.items and sometimes have this.rows. I think maybe it's whenever we have ajax based listings it uses items and when we pass in data from controllers it's rows.

Regardless, this now does break the collection actions. The listing no longer refreshes after you run an action.

e.g. If you ran this action on a collection, it would look like nothing happened. Only when you manually refreshed the page would you see the changed title.

<?php

namespace App\Actions;

use Statamic\Actions\Action;

class Plop extends Action
{
    public function run($items, $values)
    {
        $items->each(function ($c) {
            $c->title('Plopped '.$c->title())->save();
        });
    }
}

The simplest solution here I think would be to remove the "resource deleter" from the collection listing and make the Delete action available to collections.

<dropdown-item
v-if="collection.deleteable"
:text="__('Delete Collection')"
class="warning"
@click="$refs[`deleter_${collection.id}`].confirm()"
>
<resource-deleter
:ref="`deleter_${collection.id}`"
:resource="collection"
@deleted="removeRow(collection)">
</resource-deleter>
</dropdown-item>
</dropdown-list>

case $item instanceof Contracts\Taxonomies\Term:
case $item instanceof Contracts\Assets\Asset:
case $item instanceof Contracts\Assets\AssetFolder:
case $item instanceof Contracts\Forms\Form:
case $item instanceof Contracts\Forms\Submission:
case $item instanceof Contracts\Auth\User:
return true;

Dealing with the rows/items inconsistency is probably a bigger job and a breaking change.

@duncanmcclean
Copy link
Member Author

@jasonvarga Okay! I've refactored this PR to use the delete action instead. 👍

@jasonvarga jasonvarga merged commit 3bae31d into 5.x Oct 11, 2024
17 checks passed
@jasonvarga jasonvarga deleted the fix/error-when-deleting-collections branch October 11, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants