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

Introducing reusable way to display KPIs blocks in Back Office modern pages #9242

24 changes: 22 additions & 2 deletions src/PrestaShopBundle/Controller/Admin/CommonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
use PrestaShop\PrestaShop\Core\Addon\AddonsCollection;
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder;
use PrestaShop\PrestaShop\Adapter\Module\AdminModuleDataProvider;
use PrestaShop\PrestaShop\Core\Kpi\Row\KpiRowFactoryInterface;
use PrestaShop\PrestaShop\Core\Kpi\Row\KpiRowPresenterInterface;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use PrestaShopBundle\Service\DataProvider\Admin\RecommendedModules;
use Symfony\Component\HttpFoundation\Response;

/**
* Admin controller for the common actions across the whole admin interface.
Expand Down Expand Up @@ -60,7 +63,8 @@ class CommonController extends FrameworkBundleAdminController
* @param integer $offset
* @param integer $total
* @param string $view full|quicknav To change default template used to render the content
* @return array|\Symfony\Component\HttpFoundation\Response
*
* @return array|Response
*/
public function paginationAction(Request $request, $limit = 10, $offset = 0, $total = 0, $view = 'full')
{
Expand Down Expand Up @@ -195,7 +199,7 @@ public function recommendedModulesAction($domain, $limit = 0, $randomize = 0)
* @param $url
* @param string $title
* @param string $footer
* @return \Symfony\Component\HttpFoundation\Response
* @return Response
*/
public function renderSidebarAction($url, $title = '', $footer = '')
{
Expand All @@ -207,4 +211,20 @@ public function renderSidebarAction($url, $title = '', $footer = '')
'url' => urldecode($url),
]);
}

/**
* Renders a KPI row, built by provided factory
*
* @param KpiRowFactoryInterface $factory
*
* @return Response
*/
public function renderKpiRowAction(KpiRowFactoryInterface $factory)
{
$presenter = $this->get('prestashop.core.kpi_row.presenter');

return $this->render('@PrestaShop/Admin/Common/Kpi/kpi_row.html.twig', [
'kpiRow' => $presenter->present($factory->build()),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,12 @@ public function showSettingsAction(Request $request)
{
$legacyController = $request->attributes->get('_legacy_controller');
$kpiRowFactory = $this->get('prestashop.core.kpi_row.factory.translations_page');
$presenter = $this->get('prestashop.core.kpi_row.presenter');

$presentedKpiRow = $presenter->present($kpiRowFactory->build());

return [
'layoutTitle' => $this->trans('Translations', 'Admin.Navigation.Menu'),
'enableSidebar' => true,
'help_link' => $this->generateSidebarLink($legacyController),
'kpiRow' => $presentedKpiRow,
'kpiRowFactory' => $kpiRowFactory,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@

{% block translations_kpis_row %}
<div class="row">
{{ include('@PrestaShop/Admin/Common/Kpi/kpi_row.html.twig', {'kpiRow': kpiRow }) }}
{{ render(controller(
'PrestaShopBundle:Admin\\Common:renderKpiRow',
{ 'factory': kpiRowFactory }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mickaelandrieu can I render it somehow without passing the factory to twig? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not pass the Row instead of the factory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea :)

)) }}
</div>
{% endblock %}

Expand Down