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
Introducing reusable way to display KPIs blocks in Back Office modern pages #9242
Conversation
{ | ||
$enabledLanguages = $this->configuration->get('ENABLED_LANGUAGES'); | ||
|
||
$kpi = new HelperKpi(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't want to increase the scope of this PR so I'm still relying on legacy HelperKpi to render the view, but the overall kpi implementation is not dependent on legacy code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right :) it's the main purpose of using adapters
/** | ||
* @param KpiInterface ...$kpis | ||
*/ | ||
public function __construct(KpiInterface ...$kpis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't works in PHP 5.6, isn't it? I'm sad because it's an elegant implementation :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
Hello @rokaszygmantas, thinking about it, can we merge only this part "first" and then make another contribution to migrate the page? Wdyt? |
'layoutTitle' => $this->trans('Translations', 'Admin.Navigation.Menu'), | ||
'enableSidebar' => true, | ||
'help_link' => $this->generateSidebarLink($legacyController), | ||
'kpiRow' => $presentedKpiRow, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as KPI stuff is present in multiples pages, can we create a specific action to render the KPI block in CommonController
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds interesting, I'll see if that works
yes sounds really good :) should I remove the stuff related to translations controller or can it stay unused? e.g. new action, routing Edit: if the |
In this case we will also need to provide a way for QA to test this PR, how should we handle that? |
@rokaszygmantas you can keep the work done on translations controller so the QA team can test the "KPI block" only 👍 Great job making this reusable everywhere, I don't have time to report issues you have already fixed them :p Lithuanian people are wizards! edit: I've updated the PR label, description and testing sections |
{{ include('@PrestaShop/Admin/Common/Kpi/kpi_row.html.twig', {'kpiRow': kpiRow }) }} | ||
{{ render(controller( | ||
'PrestaShopBundle:Admin\\Common:renderKpiRow', | ||
{ 'factory': kpiRowFactory } |
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea :)
@@ -935,6 +935,10 @@ $(document).ready(function() | |||
if ($('.kpi-container').length) { | |||
refresh_kpis(); | |||
} | |||
|
|||
$('.kpi-refresh').on('click', '.refresh-kpis', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add this code to legacy js for the legacy refresh code to pick up the new refresh button, otherwise I would have to create all the javascript for refreshing KPIs, which I want to avoid doing in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job
@@ -32,7 +32,7 @@ | |||
<div class="row"> | |||
{{ render(controller( | |||
'PrestaShopBundle:Admin\\Common:renderKpiRow', | |||
{ 'factory': kpiRowFactory } | |||
{ 'kpiRow': kpiRow } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it sound better for you? it does for me :)
@@ -935,6 +935,10 @@ $(document).ready(function() | |||
if ($('.kpi-container').length) { | |||
refresh_kpis(); | |||
} | |||
|
|||
$('.kpi-refresh').on('click', '.refresh-kpis', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense :)
src/Adapter/Kpi/MainCountryKpi.php
Outdated
'action' => 'getKpi', | ||
'kpi' => 'main_country', | ||
]; | ||
$kpi->source = $this->legacyContext->getAdminLink('AdminStats', true, $params); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you only need legacy context to render an url, how about making this url an argument of your constructor instead? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes, good idea :) no need to inject the whole context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my secret (not anymore!) challenge is to remove LegacyContext
at some point, so when I can remove it from a class I'm happy 💃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe now everyone knows! 🙈
src/Core/Kpi/Row/KpiRow.php
Outdated
/** | ||
* @return bool | ||
*/ | ||
public function getAllowRefresh() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use a isser (isRefreshAllowed()) or an hasser here (hasRefreshAllowed) ?
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, why not :)
@mickaelandrieu thanks - addressed your feedback |
- '@translator' | ||
- '@prestashop.adapter.legacy.kpi_configuration' | ||
- '@=service("prestashop.adapter.legacy.context").getAdminLink("AdminLanguages")' | ||
- '@=service("prestashop.adapter.legacy.context").getAdminLink("AdminStats", true, {"ajax": 1, "action": "getKpi", "kpi": "enabled_languages"})' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lulz didn't even know this syntax was possible! I asked you to do some black voodoo here :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it took me a while to make this work :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was not intended ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it's still good, isn't it? Better than to inject the legacy context in the class :D
Thanks @rokaszygmantas and @marionf @rokaszygmantas we need docs in prestafony project, something basic like "how to add a KPI block in modern pages?" article |
I'll add some docs :) |
This change is