Skip to content

Commit 6bf01ae

Browse files
committed
fix: restore ITK admin styling and hide the zero-count badge
1 parent 356cbe3 commit 6bf01ae

4 files changed

Lines changed: 43 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
- [#94](https://github.com/itk-dev/devops_itksites/pull/94)
11+
Use EasyAdmin's own components in the admin templates
12+
- Replace hand-rolled badge and icon markup with `<twig:ea:Badge>` and
13+
`<twig:ea:Icon>`, so the admin follows EasyAdmin's theming
14+
- Drop the unused `AutoBadgeMenuItem`/`AutoBadgeCrudMenuItem` pair: EasyAdmin
15+
hides a badge whose content is null
16+
- Set the ITK blue with the theme API instead of overriding EasyAdmin's
17+
colour variables one by one
18+
- Load the admin stylesheet again: it was added as `css/admin.css`, a file
19+
deleted in #81, so every admin page carried a 404 and no ITK styling
1020
- [#93](https://github.com/itk-dev/devops_itksites/pull/93)
1121
Update composer dependencies, clearing 15 security advisories
1222
- `api-platform/core` 4.3.7 → 4.3.17, `easycorp/easyadmin-bundle` 5.0.11 → 5.5.1,

assets/styles/app.css

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1+
/* EasyAdmin overrides. The ITK blue is set with the theme API in
2+
DashboardController; what is left here is what that API cannot express. */
13
:root {
24
--body-max-width: 100%;
35
--sidebar-bg: #fff;
4-
/* make the base font size smaller */
5-
--button-primary-bg: rgb(0, 123, 166);
6-
--pagination-active-bg: rgb(0, 123, 166);
7-
--link-color: rgb(0, 123, 166);
8-
--sidebar-menu-active-item-color: rgb(0, 123, 166);
9-
--badge-boolean-true-bg: rgb(0, 123, 166);
6+
/* ITK red, for a false boolean badge and for danger states */
107
--badge-boolean-false-bg: rgb(228, 73, 48);
118
--badge-boolean-false-color: var(--white);
9+
--bs-danger-rgb: 228, 73, 48;
10+
/* the theme API only takes named gray ramps, not an arbitrary gray */
1211
--sidebar-menu-color: rgb(66, 66, 66);
1312
--text-color-dark: rgb(66, 66, 66);
14-
--bs-danger-rgb: 228, 73, 48;
1513
}
1614

1715
/* Grouped dropdown group styling for index pages */

src/Controller/Admin/DashboardController.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
1111
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
1212
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
13+
use EasyCorp\Bundle\EasyAdminBundle\Config\Theme;
1314
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
1415
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
1516
use Symfony\Component\HttpFoundation\Response;
@@ -39,7 +40,12 @@ public function configureDashboard(): Dashboard
3940
return Dashboard::new()
4041
->setTitle('<img src="/img/itk-sites-logo.png" width="170px" alt="ITK sites logo">')
4142
->setFaviconPath('img/favicon.ico')
42-
->renderContentMaximized();
43+
->renderContentMaximized()
44+
// ITK blue. Since EasyAdmin 5.4 one primary colour drives buttons,
45+
// links, the active sidebar item and boolean badges, and the theme
46+
// computes the text colour that sits on top of it — which the
47+
// stylesheet used to approximate variable by variable.
48+
->setTheme(Theme::new()->primaryColor('#007ba6'));
4349
}
4450

4551
#[\Override]
@@ -56,7 +62,9 @@ public function configureMenuItems(): iterable
5662
yield MenuItem::section('Dependencies');
5763
yield MenuItem::linkTo(PackageCrudController::class, 'Packages', 'fas fa-cube');
5864
yield MenuItem::linkTo(PackageVersionCrudController::class, 'Package Versions', 'fas fa-cubes');
59-
yield MenuItem::linkTo(AdvisoryCrudController::class, 'Advisories', 'fas fa-skull-crossbones')->setBadge($this->advisoryRepository->count([]), 'dark');
65+
// `?: null` because EasyAdmin hides a badge whose content is null but
66+
// renders a literal "0" for a zero count, which is noise on a menu item.
67+
yield MenuItem::linkTo(AdvisoryCrudController::class, 'Advisories', 'fas fa-skull-crossbones')->setBadge($this->advisoryRepository->count([]) ?: null, 'dark');
6068
yield MenuItem::linkTo(ModuleCrudController::class, 'Modules', 'fas fa-cube');
6169
yield MenuItem::linkTo(ModuleVersionCrudController::class, 'Modules Versions', 'fas fa-cubes');
6270
yield MenuItem::linkTo(DockerImageCrudController::class, 'Docker Images', 'fas fa-cube');
@@ -67,6 +75,20 @@ public function configureMenuItems(): iterable
6775
yield MenuItem::linkTo(DetectionResultCrudController::class, 'Detection Results', 'fas fa-upload');
6876
}
6977

78+
/**
79+
* The admin styles reach admin pages only from here.
80+
*
81+
* EasyAdmin renders its own layout rather than templates/base.html.twig, so
82+
* neither `importmap()` nor that template's Encore tags apply to it. Until
83+
* now this method added `css/admin.css`, a file deleted in #81, so every
84+
* admin page carried a 404 and none of the ITK styling below it.
85+
*/
86+
#[\Override]
87+
public function configureAssets(): Assets
88+
{
89+
return Assets::new()->addWebpackEncoreEntry('admin');
90+
}
91+
7092
#[\Override]
7193
public function configureCrud(): Crud
7294
{
@@ -77,10 +99,4 @@ public function configureCrud(): Crud
7799
->setPageTitle('detail', '%entity_label_singular%: %entity_as_string%')
78100
;
79101
}
80-
81-
#[\Override]
82-
public function configureAssets(): Assets
83-
{
84-
return Assets::new()->addCssFile('css/admin.css');
85-
}
86102
}

webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Encore
2222
*/
2323
.addEntry("easyadmin", "./assets/easyadmin.js")
2424

25+
// CSS-only entry, loaded by DashboardController for every admin page. The
26+
// stylesheet is EasyAdmin-specific despite living at styles/app.css.
27+
.addStyleEntry("admin", "./assets/styles/app.css")
28+
2529
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
2630
.splitEntryChunks()
2731

0 commit comments

Comments
 (0)