Skip to content

Commit 2e9ed86

Browse files
authored
Fix data table template when no grid is attached to the index operation (#279)
Before <img width="1683" height="751" alt="image" src="https://github.com/user-attachments/assets/45e8cb55-435f-47c0-8fb8-377c0f2cc016" /> After <img width="1683" height="751" alt="image" src="https://github.com/user-attachments/assets/fe8b6daf-7d13-4234-86c0-3ed93fd6597b" />
2 parents 5bfedae + e62a34b commit 2e9ed86

5 files changed

Lines changed: 30 additions & 4 deletions

File tree

app/Entity/Book.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
new Create(),
3737
new Update(),
3838
new Index(grid: BookGrid::class),
39+
new Index(
40+
template: '@SyliusAdminUi/crud/index.html.twig',
41+
shortName: 'withoutGrid',
42+
),
3943
new Delete(),
4044
new BulkDelete(),
4145
new Show(),

src/BootstrapAdminUi/templates/shared/crud/index/content/grid/data_table.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
{% import '@SyliusBootstrapAdminUi/shared/helper/pagination.html.twig' as pagination %}
33

44
{% set resources = hookable_metadata.context.resources %}
5-
{% set data = resources.data %}
6-
{% set definition = resources.definition %}
5+
{% set data = resources.data|default([]) %}
6+
{% set definition = resources.definition|default(null) %}
77

88
{% if data|length > 0 %}
99
<div class="card">

src/BootstrapAdminUi/templates/shared/crud/index/content/grid/filters.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{% set path = path(app.request.attributes.get('_route'), app.request.attributes.all('_route_params')) %}
77
{% set are_criteria_set = app.request.query.has('criteria') %}
88

9-
{% if resources.definition.enabledFilters is not empty %}
9+
{% if resources.definition.enabledFilters|default([]) is not empty %}
1010
<div class="position-relative z-1 bg-white mb-5">
1111
{% set content %}
1212
<div class="mb-3">

src/BootstrapAdminUi/templates/shared/crud/index/content/grid/no_results.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% set resources = hookable_metadata.context.resources %}
22

3-
{% if resources.data|length == 0 %}
3+
{% if resources.data is defined and resources.data|length == 0 %}
44
<div class="card">
55
<div class="empty">
66
{% hook 'no_results' %}

tests/Functional/BookTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,28 @@ public function testBrowsingBooks(): void
9898
self::assertSelectorExists('tr.item:last-child [data-bs-title=Delete]');
9999
}
100100

101+
public function testBrowsingBooksWithoutGrid(): void
102+
{
103+
BookFactory::new()
104+
->withTitle('The Shining')
105+
->withAuthorName('Stephen King')
106+
->create()
107+
;
108+
109+
BookFactory::new()
110+
->withTitle('Carrie')
111+
->withAuthorName('Stephen King')
112+
->create()
113+
;
114+
115+
$this->client->request('GET', '/admin/books/withoutGrid');
116+
117+
self::assertResponseIsSuccessful();
118+
119+
// Validate Header
120+
self::assertSelectorTextContains('[data-test-page-title]', 'Books');
121+
}
122+
101123
public function testSortingBooks(): void
102124
{
103125
BookFactory::new()

0 commit comments

Comments
 (0)