Skip to content

Commit

Permalink
fix: assigned categories and new dimension types (#576)
Browse files Browse the repository at this point in the history
* refactor: fixed to predefined dims

* fix: assigned categories updates

* chore: upgraded to Analytics v3.0.0
  • Loading branch information
martinkrulltott committed Jan 29, 2020
1 parent fe6a168 commit 2faae50
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 49 deletions.
10 changes: 8 additions & 2 deletions packages/app/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2020-01-28T14:43:38.800Z\n"
"PO-Revision-Date: 2020-01-28T14:43:38.800Z\n"
"POT-Creation-Date: 2020-01-29T07:22:55.986Z\n"
"PO-Revision-Date: 2020-01-29T07:22:55.986Z\n"

msgid "Rename successful"
msgstr ""
Expand Down Expand Up @@ -486,6 +486,12 @@ msgstr ""
msgid "Fix this problem by selecting data elements or removing Assigned Categories."
msgstr ""

msgid "Assigned Categories cannot be used as Filter"
msgstr ""

msgid "Fix this problem by moving or removing Assigned Categories."
msgstr ""

msgid "or"
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": "^2.8.6",
"@dhis2/analytics": "^3.0.0",
"@dhis2/d2-ui-core": "^6.5.1",
"@dhis2/d2-ui-file-menu": "^6.5.1",
"@dhis2/d2-ui-interpretations": "^6.5.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
DIMENSION_ID_ORGUNIT,
getAxisMaxNumberOfItems,
getDisplayNameByVisType,
filterOutFixedDimensions,
filterOutPredefinedDimensions,
} from '@dhis2/analytics'

import HideButton from '../../HideButton/HideButton'
Expand Down Expand Up @@ -272,11 +272,11 @@ export class DialogManager extends Component {
)
}

const dynamicDimensions = filterOutFixedDimensions(
const nonPredefinedDimensions = filterOutPredefinedDimensions(
Object.keys(this.props.dimensions)
)

if (dynamicDimensions.includes(dialogId)) {
if (nonPredefinedDimensions.includes(dialogId)) {
const dialogTitle =
dimensions[dialogId] && dimensions[dialogId].name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jest.mock('@dhis2/analytics', () => {
DIMENSION_ID_PERIOD: periodId,
DIMENSION_ID_ORGUNIT: ouId,
getAxisMaxNumberOfItems: () => {},
filterOutFixedDimensions: () => [],
filterOutPredefinedDimensions: () => [],
getAxisName: () => {},
getFixedDimensions: () => {},
getFixedDimensionProp: () => {},
getPredefinedDimensions: () => {},
getPredefinedDimensionProp: () => {},
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,11 @@ export class Dimensions extends Component {
getNumberOfDimensionItems = () =>
(this.props.itemsByDimension[this.state.dimensionId] || []).length

getFilteredDimensions = () =>
Object.values(this.props.dimensions).filter(
dimension => !dimension.noItems
)

render() {
return (
<div style={styles.divContainer}>
<DimensionsPanel
dimensions={this.getFilteredDimensions()}
dimensions={Object.values(this.props.dimensions)}
selectedIds={this.props.selectedIds}
disabledDimension={this.disabledDimension}
lockedDimension={this.lockedDimension}
Expand Down
18 changes: 13 additions & 5 deletions packages/app/src/components/Layout/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import WarningIcon from '@material-ui/icons/Warning'
import LockIcon from '@material-ui/icons/Lock'
import i18n from '@dhis2/d2-i18n'
import {
getFixedDimensionProp,
getPredefinedDimensionProp,
getAxisMaxNumberOfItems,
hasAxisTooManyItems,
getDisplayNameByVisType,
getAxisName,
DIMENSION_ID_ASSIGNED_CATEGORIES,
isDimensionLocked,
DIMENSION_PROP_NO_ITEMS,
} from '@dhis2/analytics'
import PropTypes from 'prop-types'

Expand Down Expand Up @@ -75,7 +76,12 @@ class Chip extends React.Component {
}

handleClick = () => {
if (!getFixedDimensionProp(this.props.dimensionId, 'noItems')) {
if (
!getPredefinedDimensionProp(
this.props.dimensionId,
DIMENSION_PROP_NO_ITEMS
)
) {
this.props.getOpenHandler(this.props.dimensionId)
}

Expand All @@ -92,8 +98,10 @@ class Chip extends React.Component {

getWrapperStyles = () => ({
...styles.chipWrapper,
...(!getFixedDimensionProp(this.props.dimensionId, 'noItems') &&
!this.props.items.length
...(!getPredefinedDimensionProp(
this.props.dimensionId,
DIMENSION_PROP_NO_ITEMS
) && !this.props.items.length
? styles.chipEmpty
: {}),
})
Expand All @@ -116,7 +124,7 @@ class Chip extends React.Component {
}

renderChipIcon = () => {
const Icon = getFixedDimensionProp(this.props.dimensionId, 'icon')
const Icon = getPredefinedDimensionProp(this.props.dimensionId, 'icon')
return Icon ? (
<Icon style={styles.fixedDimensionIcon} />
) : (
Expand Down
11 changes: 10 additions & 1 deletion packages/app/src/components/Layout/DefaultLayout/DefaultAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
getAxisName,
isDimensionLocked,
canDimensionBeAddedToAxis,
getPredefinedDimensionProp,
DIMENSION_PROP_NO_ITEMS,
} from '@dhis2/analytics'
import { withStyles } from '@material-ui/core'

Expand Down Expand Up @@ -50,7 +52,14 @@ class Axis extends React.Component {
const items = itemsByDimension[dimensionId]
const hasNoItems = Boolean(!items || !items.length)

if (source === SOURCE_DIMENSIONS && hasNoItems) {
if (
source === SOURCE_DIMENSIONS &&
hasNoItems &&
!getPredefinedDimensionProp(
dimensionId,
DIMENSION_PROP_NO_ITEMS
)
) {
onDropWithoutItems(dimensionId)
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/app/src/components/Visualization/Visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import { acSetLoadError } from '../../actions/loader'

import StartScreen from './StartScreen'
import {
AssignedCategoriesError,
AssignedCategoriesDataElementsError,
GenericServerError,
EmptyResponseError,
AssignedCategoriesAsFilterError,
} from '../../modules/error'

export class Visualization extends Component {
Expand All @@ -35,7 +36,9 @@ export class Visualization extends Component {
let error
if (response) {
if (response.errorCode === 'E7114') {
error = new AssignedCategoriesError()
error = new AssignedCategoriesDataElementsError()
} else if (response.errorCode === 'E7110') {
error = new AssignedCategoriesAsFilterError()
} else {
error = response
}
Expand Down
8 changes: 6 additions & 2 deletions packages/app/src/modules/current.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
dimensionCreate,
layoutGetDimensionItems,
layoutReplaceDimension,
getFixedDimensionProp,
getPredefinedDimensionProp,
DIMENSION_PROP_NO_ITEMS,
} from '@dhis2/analytics'

import options from './options'
Expand All @@ -27,7 +28,10 @@ export const getAxesFromUi = ui =>
[axisId]: dimensionIds
.map(dimensionId =>
hasItems(ui.itemsByDimension, dimensionId) ||
getFixedDimensionProp(dimensionId, 'noItems')
getPredefinedDimensionProp(
dimensionId,
DIMENSION_PROP_NO_ITEMS
)
? dimensionCreate(
dimensionId,
ui.itemsByDimension[dimensionId]
Expand Down
14 changes: 13 additions & 1 deletion packages/app/src/modules/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class GenericServerError extends VisualizationError {
}
}

export class AssignedCategoriesError extends VisualizationError {
export class AssignedCategoriesDataElementsError extends VisualizationError {
constructor() {
super(
GenericError,
Expand All @@ -125,6 +125,18 @@ export class AssignedCategoriesError extends VisualizationError {
}
}

export class AssignedCategoriesAsFilterError extends VisualizationError {
constructor() {
super(
GenericError,
i18n.t('Assigned Categories cannot be used as Filter'),
i18n.t(
'Fix this problem by moving or removing Assigned Categories.'
)
)
}
}

const getAvailableAxesDescription = visType => {
const axes = getAvailableAxes(visType)
let axesDescription = ''
Expand Down
13 changes: 2 additions & 11 deletions packages/app/src/modules/layoutAdapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
AXIS_ID_FILTERS,
DIMENSION_ID_DATA,
DIMENSION_ID_PERIOD,
DIMENSION_ID_ASSIGNED_CATEGORIES,
} from '@dhis2/analytics'

// Transform from ui.layout to pie layout format
Expand All @@ -27,11 +26,7 @@ export const yearOverYearLayoutAdapter = layout => ({
...layout[AXIS_ID_FILTERS],
...layout[AXIS_ID_COLUMNS],
...layout[AXIS_ID_ROWS],
].filter(
dim =>
dim !== DIMENSION_ID_PERIOD &&
dim !== DIMENSION_ID_ASSIGNED_CATEGORIES
),
].filter(dim => dim !== DIMENSION_ID_PERIOD),
})

// Transform from ui.layout to single value layout format
Expand All @@ -46,10 +41,6 @@ export const singleValueLayoutAdapter = layout => {
...layout[AXIS_ID_FILTERS],
...columns,
...rows,
].filter(
dim =>
dim !== DIMENSION_ID_DATA &&
dim !== DIMENSION_ID_ASSIGNED_CATEGORIES
),
].filter(dim => dim !== DIMENSION_ID_DATA),
}
}
8 changes: 6 additions & 2 deletions packages/app/src/modules/layoutValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
VIS_TYPE_PIE,
VIS_TYPE_GAUGE,
VIS_TYPE_SINGLE_VALUE,
getFixedDimensionProp,
getPredefinedDimensionProp,
dimensionIsValid,
layoutGetDimension,
DIMENSION_ID_DATA,
DIMENSION_PROP_NO_ITEMS,
} from '@dhis2/analytics'

import { BASE_FIELD_YEARLY_SERIES } from './fields/baseFields'
Expand All @@ -25,7 +26,10 @@ const isAxisValid = axis =>
AXIS.isValid(axis) &&
axis.some(axisItem =>
dimensionIsValid(axisItem, {
requireItems: !getFixedDimensionProp(axisItem.dimension, 'noItems'),
requireItems: !getPredefinedDimensionProp(
axisItem.dimension,
DIMENSION_PROP_NO_ITEMS
),
})
)

Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/reducers/__tests__/dimensions.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getFixedDimensions } from '@dhis2/analytics'
import { getPredefinedDimensions } from '@dhis2/analytics'

import reducer, { SET_DIMENSIONS } from '../dimensions'

Expand All @@ -12,7 +12,7 @@ describe('reducer: dimensions', () => {

it('should return the default state', () => {
const actualState = reducer(undefined, { type: 'NO_MATCH' })
expect(actualState).toEqual(getFixedDimensions())
expect(actualState).toEqual(getPredefinedDimensions())
})

it(`${SET_DIMENSIONS}: should set the new dimensions object`, () => {
Expand All @@ -25,7 +25,7 @@ describe('reducer: dimensions', () => {
)

const expectedState = {
...getFixedDimensions(),
...getPredefinedDimensions(),
...dimensionsToSet,
}

Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/reducers/dimensions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getFixedDimensions } from '@dhis2/analytics'
import { getPredefinedDimensions } from '@dhis2/analytics'

export const SET_DIMENSIONS = 'SET_DIMENSIONS'
export const SET_SELECTED_DIMENSION = 'SET_SELECTED_DIMENSION'

const DEFAULT_DIMENSIONS = getFixedDimensions()
const DEFAULT_DIMENSIONS = getPredefinedDimensions()

export default (state = DEFAULT_DIMENSIONS, action) => {
switch (action.type) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"module": "./build/es/lib.js",
"license": "BSD-3-Clause",
"dependencies": {
"@dhis2/analytics": "^2.8.6",
"@dhis2/analytics": "^3.0.0",
"@material-ui/core": "^3.1.2",
"d2-analysis": "33.2.11",
"lodash-es": "^4.17.11",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1442,10 +1442,10 @@
react-beautiful-dnd "^10.1.1"
styled-jsx "^3.2.1"

"@dhis2/analytics@^2.8.6":
version "2.8.6"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-2.8.6.tgz#15102d5155ba933e494b8b1409e81058899e1863"
integrity sha512-YY3f+RuCuSblyriwjF5w98P5zSse31QwHG9B8/oGIKkAxS5yZL7N4XWE1woNTz9V71x2yFl9pCOYTM0QfVp9CA==
"@dhis2/analytics@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-3.0.0.tgz#928074eedda763aa4666ac48773a4a73a680ad94"
integrity sha512-KSPJcd7EsOtn0uJONaFboSUNSiKSUQeoqFqKgFnzgaqp0+mAEj48xBhTycujkr+HphjrNCLobMgwyoUX761fuw==
dependencies:
"@dhis2/d2-i18n" "^1.0.4"
"@dhis2/d2-ui-org-unit-dialog" "^6.3.2"
Expand Down

0 comments on commit 2faae50

Please sign in to comment.