Skip to content

Commit

Permalink
fix: allow ou without items
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrulltott committed Mar 1, 2024
1 parent f3ec5ab commit bf99ae0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
13 changes: 9 additions & 4 deletions cypress/integration/layoutValidation.cy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DIMENSION_ID_ORGUNIT } from '@dhis2/analytics'
import { E2E_PROGRAM } from '../data/index.js'
import {
clickAddRemoveMainDimension,
Expand All @@ -8,6 +9,11 @@ import {
selectTrackedEntityWithType,
} from '../helpers/dimensions.js'
import { clickMenubarUpdateButton } from '../helpers/menubar.js'
import {
clickOrgUnitDimensionModalUpdateButton,
deselectUserOrgUnit,
openOuDimension,
} from '../helpers/orgUnit.js'
import { goToStartPage } from '../helpers/startScreen.js'
import { expectTableToBeVisible } from '../helpers/table.js'

Expand Down Expand Up @@ -107,10 +113,9 @@ describe('layout validation', () => {

// add org unit to columns without any items selected
clickAddRemoveMainDimension('Registration org. unit')
// FIXME: uncomment the following lines once https://dhis2.atlassian.net/browse/DHIS2-16381 is fixed
// openOuDimension(DIMENSION_ID_ORGUNIT)
// deselectUserOrgUnit('User organisation unit')
// clickOrgUnitDimensionModalUpdateButton()
openOuDimension(DIMENSION_ID_ORGUNIT)
deselectUserOrgUnit('User organisation unit')
clickOrgUnitDimensionModalUpdateButton()

clickMenubarUpdateButton()

Expand Down
26 changes: 20 additions & 6 deletions src/components/Visualization/analyticsQueryTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AXIS_ID_COLUMNS,
AXIS_ID_ROWS,
AXIS_ID_FILTERS,
DIMENSION_ID_ORGUNIT,
} from '@dhis2/analytics'
import {
DIMENSION_ID_PROGRAM_STATUS,
Expand All @@ -13,7 +14,10 @@ import {
} from '../../modules/dimensionConstants.js'
import { formatDimensionId } from '../../modules/dimensionId.js'
import { getRequestOptions } from '../../modules/getRequestOptions.js'
import { getHeadersMap } from '../../modules/visualization.js'
import {
OUTPUT_TYPE_TRACKED_ENTITY,
getHeadersMap,
} from '../../modules/visualization.js'

const excludedDimensions = [
DIMENSION_ID_CREATED,
Expand All @@ -23,7 +27,7 @@ const excludedDimensions = [

const isTimeDimension = (dimensionId) => DIMENSION_IDS_TIME.has(dimensionId)

const adaptDimensions = (dimensions, parameters) => {
const adaptDimensions = (dimensions, parameters, outputType) => {
const adaptedDimensions = []
dimensions.forEach((dimensionObj) => {
const dimensionId = dimensionObj.dimension
Expand All @@ -32,7 +36,9 @@ const adaptDimensions = (dimensions, parameters) => {
isTimeDimension(dimensionId) ||
dimensionId === DIMENSION_ID_EVENT_STATUS ||
dimensionId === DIMENSION_ID_PROGRAM_STATUS ||
dimensionId === DIMENSION_ID_CREATED
dimensionId === DIMENSION_ID_CREATED ||
(dimensionId === DIMENSION_ID_ORGUNIT &&
outputType === OUTPUT_TYPE_TRACKED_ENTITY)
) {
if (dimensionObj.items?.length) {
const items = dimensionObj.items?.map((item) => item.id)
Expand All @@ -42,6 +48,8 @@ const adaptDimensions = (dimensions, parameters) => {
Array.isArray(parameters[dimensionId])
) {
parameters[dimensionId].push(...items)
} else if (dimensionId === DIMENSION_ID_ORGUNIT) {
adaptedDimensions.push(dimensionObj)
} else {
parameters[dimensionId] = items
}
Expand All @@ -61,12 +69,18 @@ export const getAdaptedVisualization = (visualization) => {

const adaptedColumns = adaptDimensions(
visualization[AXIS_ID_COLUMNS],
parameters
parameters,
outputType
)
const adaptedRows = adaptDimensions(
visualization[AXIS_ID_ROWS],
parameters,
outputType
)
const adaptedRows = adaptDimensions(visualization[AXIS_ID_ROWS], parameters)
const adaptedFilters = adaptDimensions(
visualization[AXIS_ID_FILTERS],
parameters
parameters,
outputType
)

const dimensionHeadersMap = getHeadersMap(visualization)
Expand Down

0 comments on commit bf99ae0

Please sign in to comment.