Skip to content

fix(forms): clear hidden listener fields instead of applying default value#12459

Open
Nil20 wants to merge 7 commits intodevelopfrom
ocrvs-12433
Open

fix(forms): clear hidden listener fields instead of applying default value#12459
Nil20 wants to merge 7 commits intodevelopfrom
ocrvs-12433

Conversation

@Nil20
Copy link
Copy Markdown
Contributor

@Nil20 Nil20 commented Apr 27, 2026

CC PR: opencrvs/opencrvs-countryconfig#1401
Farajaland PR: opencrvs/opencrvs-farajaland#2120

Description

Why

When a field with a parent listener is hidden (e.g. child.birthLocation.privateHome is only shown when placeOfBirth = PRIVATE_HOME), (configured as part of this pull request) switching the parent to a different option (e.g. HEALTH_FACILITY) was still applying the field's defaultValue to hidden listener fields. This caused child.birthLocationId — a derived hidden field that reads administrativeArea from whichever location field is filled — to pick up the admin area UUID from a hidden address field's default, rather than staying empty.

This admin area UUID then propagated to placeOfEvent in the Elasticsearch index (via resolvePlaceOfEvent), causing jurisdiction-based workqueue filters to fail for NOTIFY events submitted by hospital clerk system users. https://github.com/opencrvs/e2e/actions/runs/24998390203

The bug predates the workqueue jurisdiction filter. It was only exposed when we introduced scope-based placeOfEvent filtering in workqueues, which made the incorrect placeOfEvent value visible as a query mismatch.

Fix

In setValueForListenerField, hidden listener fields are now explicitly cleared to null instead of having their defaultValue applied. This is consistent with how applyVisibilityTransitions already handles fields that transition from visible to hidden, and with how computeInitialValues skips hidden fields at form initialization.

Also fixes a flaky CI issue where the E2E trigger job would capture a stale run link from a previous dispatch. The workflow now polls until a run created after the dispatch time appears, rather than assuming a fixed 10-second wait is sufficient.

Checklist

  • I have linked the correct Github issue under "Development"
  • I have tested the changes locally, and written appropriate tests
  • I have tested beyond the happy path (e.g. edge cases, failure paths)
  • I have updated the changelog with this change (if applicable)
  • I have updated the GitHub issue status accordingly

@Nil20 Nil20 marked this pull request as draft April 27, 2026 19:10
@github-actions
Copy link
Copy Markdown

Oops! Looks like you forgot to update the changelog. When updating CHANGELOG.md, please consider the following:

  • Changelog is read by country implementors who might not always be familiar with all technical details of OpenCRVS. Keep language high-level, user friendly and avoid technical references to internals.
  • Answer "What's new?", "Why was the change made?" and "Why should I care?" for each change.
  • If it's a breaking change, include a migration guide answering "What do I need to do to upgrade?".

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

ℹ️ Coverage metrics explained:
Statements — Executed code statements (basic logic lines)
Branches — Tested decision paths (if/else, switch, ternaries)
Functions — Functions invoked during tests
Lines — Source lines executed

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

📊 commons test coverage

Statements: 75.48%
Branches:   39.88%
Functions:  56.85%
Lines:      75.05%
Updated at: Tue, 05 May 2026 11:40:37 GMT

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 27, 2026

📊 events test coverage

Statements: 86.87%
Branches:   84.8%
Functions:  91.97%
Lines:      86.87%
Updated at: Tue, 05 May 2026 11:50:14 GMT

Comment on lines +297 to +331
// Record the time just before dispatching so we can ignore any
// pre-existing runs when polling below.
const dispatchedAt = new Date();

if (runs.data.workflow_runs.length > 0) {
const runId = runs.data.workflow_runs[0].id;
console.log(`Captured runId: ${runId}`);
// GitHub Actions can take variable time to register a newly dispatched
// run in the API. Poll every 5 seconds for up to 60 seconds, and only
// accept a run whose created_at is >= dispatchedAt to avoid picking up
// a stale run from a previous dispatch (e.g. one triggered by farajaland).
let runId;
for (let i = 0; i < 12; i++) {
await new Promise(resolve => setTimeout(resolve, 5000));

// Set the runId as an output
core.setOutput('run_id', runId);
} else {
throw new Error('No workflow run found.');
const runs = await github.rest.actions.listWorkflowRunsForRepo({
owner: 'opencrvs',
repo: 'e2e',
event: 'repository_dispatch',
per_page: 5
});

const newRun = runs.data.workflow_runs.find(
r => new Date(r.created_at) >= dispatchedAt
);

if (newRun) {
runId = newRun.id;
console.log(`Captured runId: ${runId} (created at ${newRun.created_at})`);
break;
}

console.log(`Run not visible yet, retrying... (attempt ${i + 1}/12)`);
}

if (!runId) {
throw new Error('No workflow run found after 60 seconds.');
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added it because we found a stale link here: https://github.com/opencrvs/opencrvs-core/actions/runs/25014351156/job/73261242356#step:10:1

Reason: The newly triggered run hadn't appeared in the API yet after the 10-second wait. GitHub Actions has variable latency before a freshly dispatched run shows up in listWorkflowRunsForRepo. When the list was fetched, the new run wasn't there yet, so it returned the previous run from hours ago.

Fix result example: https://github.com/opencrvs/opencrvs-core/actions/runs/25017463464/job/73269507432?pr=12459#step:9:97

@ocrvs-bot
Copy link
Copy Markdown
Contributor

Your environment is deployed to https://ocrvs-12433.e2e-k8s.opencrvs.dev

@Nil20 Nil20 marked this pull request as ready for review April 28, 2026 07:40
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.

Address Field Not Updating When Switching Address Type in Edited Declaration

2 participants