Skip to content

chore: [DHIS2-21506] Consolidate me API requests#4562

Open
henrikmv wants to merge 5 commits into
hv/chore/DHIS2-20995_limit-fields-paramfrom
hv/chore/DHIS2-21506_consolidate-me-fetch
Open

chore: [DHIS2-21506] Consolidate me API requests#4562
henrikmv wants to merge 5 commits into
hv/chore/DHIS2-20995_limit-fields-paramfrom
hv/chore/DHIS2-21506_consolidate-me-fetch

Conversation

@henrikmv
Copy link
Copy Markdown
Contributor

@henrikmv henrikmv commented May 14, 2026

DHIS2-21506

Introduces a CurrentUser singleton, populated once at app startup from a single /me request, and replaces ~10 runtime /me fetches scattered across hooks and epics with synchronous reads.

init.ts already fetches /me at startup. This PR widens that fetch to include the fields previously queried ad-hoc (firstName, surname, username, userRoles{id}) and stores the result in a new CurrentUser class:

// Before: every consumer re-fetched /me
const { data } = useDataQuery({ me: { resource: 'me', params: { fields: '...' } } });
const locale = data?.me?.settings?.keyUiLocale;

// After: single init-time fetch, synchronous access
const locale = CurrentUser.get().uiLocale;

This change should not increase the initial payload size in practice.

It adds three small scalar fields — firstName, surname, and username — but reduces the amount of data requested for the four list fields: userRoles, userGroups, organisationUnits, and teiSearchOrganisationUnits.

For those collections, the request now fetches only id(and path where needed)

Removed Replaced by
useUserLocale hook (5 call sites) CurrentUser.get().uiLocale
useUserRoles hook (WidgetProfile) CurrentUser.get().userRoles
useNoteDetails hook (WidgetEventSchedule) CurrentUser.get() + generateUID() inline
useDataQuery({ me }) in OrgUnitField CurrentUser.get().organisationUnits
useApiMetadataQuery('me') in useSearchScopeWithFallback CurrentUser.get().{teiSearchOrganisationUnits, organisationUnits}
querySingleResource('me') in 5 note epics CurrentUser.get()

@henrikmv henrikmv changed the base branch from master to hv/chore/DHIS2-20995_limit-fields-param May 14, 2026 09:33
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 14, 2026

…s-param' into hv/chore/DHIS2-21506_consolidate-me-fetch
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

@henrikmv henrikmv marked this pull request as ready for review May 15, 2026 11:06
@henrikmv henrikmv requested a review from a team as a code owner May 15, 2026 11:06
Copy link
Copy Markdown
Contributor

@simonadomnisoru simonadomnisoru left a comment

Choose a reason for hiding this comment

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

Great refactor initiative @henrikmv 🙌 ! My only concern is whether the two self-contained widgets should be included or not. I'm curious to hear your thoughts on this. Thanks!

@sonarqubecloud
Copy link
Copy Markdown

@henrikmv henrikmv requested a review from simonadomnisoru May 19, 2026 12:15
@henrikmv henrikmv added testing and removed testing labels May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants