-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Improve HTMX integration in workspace UI
Use http headers for proper status codes and transport flash messages
- Loading branch information
Showing
7 changed files
with
94 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Neos.Workspace.Ui package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Workspace\Ui\Mvc; | ||
|
||
use Neos\Flow\Mvc\ActionRequest; | ||
use Neos\Flow\Security\RequestPatternInterface; | ||
|
||
final class HtmxRequestPattern implements RequestPatternInterface | ||
{ | ||
public function matchRequest(ActionRequest $request): bool | ||
{ | ||
return $request->getFormat() === 'htmx'; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Neos.Workspace.Ui/Classes/Mvc/HttpHeaderFlashMessageStorage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Neos.Workspace.Ui package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Workspace\Ui\Mvc; | ||
|
||
use Neos\Error\Messages\Message; | ||
use Neos\Flow\Mvc\FlashMessage\FlashMessageContainer; | ||
use Neos\Flow\Mvc\FlashMessage\FlashMessageStorageInterface; | ||
use Psr\Http\Message\ResponseInterface as HttpResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface as HttpRequestInterface; | ||
|
||
final class HttpHeaderFlashMessageStorage implements FlashMessageStorageInterface | ||
{ | ||
private FlashMessageContainer|null $flashMessageContainer = null; | ||
|
||
public function load(HttpRequestInterface $request): FlashMessageContainer | ||
{ | ||
if ($this->flashMessageContainer === null) { | ||
$this->flashMessageContainer = new FlashMessageContainer(); | ||
} | ||
return $this->flashMessageContainer; | ||
} | ||
|
||
public function persist(HttpResponseInterface $response): HttpResponseInterface | ||
{ | ||
$messages = array_map(static fn(Message $message) => [ | ||
'title' => $message->getTitle(), | ||
'message' => $message->render(), | ||
'severity' => $message->getSeverity(), | ||
'code' => $message->getCode(), | ||
], $this->flashMessageContainer?->getMessagesAndFlush() ?? []); | ||
if ($messages === []) { | ||
return $response; | ||
} | ||
return $response->withAddedHeader('X-Flow-FlashMessages', json_encode($messages, JSON_THROW_ON_ERROR)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Neos: | ||
Flow: | ||
mvc: | ||
flashMessages: | ||
containers: | ||
'httpHeaderFlashMessages': | ||
storage: 'Neos\Workspace\Ui\Mvc\HttpHeaderFlashMessageStorage' | ||
requestPatterns: | ||
'htmx': | ||
pattern: 'Neos\Workspace\Ui\Mvc\HtmxRequestPattern' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
Neos.Workspace.Ui/Resources/Private/Fusion/Views/Delete.fusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## | ||
# Empty template for the delete response as the payload is contained in the HTTP headers | ||
# | ||
Neos.Workspace.Ui.WorkspaceController.delete.htmx = '' |
7 changes: 0 additions & 7 deletions
7
Neos.Workspace.Ui/Resources/Private/Fusion/Views/Index.htmx.fusion
This file was deleted.
Oops, something went wrong.