Skip to content

Commit

Permalink
fix: force type COLUMN when viewing table as chart [DHIS2-9599] (#1317)
Browse files Browse the repository at this point in the history
type "CHART" was being sent in as the visualization type, which doesn't match anything. The result was getting the default layout which works fine when there is only 1 row item, but not when more than 1 row item.

Also, instead of "REPORT_TABLE", we should be sending in "PIVOT_TABLE"
  • Loading branch information
jenniferarnesen authored Nov 20, 2020
1 parent 543f168 commit fd2f1bb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,42 @@ describe('getVisualizationConfig', () => {
expect(actualResult).toEqual(expectedResult)
})

it('returns correct config when switching from REPORT_TABLE to CHART', () => {
it('returns correct config when switching from REPORT_TABLE to CHART one row item', () => {
const visConfig = {
id: 'vis1',
[AXIS_ID_COLUMNS]: [
{ dimension: DIMENSION_ID_DATA },
{ dimension: 'rainbow' },
],
[AXIS_ID_ROWS]: [{ dimension: DIMENSION_ID_PERIOD }],
[AXIS_ID_FILTERS]: [
{ dimension: DIMENSION_ID_ORGUNIT },
{ dimension: 'twilight' },
],
}

const expectedVisConfig = {
id: undefined,
type: 'COLUMN',
[AXIS_ID_COLUMNS]: [{ dimension: DIMENSION_ID_DATA }],
[AXIS_ID_ROWS]: [{ dimension: DIMENSION_ID_PERIOD }],
[AXIS_ID_FILTERS]: [
{ dimension: DIMENSION_ID_ORGUNIT },
{ dimension: 'twilight' },
{ dimension: 'rainbow' },
],
}

const actualResult = getVisualizationConfig(
visConfig,
REPORT_TABLE,
CHART
)

expect(actualResult).toEqual(expectedVisConfig)
})

it('returns correct config when switching from REPORT_TABLE to CHART >2 row items', () => {
const visConfig = {
id: 'vis1',
[AXIS_ID_COLUMNS]: [
Expand All @@ -64,6 +99,7 @@ describe('getVisualizationConfig', () => {
[AXIS_ID_ROWS]: [
{ dimension: DIMENSION_ID_PERIOD },
{ dimension: 'twilight' },
{ dimension: 'pinkiepie' },
],
[AXIS_ID_FILTERS]: [{ dimension: DIMENSION_ID_ORGUNIT }],
}
Expand All @@ -72,11 +108,14 @@ describe('getVisualizationConfig', () => {
id: undefined,
type: 'COLUMN',
[AXIS_ID_COLUMNS]: [{ dimension: DIMENSION_ID_DATA }],
[AXIS_ID_ROWS]: [{ dimension: DIMENSION_ID_PERIOD }],
[AXIS_ID_ROWS]: [
{ dimension: DIMENSION_ID_PERIOD },
{ dimension: 'twilight' },
],
[AXIS_ID_FILTERS]: [
{ dimension: DIMENSION_ID_ORGUNIT },
{ dimension: 'rainbow' },
{ dimension: 'twilight' },
{ dimension: 'pinkiepie' },
],
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ const getVisualizationConfig = (visualization, originalType, activeType) => {
type: activeType === CHART ? VIS_TYPE_COLUMN : VIS_TYPE_PIVOT_TABLE,
})
} else if (originalType === REPORT_TABLE && activeType === CHART) {
const layout = getAdaptedUiLayoutByType(visualization, activeType)
const layout = getAdaptedUiLayoutByType(visualization, VIS_TYPE_COLUMN)
return getWithoutId({
...visualization,
...layout,
type: VIS_TYPE_COLUMN,
})
} else if (originalType === CHART && activeType === REPORT_TABLE) {
const layout = getAdaptedUiLayoutByType(visualization, activeType)
const layout = getAdaptedUiLayoutByType(
visualization,
VIS_TYPE_PIVOT_TABLE
)
return getWithoutId({
...visualization,
...layout,
Expand Down

0 comments on commit fd2f1bb

Please sign in to comment.