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

ui-select not reloading value when used in entity form after the entity is saved #38643

Closed
5 tasks
ioweb-gr opened this issue Apr 20, 2024 · 9 comments
Closed
5 tasks
Assignees
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.1 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@ioweb-gr
Copy link

Preconditions and environment

  • 2.4.1

Steps to reproduce

  1. I've created my entity using the phpstorm plugin and I've added a rule_id field.
  2. I've added a field in my UI Form Component like this
<field name="rule_id" component="Magento_Ui/js/form/element/ui-select" sortOrder="10" formElement="select">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filterOptions" xsi:type="boolean">true</item>
                    <item name="multiple" xsi:type="boolean">false</item>
                    <item name="showCheckbox" xsi:type="boolean">false</item>
                    <item name="disableLabel" xsi:type="boolean">true</item>
                    <item name="levelsVisibility" xsi:type="number">0</item>
                    <item name="searchOptions" xsi:type="boolean">true</item>
                    <item name="searchUrl" xsi:type="url" path="ioweb_base/rule/search"/>
                    <item name="options" xsi:type="object">Ioweb\Base\Model\Config\Source\CartRule</item>
                    <item name="filterPlaceholder" xsi:type="string" translate="true">Rule ID or Name</item>
                    <item name="emptyOptionsHtml" xsi:type="string" translate="true">Start typing to find rules</item>
                    <item name="missingValuePlaceholder" xsi:type="string" translate="true">Rule with ID: %s doesn\'t exist</item>
                </item>
            </argument>
            <settings>
                <required>true</required>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
                <elementTmpl>ui/grid/filters/elements/ui-select</elementTmpl>
                <label translate="true">Rule ID</label>
                <dataScope>rule_id</dataScope>
                <componentType>field</componentType>
                <tooltip>
                    <description>Select rule ID. Type at least 3 characters to search.</description>
                </tooltip>
            </settings>
        </field>

The options are searched using the following controller

<?php
/**
 * Copyright (c) 2024. IOWEB TECHNOLOGIES
 */

declare(strict_types=1);

namespace Ioweb\Base\Controller\Adminhtml\Rule;

use Magento\Backend\App\Action;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\SalesRule\Api\RuleRepositoryInterface;

/**
 * Controller for the 'ioweb_base/rule/search' URL route.
 */
class Search extends Action implements HttpGetActionInterface
{
    /**
     * Authorization level of a basic admin session.
     */
    const ADMIN_RESOURCE = 'Magento_SalesRule::config_promo';

    /**
     * @var JsonFactory
     */
    private $resultJsonFactory;

    /**
     * @var RuleRepositoryInterface
     */
    private $ruleRepository;

    /**
     * @var SearchCriteriaBuilder
     */
    private $searchCriteriaBuilder;

    /**
     * @param JsonFactory $resultJsonFactory
     * @param RuleRepositoryInterface $ruleRepository
     * @param SearchCriteriaBuilder $searchCriteriaBuilder
     * @param Action\Context $context
     */
    public function __construct(
        JsonFactory             $resultJsonFactory,
        RuleRepositoryInterface $ruleRepository,
        SearchCriteriaBuilder   $searchCriteriaBuilder,
        Action\Context          $context
    ) {
        $this->resultJsonFactory = $resultJsonFactory;
        $this->ruleRepository = $ruleRepository;
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
        parent::__construct($context);
    }

    /**
     * Execute controller action.
     *
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        $options = [];

        $searchKey = $this->getRequest()->getParam('searchKey');
        $pageNum = (int)$this->getRequest()->getParam('page');
        $limit = (int)$this->getRequest()->getParam('limit');

        $this->searchCriteriaBuilder->addFilter('name', "%$searchKey%", 'like');
        $searchCriteria = $this->searchCriteriaBuilder->create();
        $searchCriteria->setCurrentPage($pageNum);
        $searchCriteria->setPageSize($limit);
        $rulesList = $this->ruleRepository->getList($searchCriteria);
        if ($rulesList->getTotalCount() > 0) {
            $rules = $rulesList->getItems();
            foreach ($rules as $rule) {
                $options[$rule->getRuleId()] = [
                    'value' => $rule->getRuleId(),
                    'label' => $rule->getName(),
                    'level' => 0,
                    'path' => $rule->getRuleId(),
                ];
            }
        }
        $resultJson = $this->resultJsonFactory->create();
        return $resultJson->setData([
                                        'options' => $options,
                                        'total' => $rulesList->getTotalCount()
                                    ]);
    }
}
  1. The searching works fine and the item is working correctly
    image

However when reopening my form the ui-select component is not searching for the rule again to display it and shows a broken value for the name of the option

image

Expected result

The item is reloaded properly based on the ID rendering the component unusable for the admin user as he can't remember which rule he selected.

Actual result

The select box shows that the item with ID: X doesn't exist

Additional information

No response

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Copy link

m2-assistant bot commented Apr 20, 2024

Hi @ioweb-gr. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

@m2-community-project m2-community-project bot added this to Ready for Confirmation in Issue Confirmation and Triage Board Apr 20, 2024
@engcom-Dash engcom-Dash added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Apr 22, 2024
@engcom-Hotel engcom-Hotel added the Reported on 2.4.1 Indicates original Magento version for the Issue report. label Apr 24, 2024
@shakil-codilar
Copy link

@magento give me 2.4.4-p1 instance

Copy link

Hi @shakil-codilar. Thank you for your request. I'm working on Magento instance for you.

Copy link

Hi @shakil-codilar, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

@engcom-Hotel engcom-Hotel self-assigned this Apr 29, 2024
Copy link

m2-assistant bot commented Apr 29, 2024

Hi @engcom-Hotel. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • 5. Add label Issue: Confirmed once verification is complete.
  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Hotel
Copy link
Contributor

Hello @ioweb-gr,

Thanks for the report and collaboration!

We have tried to reproduce the issue in the latest development branch i.e. 2.4-develop but it seems the issue is not reproducible at our end.

For us, the value is populating after saving:

image

In order to reproduce the issue, we have added a fieldset in app/code/Magento/Backend/view/adminhtml/ui_component/design_config_form.xml, it looks something like this:

<field name="rule_id" component="Magento_Ui/js/form/element/ui-select" sortOrder="10" formElement="select">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filterOptions" xsi:type="boolean">true</item>
                    <item name="multiple" xsi:type="boolean">false</item>
                    <item name="showCheckbox" xsi:type="boolean">false</item>
                    <item name="disableLabel" xsi:type="boolean">true</item>
                    <item name="levelsVisibility" xsi:type="number">0</item>
                    <item name="searchOptions" xsi:type="boolean">true</item>
                    <item name="searchUrl" xsi:type="url" path="issue38643/rule/search"/>
                    <item name="options" xsi:type="object">Magz\Issue38643\Model\Config\Source\CartRule</item>
                    <item name="filterPlaceholder" xsi:type="string" translate="true">Rule ID or Name</item>
                    <item name="emptyOptionsHtml" xsi:type="string" translate="true">Start typing to find rules</item>
                    <item name="missingValuePlaceholder" xsi:type="string" translate="true">Rule with ID: %s doesn\'t exist</item>
                </item>
            </argument>
            <settings>
                <required>true</required>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
                <elementTmpl>ui/grid/filters/elements/ui-select</elementTmpl>
                <label translate="true">Rule ID</label>
                <dataScope>rule_id</dataScope>
                <componentType>field</componentType>
                <tooltip>
                    <description>Select rule ID. Type at least 3 characters to search.</description>
                </tooltip>
            </settings>
        </field>

Please let us know if we missed anything.

Thanks

@engcom-Hotel engcom-Hotel added Issue: needs update Additional information is require, waiting for response and removed Issue: ready for confirmation labels Apr 29, 2024
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Apr 29, 2024
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Apr 29, 2024
@ioweb-gr
Copy link
Author

Please use the Magento 2 phpstorm plugin to create a new entity as that's how I noticed it

The only difference I can think of is that the area you used it on handles the data differently

@engcom-Hotel
Copy link
Contributor

Hello @ioweb-gr,

It seems the issue is specifically reproducible with the Magento 2 phpstorm plugin. So I suggest you please create this issue in the below repo:

https://github.com/magento/magento2-phpstorm-plugin/issues

Please let us know if we missed anything.

Thanks

@engcom-Hotel
Copy link
Contributor

Dear @ioweb-gr,

We've observed that there haven't been any updates on this issue for quite some time. Therefore, we're assuming it's been resolved and will be closing it. Feel free to open a new ticket or reopen this one if you require further assistance.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.1 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

No branches or pull requests

4 participants