feat: use enabled period types #1801
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.




Architecture
I decided to modify the existing components in @dhis2/analytics to communicate with the server and toggle on server version. Apps like Data Visualizer can still use PeriodDimension and release with min version 2.40 without problems.
For <=42 nothing has changed.
In 43+ the enabled PTs are fetched from the server. These are used to populate the fixed period types. For relative periods it's a bit more complicated. The following considerations have been made:
Claude Code suggested a few improvements:
Data fetching fix
The original code used useDataQuery({ skip: true }) to conditionally skip queries on pre-v43 servers. This doesn't work — useDataQuery has no skip mechanism on the query
object, and useStaticInput freezes the first query reference. Replaced with a single combined query using { lazy: true } + useEffect, which is the established pattern in
this codebase (see OpenFileDialog, AboutAOUnit, etc.). This also reduces three network requests to one.
Period options filtering consolidated in PeriodTransfer
FixedPeriodFilter and RelativePeriodFilter were computing their own filtered period lists internally, duplicating logic already in PeriodTransfer. Now PeriodTransfer
always passes pre-filtered availableOptions to both filter components, making them pure presentation components. FixedPeriodSelect (the only other consumer of
FixedPeriodFilter) now computes availableOptions from its allowedPeriodTypes prop before passing them down.
Tab toggle bug fix
onIsRelativeClick was using the raw getRelativePeriodsOptionsById/getFixedPeriodsOptionsById helpers, bypassing the filtered options. On v43+ servers with restricted
period types, switching between relative/fixed tabs could show periods from disabled types.
Screenshots v42
No changes:
Screenshots v43
Respects the enabled types: