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
Allow WidgetConfigs used in ByDimension widget containers to be shown in dashboard manager #11995
Conversation
Would it be maybe possible to iterate recursive in https://github.com/piwik/piwik/blob/3.0.5-b2/plugins/API/WidgetMetadata.php#L40-L41 and mark it here as widgetizable or so? https://github.com/piwik/piwik/blob/3.0.5-b2/plugins/Goals/Pages.php#L305 If you then made this here recursive to include categories and subcategories of widgets in containers the naming issue might be resolved as well: https://github.com/piwik/piwik/blob/3.0.5-b2/plugins/API/WidgetMetadata.php#L31 (to be tested). It might still somewhat have the same name as in the reports so probably won't fix 100% the problem just yet. I would not really want to add a I would try to fix the above mentioned issues and then it might show it correctly as they have basically a subcategory set like "Goals by XYZ", it would only need to be added to the right category. Currently they are not shown there since we do not recursively search for all widgets in containers (and not yet create categories dynamically) |
So is this your suggested solution?
I'm not sure if I understand completely, seems like it won't work out of the box. A |
Check out https://github.com/piwik/piwik/compare/11942?expand=1 there it seems to work for me. The only downside I see is that an added widget with only the title of eg "Device Type" it is not clear that it is "Ecomerce Sales by ... Device Type". We could change the widget title with some hack dynamically (eg when Here you can see you would know that those device types are only for sales: |
The fix for the widget title would be actually that when there are widgets in a widget container with a "by dimension" layout, that we automatically prepend the subcategory of the widget to the widget title like |
The issue linked specifies that there should be one new widget category "Ecommerce - Sales", not multiple "Ecommerce - Sales by ..." categories. @mattab can you confirm having multiple categories is ok? |
We could fix this as well in There may be a hack needed to do this only for |
Maybe I'm not understanding, but if we use the widget category of the container (in this case 'Sales') for the widget category of the actual widget (ie, 'Sales by Referrer'), then the widget will appear in the dashboard manager AND in the Ecommerce > Sales page, right? Then in that page, there will be the widget + the widget container with the ByDimension layout. This was one of the problems I encountered, setting the right category on the WidgetConfig makes it appear in the dashboard manager, but it also shows it twice in the actual page. EDIT: Nevermind, I think getPagesMetadata doesn't recurse, while getWidgetsMetadata does. |
Ok, I think I understand the system now, thanks for your patience @tsteur ;) |
Oki :) Just to roughly explain it: We basically would need to change only the logic in When we iterate over the widgets, we would basically somehow diff --git a/plugins/API/WidgetMetadata.php b/plugins/API/WidgetMetadata.php
index 2d77e76..453a6ec 100644
--- a/plugins/API/WidgetMetadata.php
+++ b/plugins/API/WidgetMetadata.php
@@ -36,6 +36,8 @@ class WidgetMetadata
/** @var WidgetConfig[] $widgets */
$widgets = array($widgetConfig);
+ $subcategoryId = $widgetConfig->getSubcategoryId();
+
if ($widgetConfig instanceof WidgetContainerConfig) {
// so far we go only one level down, in theory these widgetConfigs could have again containers containing configs
$widgets = array_merge($widgets, $widgetConfig->getWidgetConfigs());
@@ -47,7 +49,7 @@ class WidgetMetadata
continue;
}
- $flat[] = $this->buildWidgetMetadata($widget, $categoryList);
+ $flat[] = $this->buildWidgetMetadata($widget, $subcategoryId, $categoryList);
}
} it is just a rough idea on how to implement this but haven't tested if it would work like this |
…manager. Reports did not show currently, because widget configs in containers with ByDimension layout have modified categories/subcategories. They thus did not show up under the right category (the category of the widget container). Fixed by using the right category in getWidgetMetadata (but not getPagesMetadata).
Ready for review, though the UI tests might not pass (there were some failures in the last run I couldn't explain, they might be random). |
One thing to note: this adds widgets like 'Sales by Referrers: Referrer Type', but it also changes the name of some existing widgets, eg, 'Actions: Content Name'. Let me know if that is not desired. |
I think @mattab can probably say more about 'Actions: Content Name' whether it is desired or not. |
It should be fine to prefix the name, if it becomes a problem we could adjust later on |
Fixes #11942
Problem
The WidgetConfig's category/subcategory is used in three different contexts. It's used to place the widget in a page, used to display which widgets users can add to a dashboard and used to differentiate widgets in a 'ByDimension' layout. The last of these uses conflicts with the others.
The 'Sales by' widgets are added to a 'ByDimension' container. This container is displayed as the Ecommerce > Sales page. These widgets have a custom category/subcategory set to 'Sales by ...'. Since they don't have a recognized widget category/subcategory, they do not appear in the dashboard manager (or by themselves in a page).
We could set the category/subcategory of these widgets to Ecommerce/Sales so they appear in the dashboard manager, but this causes two problems. First, the 'ByDimension' report renders incorrectly (instead of Sales by ... categories, there will be just one, 'Sales'). Second, the name of the widget in dashboard manager becomes the dimension name (so 'City' instead of 'Sales by City').
We could add new WidgetConfig instances for the Sales by ... widgets, eg, by using the
Widget.addWidgetConfigs
event, but this causes another problem. SinceAPI.getReportPagesMetadata
automatically adds these reports to theEcommerce > Sales
page, there ends up being two of each report on that page. It seems currently impossible to add a widget to the dashboard manager, but exclude it from pages.Solution
This PR has a quick solution to the above problem. Instead of relying on the category/subcategory/report name for 'ByDimension' reports, it introduces two new widget config fields:
dimensionCategory
anddimensionName
.The
piwikWidgetByDimensionContainer
directive uses these fields if present (falling back on normal subcategory/name). This allows us to widgetize reports that are placed within a 'ByDimension' layout, keeps the API BC (mostly), and allows us to display the report in the dashboard manager while excluding it from pages.There's only one issue I can think of: consumers of the API might need to change if they use 'ByDimension' layouts (eg, maybe the mobile app?). They would have to start using the new categories.
A long term solution would require separating the conflicting concepts and implementing something more domain driven. An entry that appears in the dashboard manager is different from a widget displayed in a page is different from a widget contained in a 'ByDimension' layout. The code should reflect that. (If this is the preferred approach, I can do that instead of this approach, but it would be a larger change w/ potential BC breaks).