Skip to content

Commit 51da792

Browse files
authored
fix(#9612): hide last submitted task from task list (#9650)
Due to a recent debounce in setting contacts as dirty, task-list ended up waiting for two debounce delays when reloading tasks: one from rules engine and one from tasks component itself. It previously had only one debounce, so this issue was less visible, but still existed. As a fix: - emit the change notification early in rules engine, this way both debounces are in parallel - hide the last submitted task from the task list immediately after submission. if the task was not completed by the action, it will show up again when the task list refreshes. Optimizing an e2e test that took a long time due to getting info from "not rendered" angular elements. #9612
1 parent 58dcfb6 commit 51da792

File tree

5 files changed

+9
-2
lines changed

5 files changed

+9
-2
lines changed

tests/page-objects/default/tasks/tasks.wdio.page.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const getTaskById = (emissionId) => $(`${TASK_LIST_SELECTOR} li[data-record-id="
1212
const getTasks = () => $$(`${TASK_LIST_SELECTOR} li.content-row`);
1313

1414
const getTaskInfo = async (taskElement) => {
15+
await taskElement.scrollIntoView();
1516
const contactName = await (await taskElement.$('h4 span')).getText();
1617
const formTitle = await (await taskElement.$('.summary p')).getText();
1718
let lineage = '';

webapp/src/ts/reducers/tasks.ts

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const _tasksReducer = createReducer(
4747

4848
on(Actions.setLastSubmittedTask, (state, { payload: { task } }) => ({
4949
...state,
50+
tasksList: state.tasksList.filter(t => task?._id !== t._id),
5051
taskGroup: {
5152
...state.taskGroup,
5253
lastSubmittedTask: task

webapp/src/ts/services/rules-engine.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ export class RulesEngineService implements OnDestroy {
214214

215215
private dirtyContactCallback(change) {
216216
const subjectIds = [this.isReport(change.doc) ? RegistrationUtils.getSubjectId(change.doc) : change.id];
217+
this.observable.next(subjectIds);
217218

218219
if (this.debounceActive[this.CHANGE_WATCHER_KEY]?.active) {
219220
const oldSubjectIds = this.debounceActive[this.CHANGE_WATCHER_KEY].params;
@@ -238,7 +239,6 @@ export class RulesEngineService implements OnDestroy {
238239
this.telemetryService.record(this.getTelemetryTrackName('refresh', 'dirty-contacts'), contactIds.length);
239240

240241
await this.rulesEngineCore.updateEmissionsFor(contactIds);
241-
this.observable.next(contactIds);
242242
trackPerformance?.stop({ name: this.getTelemetryTrackName('refresh') });
243243
}, this.DEBOUNCE_CHANGE_MILLIS);
244244

webapp/tests/karma/ts/reducers/tasks.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ describe('Tasks reducer', () => {
277277
tasksList: [
278278
{ _id: 'task1', dueDate: 22, state: 'Ready' },
279279
{ _id: 'task2', dueDate: 33, state: 'Ready' },
280+
{ _id: 'task_id2', due: '33', field: 2 }
280281
],
281282
loaded: true,
282283
taskGroup: {

webapp/tests/karma/ts/services/rules-engine.service.spec.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -468,19 +468,23 @@ describe('RulesEngineService', () => {
468468

469469
const change = changesService.subscribe.args[0][0];
470470
await change.callback(changeFeedFormat({ type: 'data_record', form: 'f', fields: { patient_id: 'p1' } }));
471+
expect(callback.callCount).to.equal(1);
471472
await change.callback(changeFeedFormat({ _id: '2', type: 'person', patient_id: 'p2' }));
473+
expect(callback.callCount).to.equal(2);
472474
tick(500);
473475
await change.callback(changeFeedFormat({ _id: '3', type: 'person', patient_id: 'p3' }));
476+
expect(callback.callCount).to.equal(3);
474477
tick(900);
475478
await change.callback(changeFeedFormat({ type: 'data_record', form: 'f', fields: { patient_id: 'p3' }}));
479+
expect(callback.callCount).to.equal(4);
476480

477481
expect(rulesEngineCoreStubs.updateEmissionsFor.callCount).to.equal(0);
478482

479483
tick(1000);
480484

481485
expect(rulesEngineCoreStubs.updateEmissionsFor.callCount).to.equal(1);
482486
expect(rulesEngineCoreStubs.updateEmissionsFor.args[0][0]).to.have.members([ 'p3', '3', '2', 'p1' ]);
483-
expect(callback.callCount).to.equal(1);
487+
expect(callback.callCount).to.equal(4);
484488
subscription.unsubscribe();
485489

486490
expect(telemetryService.record.calledOnce).to.be.true;

0 commit comments

Comments
 (0)