Skip to content

Commit

Permalink
Merge branch 'master' into feat/dashboard-plugin-wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo authored Dec 4, 2024
2 parents 1b6dda6 + 0410cfc commit b6fbb11
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [26.9.3](https://github.com/dhis2/analytics/compare/v26.9.2...v26.9.3) (2024-11-22)


### Bug Fixes

* enable ou tree and levels/groups with user orgunits (DHIS2-18066) ([#1702](https://github.com/dhis2/analytics/issues/1702)) ([f58c708](https://github.com/dhis2/analytics/commit/f58c708af214f13147e5c95ede8545fc5c03bc57))

## [26.9.2](https://github.com/dhis2/analytics/compare/v26.9.1...v26.9.2) (2024-11-03)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/analytics",
"version": "26.9.2",
"version": "26.9.3",
"main": "./build/cjs/index.js",
"module": "./build/es/index.js",
"exports": {
Expand Down
16 changes: 2 additions & 14 deletions src/components/OrgUnitDimension/OrgUnitDimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ const OrgUnitDimension = ({
let result = [...selected]

if (checked && DYNAMIC_ORG_UNITS.includes(id)) {
result = [
...result.filter((item) => DYNAMIC_ORG_UNITS.includes(item.id)),
{ id, displayName },
]
result = [...result, { id, displayName }]
} else if (checked) {
result.push({ id, path, name: displayName })
} else {
Expand Down Expand Up @@ -236,13 +233,7 @@ const OrgUnitDimension = ({
/>
</div>
)}
<div
className={cx('orgUnitTreeWrapper', {
disabled: selected.some((item) =>
DYNAMIC_ORG_UNITS.includes(item.id)
),
})}
>
<div className="orgUnitTreeWrapper">
<OrganisationUnitTree
roots={roots}
initiallyExpanded={[
Expand Down Expand Up @@ -276,9 +267,6 @@ const OrgUnitDimension = ({
</div>
<div
className={cx('selectsWrapper', {
disabled: selected.some((item) =>
DYNAMIC_ORG_UNITS.includes(item.id)
),
hidden: hideLevelSelect && hideGroupSelect,
})}
>
Expand Down
59 changes: 59 additions & 0 deletions src/components/OrgUnitDimension/__tests__/OrgUnitDimension.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { shallow } from 'enzyme'
import React from 'react'
import OrgUnitDimension from '../OrgUnitDimension.js'

describe('The OrgUnitDimension component', () => {
let props
let shallowOrgUnitDimension

const getWrapper = () => {
if (!shallowOrgUnitDimension) {
shallowOrgUnitDimension = shallow(<OrgUnitDimension {...props} />)
}
return shallowOrgUnitDimension
}

beforeEach(() => {
props = {
roots: [],
selected: [],
onSelect: jest.fn(),
hideGroupSelect: false,
hideLevelSelect: false,
hideUserOrgUnits: false,
warning: '',
}
shallowOrgUnitDimension = undefined
})

it('matches the snapshot', () => {
const wrapper = getWrapper()
expect(wrapper).toMatchSnapshot()
})

it('calls onSelect when an organisation unit is selected', () => {
const wrapper = getWrapper()
const orgUnitTree = wrapper.find('OrganisationUnitTree')
const testOrgUnit = {
id: 'testId',
path: '/testPath',
displayName: 'Test Org Unit',
checked: true,
}
orgUnitTree.props().onChange(testOrgUnit)
expect(props.onSelect).toHaveBeenCalledWith({
dimensionId: 'ou',
items: [{ id: 'testId', path: '/testPath', name: 'Test Org Unit' }],
})
})

it('calls onSelect with an empty array when selection is cleared', () => {
const wrapper = getWrapper()
const deselectButton = wrapper.find('Button[onClick]')
deselectButton.simulate('click')
expect(props.onSelect).toHaveBeenCalledWith({
dimensionId: 'ou',
items: [],
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`The OrgUnitDimension component matches the snapshot 1`] = `
<div
className="container"
>
<div
className="userOrgUnitsWrapper"
>
<Checkbox
checked={false}
dataTest="dhis2-uicore-checkbox"
dense={true}
indeterminate={false}
label="User organisation unit"
onChange={[Function]}
/>
<Checkbox
checked={false}
dataTest="dhis2-uicore-checkbox"
dense={true}
indeterminate={false}
label="User sub-units"
onChange={[Function]}
/>
<Checkbox
checked={false}
dataTest="dhis2-uicore-checkbox"
dense={true}
indeterminate={false}
label="User sub-x2-units"
onChange={[Function]}
/>
</div>
<div
className="orgUnitTreeWrapper"
>
<OrganisationUnitTree
dataTest="org-unit-tree"
filter={Array []}
highlighted={Array []}
initiallyExpanded={Array []}
onChange={[Function]}
renderNodeLabel={[Function]}
roots={Array []}
selected={Array []}
/>
</div>
<div
className="selectsWrapper"
>
<MultiSelect
dataTest="org-unit-level-select"
dense={true}
loading={true}
onChange={[Function]}
placeholder="Select a level"
selected={Array []}
/>
<MultiSelect
dataTest="org-unit-group-select"
dense={true}
loading={true}
onChange={[Function]}
placeholder="Select a group"
selected={Array []}
/>
</div>
<div
className="summaryWrapper"
>
<span
className="summaryText"
>
Nothing selected
</span>
<div
className="deselectButton"
>
<Button
dataTest="dhis2-uicore-button"
disabled={true}
onClick={[Function]}
secondary={true}
small={true}
type="button"
>
Deselect all
</Button>
</div>
</div>
<style />
</div>
`;
1 change: 1 addition & 0 deletions src/components/PivotTable/PivotTableTitleRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PivotTableTitleRow } from './PivotTableTitleRow.js'

export const PivotTableTitleRows = ({ clippingResult, width }) => {
const engine = usePivotTableEngine()

return (
<>
{engine.options.title ? (
Expand Down
11 changes: 11 additions & 0 deletions src/modules/__tests__/getOuLevelAndGroupText.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,15 @@ describe('getOuLevelAndGroupText', () => {
'Fruit and Veggies groups - Second floor levels'
)
})

it('grabs name for user orgunits from items when not present in metaData', () => {
filter.items = [
{ id: 'USER_ORGUNIT', name: 'User organisation unit' },
{ id: 'LEVEL-2nd-floor' },
]

expect(getOuLevelAndGroupText(filter, metaData)).toEqual(
'Second floor levels in User organisation unit'
)
})
})
4 changes: 3 additions & 1 deletion src/modules/getOuLevelAndGroupText.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export const getOuLevelAndGroupText = (filter, metaData) => {

const getLevelAndGroupText = (items, metaData, isLevel) => {
const getNameFromMetadata = (id) =>
metaData.items[id] ? metaData.items[id].name : id
metaData.items[id]
? metaData.items[id].name
: items.find((item) => item.id === id)?.name || id

const dynamicOuItems = items.filter((item) =>
isLevel
Expand Down

0 comments on commit b6fbb11

Please sign in to comment.