Skip to content

Commit

Permalink
Merge pull request #2006 from bcgov/feature/ALCS-2322-QA-1
Browse files Browse the repository at this point in the history
2322 QA Fixes
  • Loading branch information
trslater authored Dec 5, 2024
2 parents eab439e + 80f8c50 commit 4c96f27
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ApplicationDecisionComponentDto,
UpdateApplicationDecisionConditionDto,
ApplicationDecisionConditionTypeDto,
DecisionComponentTypeDto,
} from '../../../../../../services/application/decision/application-decision-v2/application-decision-v2.dto';
import { ApplicationDecisionV2Service } from '../../../../../../services/application/decision/application-decision-v2/application-decision-v2.service';
import { ConfirmationDialogService } from '../../../../../../shared/confirmation-dialog/confirmation-dialog.service';
Expand All @@ -36,6 +37,7 @@ export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy
@Input() set types(types: ApplicationDecisionConditionTypeDto[]) {
this.activeTypes = types.filter((type) => type.isActive);
}
@Input() componentTypes!: DecisionComponentTypeDto[];
@Input() components: ApplicationDecisionComponentDto[] = [];
@Input() conditions: ApplicationDecisionConditionDto[] = [];
@Input() showError = false;
Expand All @@ -52,7 +54,7 @@ export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy

constructor(
private decisionService: ApplicationDecisionV2Service,
private confirmationDialogService: ConfirmationDialogService
private confirmationDialogService: ConfirmationDialogService,
) {}

ngOnInit(): void {
Expand All @@ -66,10 +68,10 @@ export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy
decision.uuid,
decision.components,
decision.resolutionNumber,
decision.resolutionYear
decision.resolutionYear,
);
const otherDecisionsComponents = mappedComponents.filter(
(component) => component.decisionUuid !== selectedDecision?.uuid
(component) => component.decisionUuid !== selectedDecision?.uuid,
);
otherDecisionComponents.push(...otherDecisionsComponents);
}
Expand All @@ -81,7 +83,7 @@ export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy
selectedDecision.uuid,
this.components,
selectedDecision.resolutionNumber,
selectedDecision.resolutionYear
selectedDecision.resolutionYear,
);
this.selectableComponents = [...this.allComponents, ...updatedComponents];

Expand Down Expand Up @@ -131,15 +133,15 @@ export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy
this.decision.uuid,
this.components,
this.decision.resolutionNumber,
this.decision.resolutionYear
this.decision.resolutionYear,
);
this.selectableComponents = [...this.allComponents, ...updatedComponents];
const validComponentIds = this.selectableComponents.map((component) => component.tempId);

this.mappedConditions = this.mappedConditions.map((condition) => {
if (condition.componentsToCondition) {
condition.componentsToCondition = condition.componentsToCondition.filter((component) =>
validComponentIds.includes(component.tempId)
validComponentIds.includes(component.tempId),
);
}
return condition;
Expand All @@ -157,7 +159,7 @@ export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy
this.mappedConditions = conditions.map((condition) => {
const selectedComponents = this.selectableComponents
.filter((component) =>
condition.components?.map((conditionComponent) => conditionComponent.uuid).includes(component.uuid)
condition.components?.map((conditionComponent) => conditionComponent.uuid).includes(component.uuid),
)
.map((e) => ({
componentDecisionUuid: e.decisionUuid,
Expand All @@ -177,10 +179,10 @@ export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy
decisionUuid: string,
components: ApplicationDecisionComponentDto[],
decisionNumber: number | null,
decisionYear: number | null
decisionYear: number | null,
) {
return components.map((component) => {
const matchingType = this.activeTypes.find(
const matchingType = this.componentTypes.find(
(type) => type.code === component.applicationDecisionComponentTypeCode,
);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h3>Resolution</h3>
color="primary"
(click)="onGenerateResolutionNumber()"
[ngClass]="{
'error-field-outlined ng-invalid': !resolutionNumberControl.valid && resolutionNumberControl.touched
'error-field-outlined ng-invalid': !resolutionNumberControl.valid && resolutionNumberControl.touched,
}"
>
Get Resolution Number
Expand Down Expand Up @@ -142,7 +142,7 @@ <h3>Resolution</h3>
(change)="onChangeSubjectToConditions($event)"
[ngClass]="{
'error-field-outlined':
!form.controls.isSubjectToConditions.valid && form.controls.isSubjectToConditions.touched
!form.controls.isSubjectToConditions.valid && form.controls.isSubjectToConditions.touched,
}"
>
<mat-button-toggle value="true">Yes</mat-button-toggle>
Expand Down Expand Up @@ -203,6 +203,7 @@ <h3>Resolution</h3>
<app-app-decision-conditions
*ngIf="codes && showComponents && showConditions"
[types]="codes.decisionConditionTypes"
[componentTypes]="codes.decisionComponentTypes"
[components]="components"
[conditions]="conditions"
(conditionsChange)="onConditionsChange($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ <h3>Conditions</h3>
</div>

<mat-menu xPosition="before" #decisionComponentMenu="matMenu">
<button
*ngFor="let conditionType of codes.decisionConditionTypes"
mat-menu-item
(click)="onAddNewCondition(conditionType.code)"
>
<button *ngFor="let type of activeTypes" mat-menu-item (click)="onAddNewCondition(type.code)">
<div class="board-menu-item">
<span>{{ conditionType.label }}</span>
<span>{{ type.label }}</span>
</div>
</button>
</mat-menu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ describe('DecisionConditionComponent', () => {

fixture = TestBed.createComponent(DecisionConditionsComponent);
component = fixture.componentInstance;
component.codes = {
decisionComponentTypes: [],
outcomes: [],
decisionConditionTypes: [],
};
component.types = [];
component.componentTypes = [];
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import {
import { combineLatestWith, Subject, takeUntil } from 'rxjs';
import { NoticeOfIntentDecisionV2Service } from '../../../../../../services/notice-of-intent/decision-v2/notice-of-intent-decision-v2.service';
import {
NoticeOfIntentDecisionCodesDto,
NoticeOfIntentDecisionComponentDto,
NoticeOfIntentDecisionConditionDto,
NoticeOfIntentDecisionConditionTypeDto,
NoticeOfIntentDecisionDto,
UpdateNoticeOfIntentDecisionConditionDto,
} from '../../../../../../services/notice-of-intent/decision-v2/notice-of-intent-decision.dto';
import { ConfirmationDialogService } from '../../../../../../shared/confirmation-dialog/confirmation-dialog.service';
import { DecisionConditionComponent } from './decision-condition/decision-condition.component';
import { DecisionComponentTypeDto } from 'src/app/services/application/decision/application-decision-v2/application-decision-v2.dto';

export type TempNoticeOfIntentDecisionConditionDto = UpdateNoticeOfIntentDecisionConditionDto & { tempUuid?: string };
export type SelectableComponent = { uuid?: string; tempId: string; decisionUuid: string; code: string; label: string };
Expand All @@ -32,7 +33,12 @@ export type SelectableComponent = { uuid?: string; tempId: string; decisionUuid:
export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy {
$destroy = new Subject<void>();

@Input() codes!: NoticeOfIntentDecisionCodesDto;
activeTypes!: NoticeOfIntentDecisionConditionTypeDto[];
@Input() set types(types: NoticeOfIntentDecisionConditionTypeDto[]) {
this.activeTypes = types.filter((type) => type.isActive);
console.log(this.activeTypes);
}
@Input() componentTypes!: DecisionComponentTypeDto[];
@Input() components: NoticeOfIntentDecisionComponentDto[] = [];
@Input() conditions: NoticeOfIntentDecisionConditionDto[] = [];
@Input() showError = false;
Expand Down Expand Up @@ -91,7 +97,7 @@ export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy
}

onAddNewCondition(typeCode: string) {
const matchingType = this.codes.decisionConditionTypes.find((code) => code.code === typeCode);
const matchingType = this.activeTypes.find((code) => code.code === typeCode);
this.mappedConditions.unshift({
type: matchingType,
tempUuid: (Math.random() * 10000).toFixed(0),
Expand Down Expand Up @@ -153,9 +159,8 @@ export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy
private populateConditions(conditions: NoticeOfIntentDecisionConditionDto[]) {
this.mappedConditions = conditions.map((condition) => {
const selectedComponents = this.selectableComponents
.filter(
(component) =>
condition.components?.map((conditionComponent) => conditionComponent.uuid).includes(component.uuid),
.filter((component) =>
condition.components?.map((conditionComponent) => conditionComponent.uuid).includes(component.uuid),
)
.map((e) => ({
componentDecisionUuid: e.decisionUuid,
Expand All @@ -178,7 +183,7 @@ export class DecisionConditionsComponent implements OnInit, OnChanges, OnDestroy
decisionYear: number | null,
) {
return components.map((component) => {
const matchingType = this.codes.decisionComponentTypes.find(
const matchingType = this.componentTypes.find(
(type) => type.code === component.noticeOfIntentDecisionComponentTypeCode,
);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h3>Resolution</h3>
color="primary"
(click)="onGenerateResolutionNumber()"
[ngClass]="{
'error-field-outlined ng-invalid': !resolutionNumberControl.valid && resolutionNumberControl.touched
'error-field-outlined ng-invalid': !resolutionNumberControl.valid && resolutionNumberControl.touched,
}"
>
Get Resolution Number
Expand Down Expand Up @@ -72,7 +72,7 @@ <h3>Resolution</h3>
id="decisionMaker"
formControlName="decisionMaker"
[ngClass]="{
'error-field-outlined': !form.controls.decisionMaker.valid && form.controls.decisionMaker.touched
'error-field-outlined': !form.controls.decisionMaker.valid && form.controls.decisionMaker.touched,
}"
>
<mat-button-toggle value="CEO Delegate">CEO Delegate</mat-button-toggle>
Expand Down Expand Up @@ -121,7 +121,7 @@ <h3>Resolution</h3>
(change)="onChangeSubjectToConditions($event)"
[ngClass]="{
'error-field-outlined':
!form.controls.isSubjectToConditions.valid && form.controls.isSubjectToConditions.touched
!form.controls.isSubjectToConditions.valid && form.controls.isSubjectToConditions.touched,
}"
>
<mat-button-toggle value="true">Yes</mat-button-toggle>
Expand Down Expand Up @@ -181,7 +181,8 @@ <h3>Resolution</h3>
<div>
<app-noi-decision-conditions
*ngIf="codes && showComponents && showConditions"
[codes]="codes"
[types]="codes.decisionConditionTypes"
[componentTypes]="codes.decisionComponentTypes"
[components]="components"
[conditions]="conditions"
(conditionsChange)="onConditionsChange($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ export class ApplicationDecisionConditionTypesService {
return;
}

async delete(code: string) {
async delete(code: string): Promise<ApplicationDecisionConditionTypeDto | undefined> {
try {
return await firstValueFrom(this.http.delete<ApplicationDecisionConditionTypeDto>(`${this.url}/${code}`));
const response = await firstValueFrom(
this.http.delete<ApplicationDecisionConditionTypeDto>(`${this.url}/${code}`),
);
this.toastService.showSuccessToast('Condition successfully deleted.');
return response;
} catch (e: any) {
if (e && e.error && e.error.message) {
this.toastService.showErrorToast(e.error.message);
Expand Down

0 comments on commit 4c96f27

Please sign in to comment.