From 0e3497c8ff2fe194aa030bf2f3f1e9b0b536e117 Mon Sep 17 00:00:00 2001 From: martinkrulltott Date: Tue, 5 Sep 2023 13:47:09 +0200 Subject: [PATCH 1/3] fix: enable legend for dx in rows for PT --- src/components/VisualizationPlugin/VisualizationPlugin.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/VisualizationPlugin/VisualizationPlugin.js b/src/components/VisualizationPlugin/VisualizationPlugin.js index f3d4cabe50..4b91689536 100644 --- a/src/components/VisualizationPlugin/VisualizationPlugin.js +++ b/src/components/VisualizationPlugin/VisualizationPlugin.js @@ -256,6 +256,7 @@ export const VisualizationPlugin = ({ case LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM: { if ( + fetchResult.visualization.type !== VIS_TYPE_PIVOT_TABLE && !fetchResult.visualization.columns.some( (item) => item.dimension === 'dx' ) From 8b49821e2429a88047c2847cc3cbde118679d4e4 Mon Sep 17 00:00:00 2001 From: martinkrulltott Date: Tue, 5 Sep 2023 13:48:54 +0200 Subject: [PATCH 2/3] refactor: use prop instead of string --- src/components/VisualizationPlugin/VisualizationPlugin.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/VisualizationPlugin/VisualizationPlugin.js b/src/components/VisualizationPlugin/VisualizationPlugin.js index 4b91689536..97ea47685a 100644 --- a/src/components/VisualizationPlugin/VisualizationPlugin.js +++ b/src/components/VisualizationPlugin/VisualizationPlugin.js @@ -8,6 +8,7 @@ import { LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM, isLegendSetType, VIS_TYPE_LINE, + DIMENSION_ID_DATA, } from '@dhis2/analytics' import { useDataEngine } from '@dhis2/app-runtime' import { Button, IconLegend24, Layer } from '@dhis2/ui' @@ -258,7 +259,7 @@ export const VisualizationPlugin = ({ if ( fetchResult.visualization.type !== VIS_TYPE_PIVOT_TABLE && !fetchResult.visualization.columns.some( - (item) => item.dimension === 'dx' + (item) => item.dimension === DIMENSION_ID_DATA ) ) { break From 48190cb7b117c6c2e1c6845faba54a625cd14413 Mon Sep 17 00:00:00 2001 From: martinkrulltott Date: Mon, 25 Sep 2023 15:09:58 +0200 Subject: [PATCH 3/3] test: add tests for legend with data in rows --- cypress/integration/options/legend.cy.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cypress/integration/options/legend.cy.js b/cypress/integration/options/legend.cy.js index 4b1d67b9cd..6dcf3a1940 100644 --- a/cypress/integration/options/legend.cy.js +++ b/cypress/integration/options/legend.cy.js @@ -10,6 +10,7 @@ import { DIMENSION_ID_PERIOD, AXIS_ID_COLUMNS, VIS_TYPE_AREA, + AXIS_ID_ROWS, } from '@dhis2/analytics' import { expectChartTitleToBeVisible, @@ -520,6 +521,25 @@ describe('Options - Legend', () => { expectLegendKeyToBeVisible() expectLegedKeyItemAmountToBe(1) }) + it('legend is applied when data is in rows', () => { + // swap data and period + openContextMenu(DIMENSION_ID_PERIOD) + clickContextMenuMove(DIMENSION_ID_PERIOD, AXIS_ID_COLUMNS) + openContextMenu(DIMENSION_ID_DATA) + clickContextMenuMove(DIMENSION_ID_DATA, AXIS_ID_ROWS) + clickMenuBarUpdateButton() + + // expect legend to still be applied + expectVisualizationToBeVisible(VIS_TYPE_PIVOT_TABLE) + expectLegendKeyToBeVisible() + expectLegedKeyItemAmountToBe(1) + cy.getBySel(valueCellEl).each(($el) => { + cy.wrap($el) + .invoke('attr', 'style') + .should('not.contain', 'background-color') + .and('not.contain', EXPECTED_STANDARD_TEXT_COLOR) + }) + }) }) describe('Transferring a legend: Pivot table -> Gauge', () => { const TEST_ITEM = TEST_ITEMS[0]