Skip to content

Commit

Permalink
Improve Filters Structure (#1356)
Browse files Browse the repository at this point in the history
* Structure Filters

* wip

* deprecated addColumns - use fields

* Replace addColumns in stubs and tests to fields

* rename add  to

* refactoring filters structure

* refactoring filters structure

* revert tests changes

* revert tests changes

* Fix enumSelect

* Fix enumSelect - bs5

* Remove arc test

* Remove arc test

* Fix outside filters

* Remove laradumps

* Add auto queryString

* Add auto queryString

* Add cypress test to input-text

* Test pest removed - made with cypress

* improve filters - view
  • Loading branch information
luanfreitasdev authored Feb 1, 2024
1 parent 01151f6 commit 86220a7
Show file tree
Hide file tree
Showing 46 changed files with 627 additions and 1,304 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ jobs:
- name: Pint
run: composer test:pint

- name: LaraDumps Check debug
run: composer ds:check
12 changes: 1 addition & 11 deletions .github/workflows/mysql.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
name: MySQL

on:
push:
branches:
- "**"
paths-ignore:
- "art/**"
- "README.md"
pull_request:
types: [ready_for_review, synchronize, opened]
paths-ignore:
- "art/**"
- "README.md"
workflow_dispatch:

jobs:
build:
Expand Down
12 changes: 1 addition & 11 deletions .github/workflows/pgsql.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
name: PostGreSQL

on:
push:
branches:
- "**"
paths-ignore:
- "art/**"
- "README.md"
pull_request:
types: [ready_for_review, synchronize, opened]
paths-ignore:
- "art/**"
- "README.md"
workflow_dispatch:

jobs:
build:
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
],
"require": {
"php": "^8.1",
"livewire/livewire": "^3.3.5",
"livewire/livewire": "^3.4.3",
"laravel/prompts": "^0.1.15"
},
"require-dev": {
"composer/composer": "^2.6.6",
"laravel/pint": "^1.13.8",
"laravel/pint": "^1.13.10",
"laradumps/laradumps-core": "^1.1",
"larastan/larastan": "^2.8.1",
"pestphp/pest": "2.28.0",
Expand Down Expand Up @@ -81,7 +81,11 @@
"@test:mysql",
"@test:pgsql"
],
"ds:check": [
"@php vendor/bin/laradumps check --dir=src,resources,tests --text=dump,dd --ignore=dumpTo,Dump stop-on-failure"
],
"verify": [
"@ds:check",
"@test:pint",
"@test:types",
"@test"
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
},
"homepage": "https://github.com/Power-Components/livewire-powergrid#readme",
"dependencies": {
"alpinejs": "^3.12.2",
"alpinejs": "^3.13.5",
"laravel-mix": "^6.0.49",
"tom-select": "^2.2.2"
"tom-select": "^2.3.1"
},
"devDependencies": {
"autoprefixer": "^10.4.14",
"blade-formatter": "^1.37.1",
"cypress": "^13.3.0",
"autoprefixer": "^10.4.17",
"blade-formatter": "^1.38.6",
"cypress": "^13.6.3",
"flatpickr": "^4.6.13",
"postcss": "^8.4.31",
"postcss": "^8.4.33",
"resolve-url-loader": "^5.0.0",
"sass": "^1.66.1",
"sass-loader": "^13.3.2",
"tailwindcss": "^3.3.1"
"sass": "^1.70.0",
"sass-loader": "^14.0.0",
"tailwindcss": "^3.4.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
'filter' => null,
])
@php
unset($filter['className']);
extract($filter);
$fieldClassName = data_get($filter, 'className');
$field = data_get($filter, 'field');
$title = data_get($column, 'title');
$defaultAttributes = \PowerComponents\LivewirePowerGrid\Components\Filters\FilterBoolean::getWireAttributes($field, $title);
$trueLabel = data_get($filter, 'trueLabel');
$falseLabel = data_get($filter, 'falseLabel');
$defaultAttributes = $fieldClassName::getWireAttributes($field, $title);
$selectClasses = Arr::toCssClasses([data_get($theme, 'selectClass'), data_get($column, 'headerClass'), 'power_grid']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
'type' => 'datetime',
])
@php
unset($filter['className']);
extract($filter);
$params = data_get($filter, 'params');
$field = data_get($filter, 'field');
$title = data_get($column, 'title');
$customConfig = [];
if ($params) {
Expand Down Expand Up @@ -38,11 +39,11 @@ class="{{ data_get($theme, 'baseClass') }}"
>
<form autocomplete="off">
<input
id="input_{{ $column }}"
id="input_{{ $field }}"
x-ref="rangeInput"
wire:model="filters.{{ $type }}.{{ $field }}.formatted"
autocomplete="off"
data-field="{{ $column }}"
data-field="{{ $field }}"
style="{{ data_get($theme, 'inputStyle') }} {{ data_get($column, 'headerStyle') }}"
class="power_grid {{ data_get($theme, 'inputClass') }} {{ data_get($column, 'headerClass') }}"
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
])
<div>
@php
$fieldClassName = data_get($filter, 'className');
$field = strval(data_get($filter, 'field'));
$title = strval(data_get($filter, 'title'));
$title = strval(data_get($column, 'title'));
$operators = (array) data_get($filter, 'operators', []);
$placeholder = strval(data_get($filter, 'placeholder'));
$componentAttributes = (array) data_get($filter, 'attributes', []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
])

@php
extract($filter);
unset($filter['className']);
$fieldClassName = data_get($filter, 'className');
$field = data_get($filter, 'field');
$defaultAttributes = \PowerComponents\LivewirePowerGrid\Components\Filters\FilterNumber::getWireAttributes($field, $filter);
$componentAttributes = (array) data_get($filter, 'attributes');
$defaultAttributes = $fieldClassName::getWireAttributes($field, array_merge($filter, (array)$column));
$filterClasses = Arr::toCssClasses([data_get($theme, 'inputClass'), data_get($column, 'headerClass'), 'power_grid']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
])

@php
$field = strval(data_get($filter, 'field'));
$title = strval(data_get($filter, 'title'));
$field = data_get($filter, 'field');
$title = data_get($column, 'title');
$defaultAttributes = \PowerComponents\LivewirePowerGrid\Components\Filters\FilterSelect::getWireAttributes($field, $title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class="badge rounded-pill bg-secondary">{{ trans('livewire-powergrid::datatable.
</span>
</div>
@endif
@foreach ($enabledFilters as $field => $filter)
@foreach ($enabledFilters as $filter)
@isset($filter['label'])
<div
wire:click.prevent="clearFilter('{{ $field }}')"
wire:click.prevent="clearFilter('{{ $filter['field'] }}')"
style="cursor: pointer; padding-right: 4px"
>
<span class="badge rounded-pill bg-light text-dark">{{ $filter['label'] }}
Expand Down
118 changes: 46 additions & 72 deletions resources/views/components/frameworks/tailwind/filter.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,84 +24,58 @@ class="pg-filter-container"
$customConfig = [];
@endphp
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 2xl:grid-cols-6 gap-3">
@foreach ($filtersFromColumns as $filters)
@foreach ($filters as $filter)
@if (str(data_get($filter, 'className'))->contains('FilterMultiSelect'))
<div class="{{ data_get($filter, 'baseClass') }}">
<x-livewire-powergrid::inputs.select
@foreach ($filtersFromColumns as $column)
@php
$filter = data_get($column, 'filters');
$title = data_get($column, 'title');
$baseClass = data_get($filter, 'baseClass');
$className = str(data_get($filter, 'className'));
@endphp

<div class="{{ $baseClass }}">
@if ($className->contains('FilterMultiSelect'))
<x-livewire-powergrid::inputs.select
:inline="false"
:tableName="$tableName"
:filter="$filter"
:theme="data_get($theme, 'filterMultiSelect')"
:initialValues="data_get(data_get($filters, 'multi_select'), data_get($filter, 'field'), [])"
/>
</div>
@endif
@if (str(data_get($filter, 'className'))->contains('FilterDateTimePicker'))
<div class="{{ data_get($filter, 'baseClass') }}">
@includeIf(data_get($theme, 'filterDatePicker.view'), [
'filter' => $filter,
'tableName' => $tableName,
'classAttr' => 'w-full',
'theme' => data_get($theme, 'filterDatePicker'),
'type' => 'datetime',
])
</div>
@endif
@if (str(data_get($filter, 'className'))->contains('FilterDatePicker'))
<div class="{{ data_get($filter, 'baseClass') }}">
@includeIf(data_get($theme, 'filterDatePicker.view'), [
'filter' => $filter,
'tableName' => $tableName,
'classAttr' => 'w-full',
'theme' => data_get($theme, 'filterDatePicker'),
'type' => 'date',
])
</div>
@endif
@if (str(data_get($filter, 'className'))->contains(['FilterSelect', 'FilterEnumSelect']))
<div class="{{ data_get($filter, 'baseClass') }}">
@includeIf(data_get($theme, 'filterSelect.view'), [
'filter' => $filter,
'theme' => data_get($theme, 'filterSelect'),
])
</div>
@endif
@if (str(data_get($filter, 'className'))->contains('FilterNumber'))
<div class="{{ data_get($filter, 'baseClass') }}">
@includeIf(data_get($theme, 'filterNumber.view'), [
'filter' => $filter,
'theme' => data_get($theme, 'filterNumber'),
])
</div>
@endif
@if (str(data_get($filter, 'className'))->contains('FilterInputText'))
<div class="{{ data_get($filter, 'baseClass') }}">
@includeIf(data_get($theme, 'filterInputText.view'), [
'filter' => $filter,
'theme' => data_get($theme, 'filterInputText'),
])
</div>
@endif
@if (str(data_get($filter, 'className'))->contains('FilterBoolean'))
<div class="{{ data_get($filter, 'baseClass') }}">
@includeIf(data_get($theme, 'filterBoolean.view'), [
'filter' => $filter,
'theme' => data_get($theme, 'filterBoolean'),
])
</div>
@endif
@if (str(data_get($filter, 'className'))->contains('FilterDynamic'))
<div class="{{ data_get($filter, 'baseClass') }}">
<x-dynamic-component
:initialValues="data_get(data_get($filter, 'multi_select'), data_get($filter, 'field'), [])"
/>
@elseif ($className->contains(['FilterDateTimePicker', 'FilterDatePicker']))
@includeIf(data_get($theme, 'filterDatePicker.view'), [
'filter' => $filter,
'tableName' => $tableName,
'classAttr' => 'w-full',
'theme' => data_get($theme, 'filterDatePicker'),
'type' => $className->contains('FilterDateTimePicker') ? 'datetime' : 'date',
])
@elseif ($className->contains(['FilterSelect', 'FilterEnumSelect']))
@includeIf(data_get($theme, 'filterSelect.view'), [
'filter' => $filter,
'theme' => data_get($theme, 'filterSelect'),
])
@elseif ($className->contains('FilterNumber'))
@includeIf(data_get($theme, 'filterNumber.view'), [
'filter' => $filter,
'theme' => data_get($theme, 'filterNumber'),
])
@elseif ($className->contains('FilterInputText'))
@includeIf(data_get($theme, 'filterInputText.view'), [
'filter' => $filter,
'theme' => data_get($theme, 'filterInputText'),
])
@elseif ($className->contains('FilterBoolean'))
@includeIf(data_get($theme, 'filterBoolean.view'), [
'filter' => $filter,
'theme' => data_get($theme, 'filterBoolean'),
])
@elseif ($className->contains('FilterDynamic'))
<x-dynamic-component
:component="data_get($filter, 'component', '')"
:attributes="new \Illuminate\View\ComponentAttributeBag(
data_get($filter, 'attributes', []),
)"
/>
</div>
:attributes="new \Illuminate\View\ComponentAttributeBag(data_get($filter, 'attributes', []))"
/>
@endif
@endforeach
</div>
@endforeach
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
'filter' => null,
])
@php
unset($filter['className']);
extract($filter);
$fieldClassName = data_get($filter, 'className');
$field = data_get($filter, 'field');
$title = data_get($column, 'title');
$defaultAttributes = \PowerComponents\LivewirePowerGrid\Components\Filters\FilterBoolean::getWireAttributes($field, $title);
$trueLabel = data_get($filter, 'trueLabel');
$falseLabel = data_get($filter, 'falseLabel');
$defaultAttributes = $fieldClassName::getWireAttributes($field, $title);
$selectClasses = Arr::toCssClasses([data_get($theme, 'selectClass'), $class, data_get($column, 'headerClass'), 'power_grid']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
'column' => null,
'tableName' => null,
'type' => 'datetime',
'filter' => null,
])
@php
unset($filter['className']);
extract($filter);
$params = data_get($filter, 'params');
$field = data_get($filter, 'field');
$title = data_get($column, 'title');
$customConfig = [];
if ($params) {
Expand Down Expand Up @@ -44,7 +46,7 @@ class="{{ data_get($theme, 'baseClass') }}"
@endif
<form autocomplete="off">
<input
id="input_{{ $column }}"
id="input_{{ $field }}"
x-ref="rangeInput"
wire:model="filters.{{ $type }}.{{ $field }}.formatted"
autocomplete="off"
Expand Down
Loading

0 comments on commit 86220a7

Please sign in to comment.