Skip to content

Show customer_grid indexer as green when realtime #34557

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

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Indexer\Block\Backend\Grid\Column\Renderer;

use Magento\Customer\Model\Customer;

/**
* Renderer for 'Scheduled' column in indexer grid
*/
Expand All @@ -18,13 +20,35 @@ class Scheduled extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Abstr
*/
public function render(\Magento\Framework\DataObject $row)
{
if ($this->isPreferRealtime($row->getIndexerId())) {
$scheduleClass = 'grid-severity-major';
$realtimeClass = 'grid-severity-notice';
} else {
$scheduleClass = 'grid-severity-notice';
$realtimeClass = 'grid-severity-major';
}

if ($this->_getValue($row)) {
$class = 'grid-severity-notice';
$class = $scheduleClass;
$text = __('Update by Schedule');
} else {
$class = 'grid-severity-major';
$class = $realtimeClass;
$text = __('Update on Save');
}

return '<span class="' . $class . '"><span>' . $text . '</span></span>';
}

/**
* Determine if an indexer is recommended to be in 'realtime' mode
*
* @param string $indexer
* @return bool
*/
public function isPreferRealtime(string $indexer): bool
{
return in_array($indexer, [
Customer::CUSTOMER_GRID_INDEXER_ID,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
class ScheduledTest extends TestCase
{
/**
* @param string $indexer
* @param bool $rowValue
* @param string $class
* @param string $text
* @dataProvider typeProvider
*/
public function testRender($rowValue, $class, $text)
public function testRender($indexer, $rowValue, $class, $text)
{
$html = '<span class="' . $class . '"><span>' . $text . '</span></span>';
$row = new DataObject();
Expand All @@ -32,6 +33,7 @@ public function testRender($rowValue, $class, $text)
$model = new Scheduled($context);
$column->setGetter('getValue');
$row->setValue($rowValue);
$row->setIndexerId($indexer);
$model->setColumn($column);

$result = $model->render($row);
Expand All @@ -44,9 +46,12 @@ public function testRender($rowValue, $class, $text)
public function typeProvider()
{
return [
[true, 'grid-severity-notice', __('Update by Schedule')],
[false, 'grid-severity-major', __('Update on Save')],
['', 'grid-severity-major', __('Update on Save')],
['customer_grid', true, 'grid-severity-major', __('Update by Schedule')],
['customer_grid', false, 'grid-severity-notice', __('Update on Save')],
['customer_grid', '', 'grid-severity-notice', __('Update on Save')],
['catalog_product_price', true, 'grid-severity-notice', __('Update by Schedule')],
['catalog_product_price', false, 'grid-severity-major', __('Update on Save')],
['catalog_product_price', '', 'grid-severity-major', __('Update on Save')],
];
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/Indexer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"require": {
"php": "~8.1.0||~8.2.0",
"magento/framework": "*",
"magento/module-backend": "*"
"magento/module-backend": "*",
"magento/module-customer": "*"
},
"type": "magento2-module",
"license": [
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Indexer/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Indexer" >
<sequence>
<module name="Magento_Customer"/>
<module name="Magento_Store"/>
<module name="Magento_AdminNotification"/>
</sequence>
Expand Down