Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `web_ui.header_actions` (`buttons` | `page_actions`, default `buttons`): with `page_actions` the header actions of the paths and redirects lists (New, Export, Clear routing cache, Import) are UiKit `View\Action` items of the square page-actions menu (the page header uses UiKit's split layout and no action stays a filled primary button), instead of a row of header buttons. The actions keep their kind, target, POST + CSRF form and dialog opener, and `PageHeader::$actions` is the same list a host compact header reads for its own page-actions menu. Needs UiKit 2.21+ (an older UiKit keeps the buttons). Nothing changes with the default. `Nowo\RoutingKitBundle\Panel\HeaderActionsPlacement`, `PanelView::listHeader()`.

### Changed

- Demo: runs in UiKit's demo platform shell (`nowo-tech/ui-kit-bundle` ^2.60); the demo's own header is gone and the pages use the shell page headers and section cards. Demo only, no bundle change.
Expand Down
1 change: 1 addition & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Root key: `nowo_routing_kit`.
| `web_ui.import_display` | `modal` | Signed JSON import: `modal` (UiKit `dialog` `#modal-routing-import`, opened from the "Import" page action; needs `js/nowo-ui-dialog.js`, loaded by the UiKit document layout; default since 1.9.1) or `inline` (card under the paths table) |
| `web_ui.show_row_count` | `false` | "N row(s)" caption of the tables (default `false` since 1.9.1: the pagination summary already shows the count) |
| `web_ui.primary_action_last` | `false` | Render "New path" after Export / Clear cache / Import |
| `web_ui.header_actions` | `buttons` | `buttons`: one button per header action. `page_actions`: the header actions (New, Export, Clear cache, Import; New redirect) are items of UiKit's page-actions menu (split header, no filled primary button); a host compact header reads the same `PageHeader::$actions`. UiKit 2.21+ |
| `security.access_roles` | `[ROLE_ADMIN]` | At least one role required; **empty** = fail-closed (every panel request is denied). Still firewall the prefix |
| `security.access_checker` | `null` | Custom `RoutingKitAccessCheckerInterface` service id (`null` = Configurable by roles) |
| `security.allow_unauthenticated` | `false` | DEV/DEMO only — skip in-bundle role check (AllowAll) and show the **UNSAFE** banner on every panel page; panel requires SecurityBundle when `false` |
Expand Down
4 changes: 3 additions & 1 deletion docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ UiKit and the panel inherits it — no RoutingKit-specific chrome configuration
3. **Scaffolds** — `templates/bundles/NowoUiKitBundle/page/list.html.twig` (or `form`, `confirm`) re-skins every list /
form / confirm page of every bundle.
4. **Options** — `web_ui.import_display: inline` (card instead of the default dialog), `web_ui.show_row_count: true`,
`web_ui.primary_action_last: true`. Row actions follow `nowo_ui_kit.row_actions_display` / `icon_set`.
`web_ui.primary_action_last: true`, `web_ui.header_actions: page_actions` (New / Export / Clear cache / Import as
UiKit `View\Action` items of the page-actions menu instead of header buttons; default `buttons`).
Row actions follow `nowo_ui_kit.row_actions_display` / `icon_set`.
5. **One page** — `web_ui.templates.<page>` with a template that extends `@!NowoRoutingKitBundle/…` and redefines a
data block ([TEMPLATES.md](TEMPLATES.md)).

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/RoutingPanelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function index(Request $request): Response
$actions = $this->view->primaryActionLast ? [...$actions, $create] : [$create, ...$actions];

$listPage = new ListPage(
new PageHeader(PanelView::label('panel.title'), PanelView::label('panel.subtitle', ['%default%' => $this->locales->getDefaultLocale()]), $actions, tabs: $this->view->nav('routes')),
$this->view->listHeader(PanelView::label('panel.title'), PanelView::label('panel.subtitle', ['%default%' => $this->locales->getDefaultLocale()]), $actions, $this->view->nav('routes')),
[
new Column('routeName', PanelView::label('panel.col.route'), required: true),
new Column('locale', PanelView::label('panel.col.locale')),
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/UrlRedirectPanelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public function index(Request $request): Response

return $this->view->render('redirects_index', 'redirects', [
'page' => new ListPage(
new PageHeader(PanelView::label('redirects.title'), PanelView::label('redirects.intro'), [
$this->view->listHeader(PanelView::label('redirects.title'), PanelView::label('redirects.intro'), [
new Action('create', PanelView::label('redirects.new'), $prefix . '/redirects/new', variant: 'primary', attributes: ['data-testid' => 'redirect-new']),
], tabs: $this->view->nav('redirects')),
], $this->view->nav('redirects')),
[
new Column('sourcePath', PanelView::label('redirects.col.source'), required: true),
new Column('targetUrl', PanelView::label('redirects.col.target'), required: true),
Expand Down
6 changes: 6 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Nowo\RoutingKitBundle\DependencyInjection;

use InvalidArgumentException;
use Nowo\RoutingKitBundle\Panel\HeaderActionsPlacement;
use Nowo\RoutingKitBundle\Panel\PanelChrome;
use Nowo\RoutingKitBundle\Panel\PanelView;
use Nowo\RoutingKitBundle\Redirect\ProtectedPaths;
Expand Down Expand Up @@ -279,6 +280,11 @@ public function getConfigTreeBuilder(): TreeBuilder
->info('Render the primary "New" action after the secondary page actions.')
->defaultFalse()
->end()
->enumNode('header_actions')
->info('Where the header actions (New, Export, Clear cache, Import) go: "buttons" (default) = one button per action in the page header; "page_actions" = UiKit View\\Action items in the square page-actions menu (UiKit split header; the compact header of the host reads the same PageHeader actions). Needs UiKit 2.21+.')
->values(HeaderActionsPlacement::MODES)
->defaultValue(HeaderActionsPlacement::BUTTONS)
->end()
->booleanNode('main_landmark')
->info('Deprecated, no effect: the layout (UiKit or host) owns the <main> landmark.')
->setDeprecated(self::DEPRECATION_PACKAGE, self::DEPRECATION_VERSION, 'The "%path%.%node%" option is deprecated and has no effect: the layout owns the <main> landmark.')
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/RoutingKitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ private function configurePanel(ContainerBuilder $container, array $config): voi
->setArgument('$showRowCount', (bool) $webUi['show_row_count'])
->setArgument('$primaryActionLast', (bool) $webUi['primary_action_last'])
->setArgument('$urlRedirectsEnabled', (bool) $config['url_redirects']['enabled'])
->setArgument('$headerActions', (string) $webUi['header_actions'])
// Shows panel.role_gate_warning: the in-bundle role check is skipped (AllowAll checker).
->setArgument('$roleGateDisabled', (bool) $config['security']['allow_unauthenticated']);

Expand Down
89 changes: 89 additions & 0 deletions src/Panel/HeaderActionsPlacement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace Nowo\RoutingKitBundle\Panel;

use Nowo\UiKitBundle\View\Action;
use Nowo\UiKitBundle\View\PageHeader;

use function property_exists;

/**
* Where the header actions of a panel page (New, Export, Import, Clear cache) are placed ({@code web_ui.header_actions}).
*
* {@see self::BUTTONS} (default): a button per action in the page header, as in every earlier release.
* {@see self::PAGE_ACTIONS}: the page header uses UiKit's split layout and no action stays a filled primary button, so
* every action lands in the square page-actions menu (the same {@code View\Action} objects: kind, target, POST form,
* dialog opener and attributes are kept). A host that renders the compact header ({@code nowo_ui_kit.header}) reads the
* same {@code PageHeader::$actions} for its own page-actions menu. Needs UiKit 2.21+ (split layout); an older UiKit
* keeps the buttons.
*
* Stateless: nothing is memoised (worker safe).
*/
final class HeaderActionsPlacement
{
public const BUTTONS = 'buttons';

public const PAGE_ACTIONS = 'page_actions';

public const MODES = [self::BUTTONS, self::PAGE_ACTIONS];

/**
* The header as is ({@see self::BUTTONS}) or, for {@see self::PAGE_ACTIONS}, a copy with UiKit's split layout and
* its actions demoted ({@see self::menuActions()}).
*/
public static function apply(string $mode, PageHeader $header): PageHeader
{
if ($mode !== self::PAGE_ACTIONS || $header->actions === [] || !property_exists(PageHeader::class, 'actionsLayout')) {
return $header;
}

return new PageHeader($header->title, $header->intro, self::menuActions($header->actions), $header->breadcrumbs, $header->breadcrumbCollection, $header->tabs, $header->breadcrumbsMode, $header->back, $header->status, 'split');
}

/**
* The same actions with the filled variant removed from the create / save ones, so none of them is the header's
* primary button; destructive actions keep their variant (UiKit puts them last, in red).
*
* @param list<Action> $actions
*
* @return list<Action>
*/
public static function menuActions(array $actions): array
{
$menu = [];
foreach ($actions as $action) {
$menu[] = $action->resolvedVariant() === 'primary' ? self::withVariant($action, 'secondary') : $action;
}

return $menu;
}

private static function withVariant(Action $action, string $variant): Action
{
return new Action(
kind: $action->kind,
label: $action->label,
href: $action->href,
route: $action->route,
params: $action->params,
method: $action->method,
csrfToken: $action->csrfToken,
confirm: $action->confirm,
icon: $action->icon,
variant: $variant,
attributes: $action->attributes,
form: $action->form,
csrfField: $action->csrfField,
modalId: $action->modalId,
disabled: $action->disabled,
visible: $action->visible,
display: $action->display,
confirmScope: $action->confirmScope,
fallbackHref: $action->fallbackHref,
dialogId: $action->dialogId,
title: $action->title,
);
}
}
13 changes: 13 additions & 0 deletions src/Panel/PanelView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Nowo\UiKitBundle\View\AreaNav;
use Nowo\UiKitBundle\View\AreaNavItem;
use Nowo\UiKitBundle\View\Label;
use Nowo\UiKitBundle\View\PageHeader;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

Expand Down Expand Up @@ -78,6 +79,7 @@ public function __construct(
public bool $primaryActionLast = false,
public bool $urlRedirectsEnabled = false,
public bool $roleGateDisabled = false,
public string $headerActions = HeaderActionsPlacement::BUTTONS,
) {
}

Expand All @@ -104,6 +106,17 @@ public static function importDialogAction(): Action
]);
}

/**
* Page header of the list pages: the header actions as buttons or, with {@code web_ui.header_actions: page_actions},
* in the page-actions menu ({@see HeaderActionsPlacement}).
*
* @param list<Action> $actions
*/
public function listHeader(Label $title, Label $intro, array $actions, ?AreaNav $tabs): PageHeader
{
return HeaderActionsPlacement::apply($this->headerActions, new PageHeader($title, $intro, $actions, tabs: $tabs));
}

public function template(string $page): string
{
if (!array_key_exists($page, self::TEMPLATES)) {
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/packages/nowo_routing_kit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ nowo_routing_kit:
import_display: modal # modal (dialog from the Import action) | inline (card under the table)
show_row_count: false # the pagination summary already shows the count
primary_action_last: false
header_actions: buttons # buttons | page_actions (UiKit View\Action items in the page-actions menu, UiKit 2.21+)
security:
access_roles: [ROLE_ADMIN]
allow_unauthenticated: false
Expand Down
45 changes: 45 additions & 0 deletions tests/Integration/Contract/PageContractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Nowo\UiKitBundle\Test\PageContractTestCase;
use Nowo\UiKitBundle\Test\PageFixture;
use Nowo\UiKitBundle\View\ConfirmPage;
use Nowo\UiKitBundle\View\PageHeader;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Component\Translation\DataCollectorTranslator;
Expand Down Expand Up @@ -38,6 +39,8 @@ public static function pageFixtures(): iterable
yield 'path form (edit)' => new PageFixture('@NowoRoutingKitBundle/panel/form.html.twig', PanelPageFixtures::form($definitions[2]));
yield 'path form (create, controller override)' => new PageFixture('@NowoRoutingKitBundle/panel/form.html.twig', PanelPageFixtures::form(null, controllerOverride: true));
yield 'path delete (no-JS confirm)' => new PageFixture('@NowoRoutingKitBundle/panel/delete.html.twig', PanelPageFixtures::delete($definitions[2]));
yield 'paths list (header actions in the page-actions menu)' => new PageFixture('@NowoRoutingKitBundle/panel/index.html.twig', PanelPageFixtures::index($definitions, headerActions: 'page_actions'));
yield 'redirects list (header actions in the page-actions menu)' => new PageFixture('@NowoRoutingKitBundle/panel/redirects/index.html.twig', PanelPageFixtures::redirectsIndex($redirects, headerActions: 'page_actions'));
yield 'redirects list' => new PageFixture('@NowoRoutingKitBundle/panel/redirects/index.html.twig', PanelPageFixtures::redirectsIndex($redirects, 'created'));
yield 'redirects list (row count)' => new PageFixture('@NowoRoutingKitBundle/panel/redirects/index.html.twig', PanelPageFixtures::redirectsIndex($redirects, rowCount: true));
yield 'redirects list (empty)' => new PageFixture('@NowoRoutingKitBundle/panel/redirects/index.html.twig', PanelPageFixtures::redirectsIndex([]));
Expand Down Expand Up @@ -110,6 +113,48 @@ public function testListRowsRenderTheBundleCellsAndTheConfirmDialogs(): void
self::assertStringNotContainsString('routing-kit-role-gate-warning', $html);
}

public function testHeaderActionsGoToThePageActionsMenuOnRequest(): void
{
$header = PanelPageFixtures::index(PanelPageFixtures::definitions(), headerActions: 'page_actions')['page']->header;
self::assertSame('split', $header->actionsLayout);
$html = $this->headerHtml($header);

self::assertStringContainsString('data-nowo-ui-header-more', $html, 'The square page-actions menu replaces the buttons.');
self::assertStringContainsString('href="/_routing/new"', $html, 'New path is a menu item.');
self::assertStringContainsString('action="/_routing/export"', $html, 'Export keeps its POST form.');
self::assertStringContainsString('action="/_routing/clear-cache"', $html);
self::assertStringContainsString('data-testid="routing-kit-import-open"', $html, 'Import keeps its dialog opener.');
self::assertStringNotContainsString('nowo-ui-btn--primary', substr($html, 0, (int) strpos($html, 'data-nowo-ui-header-more')), 'No filled primary button in the header.');
}

public function testHeaderActionsStayButtonsInTheKitHeaderByDefault(): void
{
$header = PanelPageFixtures::index(PanelPageFixtures::definitions())['page']->header;

self::assertSame('toolbar', $header->actionsLayout);
self::assertSame('primary', $header->actions[0]->resolvedVariant(), 'New path stays the primary button.');
}

public function testRedirectsHeaderActionsGoToThePageActionsMenuOnRequest(): void
{
$header = PanelPageFixtures::redirectsIndex(PanelPageFixtures::redirects(), headerActions: 'page_actions')['page']->header;
self::assertSame('split', $header->actionsLayout);
$html = $this->headerHtml($header);

self::assertStringContainsString('data-nowo-ui-header-more', $html);
self::assertStringContainsString('data-testid="redirect-new"', $html);
self::assertStringContainsString('href="/_routing/redirects/new"', $html);
}

/**
* The header actions the way UiKit's page header draws a split header (the contract test's stub theme replaces the
* page header partial, so the real `header_actions` partial is rendered on the header's actions).
*/
private function headerHtml(PageHeader $header): string
{
return $this->renderPage(new PageFixture('@NowoUiKitBundle/partials/_header_actions.html.twig', ['actions' => $header->actions, 'bundle' => PanelView::BUNDLE]))->html;
}

public function testRouteDeleteConfirmPagePostsWithCsrf(): void
{
$html = $this->renderPage(new PageFixture('@NowoRoutingKitBundle/panel/delete.html.twig', PanelPageFixtures::delete(PanelPageFixtures::definitions()[2])))->html;
Expand Down
Loading