Skip to content

Commit 2c78208

Browse files
fix: version specific period types (#1820)
Show and hide the correct period types for different versions. Fix github code quality issue. Export new period types.
1 parent d65967d commit 2c78208

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

src/components/PeriodDimension/PeriodTransfer.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getNowInCalendar } from '@dhis2/multi-calendar-dates'
22
import { IconInfo16, NoticeBox, TabBar, Tab, Transfer } from '@dhis2/ui'
33
import PropTypes from 'prop-types'
4-
import React, { useRef, useState, useMemo } from 'react'
4+
import React, { useCallback, useRef, useState, useMemo } from 'react'
55
import PeriodIcon from '../../assets/DimensionItemIcons/PeriodIcon.js' //TODO: Reimplement the icon.js
66
import i18n from '../../locales/index.js'
77
import {
@@ -20,7 +20,15 @@ import {
2020
filterEnabledRelativePeriodTypes,
2121
} from './utils/enabledPeriodTypes.js'
2222
import { getFixedPeriodsOptions } from './utils/fixedPeriods.js'
23-
import { MONTHLY, QUARTERLY, filterPeriodTypesById } from './utils/index.js'
23+
import {
24+
FYFEB,
25+
FYAUG,
26+
FYSEP,
27+
MONTHLY,
28+
QUARTERLY,
29+
WEEKLYFRI,
30+
filterPeriodTypesById,
31+
} from './utils/index.js'
2432
import { getRelativePeriodsOptions } from './utils/relativePeriods.js'
2533

2634
const RightHeader = ({ infoBoxMessage }) => (
@@ -91,15 +99,20 @@ const PeriodTransfer = ({
9199
} else {
92100
const allFixed = getFixedPeriodsOptions(periodsSettings)
93101
const allRelative = getRelativePeriodsOptions()
102+
const v43PeriodTypes = [WEEKLYFRI, FYFEB, FYAUG, FYSEP]
103+
const allExcludedPeriodTypes = [
104+
...excludedPeriodTypes,
105+
...v43PeriodTypes,
106+
]
94107

95108
return {
96109
filteredFixedOptions: filterPeriodTypesById(
97110
allFixed,
98-
excludedPeriodTypes
111+
allExcludedPeriodTypes
99112
),
100113
filteredRelativeOptions: filterPeriodTypesById(
101114
allRelative,
102-
excludedPeriodTypes
115+
allExcludedPeriodTypes
103116
),
104117
}
105118
}
@@ -139,11 +152,14 @@ const PeriodTransfer = ({
139152
// there is still a pending decision in Temporal regarding which era to use by default: https://github.com/js-temporal/temporal-polyfill/blob/9350ee7dd0d29f329fc097debf923a517c32f813/lib/calendar.ts#L1964
140153
const defaultFixedPeriodYear = now.eraYear || now.year
141154

142-
const fixedPeriodConfig = (year) => ({
143-
offset: year - defaultFixedPeriodYear,
144-
filterFuturePeriods: false,
145-
reversePeriods: false,
146-
})
155+
const fixedPeriodConfig = useCallback(
156+
(year) => ({
157+
offset: year - defaultFixedPeriodYear,
158+
filterFuturePeriods: false,
159+
reversePeriods: false,
160+
}),
161+
[defaultFixedPeriodYear]
162+
)
147163

148164
const [userPeriods, setUserPeriods] = useState(null)
149165
const [isRelative, setIsRelative] = useState(true)
@@ -215,6 +231,7 @@ const PeriodTransfer = ({
215231
filteredRelativeOptions,
216232
filteredFixedOptions,
217233
fixedFilter.year,
234+
fixedPeriodConfig,
218235
])
219236

220237
const allPeriods = userPeriods ?? derivedPeriods

src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ export {
353353
WEEKLY,
354354
WEEKLYWED,
355355
WEEKLYTHU,
356+
WEEKLYFRI,
356357
WEEKLYSAT,
357358
WEEKLYSUN,
358359
WEEKS_THIS_YEAR,
@@ -364,10 +365,13 @@ export {
364365
SIXMONTHLYAPR,
365366
YEARLY,
366367
FINANCIAL,
367-
FYNOV,
368-
FYOCT,
369-
FYJUL,
368+
FYFEB,
370369
FYAPR,
370+
FYJUL,
371+
FYAUG,
372+
FYSEP,
373+
FYOCT,
374+
FYNOV,
371375
} from './components/PeriodDimension/utils/index.js'
372376
export {
373377
getRelativePeriodsOptionsById,

0 commit comments

Comments
 (0)