Skip to content

Commit b723403

Browse files
author
antoine
committed
Drop SelectFilter template
1 parent 2018f4e commit b723403

File tree

7 files changed

+5
-98
lines changed

7 files changed

+5
-98
lines changed

docs/guide/filters.md

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -209,50 +209,6 @@ public function buildFilterConfig(): void
209209
}
210210
```
211211

212-
## Filter template
213-
214-
Sometimes you need your select filter results to be a little more than a label. For this, configure a template (similar to form fields with templates):
215-
216-
```php
217-
public function buildFilterConfig(): void
218-
{
219-
$this->configureTemplate('<div>{{label}}</div><div><small>{{detail}}</small></div>');
220-
}
221-
```
222-
223-
You can also, for more control, return a view here.
224-
225-
The template will be [interpreted by Vue.js](https://vuejs.org/v2/guide/syntax.html), meaning you can add data placeholders, DOM structure but also directives, and anything that Vue will parse. It's the same as [Autocomplete's templates](form-fields/autocomplete.md).
226-
227-
You'll need also to change your `values()` function, returning more than an `[{id}=>{value}]` array. For instance:
228-
229-
```php
230-
public function values()
231-
{
232-
return ProductCategory::orderBy('label')
233-
->get()
234-
->map(function ($category) {
235-
return [
236-
'id' => $category->id,
237-
'label' => $category->label,
238-
'detail' => $category->detail_text
239-
];
240-
});
241-
}
242-
```
243-
244-
Note that **the label attribute is mandatory**: it is used for the result display of the filter.
245-
246-
Finally, if your filter is also searchable, you'll need to configure attributes which should be searched in the template:
247-
248-
```php
249-
public function buildFilterConfig(): void
250-
{
251-
$this->configureSearchable()
252-
->configureSearchKeys(['label', 'detail']);
253-
}
254-
```
255-
256212
## Check filter
257213

258214
In case of a filter that is just a matter on true / false ("only show admins" for example), just make your filter class extend `Code16\Sharp\EntityList\Filters\EntityListCheckFilter`.

docs/guide/upgrading/9.0.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ $instance: // the **Customer** instance
234234
$attribute: 'name'
235235
```
236236

237-
238-
239237
### Thumbnails custom filters must be refactored to Modifiers
240238

241239
First, if you defined custom filters classes for your thumbnails, you must refactor it to the new ThumbnailModifier API, which is very close:
@@ -472,6 +470,10 @@ class PostBlockList extends SharpEntityList
472470

473471
You can of course instead declare a real Filter.
474472

473+
### Select filter `configureTemplate()` has been dropped
474+
475+
If you were using this method, you must do the string transformation in the label of each value.
476+
475477
### New performance optimization for Commands and Policies in Entity List (n+1)
476478

477479
This is not a breaking change, in fact you can ignore this step entirely, but since it's can lead to a significative performance boost, this is worth mentioning: you can now quite easily implement a [caching mechanism of instances for your Commands and Policies in Entity List](../avoid-n1-queries-in-entity-lists.md).

src/Data/Filters/SelectFilterData.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ public function __construct(
2222
// public mixed $default,
2323
public bool $multiple,
2424
public bool $required,
25-
#[LiteralTypeScriptType('Array<{ id:string|number } & { [key: string]: any }>')]
25+
#[LiteralTypeScriptType('Array<{ id: string|number } & { [key: string]: any }>')]
2626
public array $values,
2727
public bool $master,
2828
public bool $searchable,
2929
/** string[] */
3030
public array $searchKeys,
31-
public string $template,
3231
) {}
3332

3433
public static function from(array $filter): self

src/Utils/Filters/Concerns/BuildsFiltersConfigArray.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function getFiltersConfigArray(): ?array
3737
'master' => $filterHandler->isMaster(),
3838
'searchable' => $filterHandler->isSearchable(),
3939
'searchKeys' => $filterHandler->getSearchKeys(),
40-
'template' => $filterHandler->getTemplate(),
4140
];
4241
} elseif ($filterHandler instanceof DateRangeFilter) {
4342
$filterConfigData += [

src/Utils/Filters/SelectFilter.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ abstract class SelectFilter extends Filter
77
private bool $isMaster = false;
88
private bool $isSearchable = false;
99
private array $searchKeys = ['label'];
10-
private string $template = '{{label}}';
1110

1211
final public function isMaster(): bool
1312
{
@@ -24,11 +23,6 @@ final public function getSearchKeys(): array
2423
return $this->searchKeys;
2524
}
2625

27-
final public function getTemplate(): string
28-
{
29-
return $this->template;
30-
}
31-
3226
final public function configureSearchable(bool $isSearchable = true): self
3327
{
3428
$this->isSearchable = $isSearchable;
@@ -43,13 +37,6 @@ final public function configureSearchKeys(array $searchKeys): self
4337
return $this;
4438
}
4539

46-
final public function configureTemplate(string $template): self
47-
{
48-
$this->template = $template;
49-
50-
return $this;
51-
}
52-
5340
final public function configureMaster(bool $isMaster = true): self
5441
{
5542
$this->isMaster = $isMaster;

tests/Unit/Dashboard/DashboardFilterTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public function values(): array
4444
'master' => false,
4545
'searchable' => false,
4646
'searchKeys' => ['label'],
47-
'template' => '{{label}}',
4847
],
4948
],
5049
]);

tests/Unit/EntityList/SharpEntityListFilterTest.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public function values(): array
5050
'master' => false,
5151
'searchable' => false,
5252
'searchKeys' => ['label'],
53-
'template' => '{{label}}',
5453
],
5554
],
5655
]);
@@ -291,40 +290,6 @@ public function values(): array
291290
expect($list->listConfig()['filters']['_root'][0]['searchKeys'])->toEqual(['a', 'b']);
292291
});
293292

294-
it('allows to define an inline template for a filter', function () {
295-
$list = new class() extends FakeSharpEntityList
296-
{
297-
public function getFilters(): array
298-
{
299-
return [
300-
new class() extends EntityListSelectFilter
301-
{
302-
public function buildFilterConfig(): void
303-
{
304-
$this->configureTemplate('{{letter}} {{maj}}');
305-
}
306-
307-
public function values(): array
308-
{
309-
return [
310-
['id' => 1, 'letter' => 'a', 'maj' => 'A'],
311-
['id' => 2, 'letter' => 'b', 'maj' => 'B'],
312-
];
313-
}
314-
},
315-
];
316-
}
317-
};
318-
319-
$list->buildListConfig();
320-
321-
expect($list->listConfig()['filters']['_root'][0]['template'])->toEqual('{{letter}} {{maj}}')
322-
->and($list->listConfig()['filters']['_root'][0]['values'])->toEqual([
323-
['id' => 1, 'letter' => 'a', 'maj' => 'A'],
324-
['id' => 2, 'letter' => 'b', 'maj' => 'B'],
325-
]);
326-
});
327-
328293
it('allows to declare a filter as retained and to set its default value', function () {
329294
$list = new class() extends FakeSharpEntityList
330295
{

0 commit comments

Comments
 (0)