Skip to content

Commit b010b59

Browse files
authored
Merge pull request #1976 from bcgov/bugfix/ALCS-2373
Fix residential clearing when it remains
2 parents 5c591fc + bcfc2e1 commit b010b59

File tree

3 files changed

+88
-97
lines changed

3 files changed

+88
-97
lines changed

portal-frontend/src/app/features/applications/edit-submission/proposal/pfrs-proposal/pfrs-proposal.component.ts

+32-33
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,
420420

421421
this.structuresSource = new MatTableDataSource(this.proposedStructures);
422422

423-
if (this.hasInput(structure.type)) {
423+
if (this.structureChangeRequiresConfirmation(structure.type, newType)) {
424424
this.confirmationDialogService
425425
.openDialog({
426426
title: 'Change Structure Type',
@@ -455,29 +455,29 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,
455455
this.form.markAsDirty();
456456
}
457457

458-
private hasInput(type: STRUCTURE_TYPES | null) {
459-
switch (type) {
460-
case STRUCTURE_TYPES.FARM_STRUCTURE:
461-
return !!(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value);
462-
463-
case STRUCTURE_TYPES.ACCESSORY_STRUCTURE:
464-
return !!(
465-
this.soilStructureResidentialUseReason.value || this.soilStructureResidentialAccessoryUseReason.value
466-
);
467-
468-
case STRUCTURE_TYPES.OTHER_STRUCTURE:
469-
return !!this.soilStructureOtherUseReason.value;
470-
471-
case STRUCTURE_TYPES.PRINCIPAL_RESIDENCE:
472-
case STRUCTURE_TYPES.ADDITIONAL_RESIDENCE:
473-
return !!this.soilStructureResidentialUseReason.value;
474-
475-
case null:
476-
return false;
477-
478-
default:
479-
return true;
480-
}
458+
private structureChangeRequiresConfirmation(
459+
oldType: STRUCTURE_TYPES | null,
460+
newType: STRUCTURE_TYPES | null,
461+
): boolean {
462+
const residentialTypes = [
463+
STRUCTURE_TYPES.PRINCIPAL_RESIDENCE,
464+
STRUCTURE_TYPES.ADDITIONAL_RESIDENCE,
465+
STRUCTURE_TYPES.ACCESSORY_STRUCTURE,
466+
];
467+
const changingFromResidentialType = oldType && residentialTypes.includes(oldType);
468+
const changingToResidentialType = newType && residentialTypes.includes(newType);
469+
470+
return !!(
471+
oldType !== newType &&
472+
((oldType &&
473+
oldType === STRUCTURE_TYPES.FARM_STRUCTURE &&
474+
(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value)) ||
475+
(changingFromResidentialType && !changingToResidentialType && this.soilStructureResidentialUseReason.value) ||
476+
(oldType &&
477+
oldType === STRUCTURE_TYPES.ACCESSORY_STRUCTURE &&
478+
this.soilStructureResidentialAccessoryUseReason.value) ||
479+
(oldType && oldType === STRUCTURE_TYPES.OTHER_STRUCTURE && this.soilStructureOtherUseReason.value))
480+
);
481481
}
482482

483483
private setStructureTypeInput(structure: FormProposedStructure, newType: STRUCTURE_TYPES) {
@@ -502,9 +502,10 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,
502502

503503
updateStructureTypeFields() {
504504
// Remove
505-
506505
if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] === 0) {
506+
this.soilStructureFarmUseReason.reset();
507507
this.soilStructureFarmUseReason.removeValidators([Validators.required]);
508+
this.soilAgriParcelActivity.reset();
508509
this.soilAgriParcelActivity.removeValidators([Validators.required]);
509510
}
510511

@@ -513,24 +514,25 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,
513514
this.structureTypeCounts[STRUCTURE_TYPES.ADDITIONAL_RESIDENCE] === 0 &&
514515
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0
515516
) {
517+
this.soilStructureResidentialUseReason.reset();
516518
this.soilStructureResidentialUseReason.removeValidators([Validators.required]);
517519
}
518520

519-
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
521+
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
522+
this.soilStructureResidentialAccessoryUseReason.reset();
520523
this.soilStructureResidentialAccessoryUseReason.removeValidators([Validators.required]);
521524
}
522525

523-
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
526+
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
527+
this.soilStructureOtherUseReason.reset();
524528
this.soilStructureOtherUseReason.removeValidators([Validators.required]);
525529
}
526530

527531
// Add
528532

529533
if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] > 0) {
530534
this.soilStructureFarmUseReason.setValidators([Validators.required]);
531-
this.soilStructureFarmUseReason.reset();
532535
this.soilAgriParcelActivity.setValidators([Validators.required]);
533-
this.soilAgriParcelActivity.reset();
534536
}
535537

536538
if (
@@ -539,17 +541,14 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,
539541
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0
540542
) {
541543
this.soilStructureResidentialUseReason.setValidators([Validators.required]);
542-
this.soilStructureResidentialUseReason.reset();
543544
}
544545

545546
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0) {
546547
this.soilStructureResidentialAccessoryUseReason.setValidators([Validators.required]);
547-
this.soilStructureResidentialAccessoryUseReason.reset();
548548
}
549549

550550
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] > 0) {
551551
this.soilStructureOtherUseReason.setValidators([Validators.required]);
552-
this.soilStructureOtherUseReason.reset();
553552
}
554553
}
555554

@@ -631,8 +630,8 @@ export class PfrsProposalComponent extends FilesStepComponent implements OnInit,
631630
this.structuresForm.removeControl(`${id}-area`);
632631
this.structuresForm.markAsDirty();
633632

634-
this.updateStructureTypeFields();
635633
this.updateStructureCounts(structureToDelete.type, null);
634+
this.updateStructureTypeFields();
636635
}
637636

638637
onStructureEdit(id: string) {

portal-frontend/src/app/features/applications/edit-submission/proposal/pofo-proposal/pofo-proposal.component.ts

+28-32
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
347347

348348
this.structuresSource = new MatTableDataSource(this.proposedStructures);
349349

350-
if (this.hasInput(structure.type)) {
350+
if (this.hasInput(structure.type, newType)) {
351351
this.confirmationDialogService
352352
.openDialog({
353353
title: 'Change Structure Type',
@@ -382,29 +382,25 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
382382
this.form.markAsDirty();
383383
}
384384

385-
private hasInput(type: STRUCTURE_TYPES | null) {
386-
switch (type) {
387-
case STRUCTURE_TYPES.FARM_STRUCTURE:
388-
return !!(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value);
389-
390-
case STRUCTURE_TYPES.ACCESSORY_STRUCTURE:
391-
return !!(
392-
this.soilStructureResidentialUseReason.value || this.soilStructureResidentialAccessoryUseReason.value
393-
);
394-
395-
case STRUCTURE_TYPES.OTHER_STRUCTURE:
396-
return !!this.soilStructureOtherUseReason.value;
397-
398-
case STRUCTURE_TYPES.PRINCIPAL_RESIDENCE:
399-
case STRUCTURE_TYPES.ADDITIONAL_RESIDENCE:
400-
return !!this.soilStructureResidentialUseReason.value;
401-
402-
case null:
403-
return false;
404-
405-
default:
406-
return true;
407-
}
385+
private hasInput(oldType: STRUCTURE_TYPES | null, newType: STRUCTURE_TYPES | null) {
386+
const residentialTypes = [
387+
STRUCTURE_TYPES.PRINCIPAL_RESIDENCE,
388+
STRUCTURE_TYPES.ADDITIONAL_RESIDENCE,
389+
STRUCTURE_TYPES.ACCESSORY_STRUCTURE,
390+
];
391+
const changingFromResidentialType = oldType && residentialTypes.includes(oldType);
392+
const changingToResidentialType = newType && residentialTypes.includes(newType);
393+
394+
return !!(
395+
(oldType &&
396+
oldType === STRUCTURE_TYPES.FARM_STRUCTURE &&
397+
(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value)) ||
398+
(changingFromResidentialType && !changingToResidentialType && this.soilStructureResidentialUseReason.value) ||
399+
(oldType &&
400+
oldType === STRUCTURE_TYPES.ACCESSORY_STRUCTURE &&
401+
this.soilStructureResidentialAccessoryUseReason.value) ||
402+
(oldType && oldType === STRUCTURE_TYPES.OTHER_STRUCTURE && this.soilStructureOtherUseReason.value)
403+
);
408404
}
409405

410406
private setStructureTypeInput(structure: FormProposedStructure, newType: STRUCTURE_TYPES) {
@@ -431,7 +427,9 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
431427
// Remove
432428

433429
if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] === 0) {
430+
this.soilStructureFarmUseReason.reset();
434431
this.soilStructureFarmUseReason.removeValidators([Validators.required]);
432+
this.soilAgriParcelActivity.reset();
435433
this.soilAgriParcelActivity.removeValidators([Validators.required]);
436434
}
437435

@@ -440,24 +438,25 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
440438
this.structureTypeCounts[STRUCTURE_TYPES.ADDITIONAL_RESIDENCE] === 0 &&
441439
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0
442440
) {
441+
this.soilStructureResidentialUseReason.reset();
443442
this.soilStructureResidentialUseReason.removeValidators([Validators.required]);
444443
}
445444

446-
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
445+
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
446+
this.soilStructureResidentialAccessoryUseReason.reset();
447447
this.soilStructureResidentialAccessoryUseReason.removeValidators([Validators.required]);
448448
}
449449

450-
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
450+
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
451+
this.soilStructureOtherUseReason.reset();
451452
this.soilStructureOtherUseReason.removeValidators([Validators.required]);
452453
}
453454

454455
// Add
455456

456457
if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] > 0) {
457458
this.soilStructureFarmUseReason.setValidators([Validators.required]);
458-
this.soilStructureFarmUseReason.reset();
459459
this.soilAgriParcelActivity.setValidators([Validators.required]);
460-
this.soilAgriParcelActivity.reset();
461460
}
462461

463462
if (
@@ -466,17 +465,14 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
466465
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0
467466
) {
468467
this.soilStructureResidentialUseReason.setValidators([Validators.required]);
469-
this.soilStructureResidentialUseReason.reset();
470468
}
471469

472470
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0) {
473471
this.soilStructureResidentialAccessoryUseReason.setValidators([Validators.required]);
474-
this.soilStructureResidentialAccessoryUseReason.reset();
475472
}
476473

477474
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] > 0) {
478475
this.soilStructureOtherUseReason.setValidators([Validators.required]);
479-
this.soilStructureOtherUseReason.reset();
480476
}
481477
}
482478

@@ -558,8 +554,8 @@ export class PofoProposalComponent extends FilesStepComponent implements OnInit,
558554
this.structuresForm.removeControl(`${id}-area`);
559555
this.structuresForm.markAsDirty();
560556

561-
this.updateStructureTypeFields();
562557
this.updateStructureCounts(structureToDelete.type, null);
558+
this.updateStructureTypeFields();
563559
}
564560

565561
onStructureEdit(id: string) {

portal-frontend/src/app/features/applications/edit-submission/proposal/roso-proposal/roso-proposal.component.ts

+28-32
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
406406
this.structuresForm.removeControl(`${id}-area`);
407407
this.structuresForm.markAsDirty();
408408

409-
this.updateStructureTypeFields();
410409
this.updateStructureCounts(structureToDelete.type, null);
410+
this.updateStructureTypeFields();
411411
}
412412

413413
onStructureEdit(id: string) {
@@ -456,7 +456,7 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
456456

457457
this.structuresSource = new MatTableDataSource(this.proposedStructures);
458458

459-
if (this.hasInput(structure.type)) {
459+
if (this.hasInput(structure.type, newType)) {
460460
this.confirmationDialogService
461461
.openDialog({
462462
title: 'Change Structure Type',
@@ -491,29 +491,25 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
491491
this.form.markAsDirty();
492492
}
493493

494-
private hasInput(type: STRUCTURE_TYPES | null) {
495-
switch (type) {
496-
case STRUCTURE_TYPES.FARM_STRUCTURE:
497-
return !!(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value);
498-
499-
case STRUCTURE_TYPES.ACCESSORY_STRUCTURE:
500-
return !!(
501-
this.soilStructureResidentialUseReason.value || this.soilStructureResidentialAccessoryUseReason.value
502-
);
503-
504-
case STRUCTURE_TYPES.OTHER_STRUCTURE:
505-
return !!this.soilStructureOtherUseReason.value;
506-
507-
case STRUCTURE_TYPES.PRINCIPAL_RESIDENCE:
508-
case STRUCTURE_TYPES.ADDITIONAL_RESIDENCE:
509-
return !!this.soilStructureResidentialUseReason.value;
510-
511-
case null:
512-
return false;
513-
514-
default:
515-
return true;
516-
}
494+
private hasInput(oldType: STRUCTURE_TYPES | null, newType: STRUCTURE_TYPES | null) {
495+
const residentialTypes = [
496+
STRUCTURE_TYPES.PRINCIPAL_RESIDENCE,
497+
STRUCTURE_TYPES.ADDITIONAL_RESIDENCE,
498+
STRUCTURE_TYPES.ACCESSORY_STRUCTURE,
499+
];
500+
const changingFromResidentialType = oldType && residentialTypes.includes(oldType);
501+
const changingToResidentialType = newType && residentialTypes.includes(newType);
502+
503+
return !!(
504+
(oldType &&
505+
oldType === STRUCTURE_TYPES.FARM_STRUCTURE &&
506+
(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value)) ||
507+
(changingFromResidentialType && !changingToResidentialType && this.soilStructureResidentialUseReason.value) ||
508+
(oldType &&
509+
oldType === STRUCTURE_TYPES.ACCESSORY_STRUCTURE &&
510+
this.soilStructureResidentialAccessoryUseReason.value) ||
511+
(oldType && oldType === STRUCTURE_TYPES.OTHER_STRUCTURE && this.soilStructureOtherUseReason.value)
512+
);
517513
}
518514

519515
private setStructureTypeInput(structure: FormProposedStructure, newType: STRUCTURE_TYPES) {
@@ -540,7 +536,9 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
540536
// Remove
541537

542538
if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] === 0) {
539+
this.soilStructureFarmUseReason.reset();
543540
this.soilStructureFarmUseReason.removeValidators([Validators.required]);
541+
this.soilAgriParcelActivity.reset();
544542
this.soilAgriParcelActivity.removeValidators([Validators.required]);
545543
}
546544

@@ -549,24 +547,25 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
549547
this.structureTypeCounts[STRUCTURE_TYPES.ADDITIONAL_RESIDENCE] === 0 &&
550548
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0
551549
) {
550+
this.soilStructureResidentialUseReason.reset();
552551
this.soilStructureResidentialUseReason.removeValidators([Validators.required]);
553552
}
554553

555-
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
554+
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
555+
this.soilStructureResidentialAccessoryUseReason.reset();
556556
this.soilStructureResidentialAccessoryUseReason.removeValidators([Validators.required]);
557557
}
558558

559-
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] === 0) {
559+
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] === 0) {
560+
this.soilStructureOtherUseReason.reset();
560561
this.soilStructureOtherUseReason.removeValidators([Validators.required]);
561562
}
562563

563564
// Add
564565

565566
if (this.structureTypeCounts[STRUCTURE_TYPES.FARM_STRUCTURE] > 0) {
566567
this.soilStructureFarmUseReason.setValidators([Validators.required]);
567-
this.soilStructureFarmUseReason.reset();
568568
this.soilAgriParcelActivity.setValidators([Validators.required]);
569-
this.soilAgriParcelActivity.reset();
570569
}
571570

572571
if (
@@ -575,17 +574,14 @@ export class RosoProposalComponent extends FilesStepComponent implements OnInit,
575574
this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0
576575
) {
577576
this.soilStructureResidentialUseReason.setValidators([Validators.required]);
578-
this.soilStructureResidentialUseReason.reset();
579577
}
580578

581579
if (this.structureTypeCounts[STRUCTURE_TYPES.ACCESSORY_STRUCTURE] > 0) {
582580
this.soilStructureResidentialAccessoryUseReason.setValidators([Validators.required]);
583-
this.soilStructureResidentialAccessoryUseReason.reset();
584581
}
585582

586583
if (this.structureTypeCounts[STRUCTURE_TYPES.OTHER_STRUCTURE] > 0) {
587584
this.soilStructureOtherUseReason.setValidators([Validators.required]);
588-
this.soilStructureOtherUseReason.reset();
589585
}
590586
}
591587

0 commit comments

Comments
 (0)