From d394b2f3cd550915bc8a7051bd04f65097d52fe7 Mon Sep 17 00:00:00 2001 From: Dan <79267265+dansysanalyst@users.noreply.github.com> Date: Tue, 14 May 2024 14:15:09 +0200 Subject: [PATCH 1/5] Clear Table Cache when running migrations (#1531) * create TableCache support class * Forget PowerGrid table cache on migrations * replace Cache with PowerGridTableCache * ignore template error --- phpstan.neon | 10 ++++ src/DataSource/Builder.php | 13 ++--- src/Providers/PowerGridServiceProvider.php | 6 ++- src/Support/PowerGridTableCache.php | 61 ++++++++++++++++++++++ 4 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 src/Support/PowerGridTableCache.php diff --git a/phpstan.neon b/phpstan.neon index c4c9af96b..04cb3059c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -13,6 +13,16 @@ parameters: - '#^Method .*::fromLivewire\(\) has no return type specified\.#' - '#^Method .*::fromLivewire\(\) has parameter \$value with no type specified\.#' - '#Call to an undefined method PowerComponents\\LivewirePowerGrid\\PowerGridComponent::datasource\(\).#' + - + message: "#^Unable to resolve the template type TKey in call to function collect$#" + count: 1 + path: src/Support/PowerGridTableCache.php + + - + message: "#^Unable to resolve the template type TValue in call to function collect$#" + count: 1 + path: src/Support/PowerGridTableCache.php + paths: - src diff --git a/src/DataSource/Builder.php b/src/DataSource/Builder.php index 5da32fcff..1d117f5af 100644 --- a/src/DataSource/Builder.php +++ b/src/DataSource/Builder.php @@ -5,8 +5,10 @@ use Illuminate\Database\Eloquent\{Builder as EloquentBuilder, RelationNotFoundException}; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\{Cache, Schema}; +use Illuminate\Support\Facades\Schema; use PowerComponents\LivewirePowerGrid\Components\Filters\{Builders\Number}; +use PowerComponents\LivewirePowerGrid\Support\PowerGridTableCache; + use PowerComponents\LivewirePowerGrid\{Column, Components\Filters\Builders\Boolean, Components\Filters\Builders\DatePicker, @@ -317,12 +319,11 @@ private function getColumnType(string $modelTable, string $field): ?string private function getColumnList(string $modelTable): array { try { - return (array) Cache::remember( - 'powergrid_columns_in_' . $modelTable, - 60 * 60 * 3, + return PowerGridTableCache::getOrCreate( + $modelTable, fn () => collect(Schema::getColumns($modelTable)) - ->pluck('type', 'name') - ->toArray() + ->pluck('type', 'name') + ->toArray() ); } catch (\Throwable $throwable) { logger()->warning('PowerGrid [getColumnList] warning: ', [ diff --git a/src/Providers/PowerGridServiceProvider.php b/src/Providers/PowerGridServiceProvider.php index 68dc98424..eb064074c 100644 --- a/src/Providers/PowerGridServiceProvider.php +++ b/src/Providers/PowerGridServiceProvider.php @@ -2,7 +2,8 @@ namespace PowerComponents\LivewirePowerGrid\Providers; -use Illuminate\Support\Facades\Blade; +use Illuminate\Database\Events\MigrationsEnded; +use Illuminate\Support\Facades\{Blade, Event}; use Illuminate\Support\ServiceProvider; use Livewire\Features\SupportLegacyModels\{EloquentCollectionSynth, EloquentModelSynth}; use Livewire\Livewire; @@ -11,6 +12,7 @@ use PowerComponents\LivewirePowerGrid\Components\Actions\Macros; use PowerComponents\LivewirePowerGrid\Components\Filters\FilterManager; use PowerComponents\LivewirePowerGrid\Components\Rules\RuleManager; +use PowerComponents\LivewirePowerGrid\Support\PowerGridTableCache; use PowerComponents\LivewirePowerGrid\Themes\ThemeManager; use PowerComponents\LivewirePowerGrid\{Livewire\LazyChild, Livewire\PerformanceCard, PowerGridManager}; @@ -56,6 +58,8 @@ public function register(): void Livewire::component('lazy-child', LazyChild::class); + Event::listen(MigrationsEnded::class, fn () => PowerGridTableCache::forgetAll()); + if (class_exists(\Laravel\Pulse\Facades\Pulse::class)) { Livewire::component('powergrid-performance-card', PerformanceCard::class); } diff --git a/src/Support/PowerGridTableCache.php b/src/Support/PowerGridTableCache.php new file mode 100644 index 000000000..c4472ea61 --- /dev/null +++ b/src/Support/PowerGridTableCache.php @@ -0,0 +1,61 @@ +each(fn (string $tag): bool => Cache::forget($tag)); + + Cache::forget('pg_cached_tables'); + }, report: false); + } + + private static function list(): Collection + { + return collect( + /** @phpstan-ignore-next-line */ + rescue( + fn () => (Cache::get(self::$cachedTablesListTag) ?? []), + [], + report: false + ) + ); + } + + private static function addToCachedTablesList(string $tag): void + { + rescue(fn () => Cache::put(self::$cachedTablesListTag, self::list()->push($tag)->unique()->toArray()), report: false); + } + + private static function generateTag(string $tableName): string + { + return self::$cachedTableTag . $tableName; + } +} From 6aba7ecddcb7ae68ad737ad9d511fd8cdabed3b0 Mon Sep 17 00:00:00 2001 From: devsquad-joao-dias <95714663+devsquad-joao-dias@users.noreply.github.com> Date: Tue, 14 May 2024 09:16:51 -0300 Subject: [PATCH 2/5] Update base.css (#1547) --- resources/css/base.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/css/base.css b/resources/css/base.css index 35d0557e2..8d8bf41a7 100644 --- a/resources/css/base.css +++ b/resources/css/base.css @@ -6,6 +6,10 @@ table { width: 100%; } +select { + background-color: inherit; +} + .loader { border-top-color: #222; -webkit-animation: spinner 1.5s linear infinite; From b808e498df6861f0238efc9fa42a1ff3012f72da Mon Sep 17 00:00:00 2001 From: Luan Freitas <33601626+luanfreitasdev@users.noreply.github.com> Date: Tue, 14 May 2024 10:03:25 -0300 Subject: [PATCH 3/5] Fix resolveFilters for dynamic filters (#1550) --- src/Concerns/Filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Concerns/Filter.php b/src/Concerns/Filter.php index 32bf89cf5..8453e4e13 100644 --- a/src/Concerns/Filter.php +++ b/src/Concerns/Filter.php @@ -306,7 +306,7 @@ private function resolveFilters(): void $attributes = array_values((array) data_get($filter, 'attributes')); foreach ($attributes as $value) { - if (is_string($value) && str_contains($value, 'filters.')) { + if (is_string($value) && str_contains($value, 'filters.') && is_null(data_get($this->filters, str($value)->after('filters.')))) { data_set($this->filters, str($value)->replace('filters.', ''), null); } } From 780ebd39b7b39af726e2c009db81b233f852d4f3 Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Wed, 15 May 2024 09:35:42 -0300 Subject: [PATCH 4/5] build assets --- dist/bootstrap5.css | 2 +- dist/mix-manifest.json | 4 ++-- dist/tailwind.css | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/bootstrap5.css b/dist/bootstrap5.css index 11ab72f07..f74e81ae4 100644 --- a/dist/bootstrap5.css +++ b/dist/bootstrap5.css @@ -1,3 +1,3 @@ -[x-cloak]{display:none}table{width:100%}.loader{animation:spinner 1.5s linear infinite;border-top-color:#222}@keyframes spinner{0%{transform:rotate(0)}to{transform:rotate(1turn)}}table thead{color:#6b6a6a;font-size:.75rem;padding-bottom:8px;padding-left:15px;padding-top:8px;text-transform:uppercase}.pg-actions{display:flex;gap:4px;width:100%} +[x-cloak]{display:none}table{width:100%}select{background-color:inherit}.loader{animation:spinner 1.5s linear infinite;border-top-color:#222}@keyframes spinner{0%{transform:rotate(0)}to{transform:rotate(1turn)}}table thead{color:#6b6a6a;font-size:.75rem;padding-bottom:8px;padding-left:15px;padding-top:8px;text-transform:uppercase}.pg-actions{display:flex;gap:4px;width:100%} [x-ref=editable].pg-single-line{overflow:hidden;white-space:nowrap}[x-ref=editable].pg-single-line br{display:none}[x-ref=editable].pg-single-line *{display:inline;white-space:nowrap}[x-ref=editable][placeholder]:empty:before{background-color:transparent;color:gray;content:attr(placeholder);position:absolute} .table .checkbox-column{max-width:50px!important;text-align:center;width:50px!important}.btn-light{background-color:#fff;border-color:#d7dbdf;color:#000;font-size:.85rem}.form-control:disabled,.form-control[readonly]{background-color:#fff!important;opacity:1}.btn-light:hover{background-color:#fff;border-color:#d7dbdf;color:#000;font-size:.85rem}.btn-light,.has-search .form-control{padding-left:10px!important}.accordion-button{padding:.7rem}.btn-light,.has-search .form-control{padding-left:2.375rem}.page-link{color:gray!important}.page-item.active .page-link{background-color:gray;border-color:gray;color:#fff!important}@keyframes spinner{0%{transform:rotate(0)}to{transform:rotate(1turn)}}.badge{font-size:.77em}.btn,.form-control{box-shadow:none!important}.btn-group-vertical>.btn,.btn-group>.btn{border-color:#ced4da!important;flex:1 1 auto;position:relative}.bs5-rotate-0{transform:rotate(0deg);transition:all .3s ease}.bs5-rotate-90{transform:rotate(90deg);transition:all .3s ease}.bs5-w-h-1_5em{height:1.5em;width:1.5em} diff --git a/dist/mix-manifest.json b/dist/mix-manifest.json index 66b357b63..2ef7f471e 100644 --- a/dist/mix-manifest.json +++ b/dist/mix-manifest.json @@ -1,7 +1,7 @@ { "/powergrid.js": "/powergrid.js?id=8dbd9927fb1c6a57be1f269d484ae3c8", - "/bootstrap5.css": "/bootstrap5.css?id=03aba1df82c23db07c1d1096efcd42ae", - "/tailwind.css": "/tailwind.css?id=91710d66f68761c8de252c2e785ec55d", + "/bootstrap5.css": "/bootstrap5.css?id=53502dbf663eae6fd63228e4b6039b23", + "/tailwind.css": "/tailwind.css?id=7f99edb6d5db5fef976a545730668daa", "/tom-select.css": "/tom-select.css?id=7af730d2c4bf937316d4002948b1571d", "/powergrid.css": "/powergrid.css?id=ccf9e99db3929ffc436445d5befaf2ac" } diff --git a/dist/tailwind.css b/dist/tailwind.css index c874f2c9e..4af50491d 100644 --- a/dist/tailwind.css +++ b/dist/tailwind.css @@ -1,3 +1,3 @@ -[x-cloak]{display:none}table{width:100%}.loader{animation:spinner 1.5s linear infinite;border-top-color:#222}@keyframes spinner{0%{transform:rotate(0)}to{transform:rotate(1turn)}}table thead{color:#6b6a6a;font-size:.75rem;padding-bottom:8px;padding-left:15px;padding-top:8px;text-transform:uppercase}.pg-actions{display:flex;gap:4px;width:100%} +[x-cloak]{display:none}table{width:100%}select{background-color:inherit}.loader{animation:spinner 1.5s linear infinite;border-top-color:#222}@keyframes spinner{0%{transform:rotate(0)}to{transform:rotate(1turn)}}table thead{color:#6b6a6a;font-size:.75rem;padding-bottom:8px;padding-left:15px;padding-top:8px;text-transform:uppercase}.pg-actions{display:flex;gap:4px;width:100%} [x-ref=editable].pg-single-line{overflow:hidden;white-space:nowrap}[x-ref=editable].pg-single-line br{display:none}[x-ref=editable].pg-single-line *{display:inline;white-space:nowrap}[x-ref=editable][placeholder]:empty:before{background-color:transparent;color:gray;content:attr(placeholder);position:absolute} .page-link{--tw-border-opacity:1;--tw-bg-opacity:1;--tw-text-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity));border-color:rgb(229 231 235/var(--tw-border-opacity));border-right-width:1px;color:rgb(30 64 175/var(--tw-text-opacity));display:block;font-size:.875rem;line-height:1.25rem;outline:2px solid transparent;outline-offset:2px;padding-bottom:.5rem;padding-top:.5rem;text-align:center;width:3rem}.page-link:last-child{border-width:0}.page-item.active .page-link,.page-link:hover{--tw-border-opacity:1;--tw-bg-opacity:1;--tw-text-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity));border-color:rgb(29 78 216/var(--tw-border-opacity));color:rgb(255 255 255/var(--tw-text-opacity))}.page-item.disabled .page-link{border-color:rgb(229 231 235/var(--tw-border-opacity));color:rgb(209 213 219/var(--tw-text-opacity))}.page-item.disabled .page-link,.pg-btn-white{--tw-border-opacity:1;--tw-bg-opacity:1;--tw-text-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.pg-btn-white{--tw-ring-opacity:1;--tw-ring-color:rgb(226 232 240/var(--tw-ring-opacity));align-items:center;border-color:rgb(203 213 225/var(--tw-border-opacity));border-radius:.5rem;border-width:1px;color:rgb(100 116 139/var(--tw-text-opacity));-moz-column-gap:.5rem;column-gap:.5rem;display:inline-flex;font-size:.875rem;justify-content:center;line-height:1.25rem;outline:2px solid transparent;outline-offset:2px;padding:.5rem .75rem}.pg-btn-white:hover{--tw-bg-opacity:1;--tw-shadow:0 1px 2px 0 rgba(0,0,0,.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);background-color:rgb(241 245 249/var(--tw-bg-opacity));box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.pg-btn-white:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);--tw-ring-offset-width:1px;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.pg-btn-white:disabled{cursor:not-allowed;opacity:.8}.pg-filter-container{padding-bottom:.75rem;padding-top:.75rem}.pg-enabled-filters-base{align-items:center;display:flex;flex-wrap:wrap;gap:.5rem;margin-top:.5rem}@media (min-width:768px){.pg-enabled-filters-base{margin-top:0}} From 37402696522262bf33dca8f81a23f3375844297d Mon Sep 17 00:00:00 2001 From: William Almeida Date: Thu, 16 May 2024 08:50:26 -0300 Subject: [PATCH 5/5] Update search.blade.php (#1553) Fixed search input styling. Previously, the styling of the search input was being incorrectly set using 'inputClass', now it has been corrected to use 'inputStyle', as specified correctly in the theme. --- .../components/frameworks/tailwind/header/search.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/frameworks/tailwind/header/search.blade.php b/resources/views/components/frameworks/tailwind/header/search.blade.php index cd9cdfe57..d46da7029 100644 --- a/resources/views/components/frameworks/tailwind/header/search.blade.php +++ b/resources/views/components/frameworks/tailwind/header/search.blade.php @@ -13,7 +13,7 @@ class="{{ data_get($theme, 'searchBox.iconSearchClass') }}" wire:model.live.debounce.700ms="search" type="text" class="{{ data_get($theme, 'searchBox.inputClass') }}" - style="{{ data_get($theme, 'searchBox.inputClass') }}" + style="{{ data_get($theme, 'searchBox.inputStyle') }}" placeholder="{{ trans('livewire-powergrid::datatable.placeholders.search') }}" > @if ($search)