Skip to content

Update DataTableComponent.php #533

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

Closed
wants to merge 1 commit into from
Closed

Update DataTableComponent.php #533

wants to merge 1 commit into from

Conversation

cobogt
Copy link

@cobogt cobogt commented Oct 26, 2021

When updates composer all the tables shows this error, just needs to add this property to the Main DataTableComponent to solve it

TypeError
count(): Argument #1 ($value) must be of type Countable|array, null given

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests and did you add any new tests needed for your feature?
  2. Did you update all templates (if applicable)?
  3. Did you add the relevant documentation (if applicable)?
  4. Did you test locally to make sure your feature works as intended?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

When updates composer all the tables shows this error, just needs to add this property to the Main DataTableComponent to solve it

TypeError
count(): Argument #1 ($value) must be of type Countable|array, null given
@rappasoft
Copy link
Owner

That property was removed yesterday to fix bulk actions. I currently see no errors with bulk actions using either the array or method.

@fabio-ivona
Copy link
Contributor

@cobogt where does the error occur in your code? Could you show us an example?

@cobogt
Copy link
Author

cobogt commented Oct 26, 2021

imagen

`<?php

namespace App\Http\Livewire;

use App\Models\Libro;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Auth;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;

class ListaLibros extends DataTableComponent
{
public $model = Libros::class;

protected $listeners = ['refreshList'];

public $libros;
public $filtro;
public $libro_delete;
public $ocultar_boton = false;

public function mount()
{
    $this->refreshList();
}

public function refreshList()
{
    $this->libros = Libro::where('nombre', 'like', '%' . $this->filtro . '%')->get();
}

public function delete()
{
    if ($this->libro_delete->paquetes()->get()->count() == 0 && $this->libro_delete->colegios()->get()->count() == 0) {
        $this->libro_delete->delete();

        activity()
            ->performedOn($this->libro_delete)
            ->causedBy(Auth::user()->id)
            ->log('Eliminó un libro: ' . $this->libro_delete->isbn);

        $this->emit('swalAlert', ['title' => 'Libro eliminado', 'text' => 'El libro ha sido eliminado exitosamente', 'icon' => 'success']);
    } else {
        $this->ocultar_boton = true;
        $this->emit('swalAlert', ['title' => 'Error al eliminar', 'text' => 'El libro no pude ser eliminado debido a que está asociado a un colegio y/o paquete.', 'icon' => 'error']);
    }
}

public function before_delete(Libro $libro)
{
    $this->libro_delete = $libro;
    session()->flash('message_' . $libro->id, '¿Está seguro que desea eliminar este libro?');
}

public function editar(Libro $libro)
{
    $this->libro = $libro;
    $this->emit('editLibro', $libro->id);
    return redirect()->to('admin/editar_libro');
}

public function cancelar()
{
    return redirect()->to('admin/libros');
}

function columns(): array
{
    return [
        Column::make('ISBN', 'isbn')
            ->sortable()
            ->searchable(),
        Column::make('Nombre', 'nombre')
            ->sortable()
            ->searchable(),
            Column::make('Activo', 'activo')
            ->sortable()
            ->searchable(),
        Column::make('Colegios'),
        Column::blank(),
        Column::blank()

    ];
}

public function query(): Builder
{
    return Libro::query();
}

public function rowView(): string
{
    return ('livewire.lista-libros');
}

}`

@cobogt
Copy link
Author

cobogt commented Oct 26, 2021

imagen

@fabio-ivona
Copy link
Contributor

@cobogt maybe you have published some asset like views?

in that case they have not been updated with the last version

in some places the old code used:

count($bulkActions)

and it has been updated with

count($this->bulkActions)

the latter allows the component to pass bulk actions both by property and by function (through the getBulkActionsProperty() method in WithBulkActions.php

@dejury
Copy link

dejury commented Oct 28, 2021

I am experiencing this issue too, since update 1.19.3. It breaks all my laravel livewire tables.

This is the blade:

<x-livewire-tables::uikit.table.heading
                    :sortingEnabled="$sortingEnabled"
                    :sortable="$column->isSortable()"
                    :column="$column->column()"
                    :direction="$column->column() ? $sorts[$column->column()] ?? null : null"
                    :text="$column->text() ?? ''"
                    :class="$column->class() ?? ''"
                    :customAttributes="$column->attributes()"
                />

I am using a custom theme for the tables, when I switch back to an original theme (with the vendor views published again) it works.

Two things here:

  • There should be some upgrade guide when something in the views is changed to make sure that custom themes can be updated too
  • Using the SEMVER pattern for version releases; a PATCH (and a MINOR) (1.19.3) should NEVER make backwards incompatible changes

Please create a new version with changes that make it work backwards compatible!

@fabio-ivona
Copy link
Contributor

@dejury this was a mistake that did not got catched by tests, I'm really sorry about that

I'm opening a PR to fix this breaking change

would you mind to make a test for me? just to be sure to fix your problem?

just edit vendor/rappasoft/laravel-livewire-tables/src/DataTableComponent.php

and add this at line 224, after modalsView

 public function render()
{
    return view('livewire-tables::'.config('livewire-tables.theme').'.datatable')
        ->with([
            'columns' => $this->columns(),
            'rowView' => $this->rowView(),
            'filtersView' => $this->filtersView(),
            'customFilters' => $this->filters(),
            'rows' => $this->rows,
            'modalsView' => $this->modalsView(),
            'bulkActions' => $this->bulkActions   // <<--- add this one
        ]);
}

tests seems to work, but coverage isn't 100% so it would be good to have a double check first

@dejury
Copy link

dejury commented Oct 28, 2021

@fabio-ivona No worries about the mistake, everybody makes them ;) I will give it a try, one moment!

@dejury
Copy link

dejury commented Oct 28, 2021

@fabio-ivona I can confirm this fixes the issue!

@fabio-ivona
Copy link
Contributor

@fabio-ivona I can confirm this fixes the issue!

Ok I'm opening a PR right now 😉

@fabio-ivona
Copy link
Contributor

here's the PR #535

@rappasoft let me know if you need support for this

@dejury
Copy link

dejury commented Oct 28, 2021

I suppose this PR can be closed then, moving to #535

@rappasoft rappasoft closed this Nov 2, 2021
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.

4 participants