Skip to content

Commit

Permalink
fix: Pivot Table allow empty col or row (#789)
Browse files Browse the repository at this point in the history
* New validation that let's through Pivot Table with only row or column
* New error message for Pivot Table with neither row nor column
* Upgrades Analytics dep to v4.3.11 to enable single axis tables
  • Loading branch information
martinkrulltott authored Mar 10, 2020
1 parent 00f385e commit ee337a5
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 11 deletions.
8 changes: 8 additions & 0 deletions packages/app/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,14 @@ msgstr ""
msgid "Add at least one item to {{axisName}}."
msgstr ""

msgid "{{columnsAxisName}} and {{rowsAxisName}} are empty"
msgstr ""

msgid ""
"Add at least one item to {{columnsAxisName}} or {{rowsAxisName}} to create "
"a {{visualizationType}}."
msgstr ""

msgid "No period selected"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"redux-mock-store": "^1.5.3"
},
"dependencies": {
"@dhis2/analytics": "^4.3.8",
"@dhis2/analytics": "^4.3.11",
"@dhis2/app-runtime": "*",
"@dhis2/d2-i18n": "*",
"@dhis2/d2-ui-core": "^6.5.5",
Expand Down
32 changes: 32 additions & 0 deletions packages/app/src/modules/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,38 @@ export class NoCategoryError extends VisualizationError {
}
}

export class NoSeriesOrCategoryError extends VisualizationError {
constructor(visType) {
super(
EmptyBox,
i18n.t(`{{columnsAxisName}} and {{rowsAxisName}} are empty`, {
columnsAxisName: getAxisNameByLayoutType(
AXIS_ID_COLUMNS,
getLayoutTypeByVisType(visType)
),
rowsAxisName: getAxisNameByLayoutType(
AXIS_ID_ROWS,
getLayoutTypeByVisType(visType)
),
}),
i18n.t(
'Add at least one item to {{columnsAxisName}} or {{rowsAxisName}} to create a {{visualizationType}}.',
{
columnsAxisName: getAxisNameByLayoutType(
AXIS_ID_COLUMNS,
getLayoutTypeByVisType(visType)
),
rowsAxisName: getAxisNameByLayoutType(
AXIS_ID_ROWS,
getLayoutTypeByVisType(visType)
),
visualizationType: getDisplayNameByVisType(visType),
}
)
)
}
}

export class NoPeriodError extends VisualizationError {
constructor(visType) {
super(
Expand Down
16 changes: 14 additions & 2 deletions packages/app/src/modules/layoutValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
VIS_TYPE_PIE,
VIS_TYPE_GAUGE,
VIS_TYPE_SINGLE_VALUE,
VIS_TYPE_PIVOT_TABLE,
getPredefinedDimensionProp,
dimensionIsValid,
layoutGetDimension,
Expand All @@ -19,6 +20,7 @@ import {
NoCategoryError,
NoPeriodError,
NoDataError,
NoSeriesOrCategoryError,
} from './error'

// Layout validation helper functions
Expand Down Expand Up @@ -55,6 +57,16 @@ const validateDefaultLayout = layout => {
)
}

const validatePivotTableLayout = layout => {
if (!isAxisValid(layout.columns) && !isAxisValid(layout.rows)) {
throw new NoSeriesOrCategoryError(layout.type)
}
validateDimension(
layoutGetDimension(layout, DIMENSION_ID_PERIOD),
new NoPeriodError(layout.type)
)
}

const validateYearOverYearLayout = layout => {
validateDimension(
layoutGetDimension(layout, DIMENSION_ID_DATA),
Expand Down Expand Up @@ -93,8 +105,6 @@ const validateSingleValueLayout = layout => {
)
}

// TODO: Add validatePivotLayout

export const validateLayout = layout => {
switch (layout.type) {
case VIS_TYPE_PIE:
Expand All @@ -105,6 +115,8 @@ export const validateLayout = layout => {
case VIS_TYPE_SINGLE_VALUE:
case VIS_TYPE_GAUGE:
return validateSingleValueLayout(layout)
case VIS_TYPE_PIVOT_TABLE:
return validatePivotTableLayout(layout)
default:
return validateDefaultLayout(layout)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"access": "public"
},
"dependencies": {
"@dhis2/analytics": "^4.3.8",
"@dhis2/analytics": "^4.3.11",
"@material-ui/core": "^3.1.2",
"d2-analysis": "33.2.11",
"lodash-es": "^4.17.11"
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1417,9 +1417,9 @@
lodash.once "^4.1.1"

"@dhis2/analytics@^4.0.1":
version "4.3.6"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-4.3.6.tgz#67e301b45a81e12502051f0a1533ae07ad580b28"
integrity sha512-t4nI8oa3Mp5LlhPuYIEaV4TmdGLYnsa1zhCAHzC0dWjSmp9/fy/+0LXxCguBLagnJKL8ONrMob1X07L1GIvz4A==
version "4.3.10"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-4.3.10.tgz#32844e1832ba76db4cf570df96592643482036bf"
integrity sha512-yKu1QnnMJbI3I4eM7P4A0meSk533KfS4mzgB7HxaVxg/UTSQdPQk67jRWwSqfjjv/atv8pmWOpSQQ99Ni/ePug==
dependencies:
"@dhis2/d2-i18n" "^1.0.4"
"@dhis2/d2-ui-org-unit-dialog" "^6.5.9"
Expand All @@ -1436,10 +1436,10 @@
resize-observer-polyfill "^1.5.1"
styled-jsx "^3.2.1"

"@dhis2/analytics@^4.3.8":
version "4.3.8"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-4.3.8.tgz#3fca235bc36cd09d1df78e3f15946b3a46aec2f7"
integrity sha512-Gxm00ECiOzXNluJsPMp7J5VKCJUz0cIqENbmhu2Osm04MvfNtO2YmS9SghjfZIP7GB7eFJDDz/eRlomXDwy3yw==
"@dhis2/analytics@^4.3.11":
version "4.3.11"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-4.3.11.tgz#72874f23478d9f76f906fd975ab101e37daac024"
integrity sha512-2uVw+4zoSpZv5xLbQFcXdeUzhh/JFjO0fJJ675d2L9k6hVZe6ZMlaBVEdhZe2m19ruP4kj/Z6fePCaORqc1Now==
dependencies:
"@dhis2/d2-i18n" "^1.0.4"
"@dhis2/d2-ui-org-unit-dialog" "^6.5.9"
Expand Down

0 comments on commit ee337a5

Please sign in to comment.