mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-27 22:54:05 +08:00
Fixed tags listing grouping by name only on search
Included test to cover case
This commit is contained in:
parent
056d7c119f
commit
555723a966
@ -23,7 +23,6 @@ class TagRepo
|
|||||||
*/
|
*/
|
||||||
public function queryWithTotals(string $searchTerm, string $nameFilter): Builder
|
public function queryWithTotals(string $searchTerm, string $nameFilter): Builder
|
||||||
{
|
{
|
||||||
$groupingAttribute = $nameFilter ? 'value' : 'name';
|
|
||||||
$query = Tag::query()
|
$query = Tag::query()
|
||||||
->select([
|
->select([
|
||||||
'name',
|
'name',
|
||||||
@ -34,11 +33,15 @@ class TagRepo
|
|||||||
DB::raw('SUM(IF(entity_type = \'BookStack\\\\Book\', 1, 0)) as book_count'),
|
DB::raw('SUM(IF(entity_type = \'BookStack\\\\Book\', 1, 0)) as book_count'),
|
||||||
DB::raw('SUM(IF(entity_type = \'BookStack\\\\BookShelf\', 1, 0)) as shelf_count'),
|
DB::raw('SUM(IF(entity_type = \'BookStack\\\\BookShelf\', 1, 0)) as shelf_count'),
|
||||||
])
|
])
|
||||||
->groupBy($groupingAttribute)
|
->orderBy($nameFilter ? 'value' : 'name');
|
||||||
->orderBy($groupingAttribute);
|
|
||||||
|
|
||||||
if ($nameFilter) {
|
if ($nameFilter) {
|
||||||
$query->where('name', '=', $nameFilter);
|
$query->where('name', '=', $nameFilter);
|
||||||
|
$query->groupBy('value');
|
||||||
|
} else if ($searchTerm) {
|
||||||
|
$query->groupBy('name', 'value');
|
||||||
|
} else {
|
||||||
|
$query->groupBy('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($searchTerm) {
|
if ($searchTerm) {
|
||||||
|
@ -145,6 +145,18 @@ class TagTest extends TestCase
|
|||||||
$resp->assertElementNotExists('.tag-item .tag-name');
|
$resp->assertElementNotExists('.tag-item .tag-name');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_tag_index_search_will_show_mulitple_values_of_a_single_tag_name()
|
||||||
|
{
|
||||||
|
/** @var Page $page */
|
||||||
|
$page = Page::query()->first();
|
||||||
|
$page->tags()->create(['name' => 'Animal', 'value' => 'Catfish']);
|
||||||
|
$page->tags()->create(['name' => 'Animal', 'value' => 'Catdog']);
|
||||||
|
|
||||||
|
$resp = $this->asEditor()->get('/tags?search=cat');
|
||||||
|
$resp->assertElementContains('.tag-item .tag-value', 'Catfish');
|
||||||
|
$resp->assertElementContains('.tag-item .tag-value', 'Catdog');
|
||||||
|
}
|
||||||
|
|
||||||
public function test_tag_index_can_be_scoped_to_specific_tag_name()
|
public function test_tag_index_can_be_scoped_to_specific_tag_name()
|
||||||
{
|
{
|
||||||
/** @var Page $page */
|
/** @var Page $page */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user