Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Commit d53b324

Browse files
committed
WIP
1 parent be6df28 commit d53b324

File tree

5 files changed

+50
-47
lines changed

5 files changed

+50
-47
lines changed

js/Table.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
name="tableFilter"
66
:has-filters="queryBuilderProps.hasFilters"
77
:has-enabled-filters="queryBuilderProps.hasEnabledFilters"
8-
:select-filters="queryBuilderProps.selectFilters"
9-
:on-select-filter-change="changeSelectFilterValue"
8+
:filters="queryBuilderProps.filters"
9+
:on-filter-change="changeFilterValue"
1010
>
1111
<TableFilter
1212
v-if="queryBuilderProps.hasFilters"
1313
:has-enabled-filters="queryBuilderProps.hasEnabledFilters"
14-
:select-filters="queryBuilderProps.selectFilters"
15-
:on-select-filter-change="changeSelectFilterValue"
14+
:filters="queryBuilderProps.filters"
15+
:on-filter-change="changeFilterValue"
1616
/>
1717
</slot>
1818

@@ -307,10 +307,10 @@ function changeGlobalSearchValue(value) {
307307
changeSearchInputValue("global", value);
308308
}
309309
310-
function changeSelectFilterValue(key, value) {
311-
const intKey = findDataKey("selectFilters", key);
310+
function changeFilterValue(key, value) {
311+
const intKey = findDataKey("filters", key);
312312
313-
queryBuilderData.value.selectFilters[intKey].value = value;
313+
queryBuilderData.value.filters[intKey].value = value;
314314
queryBuilderData.value.page = 1;
315315
}
316316
@@ -335,9 +335,9 @@ function getFilterForQuery() {
335335
}
336336
});
337337
338-
forEach(queryBuilderData.value.selectFilters, (selectFilters) => {
339-
if (selectFilters.value !== null) {
340-
filtersWithValue[selectFilters.key] = selectFilters.value;
338+
forEach(queryBuilderData.value.filters, (filters) => {
339+
if (filters.value !== null) {
340+
filtersWithValue[filters.key] = filters.value;
341341
}
342342
});
343343

js/TableFilter.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@
2929
class="min-w-max"
3030
>
3131
<div
32-
v-for="selectFilter in selectFilters"
33-
:key="selectFilter.key"
32+
v-for="filter in filters"
33+
:key="filter.key"
3434
>
3535
<h3 class="text-xs uppercase tracking-wide bg-gray-100 p-3">
36-
{{ selectFilter.label }}
36+
{{ filter.label }}
3737
</h3>
3838
<div class="p-2">
3939
<select
40-
:value="selectFilter.value"
40+
v-if="filter.type === 'select'"
41+
:value="filter.value"
4142
class="
4243
block
4344
focus:ring-indigo-500 focus:border-indigo-500
@@ -47,10 +48,10 @@
4748
border-gray-300
4849
rounded-md
4950
"
50-
@change="onSelectFilterChange(selectFilter.key, $event.target.value)"
51+
@change="onFilterChange(filter.key, $event.target.value)"
5152
>
5253
<option
53-
v-for="(option, key) in selectFilter.options"
54+
v-for="(option, key) in filter.options"
5455
:key="key"
5556
:value="key"
5657
>
@@ -72,12 +73,12 @@ defineProps({
7273
required: true,
7374
},
7475
75-
selectFilters: {
76+
filters: {
7677
type: Object,
7778
required: true,
7879
},
7980
80-
onSelectFilterChange: {
81+
onFilterChange: {
8182
type: Function,
8283
required: true,
8384
},

php/Column.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ public function __construct(
1111
public string $label,
1212
public bool $canBeHidden,
1313
public bool $hidden,
14-
public bool $sortable,
15-
public bool $custom
14+
public bool $sortable
1615
) {
1716
}
1817

@@ -24,7 +23,6 @@ public function toArray()
2423
'can_be_hidden' => $this->canBeHidden,
2524
'hidden' => $this->hidden,
2625
'sortable' => $this->sortable,
27-
'custom' => $this->custom,
2826
];
2927
}
3028
}

php/SelectFilter.php renamed to php/Filter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
use Illuminate\Contracts\Support\Arrayable;
66
use Illuminate\Support\Arr;
77

8-
class SelectFilter implements Arrayable
8+
class Filter implements Arrayable
99
{
1010
public function __construct(
1111
public string $key,
1212
public string $label,
1313
public array $options,
1414
public ?string $value = null,
1515
public bool $noFilterOption,
16-
public string $noFilterOptionLabel
16+
public string $noFilterOptionLabel,
17+
public string $type
1718
) {
1819
}
1920

@@ -30,6 +31,7 @@ public function toArray()
3031
'label' => $this->label,
3132
'options' => $options,
3233
'value' => $this->value,
34+
'type' => $this->type,
3335
];
3436
}
3537
}

php/InertiaTable.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class InertiaTable
1414
private Request $request;
1515
private Collection $columns;
1616
private Collection $searchInputs;
17-
private Collection $selectFilters;
17+
private Collection $filters;
1818

1919
public function __construct(Request $request)
2020
{
21-
$this->request = $request;
22-
$this->columns = new Collection;
23-
$this->searchInputs = new Collection;
24-
$this->selectFilters = new Collection;
21+
$this->request = $request;
22+
$this->columns = new Collection;
23+
$this->searchInputs = new Collection;
24+
$this->filters = new Collection;
2525
}
2626

2727
/**
@@ -51,9 +51,9 @@ protected function getQueryBuilderProps(): array
5151
'hasHiddenColumns' => $this->columns->filter->hidden->isNotEmpty(),
5252
'hasToggleableColumns' => $this->columns->filter->canBeHidden->isNotEmpty(),
5353

54-
'selectFilters' => $this->transformSelectFilters(),
55-
'hasFilters' => $this->selectFilters->isNotEmpty(),
56-
'hasEnabledFilters' => $this->selectFilters->filter->value->isNotEmpty(),
54+
'filters' => $this->transformFilters(),
55+
'hasFilters' => $this->filters->isNotEmpty(),
56+
'hasEnabledFilters' => $this->filters->filter->value->isNotEmpty(),
5757

5858
'searchInputs' => $searchInputs = $this->transformSearchInputs(),
5959
'searchInputsWithoutGlobal' => $searchInputsWithoutGlobal = $searchInputs->where('key', '!=', 'global'),
@@ -93,22 +93,22 @@ protected function transformColumns(): Collection
9393
*
9494
* @return \Illuminate\Support\Collection
9595
*/
96-
protected function transformSelectFilters(): Collection
96+
protected function transformFilters(): Collection
9797
{
98-
$selectFilters = $this->selectFilters;
98+
$filters = $this->filters;
9999

100-
$filters = $this->request->query('filter', []);
100+
$queryFilters = $this->request->query('filter', []);
101101

102-
if (empty($filters)) {
103-
return $selectFilters;
102+
if (empty($queryFilters)) {
103+
return $filters;
104104
}
105105

106-
return $selectFilters->map(function (SelectFilter $selectFilter) use ($filters) {
107-
if (array_key_exists($selectFilter->key, $filters)) {
108-
$selectFilter->value = $filters[$selectFilter->key];
106+
return $filters->map(function (Filter $filter) use ($queryFilters) {
107+
if (array_key_exists($filter->key, $queryFilters)) {
108+
$filter->value = $queryFilters[$filter->key];
109109
}
110110

111-
return $selectFilter;
111+
return $filter;
112112
});
113113
}
114114

@@ -146,8 +146,7 @@ public function column(string $key = null, string $label = null, bool $canBeHidd
146146
label: $label ?: Str::headline($key),
147147
canBeHidden: $canBeHidden,
148148
hidden: $hidden,
149-
sortable: $sortable,
150-
custom: $custom,
149+
sortable: $sortable
151150
));
152151

153152
if ($searchable) {
@@ -161,12 +160,13 @@ public function withGlobalSearch(string $label = null): self
161160
{
162161
return $this->searchInput('global', $label ?: __('Search...'));
163162
}
164-
165-
public function searchInput(string $key, string $label = null): self
163+
,
164+
public function searchInput(string $key, string $label = null, string $defaultValue = null): self
166165
{
167166
$this->searchInputs->push(new SearchInput(
168167
key: $key,
169168
label: $label ?: Str::headline($key),
169+
value: $defaultValue
170170
));
171171

172172
return $this;
@@ -180,14 +180,16 @@ public function searchInput(string $key, string $label = null): self
180180
* @param array $options
181181
* @return self
182182
*/
183-
public function selectFilter(string $key, string $label = null, array $options, bool $noFilterOption = true, string $noFilterOptionLabel = null): self
183+
public function selectFilter(string $key, string $label = null, array $options, string $defaultValue = null, bool $noFilterOption = true, string $noFilterOptionLabel = null): self
184184
{
185-
$this->selectFilters->push(new SelectFilter(
185+
$this->filters->push(new Filter(
186186
key: $key,
187187
label: $label ?: Str::headline($key),
188188
options: $options,
189+
value: $defaultValue,
189190
noFilterOption: $noFilterOption,
190-
noFilterOptionLabel: $noFilterOptionLabel ?: '-'
191+
noFilterOptionLabel: $noFilterOptionLabel ?: '-',
192+
type: 'select'
191193
));
192194

193195
return $this;

0 commit comments

Comments
 (0)