diff --git a/src/actions/itemFilters.js b/src/actions/itemFilters.js index 2b5c1b20c..1e4576a0f 100644 --- a/src/actions/itemFilters.js +++ b/src/actions/itemFilters.js @@ -6,6 +6,8 @@ import { export const FILTER_ORG_UNIT = 'ou' +export const FILTER_PE = 'pe' + // actions export const acAddItemFilter = (filter) => ({ diff --git a/src/components/Item/AppItem/__tests__/getIframeSrc.spec.js b/src/components/Item/AppItem/__tests__/getIframeSrc.spec.js index fd85d6037..3807f1dea 100644 --- a/src/components/Item/AppItem/__tests__/getIframeSrc.spec.js +++ b/src/components/Item/AppItem/__tests__/getIframeSrc.spec.js @@ -103,4 +103,64 @@ describe('getIframeSrc', () => { `${expectedSrc}&userOrgUnit=USER_ORGUNIT_CHILDREN,USER_ORGUNIT_GRANDCHILDREN,USER_ORGUNIT` ) }) + + it('only period filter with a single value', () => { + const peFilter = [{ id: 'LAST_MONTH' }]; + + const src = getIframeSrc(appDetails, dashboardItem, { pe: peFilter }); + expect(src).toEqual(`${expectedSrc}&period=LAST_MONTH`); + }); + + it('only period filter with multiple values', () => { + const peFilter = [ + { id: 'LAST_MONTH' }, + { id: 'LAST_3_MONTHS' }, + ]; + + const src = getIframeSrc(appDetails, dashboardItem, { pe: peFilter }); + expect(src).toEqual(`${expectedSrc}&period=LAST_MONTH,LAST_3_MONTHS`); + }); + + it('period filter and org unit filter', () => { + const peFilter = [{ id: 'LAST_MONTH' }]; + const ouFilter = [ + { + id: 'fdc6uOvgoji', + path: '/ImspTQPwCqd/fdc6uOvgoji', + name: 'Bombali', + }, + ]; + + const src = getIframeSrc(appDetails, dashboardItem, { pe: peFilter, ou: ouFilter }); + expect(src).toEqual(`${expectedSrc}&userOrgUnit=fdc6uOvgoji&period=LAST_MONTH`); + }); + + it('period filter with multiple values and org unit filter', () => { + const peFilter = [ + { id: 'LAST_MONTH' }, + { id: 'LAST_3_MONTHS' }, + ]; + const ouFilter = [ + { + id: 'fdc6uOvgoji', + path: '/ImspTQPwCqd/fdc6uOvgoji', + name: 'Bombali', + }, + { + id: 'lc3eMKXaEfw', + path: '/ImspTQPwCqd/lc3eMKXaEfw', + name: 'Bonthe', + }, + ]; + + const src = getIframeSrc(appDetails, dashboardItem, { pe: peFilter, ou: ouFilter }); + expect(src).toEqual(`${expectedSrc}&userOrgUnit=fdc6uOvgoji,lc3eMKXaEfw&period=LAST_MONTH,LAST_3_MONTHS`); + }); + + it('empty pe filter', () => { + const peFilter = []; + + const src = getIframeSrc(appDetails, dashboardItem, { pe: peFilter }); + expect(src).toEqual(expectedSrc); + }); }) diff --git a/src/components/Item/AppItem/getIframeSrc.js b/src/components/Item/AppItem/getIframeSrc.js index ae2b1c2c8..0c7a559b6 100644 --- a/src/components/Item/AppItem/getIframeSrc.js +++ b/src/components/Item/AppItem/getIframeSrc.js @@ -1,4 +1,4 @@ -import { FILTER_ORG_UNIT } from '../../../actions/itemFilters.js' +import { FILTER_ORG_UNIT, FILTER_PE } from '../../../actions/itemFilters.js' export const getIframeSrc = (appDetails, item, itemFilters) => { let iframeSrc = `${appDetails.launchUrl}?dashboardItemId=${item.id}` @@ -11,5 +11,12 @@ export const getIframeSrc = (appDetails, item, itemFilters) => { iframeSrc += `&userOrgUnit=${ouIds.join(',')}` } + // Add period (pe) to iframeSrc + if (itemFilters[FILTER_PE]?.length) { + const peValues = itemFilters[FILTER_PE].map(x => x.id).join(','); + iframeSrc += `&period=${peValues}`; + } + + return iframeSrc }