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

Conversation

rokaszygmantas
Copy link
Contributor

@rokaszygmantas rokaszygmantas commented Jul 1, 2018

Questions Answers
Branch? develop
Description? We needed a common and re-usable system to display KPIs block everywhere in Symfony pages
Type? improvement
Category? BO
BC breaks? no
Deprecations? no
Fixed ticket? no
How to test? Compare to legacy translations page (only the page that you land in when going to International > Translations), for the KPI block on top of the page.

This change is Reviewable

@prestonBot prestonBot added develop Branch Waiting for wording Status: action required, waiting for wording labels Jul 1, 2018
{
$enabledLanguages = $this->configuration->get('ENABLED_LANGUAGES');

$kpi = new HelperKpi();
Copy link
Contributor Author

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.

Copy link
Contributor

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)
Copy link
Contributor

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 :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

great!

@mickaelandrieu
Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Contributor Author

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

@rokaszygmantas
Copy link
Contributor Author

rokaszygmantas commented Jul 2, 2018

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 CommonController implementation works fine, I'll just remove the action from translations controller and will do that in a new PR.

@rokaszygmantas
Copy link
Contributor Author

In this case we will also need to provide a way for QA to test this PR, how should we handle that?

@mickaelandrieu
Copy link
Contributor

mickaelandrieu commented Jul 2, 2018

@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

@mickaelandrieu mickaelandrieu changed the title [WIP] Migrate Improve > International > Translations page Introducing reusable way to display KPIs blocks in Back Office modern pages Jul 2, 2018
@LouiseBonnard LouiseBonnard removed the Waiting for wording Status: action required, waiting for wording label Jul 2, 2018
@mickaelandrieu mickaelandrieu added the Improvement Type: Improvement label Jul 2, 2018
{{ 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 :)

@@ -935,6 +935,10 @@ $(document).ready(function()
if ($('.kpi-container').length) {
refresh_kpis();
}

$('.kpi-refresh').on('click', '.refresh-kpis', function () {
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

make sense :)

Copy link
Contributor

@mickaelandrieu mickaelandrieu left a 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 }
Copy link
Contributor

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 () {
Copy link
Contributor

Choose a reason for hiding this comment

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

make sense :)

'action' => 'getKpi',
'kpi' => 'main_country',
];
$kpi->source = $this->legacyContext->getAdminLink('AdminStats', true, $params);
Copy link
Contributor

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? :)

Copy link
Contributor Author

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

Copy link
Contributor

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 💃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hehe now everyone knows! 🙈

/**
* @return bool
*/
public function getAllowRefresh()
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, why not :)

@rokaszygmantas
Copy link
Contributor Author

@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"})'
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

it was not intended ^^

Copy link
Contributor Author

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

@mickaelandrieu mickaelandrieu added the Waiting for QA Status: action required, waiting for test feedback label Jul 5, 2018
@marionf marionf added QA ✔️ Status: check done, code approved and removed Waiting for QA Status: action required, waiting for test feedback labels Jul 5, 2018
@mickaelandrieu mickaelandrieu merged commit decc6e8 into PrestaShop:develop Jul 6, 2018
@mickaelandrieu
Copy link
Contributor

mickaelandrieu commented Jul 6, 2018

Thanks @rokaszygmantas and @marionf

@rokaszygmantas we need docs in prestafony project, something basic like "how to add a KPI block in modern pages?" article

@mickaelandrieu mickaelandrieu added this to the 1.7.5.0 milestone Jul 6, 2018
@rokaszygmantas
Copy link
Contributor Author

I'll add some docs :)

@rokaszygmantas rokaszygmantas deleted the migration/international_translations branch July 6, 2018 22:38
@matks matks added the migration symfony migration project label Sep 18, 2018
@matks matks mentioned this pull request Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
develop Branch Improvement Type: Improvement migration symfony migration project QA ✔️ Status: check done, code approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants