Skip to content

Commit

Permalink
ALCS-1858 Move get status to parent component
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarreta committed Dec 13, 2024
1 parent 1dcd77c commit cd457f4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -149,18 +148,15 @@ export class ConditionsComponent implements OnInit {
});
}

private mapConditions(
private async mapConditions(
decision: ApplicationDecisionWithLinkedResolutionDto,
datesByConditionUuid: Map<string, ApplicationDecisionConditionDateDto[]>,
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,
Expand All @@ -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;
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand All @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -145,18 +144,15 @@ export class ConditionsComponent implements OnInit {
});
}

private mapConditions(
private async mapConditions(
decision: NoticeOfIntentDecisionWithLinkedResolutionDto,
datesByConditionUuid: Map<string, NoticeOfIntentDecisionConditionDateDto[]>,
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,
Expand All @@ -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;
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand All @@ -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));
}

Expand Down

0 comments on commit cd457f4

Please sign in to comment.