Skip to content

Feature: Add missing dhis2 periods#385

Open
nshandra wants to merge 19 commits intodevelopmentfrom
feat/add-missing-dhis2-periods
Open

Feature: Add missing dhis2 periods#385
nshandra wants to merge 19 commits intodevelopmentfrom
feat/add-missing-dhis2-periods

Conversation

@nshandra
Copy link
Copy Markdown

@nshandra nshandra commented Dec 23, 2025

📌 References

📝 Implementation

Added the following dataSet periods:

  • WeeklyWednesday
  • WeeklyThursday
  • WeeklySaturday
  • WeeklySunday
  • BiWeekly
  • BiMonthly
  • QuarterlyNov
  • SixMonthly
  • SixMonthlyApril
  • SixMonthlyNov

Added tests for all periods.

🔥 Notes for the reviewer

📹 Screenshots/Screen capture

📑 Others

#869b9v6pp

@nshandra nshandra self-assigned this Dec 23, 2025
@ifoche
Copy link
Copy Markdown
Member

ifoche commented Dec 23, 2025

@bundlemon
Copy link
Copy Markdown

bundlemon Bot commented Dec 23, 2025

BundleMon

No change in files bundle size

Groups updated (1)
Status Path Size Limits
Build Folder
./**/*
1.72MB (+1.43KB +0.08%) +20%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@nshandra nshandra marked this pull request as ready for review January 13, 2026 19:30
@nshandra nshandra requested a review from adrianq January 13, 2026 19:32
@adrianq adrianq requested a review from xurxodev March 19, 2026 12:15
Copy link
Copy Markdown

@xurxodev xurxodev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @nshandra

This PR expands the supported DHIS2 dataset period types and adds a new TypeScript implementation of buildAllPossiblePeriods, along with Jest coverage for all newly added variants.

It's great.

I've found some issues to review.

1. Should fix

  • src/domain/entities/DataForm.ts declares periodType?: DataFormPeriod, but src/webapp/utils/periods.ts can throw for missing/unsupported periodType.
    buildAllPossiblePeriods should not throw when periodType is missing; either accept periodType?: DataFormPeriod and return [], or add an early guard in the function.
  • Improve type safety/readability in src/webapp/utils/periods.ts and push it towards a more functional/immutable style without introducing mutable let state. It's safe this change because now we have unit test. Examples:
    • eliminate let current; in generateSixMonthlyNovPeriods by computing current as a const expression (ternary) and, where feasible, use clone().add(...) to avoid mutating Moment instances;
    • type the accumulator/output arrays explicitly (e.g. const dates: string[] = []) so the contract is clear at a glance;
    • make intermediate values explicit/typed in helpers (so the types of start/end/current and formatting pieces are obvious during review).

2. Recommendations non blocking

  • Tests status: src/test/utils/periods.spec.ts covers the newly added period variants and passes (yarn test --runInBand src/test/utils/periods.spec.ts). Consider adding a couple more edge cases (e.g. startDate > endDate) to validate robustness.

@nshandra
Copy link
Copy Markdown
Author

nshandra commented Apr 15, 2026

@xurxodev

Added:

  • Period input validation tests
  • Leap day and ISO weeks tests
  • DataFormPeriod guard that removes template selection if the template has an incompatible periodType.

Refactor:

  • improve type safety and inmutability in src/webapp/utils/periods.ts

@nshandra nshandra requested a review from xurxodev April 15, 2026 11:51
Copy link
Copy Markdown

@xurxodev xurxodev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @nshandra

The following items emerged from the commits that addressed the first review round.

  1. Should fix

1.1. FinancialType and WeeklyPeriodType duplicate DataFormPeriod subsets

src/webapp/utils/periods.ts:233 defines type FinancialType = "FinancialApril" | "FinancialJuly" | "FinancialOct" | "FinancialNov" and WeeklyPeriodType at line 77. These are subsets of DataFormPeriod but defined
independently — if a new financial or weekly period is added to dataFormPeriods, these local types won't update. Extract them from DataFormPeriod using Extract<>:

type FinancialType = Extract<DataFormPeriod, Financial${string}>;
type WeeklyPeriodType = Extract<DataFormPeriod, "Weekly" | Weekly${string}>;

This ensures they stay in sync with the source of truth.

1.2. isDataFormPeriod type guard uses any

src/domain/entities/DataForm.ts:47 — the parameter type should be unknown instead of any:

export function isDataFormPeriod(value: unknown): value is DataFormPeriod {
return typeof value === "string" && (dataFormPeriods as readonly string[]).includes(value);
}

Using any defeats the purpose of a type guard — callers can pass anything without the compiler flagging it.

1.3. generateFinancialPeriods uses moment().month(monthName) — implicit locale dependency

src/webapp/utils/periods.ts:237 — moment().month(monthName).month() parses month names using the current locale. If the app locale is set to something other than English, "April" won't resolve to month index 3 and
periods will be silently wrong. Use an explicit map instead:

const financialMonthMap: Record<string, number> = { April: 3, July: 6, Oct: 9, Nov: 10 };
const startMonthIndex = financialMonthMap[monthName];

  1. Recommendations non blocking

2.1. onPeriodValidationError is optional — silent failure for other consumers

src/webapp/components/template-selector/TemplateSelector.tsx:54 — onPeriodValidationError? is optional. If a future consumer of TemplateSelector doesn't pass it, the unsupported period selection will silently reset
state without any user feedback. Consider either making it required or adding a fallback (e.g. console.warn) inside the component.

2.2. Test import uses @jest/globals but project uses Vitest

src/test/utils/periods.spec.ts:2 — import { describe, it, expect } from "@jest/globals". The project migrated to Vitest. Consider importing from vitest instead to avoid confusion:

import { describe, it, expect } from "vitest";

@nshandra
Copy link
Copy Markdown
Author

@xurxodev

1. To Fix

  • 1.1. Fixed the sub-types to be extracted from DataFormPeriod
  • 1.2. Fixed.
  • 1.3. AFAIK yo have to set moment locale via moment.locale('..') but i agree that it can lead to hard to debug issues. Changed.

2. Recommended

  • 2.1. Given than TemplateSelector is only used in DownloadTemplatePage i made it required.
  • 2.2. I see the branch feature/security has the switch to Vitest but its not merged yet. Import removed as the test works without it.

@nshandra nshandra requested a review from xurxodev April 22, 2026 08:08
Copy link
Copy Markdown

@xurxodev xurxodev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @nshandra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants