Skip to content

Commit

Permalink
refactor component
Browse files Browse the repository at this point in the history
  • Loading branch information
luanfreitasdev committed Sep 21, 2023
2 parents 3daf963 + 3a3c5ae commit ed05e64
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 251 deletions.
Binary file removed .DS_Store
Binary file not shown.
6 changes: 0 additions & 6 deletions .github/workflows/pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,3 @@ jobs:

- name: PostGreSQL
run: composer test:pgsql

- name: Cypress
run: |
chmod +x ./tests/cypress/server.sh
./tests/cypress/server.sh
shell: bash
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ dist/powergrid.js.LICENSE.txt
.env
tests/cypress/app/
.DS_Store

14 changes: 7 additions & 7 deletions resources/views/components/editable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
$resolveContent = function (string $currentTable, string $field, \Illuminate\Database\Eloquent\Model|\stdClass $row): ?string {
$currentField = $field;
$replace = fn($content) => preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content);
/** @codeCoverageIgnore */
if (str_contains($currentField, '.')) {
$data = \Illuminate\Support\Str::of($field)->explode('.');
$table = $data->get(0);
$field = $data->get(1);
if ($table === $currentTable) {
return $replace($row->{$field});
}
return $replace($row->{$table}->{$field});
}
return $replace($row->{$field});
};
$fallback = html_entity_decode(strval(data_get($editable, 'fallback')), ENT_QUOTES, 'utf-8');
$value = html_entity_decode(strval($resolveContent($currentTable, $field, $row)), ENT_QUOTES, 'utf-8');
$content = !empty($value) || $value == '0' ? $value : $fallback;
$params = [
'theme' => $theme->name,
'tableName' => $tableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class="mt-2 md:mt-0"
x-transition:leave-start="opacity-100 scale-100"
x-transition:leave-end="opacity-0 scale-90"
class="py-3"
wire:key="{{ uniqid() }}"
wire:key="filter-{{ uniqid() }}"
>
@php
$customConfig = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'justify-between' => filled(data_get($setUp, 'footer.perPage')),
'justify-end' => blank(data_get($setUp, 'footer.perPage')),
'md:flex md:flex-row w-full items-center py-3 bg-white overflow-y-auto pl-2 pr-2 relative
dark:bg-pg-primary-900' => blank(
dark:bg-pg-primary-900' => blank(
data_get($setUp, 'footer.pagination')),
])>
@if (filled(data_get($setUp, 'footer.perPage')) &&
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/radio-row.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@php
$rulesValues = $actionRulesClass->recoverFromAction($row, 'pg:radio');
$inputAttributes = new \Illuminate\View\ComponentAttributeBag([
'class' => $theme->radio->inputClass,
]);
if (filled($rulesValues['setAttributes'])) {
foreach ($rulesValues['setAttributes'] as $rulesAttributes) {
$inputAttributes = $inputAttributes->merge([
Expand Down
32 changes: 30 additions & 2 deletions resources/views/components/row.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
@props([
'rowIndex' => 0,
])

@includeWhen(isset($setUp['responsive']), powerGridThemeRoot() . '.toggle-detail-responsive', [
'theme' => $theme->table,
'rowId' => $rowId,
'view' => data_get($setUp, 'detail.viewIcon') ?? null,
])

@php
$ruleDetailView = data_get($rulesValues, 'detailView');
@endphp

@includeWhen(data_get($setUp, 'detail.showCollapseIcon'), powerGridThemeRoot() . '.toggle-detail', [
'theme' => $theme->table,
'view' => data_get($setUp, 'detail.viewIcon') ?? null,
])

@includeWhen($radio, 'livewire-powergrid::components.radio-row', [
'attribute' => $row->{$radioAttribute},
])

@includeWhen($checkbox, 'livewire-powergrid::components.checkbox-row', [
'attribute' => $row->{$checkboxAttribute},
])

@foreach ($columns as $column)
@php
$content = $row->{$column->field} ?? null;
Expand All @@ -11,9 +38,10 @@
$contentClass = array_key_exists($content, $column->contentClasses) ? $column->contentClasses[$content] : '';
}
@endphp
<td @class([$theme->table->tdBodyClass, $column->bodyClass])
<td
@class([$theme->table->tdBodyClass, $column->bodyClass])
style="{{ $column->hidden === true ? 'display:none' : '' }}; {{ $theme->table->tdBodyStyle . ' ' . $column->bodyStyle ?? '' }}"
wire:key="row-{{ $column->field }}-{{ uniqid() }}"
wire:key="row-{{ $column->field }}"
>
<div class="flex gap-2 w-full">
<!-- Render Action -->
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/table-base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class="{{ $theme->theadClass }}"
class="{{ $theme->tbodyClass }}"
style="{{ $theme->tbodyStyle }}"
>
{{ $rows }}
{{ $body }}
</tbody>
@else
<tbody
Expand Down
219 changes: 25 additions & 194 deletions resources/views/components/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,123 +5,20 @@
:ready-to-load="$readyToLoad"
>
<x-slot:header>
<tr
class="{{ $theme->table->trClass }}"
style="{{ $theme->table->trStyle }}"
>
@if (data_get($setUp, 'detail.showCollapseIcon'))
<th
scope="col"
class="{{ $theme->table->thClass }}"
style="{{ $theme->table->thStyle }}"
wire:key="{{ md5('showCollapseIcon') }}"
>
</th>
@endif

@isset($setUp['responsive'])
<th
fixed
x-show="hasHiddenElements"
class="{{ $theme->table->thClass }}"
style="{{ $theme->table->thStyle }}"
>
</th>
@endisset

@if ($radio)
<th
class="{{ $theme->table->thClass }}"
style="{{ $theme->table->thStyle }}"
>
</th>
@endif

@if ($checkbox)
<x-livewire-powergrid::checkbox-all
:checkbox="$checkbox"
:theme="$theme->checkbox"
/>
@endif

@foreach ($columns as $column)
<x-livewire-powergrid::cols
wire:key="cols-{{ $column->field }} }}"
:column="$column"
:theme="$theme"
:enabledFilters="$enabledFilters"
/>
@endforeach

@if (isset($actions) && count($actions))
@php
$responsiveActionsColumnName = PowerComponents\LivewirePowerGrid\Responsive::ACTIONS_COLUMN_NAME;
$isActionFixedOnResponsive = isset($this->setUp['responsive']) && in_array($responsiveActionsColumnName, data_get($this->setUp, 'responsive.fixedColumns')) ? true : false;
@endphp

<th
@if ($isActionFixedOnResponsive) fixed @endif
class="{{ $theme->table->thClass . ' ' . $theme->table->thActionClass }}"
scope="col"
style="{{ $theme->table->thStyle . ' ' . $theme->table->thActionStyle }}"
colspan="{{ count($actions) }}"
wire:key="{{ md5('actions') }}"
>
{{ trans('livewire-powergrid::datatable.labels.action') }}
</th>
@endif

</tr>
@include('livewire-powergrid::components.table.tr')
</x-slot:header>

<x-slot:loading>
<tr
class="{{ $theme->table->trBodyClass }}"
style="{{ $theme->table->trBodyStyle }}"
>
<td
class="{{ $theme->table->tdBodyEmptyClass }}"
colspan="{{ ($checkbox ? 1 : 0) + count($columns) }}"
>
@if ($loadingComponent)
@include($loadingComponent)
@else
{{ __('Loading') }}
@endif
</td>
</tr>
@include('livewire-powergrid::components.table.tr', ['loading' => true])
</x-slot:loading>

<x-slot:rows>

<x-slot:body>
@if ($this->hasColumnFilters)
<x-livewire-powergrid::inline-filters
:checkbox="$checkbox"
:actions="$actions"
:columns="$columns"
:theme="$theme"
:filters="$filters"
:enabledFilters="$enabledFilters"
:tableName="$tableName"
:setUp="$setUp"
/>
@include('livewire-powergrid::components.inline-filters')
@endif

@if (is_null($data) || count($data) === 0)
<th>
<tr
class="{{ $theme->table->trBodyClass }}"
style="{{ $theme->table->trBodyStyle }}"
>
<td
class="{{ $theme->table->tdBodyEmptyClass }}"
style="{{ $theme->table->tdBodyEmptyStyle }}"
colspan="{{ ($checkbox ? 1 : 0) + count($columns) + (data_get($setUp, 'detail.showCollapseIcon') ? 1 : 0) }}"
>
<span>{{ trans('livewire-powergrid::datatable.labels.no_data') }}</span>
</td>
</tr>
</th>
@include('livewire-powergrid::components.table.th-empty')
@else
@includeWhen($headerTotalColumn, 'livewire-powergrid::components.table-header')
@foreach ($data as $row)
Expand Down Expand Up @@ -151,102 +48,36 @@ class="{{ $theme->table->tdBodyEmptyClass }}"
]);
}
}
@endphp

<div wire:key="{{ md5($row->{$primaryKey} ?? $loop->index) }}">
@if (isset($setUp['detail']))
<tbody
{{ $trAttributesBag }}
x-data="{ detailState: @entangle('setUp.detail.state.' . $row->{$primaryKey}) }"
>
@else
<tr
style="{{ $theme->table->trBodyStyle }}"
{{ $trAttributesBag }}
>
@endif
</div>

@includeWhen(isset($setUp['responsive']), powerGridThemeRoot() . '.toggle-detail-responsive', [
'theme' => $theme->table,
'rowId' => $rowId,
'view' => data_get($setUp, 'detail.viewIcon') ?? null,
])

@php
$ruleDetailView = data_get($rulesValues, 'detailView');
@endphp

@includeWhen(data_get($setUp, 'detail.showCollapseIcon'),
powerGridThemeRoot() . '.toggle-detail',
[
'theme' => $theme->table,
'view' => data_get($setUp, 'detail.viewIcon') ?? null,
]
)

@includeWhen($radio, 'livewire-powergrid::components.radio-row', [
'attribute' => $row->{$radioAttribute},
])

{{-- @includeWhen($checkbox, 'livewire-powergrid::components.checkbox-row', [--}}
{{-- 'attribute' => $row->{$checkboxAttribute},--}}
{{-- ])--}}


@php
$rules = $actionRulesClass->recoverFromAction($row, 'pg:rows');
$ruleHide = data_get($rules, 'hide');
$ruleDisable = data_get($rules, 'disable');
$ruleSetAttribute = data_get($rules, 'setAttribute') ?? [];
@endphp

<div wire:key="row-{{ $row->{$primaryKey} }}-{{ uniqid() }}">
@include('livewire-powergrid::components.row', ['rowIndex' => $loop->index + 1])
</div>

</tr>
@if (isset($setUp['detail']))
<template
x-cloak
x-if="detailState"
<tbody
wire:key="tbody-{{ $row->{$primaryKey} }}"
{{ $trAttributesBag }}
x-data="{ detailState: @entangle('setUp.detail.state.' . $row->{$primaryKey}) }"
>
<tr>
<td colspan="999">
@if (isset($ruleDetailView[0]['detailView']))
@includeWhen(data_get($setUp, 'detail.state.' . $row->{$primaryKey}),
$ruleDetailView[0]['detailView'],
[
'id' => data_get($row, $primaryKey),
'options' => array_merge(
data_get($setUp, 'detail.options'),
$ruleDetailView[0]['options']),
]
)
@else
@includeWhen(data_get($setUp, 'detail.state.' . $row->{$primaryKey}),
data_get($setUp, 'detail.view'),
[
'id' => data_get($row, $primaryKey),
'options' => data_get($setUp, 'detail.options'),
]
)
@endif
</td>
@include('livewire-powergrid::components.row', ['rowIndex' => $loop->index + 1])
<tr
style="{{ $theme->table->trBodyStyle }}"
{{ $trAttributesBag }}
>
@include('livewire-powergrid::components.table.detail')
</tr>
</template>
@endif
@if (isset($setUp['detail']))
</tbody>
@else
<tr
wire:key="tbody-{{ $row->{$primaryKey} }}"
style="{{ $theme->table->trBodyStyle }}"
{{ $trAttributesBag }}
>
@include('livewire-powergrid::components.row', ['rowIndex' => $loop->index + 1])
</tr>
@endif

@includeWhen(isset($setUp['responsive']), 'livewire-powergrid::components.expand-container')
@endforeach

@includeWhen($footerTotalColumn, 'livewire-powergrid::components.table-footer')
@endif
</x-slot:rows>
</x-slot:body>
</x-livewire-powergrid::table-base>
Loading

0 comments on commit ed05e64

Please sign in to comment.