Skip to content

Commit

Permalink
Revert "Add primaryKeyAlias property"
Browse files Browse the repository at this point in the history
This reverts commit 8eab0ae.
  • Loading branch information
devsquad-luan-freitas committed Jul 18, 2024
1 parent 8eab0ae commit 45fc6b0
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 31 deletions.
6 changes: 3 additions & 3 deletions resources/views/components/editable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
$params = [
'theme' => data_get($theme, 'name'),
'tableName' => $tableName,
'id' => data_get($row, $this->realPrimaryKey),
'id' => data_get($row, $primaryKey),
'dataField' => $field,
'content' => $content,
'fallback' => $fallback,
Expand Down Expand Up @@ -74,9 +74,9 @@
<div x-html="editableInput"></div>
</template>
@if ($showErrorBag)
@error($field . '.' . $row->{$this->realPrimaryKey})
@error($field . '.' . $row->{$primaryKey})
<div class="text-sm text-red-800 p-1 transition-all duration-200">
{{ str($message)->replace($field . '.' . $row->{$this->realPrimaryKey}, $field) }}
{{ str($message)->replace($field . '.' . $row->{$primaryKey}, $field) }}
</div>
@enderror
@endif
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<x-livewire-powergrid::editable
:tableName="$tableName"
:primaryKey="$this->realPrimaryKey"
:primaryKey="$primaryKey"
:row="$row"
:field="$field"
:theme="$theme"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class="{{ data_get($theme, 'tdBodyClass') }}"
>
<div
class="cursor-pointer"
x-on:click.prevent="$wire.toggleDetail('{{ $row->{$this->realPrimaryKey} }}')"
x-on:click.prevent="$wire.toggleDetail('{{ $row->{$primaryKey} }}')"
>
@includeIf(data_get($setUp, 'detail.viewIcon'))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@php
$params = [
'id' => data_get($row, $this->realPrimaryKey),
'id' => data_get($row, $primaryKey),
'isHidden' => !$showToggleable,
'tableName' => $tableName,
'field' => $column->field,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<x-livewire-powergrid::editable
:tableName="$tableName"
:primaryKey="$this->realPrimaryKey"
:primaryKey="$primaryKey"
:row="$row"
:field="$field"
:theme="$theme"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class="{{ data_get($theme, 'tdBodyClass') }}"
>
<div
class="cursor-pointer"
x-on:click.prevent="$wire.toggleDetail('{{ $row->{$this->realPrimaryKey} }}')"
x-on:click.prevent="$wire.toggleDetail('{{ $row->{$primaryKey} }}')"
>
@includeIf(data_get($setUp, 'detail.viewIcon'))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$falseValue = $column->toggleable['default'][1];
$params = [
'id' => data_get($row, $this->realPrimaryKey),
'id' => data_get($row, $primaryKey),
'isHidden' => !$showToggleable,
'tableName' => $tableName,
'field' => $column->field,
Expand Down
8 changes: 4 additions & 4 deletions resources/views/components/row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<div class="pg-actions">
@if(empty(data_get($row, 'actions')) && $column->isAction)
@if (method_exists($this, 'actionsFromView') && $actionsFromView = $this->actionsFromView($row))
<div wire:key="actions-view-{{ data_get($row, $this->realPrimaryKey) }}">
<div wire:key="actions-view-{{ data_get($row, $primaryKey) }}">
{!! $actionsFromView !!}
</div>
@endif
Expand All @@ -80,7 +80,7 @@
@if (filled(data_get($row, 'actions')) && $column->isAction)
@foreach (data_get($row, 'actions') as $key => $action)
@if(filled($action))
<span wire:key="action-{{ data_get($row, $this->realPrimaryKey) }}-{{ $key }}">
<span wire:key="action-{{ data_get($row, $primaryKey) }}-{{ $key }}">
{!! $action !!}
</span>
@endif
Expand All @@ -92,7 +92,7 @@
$hasFieldRules = $actionRulesClass->recoverActionForField($row, $field);
// =============* Edit On Click *=====================
$showEditOnClick = false;
if (data_get($column->editable, 'hasPermission')) {
Expand Down Expand Up @@ -125,7 +125,7 @@
$showEditOnClick = false;
}
@endphp

@if($showEditOnClick === true)
<span @class([$contentClassField, $contentClass])>
@include(data_get($theme, 'editable.view') ?? null, ['editable' => $column->editable])
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@php throw new Exception('To use checkboxes, you must define a unique key attribute in your data source.') @endphp
@endif
@php
$rowId = data_get($row, $this->realPrimaryKey);
$rowId = data_get($row, $primaryKey);
$class = data_get($theme, 'table.trBodyClass');
Expand Down Expand Up @@ -96,7 +96,7 @@
<livewire:lazy-child
key="{{ $this->getLazyKeys }}"
:child-index="$item"
:primary-key="$this->realPrimaryKey"
:$primaryKey
:$radio
:$radioAttribute
:$checkbox
Expand Down
8 changes: 4 additions & 4 deletions resources/views/components/table/detail.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

<td colspan="999">
@if (filled($rulesValues['detailView']))
@includeWhen(data_get($setUp, 'detail.state.' . $row->{$this->realPrimaryKey}),
@includeWhen(data_get($setUp, 'detail.state.' . $row->{$primaryKey}),
$rulesValues['detailView'][0]['detailView'],
[
'id' => data_get($row, $this->realPrimaryKey),
'id' => data_get($row, $primaryKey),
'options' => array_merge(
data_get($setUp, 'detail.options'),
$rulesValues['detailView']['0']['options']),
]
)
@else
@includeWhen(data_get($setUp, 'detail.state.' . $row->{$this->realPrimaryKey}),
@includeWhen(data_get($setUp, 'detail.state.' . $row->{$primaryKey}),
data_get($setUp, 'detail.view'),
[
'id' => data_get($row, $this->realPrimaryKey),
'id' => data_get($row, $primaryKey),
'options' => data_get($setUp, 'detail.options'),
]
)
Expand Down
9 changes: 0 additions & 9 deletions src/Concerns/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

namespace PowerComponents\LivewirePowerGrid\Concerns;

use Livewire\Attributes\Computed;
use PowerComponents\LivewirePowerGrid\ProcessDataSource;

trait Base
{
public string $primaryKey = 'id';

public ?string $primaryKeyAlias = null;

public bool $ignoreTablePrefix = true;

public string $tableName = 'default';
Expand Down Expand Up @@ -47,12 +44,6 @@ trait Base

public int $totalCurrentPage = 0;

#[Computed]
public function realPrimaryKey(): string
{
return $this->primaryKeyAlias ?? $this->primaryKey;
}

public function template(): ?string
{
return null;
Expand Down
4 changes: 1 addition & 3 deletions src/Concerns/ToggleDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ private function resolveDetailRow(mixed $results): void
$collection = !is_array($results) && method_exists($results, 'items') ? collect($results->items()) : collect($results);
}

$primaryKey = $this->primaryKeyAlias ?? $this->primaryKey;

$collection->pluck($primaryKey)
$collection->pluck($this->primaryKey)
->map(fn ($id) => strval($id))
->each(function ($id) {
$state = data_get($this->setUp, "detail.state.$id", false);
Expand Down

0 comments on commit 45fc6b0

Please sign in to comment.