Skip to content
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

Merged
merged 20 commits into from
Sep 27, 2017
Merged

Admin Config Search #10335

merged 20 commits into from
Sep 27, 2017

Conversation

maximgubar
Copy link
Contributor

@maximgubar maximgubar commented Jul 26, 2017

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

  1. Open Magento admin in your browser.
  2. Type the keyword in global search input field.
  3. If there is a match in the config elements - results should appear in 'autocomplete results' area.
  4. Each result is clickable and should redirect to you to proper section/group of configuration UI.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

- 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 = '')
Copy link
Contributor

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;
}
Copy link
Contributor

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 = '')
Copy link
Contributor

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) {
Copy link
Contributor

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;
}
Copy link
Contributor

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,
];
Copy link
Contributor

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(),
];
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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';
Copy link
Contributor

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)
Copy link
Contributor

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()
Copy link
Contributor

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

@ishakhsuvarov
Copy link
Contributor

Hi @maximgubar
Please check the Magento\Backend\Model\Search\ConfigTest failures. Looks like search result in the test is always empty. Let us know if you need any assistance.
Thank you.

@ishakhsuvarov
Copy link
Contributor

@maximgubar Thank you for the update

@vrann
Copy link
Contributor

vrann commented Sep 20, 2017

@maximgubar

  • add description to the pull request
  • please fix static test:
Magento\Test\Php\XssPhtmlTemplateTest::testXssSensitiveOutput
Passed: 1172, Failed: 1, Incomplete: 0, Skipped: 0.
Data set: /opt/bamboo/agents/agent1/xml-data/build-dir/M2-AT2472-SLE1/magento2/app/code/Magento/Config/view/adminhtml/templates/system/config/edit.phtml
Potentially XSS vulnerability. Please verify that output is escaped at lines 391
Failed asserting that a string is empty.
/opt/bamboo/agents/agent1/xml-data/build-dir/M2-AT2472-SLE1/magento2/dev/tests/static/testsuite/Magento/Test/Php/XssPhtmlTemplateTest.php:48
/opt/bamboo/agents/agent1/xml-data/build-dir/M2-AT2472-SLE1/magento2/lib/internal/Magento/Framework/App/Utility/AggregateInvoker.php:56
/opt/bamboo/agents/agent1/xml-data/build-dir/M2-AT2472-SLE1/magento2/dev/tests/static/testsuite/Magento/Test/Php/XssPhtmlTemplateTest.php:51
(4 more lines...)

@maximgubar maximgubar changed the title WIP: Admin Config Search Admin Config Search Sep 21, 2017
@vrann
Copy link
Contributor

vrann commented Sep 25, 2017

added changes per UX request:

  1. .highlighted should be added to tr around the input
  2. .highlighted color should be #DFF7FF

@magento-team magento-team merged commit fab44c3 into magento:develop Sep 27, 2017
magento-team pushed a commit that referenced this pull request Sep 27, 2017
- address UX request for config search
magento-team pushed a commit that referenced this pull request Sep 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants