Skip to content

Commit

Permalink
fix: update recuder to handle empty axes (#630)
Browse files Browse the repository at this point in the history
* fix: make sure empty arrays are not shifted

* fix: change test to cover empty array

Co-authored-by: Martin <martin@moid.se>
  • Loading branch information
janhenrikoverland and martinkrulltott committed Feb 11, 2020
1 parent 8b9ec45 commit 077dd68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 13 additions & 4 deletions packages/app/src/modules/__tests__/layoutAdapters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,25 @@ describe('defaultLayoutAdapter', () => {
it('should move all extra dimensions in columns and rows to filters', () => {
const initialState = {
[AXIS_ID_COLUMNS]: [DIMENSION_ID_DATA, someId],
[AXIS_ID_ROWS]: [DIMENSION_ID_PERIOD, otherId],
[AXIS_ID_FILTERS]: [DIMENSION_ID_ORGUNIT],
[AXIS_ID_ROWS]: [],
[AXIS_ID_FILTERS]: [
DIMENSION_ID_PERIOD,
DIMENSION_ID_ORGUNIT,
otherId,
],
}

const actualState = defaultLayoutAdapter(initialState)

const expectedState = {
[AXIS_ID_COLUMNS]: [DIMENSION_ID_DATA],
[AXIS_ID_ROWS]: [DIMENSION_ID_PERIOD],
[AXIS_ID_FILTERS]: [DIMENSION_ID_ORGUNIT, someId, otherId],
[AXIS_ID_ROWS]: [],
[AXIS_ID_FILTERS]: [
DIMENSION_ID_PERIOD,
DIMENSION_ID_ORGUNIT,
otherId,
someId,
],
}

expect(actualState).toEqual(expectedState)
Expand Down
10 changes: 7 additions & 3 deletions packages/app/src/modules/layoutAdapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const defaultLayoutAdapter = layout => {
const rows = layout[AXIS_ID_ROWS].slice()

return {
[AXIS_ID_COLUMNS]: [columns.shift()],
[AXIS_ID_ROWS]: [rows.shift()],
[AXIS_ID_COLUMNS]: columns.length ? [columns.shift()] : columns,
[AXIS_ID_ROWS]: rows.length ? [rows.shift()] : rows,
[AXIS_ID_FILTERS]: [...layout[AXIS_ID_FILTERS], ...columns, ...rows],
}
}
Expand All @@ -24,7 +24,11 @@ export const pieLayoutAdapter = layout => {
const rows = layout[AXIS_ID_ROWS].slice()

return {
[AXIS_ID_COLUMNS]: [columns.shift() || rows.shift()],
[AXIS_ID_COLUMNS]: columns.length
? [columns.shift()]
: rows.length
? [rows.shift()]
: [],
[AXIS_ID_ROWS]: [],
[AXIS_ID_FILTERS]: [...layout[AXIS_ID_FILTERS], ...columns, ...rows],
}
Expand Down

0 comments on commit 077dd68

Please sign in to comment.