-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Admin Config Search #10335
Admin Config Search #10335
Conversation
- reduced text info in search results - injection of dependency was changed to optional (backward compatibility) - highlighting of found field - defined vertical size of results list
* @param string $needle | ||
* @param string $pathLabel | ||
*/ | ||
public function findInStructure(ElementIterator $structureElementIterator, $needle, $pathLabel = '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this method declared as public?
We use it just inside this class
foreach ($structureElementIterator as $structureElement) { | ||
if (!($structureElement instanceof ElementInterface)) { | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have this check?
Magento\Config\Model\Config\Structure\Element\Iterator returns \Magento\Config\Model\Config\Structure\ElementInterface by contract, do we have any reasons not to trust the declared contract and make additional check?
/**
* Return the current element
*
* @return \Magento\Config\Model\Config\Structure\ElementInterface
*/
public function current()
{
return $this->_flyweight;
}
* @param string $needle | ||
* @param string $pathLabel | ||
*/ | ||
public function findInStructure(ElementIterator $structureElementIterator, $needle, $pathLabel = '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think "needle" is a good name.
Unless we call $structureElementIterator as haystack
It's the user's search term, so let's call it this way
if (!($structureElement instanceof ElementInterface)) { | ||
continue; | ||
} | ||
if (stripos((string)$structureElement->getLabel(), $needle) !== false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to use
mb_stripos than stripos
Magento requires "ext-mbstring": "*",
to be installed
if (!$this->hasQuery()) { | ||
$this->setResults($this->resultBuilder->getAll()); | ||
return $this; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we will move a check for the empty query into the findInStructure function, we could end-up with
public function load()
{
$this->findInStructure($this->configStructure->getTabs(), $this->getQuery());
$this->setResults($this->resultBuilder->getAll());
return $this;
}
self::STRUCTURE_ELEMENT_TYPE_SECTION, | ||
self::STRUCTURE_ELEMENT_TYPE_GROUP, | ||
self::STRUCTURE_ELEMENT_TYPE_FIELD, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better not to hard code supported elements, but accept an additional parameter, which is configured through the DI.
So, if some new supported component would be added in future we could easily add this new type with DI configuration.
'section' => $elementPathParts[0], | ||
'group' => $elementPathParts[1], | ||
'field' => $structureElement->getId(), | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to introduce an interface and provide implementation for each of the type.
To have an ability to add new supported type in future.
For now, we hardcoded existing structure elements
*/ | ||
public function __construct( | ||
\Magento\Backend\Block\Template\Context $context, | ||
\Magento\Config\Model\Config\Structure $configStructure, | ||
array $data = [] | ||
array $data = [], | ||
Json $jsonSerializer = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to have a dependency on the interface instead?
Magento\Framework\Serialize\SerializerInterface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned on #8331 (comment) and referenced on #10342 (comment) , SerializerInterface
is not guaranteed to return a JSON serializer in the future. And \Magento\Config\Block\System\Config
uses it in a method explicitly named getConfigSearchParamsJson
- changed visibility of findInStructure() method + renamed its argument - removed unnecessary verifications
# Conflicts: # app/code/Magento/Backend/i18n/en_US.csv
- introduced extended interface for \Magento\Config\Model\Config\Structure\ElementInterface - moved structure element types from static dependency to DI
/** | ||
* @api | ||
*/ | ||
interface ElementNewInterface extends ElementInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think that naming is very good in this case ElementInterface -> ElementNewInterface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll move it up and name it StructureElementInterface, wdyt ?
{ | ||
const STRUCTURE_ELEMENT_TYPE_SECTION = 'section'; | ||
const STRUCTURE_ELEMENT_TYPE_GROUP = 'group'; | ||
const STRUCTURE_ELEMENT_TYPE_FIELD = 'field'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need these constants if they not used
* | ||
* @method string|null getQuery() | ||
* @method bool hasQuery() | ||
* @method Config setResults(array $results) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to have all these methods as a part of Object contract, not relying on __call
usage
* @method string|null getQuery() | ||
* @method bool hasQuery() | ||
* @method Config setResults(array $results) | ||
* @method array getResults() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to have these methods in class contract, not relying on __call
method
# Conflicts: # app/code/Magento/Config/Model/Config/Structure/ElementInterface.php
Hi @maximgubar |
@maximgubar Thank you for the update |
|
added changes per UX request:
|
- address UX request for config search
Description
This feature will provide a possibility to find the config fields in Magento in a fast and easy way (e.g. live search).
Manual testing scenarios
Contribution checklist