From cd457f46c21c3249d7d8e643c50f0083061c7853 Mon Sep 17 00:00:00 2001 From: Felipe Barreta Date: Thu, 12 Dec 2024 16:19:00 -0800 Subject: [PATCH] ALCS-1858 Move get status to parent component --- .../condition/condition.component.ts | 7 +--- .../conditions/conditions.component.ts | 40 +++++-------------- .../decision-condition.component.ts | 5 +++ .../condition/condition.component.ts | 7 +--- .../conditions/conditions.component.ts | 40 +++++-------------- .../decision-condition.component.ts | 5 +++ 6 files changed, 32 insertions(+), 72 deletions(-) diff --git a/alcs-frontend/src/app/features/application/decision/conditions/condition/condition.component.ts b/alcs-frontend/src/app/features/application/decision/conditions/condition/condition.component.ts index d41ca99f07..e14ba1a88e 100644 --- a/alcs-frontend/src/app/features/application/decision/conditions/condition/condition.component.ts +++ b/alcs-frontend/src/app/features/application/decision/conditions/condition/condition.component.ts @@ -75,7 +75,7 @@ export class ConditionComponent implements OnInit, AfterViewInit { this.dates = this.condition.dates ?? []; this.singleDateFormated = this.dates[0] && this.dates[0].date ? moment(this.dates[0].date).format(environment.dateFormat) : undefined; - this.calcStatus(); + this.setPillLabel(this.condition.status); this.singleDateLabel = this.condition.type?.singleDateLabel ? this.condition.type?.singleDateLabel : 'End Date'; this.showSingleDateField = this.condition.type?.dateType === DateType.SINGLE; this.showAdmFeeField = this.condition.type?.isAdministrativeFeeAmountChecked @@ -198,11 +198,6 @@ export class ConditionComponent implements OnInit, AfterViewInit { return this.condition.conditionComponentsLabels?.find((e) => e.componentUuid === componentUuid)?.label; } - async calcStatus() { - const conditionStatus = await this.decisionService.getStatus(this.condition.uuid); - this.setPillLabel(conditionStatus.status); - } - private setPillLabel(status: string) { switch (status) { case 'ONGOING': diff --git a/alcs-frontend/src/app/features/application/decision/conditions/conditions.component.ts b/alcs-frontend/src/app/features/application/decision/conditions/conditions.component.ts index 12c0116c9f..242914fc5d 100644 --- a/alcs-frontend/src/app/features/application/decision/conditions/conditions.component.ts +++ b/alcs-frontend/src/app/features/application/decision/conditions/conditions.component.ts @@ -100,18 +100,17 @@ export class ConditionsComponent implements OnInit { ), ), ) - .subscribe(({ decisions, datesByConditionUuid }) => { - this.decisions = decisions.map((decision) => { + .subscribe(async ({ decisions }) => { + this.decisions = await Promise.all(decisions.map(async (decision) => { if (decision.uuid === this.decisionUuid) { - const conditions = this.mapConditions(decision, datesByConditionUuid, decisions); - + const conditions = await this.mapConditions(decision, decisions); this.sortConditions(decision, conditions); this.decision = decision as ApplicationDecisionWithConditionComponentLabels; } return decision as ApplicationDecisionWithConditionComponentLabels; - }); + })); }); this.decisionService.loadDecisions(fileNumber); @@ -136,7 +135,7 @@ export class ConditionsComponent implements OnInit { conditions: ApplicationDecisionConditionWithStatus[], ) { decision.conditions = conditions.sort((a, b) => { - const order = [CONDITION_STATUS.ONGOING, CONDITION_STATUS.COMPLETE]; + const order = [CONDITION_STATUS.ONGOING, CONDITION_STATUS.COMPLETE, CONDITION_STATUS.PASTDUE, CONDITION_STATUS.EXPIRED]; if (a.status === b.status) { if (a.type && b.type) { return a.type?.label.localeCompare(b.type.label); @@ -149,18 +148,15 @@ export class ConditionsComponent implements OnInit { }); } - private mapConditions( + private async mapConditions( decision: ApplicationDecisionWithLinkedResolutionDto, - datesByConditionUuid: Map, decisions: ApplicationDecisionWithLinkedResolutionDto[], ) { - return decision.conditions.map((condition) => { - const dates = datesByConditionUuid.get(condition.uuid) ?? []; - const status = this.getStatus(dates, decision); - + return Promise.all(decision.conditions.map(async (condition) => { + const conditionStatus = await this.decisionService.getStatus(condition.uuid); return { ...condition, - status, + status: conditionStatus.status, conditionComponentsLabels: condition.components?.map((c) => { const matchingType = this.codes.decisionComponentTypes.find( (type) => type.code === c.applicationDecisionComponentTypeCode, @@ -180,22 +176,6 @@ export class ConditionsComponent implements OnInit { return { label, conditionUuid: condition.uuid, componentUuid: c.uuid }; }), } as ApplicationDecisionConditionWithStatus; - }); - } - - private getStatus( - dates: ApplicationDecisionConditionDateDto[], - decision: ApplicationDecisionWithLinkedResolutionDto, - ) { - let status = ''; - status = CONDITION_STATUS.COMPLETE; - if (dates.length > 0 && dates.every((date) => date.completedDate && date.completedDate <= this.today)) { - status = CONDITION_STATUS.COMPLETE; - } else if (decision.isDraft === false) { - status = CONDITION_STATUS.ONGOING; - } else { - status = ''; - } - return status; + })); } } diff --git a/alcs-frontend/src/app/features/application/decision/decision-v2/decision-input/decision-conditions/decision-condition/decision-condition.component.ts b/alcs-frontend/src/app/features/application/decision/decision-v2/decision-input/decision-conditions/decision-condition/decision-condition.component.ts index 1dd634cf28..74a637be6f 100644 --- a/alcs-frontend/src/app/features/application/decision/decision-v2/decision-input/decision-conditions/decision-condition/decision-condition.component.ts +++ b/alcs-frontend/src/app/features/application/decision/decision-v2/decision-input/decision-conditions/decision-condition/decision-condition.component.ts @@ -59,6 +59,7 @@ export class DecisionConditionComponent implements OnInit, OnChanges { administrativeFee: this.administrativeFee, description: this.description, componentsToCondition: this.componentsToCondition, + singleDate: this.singleDate, }); constructor(protected dialog: MatDialog) {} @@ -82,6 +83,10 @@ export class DecisionConditionComponent implements OnInit, OnChanges { description: this.data.description ?? null, }); + if (this.showSingleDateField && this.dates.length > 0 && this.dates[0].date) { + this.form.patchValue({ singleDate: moment(this.dates[0].date) }); + } + this.form.valueChanges.subscribe(this.emitChanges.bind(this)); } diff --git a/alcs-frontend/src/app/features/notice-of-intent/decision/conditions/condition/condition.component.ts b/alcs-frontend/src/app/features/notice-of-intent/decision/conditions/condition/condition.component.ts index fd182dea13..939859c7f1 100644 --- a/alcs-frontend/src/app/features/notice-of-intent/decision/conditions/condition/condition.component.ts +++ b/alcs-frontend/src/app/features/notice-of-intent/decision/conditions/condition/condition.component.ts @@ -61,7 +61,7 @@ export class ConditionComponent implements OnInit, AfterViewInit { this.dates = this.condition.dates ?? []; this.singleDateFormated = this.dates[0] && this.dates[0].date ? moment(this.dates[0].date).format(environment.dateFormat) : undefined; - this.calcStatus(); + this.setPillLabel(this.condition.status); this.singleDateLabel = this.condition.type?.singleDateLabel ? this.condition.type?.singleDateLabel : 'End Date'; this.showSingleDateField = this.condition.type?.dateType === DateType.SINGLE; @@ -112,11 +112,6 @@ export class ConditionComponent implements OnInit, AfterViewInit { return this.isReadMoreClicked || this.isEllipsisActive(this.condition.uuid + 'Description'); } - async calcStatus() { - const conditionStatus = await this.decisionService.getStatus(this.condition.uuid); - this.setPillLabel(conditionStatus.status); - } - private setPillLabel(status: string) { switch (status) { case 'ONGOING': diff --git a/alcs-frontend/src/app/features/notice-of-intent/decision/conditions/conditions.component.ts b/alcs-frontend/src/app/features/notice-of-intent/decision/conditions/conditions.component.ts index c82994961c..e4bfbad900 100644 --- a/alcs-frontend/src/app/features/notice-of-intent/decision/conditions/conditions.component.ts +++ b/alcs-frontend/src/app/features/notice-of-intent/decision/conditions/conditions.component.ts @@ -96,18 +96,17 @@ export class ConditionsComponent implements OnInit { ), ), ) - .subscribe(({ decisions, datesByConditionUuid }) => { - this.decisions = decisions.map((decision) => { + .subscribe(async ({ decisions }) => { + this.decisions = await Promise.all(decisions.map(async (decision) => { if (decision.uuid === this.decisionUuid) { - const conditions = this.mapConditions(decision, datesByConditionUuid, decisions); - + const conditions = await this.mapConditions(decision, decisions); this.sortConditions(decision, conditions); this.decision = decision as DecisionWithConditionComponentLabels; } return decision as DecisionWithConditionComponentLabels; - }); + })); }); this.decisionService.loadDecisions(fileNumber); @@ -132,7 +131,7 @@ export class ConditionsComponent implements OnInit { conditions: DecisionConditionWithStatus[], ) { decision.conditions = conditions.sort((a, b) => { - const order = [CONDITION_STATUS.ONGOING, CONDITION_STATUS.COMPLETE]; + const order = [CONDITION_STATUS.ONGOING, CONDITION_STATUS.COMPLETE, CONDITION_STATUS.PASTDUE, CONDITION_STATUS.EXPIRED]; if (a.status === b.status) { if (a.type && b.type) { return a.type?.label.localeCompare(b.type.label); @@ -145,18 +144,15 @@ export class ConditionsComponent implements OnInit { }); } - private mapConditions( + private async mapConditions( decision: NoticeOfIntentDecisionWithLinkedResolutionDto, - datesByConditionUuid: Map, decisions: NoticeOfIntentDecisionWithLinkedResolutionDto[], ) { - return decision.conditions.map((condition) => { - const dates = datesByConditionUuid.get(condition.uuid) ?? []; - const status = this.getStatus(dates, decision); - + return Promise.all(decision.conditions.map(async (condition) => { + const conditionStatus = await this.decisionService.getStatus(condition.uuid); return { ...condition, - status, + status: conditionStatus.status, conditionComponentsLabels: condition.components?.map((c) => { const matchingType = this.codes.decisionComponentTypes.find( (type) => type.code === c.noticeOfIntentDecisionComponentTypeCode, @@ -176,22 +172,6 @@ export class ConditionsComponent implements OnInit { return { label, conditionUuid: condition.uuid, componentUuid: c.uuid }; }), } as DecisionConditionWithStatus; - }); - } - - private getStatus( - dates: NoticeOfIntentDecisionConditionDateDto[], - decision: NoticeOfIntentDecisionWithLinkedResolutionDto, - ) { - let status = ''; - status = CONDITION_STATUS.COMPLETE; - if (dates.length > 0 && dates.every((date) => date.completedDate && date.completedDate <= this.today)) { - status = CONDITION_STATUS.COMPLETE; - } else if (decision.isDraft === false) { - status = CONDITION_STATUS.ONGOING; - } else { - status = ''; - } - return status; + })); } } diff --git a/alcs-frontend/src/app/features/notice-of-intent/decision/decision-v2/decision-input/decision-conditions/decision-condition/decision-condition.component.ts b/alcs-frontend/src/app/features/notice-of-intent/decision/decision-v2/decision-input/decision-conditions/decision-condition/decision-condition.component.ts index c84b559924..4f179f4b51 100644 --- a/alcs-frontend/src/app/features/notice-of-intent/decision/decision-v2/decision-input/decision-conditions/decision-condition/decision-condition.component.ts +++ b/alcs-frontend/src/app/features/notice-of-intent/decision/decision-v2/decision-input/decision-conditions/decision-condition/decision-condition.component.ts @@ -59,6 +59,7 @@ export class DecisionConditionComponent implements OnInit, OnChanges { administrativeFee: this.administrativeFee, description: this.description, componentsToCondition: this.componentsToCondition, + singleDate: this.singleDate, }); constructor(protected dialog: MatDialog) {} @@ -82,6 +83,10 @@ export class DecisionConditionComponent implements OnInit, OnChanges { description: this.data.description ?? null, }); + if (this.showSingleDateField && this.dates.length > 0 && this.dates[0].date) { + this.form.patchValue({ singleDate: moment(this.dates[0].date) }); + } + this.form.valueChanges.subscribe(this.emitChanges.bind(this)); }