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
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')],
];
}
}