-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Show selectable search results
Resolves: #3
- Loading branch information
Showing
18 changed files
with
316 additions
and
44 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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shel\Neos\CommandBar\Helper; | ||
|
||
/* | ||
* This script belongs to the Neos CMS package "Shel.Neos.CommandBar". | ||
* | ||
* 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. | ||
*/ | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\I18n\EelHelper\TranslationParameterToken; | ||
|
||
#[Flow\Proxy(false)] | ||
class TranslationHelper | ||
{ | ||
|
||
public static function translateByShortHandString(string $shortHandString): string | ||
{ | ||
$shortHandStringParts = explode(':', $shortHandString); | ||
if (count($shortHandStringParts) === 3) { | ||
[$package, $source, $id] = $shortHandStringParts; | ||
return (new TranslationParameterToken($id)) | ||
->package($package) | ||
->source(str_replace('.', '/', $source)) | ||
->translate(); | ||
} | ||
|
||
return $shortHandString; | ||
} | ||
} |
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,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shel\Neos\CommandBar\Service\DataSource; | ||
|
||
/* | ||
* This script belongs to the Neos CMS package "Shel.Neos.CommandBar". | ||
* | ||
* 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. | ||
*/ | ||
|
||
use Neos\ContentRepository\Domain\Model\NodeInterface; | ||
use Neos\Flow\I18n\EelHelper\TranslationParameterToken; | ||
use Neos\Neos\Domain\Service\NodeSearchServiceInterface; | ||
use Neos\Neos\Service\DataSource\AbstractDataSource; | ||
use Neos\Neos\Service\LinkingService; | ||
use Shel\Neos\CommandBar\Helper\TranslationHelper; | ||
|
||
class SearchNodesDataSource extends AbstractDataSource | ||
{ | ||
|
||
static protected $identifier = 'shel-neos-commandbar-search-nodes'; | ||
|
||
public function __construct( | ||
private readonly NodeSearchServiceInterface $nodeSearchService, | ||
private readonly LinkingService $linkingService | ||
) { | ||
} | ||
|
||
public function getData(NodeInterface $node = null, array $arguments = []): array | ||
{ | ||
$query = $arguments['query'] ?? ''; | ||
|
||
if (!$node || !$query) { | ||
return []; | ||
} | ||
|
||
$matchingNodes = $this->nodeSearchService->findByProperties($query, [ | ||
'Neos.Neos:Document', | ||
'Neos.Neos:Shortcut', | ||
], $node->getContext(), $node); | ||
|
||
return array_map(function (NodeInterface $matchingNode) { | ||
return [ | ||
'name' => $matchingNode->getLabel(), | ||
'nodetype' => $this->translateByShortHandString($matchingNode->getNodeType()->getLabel()), | ||
'contextPath' => $matchingNode->getContextPath(), | ||
'icon' => $matchingNode->getNodeType()->getFullConfiguration()['ui']['icon'] ?? 'file', | ||
'uri' => $this->getNodeUri($matchingNode), | ||
]; | ||
}, array_values($matchingNodes)); | ||
} | ||
|
||
protected function getNodeUri(NodeInterface $node): string | ||
{ | ||
try { | ||
return $this->linkingService->createNodeUri($this->controllerContext, $node, null, 'html', true); | ||
} catch (\Exception $e) { | ||
return ''; | ||
} | ||
} | ||
|
||
// FIXME: Using the TranslationHelper instead throws class not found error, why? | ||
public function translateByShortHandString(string $shortHandString): string | ||
{ | ||
$shortHandStringParts = explode(':', $shortHandString); | ||
if (count($shortHandStringParts) === 3) { | ||
[$package, $source, $id] = $shortHandStringParts; | ||
return (new TranslationParameterToken($id)) | ||
->package($package) | ||
->source(str_replace('.', '/', $source)) | ||
->translate(); | ||
} | ||
|
||
return $shortHandString; | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
.results { | ||
min-height: 0; | ||
transition: opacity 0.3s ease-in; | ||
opacity: 0; | ||
overflow-y: auto; | ||
max-height: 60vh; | ||
} | ||
|
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
packages/commandbar/src/CommandResultsView/CommandResultsView.module.css
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 @@ | ||
.commandResultsView { | ||
max-width: 100%; | ||
overflow: auto; | ||
} |
Oops, something went wrong.