From 625be72a934b9b87d9d261cfa47309ffaf79b5a7 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 9 Nov 2023 15:34:58 +0100 Subject: [PATCH] fix: legend sets fail to load in table with data dimension in the row (DHIS2-12830) v39 (#2899) --- cypress/integration/options/legend.cy.js | 20 ++++++++++++++++++++ packages/plugin/src/VisualizationPlugin.js | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cypress/integration/options/legend.cy.js b/cypress/integration/options/legend.cy.js index 022ea9e717..04197b3b8b 100644 --- a/cypress/integration/options/legend.cy.js +++ b/cypress/integration/options/legend.cy.js @@ -9,6 +9,7 @@ import { visTypeDisplayNames, DIMENSION_ID_PERIOD, AXIS_ID_COLUMNS, + AXIS_ID_ROWS, VIS_TYPE_AREA, } from '@dhis2/analytics' import { @@ -543,6 +544,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] diff --git a/packages/plugin/src/VisualizationPlugin.js b/packages/plugin/src/VisualizationPlugin.js index 9b9f0eaed1..2ad794e643 100644 --- a/packages/plugin/src/VisualizationPlugin.js +++ b/packages/plugin/src/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' @@ -212,8 +213,9 @@ 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' + (item) => item.dimension === DIMENSION_ID_DATA ) ) { break