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

fix: force type COLUMN when viewing table as chart [DHIS2-9599] #1317

Merged
merged 6 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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