From b15b77920cd74040669328df5677f3c715b7ce04 Mon Sep 17 00:00:00 2001 From: Manuel Rodriguez Date: Mon, 6 Nov 2023 13:55:58 -0800 Subject: [PATCH 1/2] Updated models and added is dedication checks --- .../api/Models/Concepts/Take/TakeMap.cs | 43 ++--- .../api/Models/Concepts/Take/TakeModel.cs | 29 ++-- .../api/Services/AcquisitionFileService.cs | 17 +- .../Interfaces/IPropertyRepository.cs | 2 +- .../dal/Repositories/PropertyRepository.cs | 13 +- .../dal/Repositories/TakeRepository.cs | 2 +- .../Services/AcquisitionFileServiceTest.cs | 59 +++---- .../takes/detail/TakesDetailView.test.tsx | 26 +-- .../tabs/takes/detail/TakesDetailView.tsx | 64 ++++++-- .../tabs/takes/update/TakeSubForm.tsx | 60 ++++--- .../takes/update/TakesUpdateForm.test.tsx | 18 +-- .../tabs/takes/update/TakesUpdateForm.tsx | 23 +-- .../TakesUpdateForm.test.tsx.snap | 150 +++++++++++++++--- .../tabs/takes/update/models.test.tsx | 52 +++--- .../property/tabs/takes/update/models.ts | 108 +++++++------ source/frontend/src/mocks/takes.mock.ts | 20 +-- source/frontend/src/models/api/Take.ts | 30 ++-- source/frontend/src/utils/formUtils.ts | 8 + 18 files changed, 465 insertions(+), 259 deletions(-) diff --git a/source/backend/api/Models/Concepts/Take/TakeMap.cs b/source/backend/api/Models/Concepts/Take/TakeMap.cs index 0d778e113f..8f5c9da283 100644 --- a/source/backend/api/Models/Concepts/Take/TakeMap.cs +++ b/source/backend/api/Models/Concepts/Take/TakeMap.cs @@ -10,50 +10,53 @@ public void Register(TypeAdapterConfig config) config.NewConfig() .Map(dest => dest.Id, src => src.TakeId) .Map(dest => dest.Description, src => src.Description) - .Map(dest => dest.IsSurplus, src => src.IsThereSurplus) + .Map(dest => dest.NewHighwayDedicationArea, src => src.NewHighwayDedicationArea) + .Map(dest => dest.AreaUnitTypeCode, src => src.AreaUnitTypeCodeNavigation) + .Map(dest => dest.IsAcquiredForInventory, src => src.IsAcquiredForInventory) + .Map(dest => dest.IsThereSurplus, src => src.IsThereSurplus) + .Map(dest => dest.IsNewLicenseToConstruct, src => src.IsNewLicenseToConstruct) + .Map(dest => dest.IsNewHighwayDedication, src => src.IsNewHighwayDedication) + .Map(dest => dest.IsNewLandAct, src => src.IsNewLandAct) + .Map(dest => dest.IsNewInterestInSrw, src => src.IsNewInterestInSrw) .Map(dest => dest.LicenseToConstructArea, src => src.LicenseToConstructArea) .Map(dest => dest.LtcEndDt, src => src.LtcEndDt) - .Map(dest => dest.NewRightOfWayArea, src => src.NewHighwayDedicationArea) .Map(dest => dest.LandActArea, src => src.LandActArea) .Map(dest => dest.LandActEndDt, src => src.LandActEndDt) .Map(dest => dest.PropertyAcquisitionFile, src => src.PropertyAcquisitionFile) .Map(dest => dest.PropertyAcquisitionFileId, src => src.PropertyAcquisitionFileId) .Map(dest => dest.StatutoryRightOfWayArea, src => src.StatutoryRightOfWayArea) + .Map(dest => dest.SrwEndDt, src => src.SrwEndDt) .Map(dest => dest.SurplusArea, src => src.SurplusArea) - .Map(dest => dest.TakeSiteContamTypeCode, src => src.TakeSiteContamTypeCode) - .Map(dest => dest.TakeTypeCode, src => src.TakeTypeCode) - .Map(dest => dest.TakeStatusTypeCode, src => src.TakeStatusTypeCode) + .Map(dest => dest.TakeSiteContamTypeCode, src => src.TakeSiteContamTypeCodeNavigation) + .Map(dest => dest.TakeTypeCode, src => src.TakeTypeCodeNavigation) + .Map(dest => dest.TakeStatusTypeCode, src => src.TakeStatusTypeCodeNavigation) .Map(dest => dest.LandActTypeCode, src => src.LandActTypeCodeNavigation) - .Map(dest => dest.IsLicenseToConstruct, src => src.IsNewLicenseToConstruct) - .Map(dest => dest.IsNewRightOfWay, src => src.IsNewHighwayDedication) - .Map(dest => dest.IsLandAct, src => src.IsNewLandAct) - .Map(dest => dest.IsNewInterestInSrw, src => src.IsNewInterestInSrw) - .Map(dest => dest.SrwEndDt, src => src.SrwEndDt) .Inherits(); config.NewConfig() .Map(dest => dest.TakeId, src => src.Id) .Map(dest => dest.Description, src => src.Description) - .Map(dest => dest.IsThereSurplus, src => src.IsSurplus) - .Map(dest => dest.IsNewHighwayDedication, src => src.IsNewRightOfWay) - .Map(dest => dest.IsNewLandAct, src => src.IsLandAct) + .Map(dest => dest.NewHighwayDedicationArea, src => src.NewHighwayDedicationArea) + .Map(dest => dest.AreaUnitTypeCode, src => src.AreaUnitTypeCode.Id) + .Map(dest => dest.IsAcquiredForInventory, src => src.IsAcquiredForInventory) + .Map(dest => dest.IsThereSurplus, src => src.IsThereSurplus) + .Map(dest => dest.IsNewLicenseToConstruct, src => src.IsNewLicenseToConstruct) + .Map(dest => dest.IsNewHighwayDedication, src => src.IsNewHighwayDedication) + .Map(dest => dest.IsNewLandAct, src => src.IsNewLandAct) .Map(dest => dest.IsNewInterestInSrw, src => src.IsNewInterestInSrw) - .Map(dest => dest.IsNewLicenseToConstruct, src => src.IsLicenseToConstruct) .Map(dest => dest.LicenseToConstructArea, src => src.LicenseToConstructArea) .Map(dest => dest.LtcEndDt, src => src.LtcEndDt) - .Map(dest => dest.NewHighwayDedicationArea, src => src.NewRightOfWayArea) .Map(dest => dest.LandActArea, src => src.LandActArea) .Map(dest => dest.LandActEndDt, src => src.LandActEndDt) .Map(dest => dest.PropertyAcquisitionFile, src => src.PropertyAcquisitionFile) .Map(dest => dest.PropertyAcquisitionFileId, src => src.PropertyAcquisitionFileId) .Map(dest => dest.StatutoryRightOfWayArea, src => src.StatutoryRightOfWayArea) + .Map(dest => dest.SrwEndDt, src => src.SrwEndDt) .Map(dest => dest.SurplusArea, src => src.SurplusArea) - .Map(dest => dest.TakeSiteContamTypeCode, src => src.TakeSiteContamTypeCode) - .Map(dest => dest.TakeTypeCode, src => src.TakeTypeCode) - .Map(dest => dest.TakeStatusTypeCode, src => src.TakeStatusTypeCode) + .Map(dest => dest.TakeSiteContamTypeCode, src => src.TakeSiteContamTypeCode.Id) + .Map(dest => dest.TakeTypeCode, src => src.TakeTypeCode.Id) + .Map(dest => dest.TakeStatusTypeCode, src => src.TakeStatusTypeCode.Id) .Map(dest => dest.LandActTypeCode, src => src.LandActTypeCode.Id) - .Map(dest => dest.SrwEndDt, src => src.SrwEndDt) - .Map(dest => dest.IsAcquiredForInventory, () => true) // TODO: fix this .Inherits(); } } diff --git a/source/backend/api/Models/Concepts/Take/TakeModel.cs b/source/backend/api/Models/Concepts/Take/TakeModel.cs index cd069d432f..1dfa57d521 100644 --- a/source/backend/api/Models/Concepts/Take/TakeModel.cs +++ b/source/backend/api/Models/Concepts/Take/TakeModel.cs @@ -4,34 +4,35 @@ namespace Pims.Api.Models.Concepts { /// /// TakeModel class, provides a model to represent the take. + /// LINK @frontend/src/models/api/Take.ts /// public class TakeModel : BaseAppModel { #region Properties - - /// - /// get/set - The primary key to identify the property. - /// public long Id { get; set; } public string Description { get; set; } - public bool IsSurplus { get; set; } + public float? NewHighwayDedicationArea { get; set; } + + public TypeModel AreaUnitTypeCode { get; set; } + + public bool? IsAcquiredForInventory { get; set; } - public bool IsLicenseToConstruct { get; set; } + public bool? IsThereSurplus { get; set; } - public bool IsNewRightOfWay { get; set; } + public bool? IsNewLicenseToConstruct { get; set; } - public bool IsLandAct { get; set; } + public bool? IsNewHighwayDedication { get; set; } - public bool IsNewInterestInSrw { get; set; } + public bool? IsNewLandAct { get; set; } + + public bool? IsNewInterestInSrw { get; set; } public float? LicenseToConstructArea { get; set; } public DateTime? LtcEndDt { get; set; } - public float? NewRightOfWayArea { get; set; } - public float? LandActArea { get; set; } public DateTime? LandActEndDt { get; set; } @@ -46,11 +47,11 @@ public class TakeModel : BaseAppModel public float? SurplusArea { get; set; } - public string TakeSiteContamTypeCode { get; set; } + public TypeModel TakeSiteContamTypeCode { get; set; } - public string TakeTypeCode { get; set; } + public TypeModel TakeTypeCode { get; set; } - public string TakeStatusTypeCode { get; set; } + public TypeModel TakeStatusTypeCode { get; set; } public TypeModel LandActTypeCode { get; set; } #endregion diff --git a/source/backend/api/Services/AcquisitionFileService.cs b/source/backend/api/Services/AcquisitionFileService.cs index 541deaf73f..fed4e81754 100644 --- a/source/backend/api/Services/AcquisitionFileService.cs +++ b/source/backend/api/Services/AcquisitionFileService.cs @@ -712,12 +712,25 @@ private void TransferPropertiesOfInterest(PimsAcquisitionFile acquisitionFile, b !(t.IsNewLandAct.HasValue && t.IsNewLandAct.Value && t.LandActEndDt.HasValue && t.LandActEndDt.Value.Date < DateTime.UtcNow.Date) && !(t.IsNewLicenseToConstruct.HasValue && t.IsNewLicenseToConstruct.Value && t.LtcEndDt.HasValue && t.LtcEndDt.Value.Date < DateTime.UtcNow.Date) && !(t.IsNewInterestInSrw.HasValue && t.IsNewInterestInSrw.Value && t.SrwEndDt.HasValue && t.SrwEndDt.Value.Date < DateTime.UtcNow.Date)); - //see psp-6589 for business rules. + + // see psp-6589 for business rules. var isOwned = !(activeTakes.All(t => (t.IsNewLandAct.HasValue && t.IsNewLandAct.Value && coreInventoryInterestCodes.Contains(t.LandActTypeCode)) || (t.IsNewInterestInSrw.HasValue && t.IsNewInterestInSrw.Value) || (t.IsThereSurplus.HasValue && t.IsThereSurplus.Value) || (t.IsNewLicenseToConstruct.HasValue && t.IsNewLicenseToConstruct.Value)) && activeTakes.Any()); - _propertyRepository.TransferFileProperty(property, isOwned); + var isPropertyOfInterest = false; + + // Override for dedication psp-7048. + var doNotAcquire = takes.All(t => + t.IsNewHighwayDedication.HasValue && t.IsNewHighwayDedication.Value && t.IsAcquiredForInventory.HasValue && !t.IsAcquiredForInventory.Value); + + if (doNotAcquire) + { + isOwned = false; + isPropertyOfInterest = true; + } + + _propertyRepository.TransferFileProperty(property, isOwned, isPropertyOfInterest); } } diff --git a/source/backend/dal/Repositories/Interfaces/IPropertyRepository.cs b/source/backend/dal/Repositories/Interfaces/IPropertyRepository.cs index 73fe5a6ad5..ad9fc18689 100644 --- a/source/backend/dal/Repositories/Interfaces/IPropertyRepository.cs +++ b/source/backend/dal/Repositories/Interfaces/IPropertyRepository.cs @@ -31,7 +31,7 @@ public interface IPropertyRepository : IRepository void Delete(PimsProperty property); - PimsProperty TransferFileProperty(PimsProperty property, bool isOwned = true); + PimsProperty TransferFileProperty(PimsProperty property, bool isOwned, bool isPropertyOfInterest); HashSet GetMatchingIds(PropertyFilterCriteria filter); } diff --git a/source/backend/dal/Repositories/PropertyRepository.cs b/source/backend/dal/Repositories/PropertyRepository.cs index 53b2849a72..a629f1200a 100644 --- a/source/backend/dal/Repositories/PropertyRepository.cs +++ b/source/backend/dal/Repositories/PropertyRepository.cs @@ -381,20 +381,25 @@ public void Delete(PimsProperty property) /// /// The property to update. /// The updated property. - public PimsProperty TransferFileProperty(PimsProperty property, bool isOwned = true) + public PimsProperty TransferFileProperty(PimsProperty property, bool isOwned, bool isPropertyOfInterest) { property.ThrowIfNull(nameof(property)); var existingProperty = Context.PimsProperties .FirstOrDefault(p => p.PropertyId == property.Internal_Id) ?? throw new KeyNotFoundException(); - existingProperty.IsPropertyOfInterest = false; + existingProperty.IsPropertyOfInterest = isPropertyOfInterest; existingProperty.IsOwned = isOwned; - existingProperty.PropertyClassificationTypeCode = "COREOPER"; - if (!isOwned) + + if (isOwned) + { + existingProperty.PropertyClassificationTypeCode = "COREOPER"; + } + else { existingProperty.PropertyClassificationTypeCode = "OTHER"; } + return existingProperty; } diff --git a/source/backend/dal/Repositories/TakeRepository.cs b/source/backend/dal/Repositories/TakeRepository.cs index 11fd60a9d0..59e55a7a23 100644 --- a/source/backend/dal/Repositories/TakeRepository.cs +++ b/source/backend/dal/Repositories/TakeRepository.cs @@ -85,7 +85,7 @@ public void UpdateAcquisitionPropertyTakes(long acquisitionFilePropertyId, IEnum public IEnumerable GetAllByPropertyAcquisitionFileId(long acquisitionFilePropertyId) { - return Context.PimsTakes.Include(t => t.PropertyAcquisitionFile).Where(pf => pf.PropertyAcquisitionFileId == acquisitionFilePropertyId); + return Context.PimsTakes.Include(t => t.PropertyAcquisitionFile).Where(pf => pf.PropertyAcquisitionFileId == acquisitionFilePropertyId).ToList(); } } } diff --git a/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs b/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs index 018d961370..00d89339e8 100644 --- a/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs +++ b/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs @@ -43,27 +43,6 @@ private AcquisitionFileService CreateAcquisitionServiceWithPermissions(params Pe return this._helper.Create(user); } - public static object[] takes = new List() { - new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true }, new PimsTake() { IsNewLicenseToConstruct = true } }, true }, - new object[] { new List() { new PimsTake() { IsNewLandAct = true }, new PimsTake() { IsNewLicenseToConstruct = true } }, true }, // core inventory takes priority over other interest - new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActEndDt = DateTime.UtcNow.AddDays(-1) }, new PimsTake() { IsNewLicenseToConstruct = true } }, false }, // should ignore any expired takes - new object[] { new List(), true }, // No takes should be core inventory - new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActEndDt = DateTime.UtcNow.AddDays(-1) } }, true }, // only expired takes is the same as no takes - new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true }, new PimsTake() { IsNewLicenseToConstruct = true } }, true }, - new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true }, new PimsTake() { IsNewLicenseToConstruct = true } }, true }, - new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true }, new PimsTake() { IsNewLicenseToConstruct = true } }, true }, - new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Section 15" } }, false }, - new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Section 16" } }, true }, - new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Section 17" } }, false }, - new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "NOI" } }, false }, - new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Section 66" } }, false }, - new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Crown Grant (New)" } }, true }, - new object[] { new List() { new PimsTake() { IsNewInterestInSrw = true } }, false }, - new object[] { new List() { new PimsTake() { IsNewLicenseToConstruct = true } }, false }, - new object[] { new List() { new PimsTake() { IsThereSurplus = true } }, false }, - new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true } }, true }, - }.ToArray(); - #region Add [Fact] public void Add_Success() @@ -510,7 +489,7 @@ public void Update_Success_PropertyOfInterest_UserOverride() filePropertyRepository.Setup(x => x.GetPropertiesByAcquisitionFileId(It.IsAny())).Returns(acqFile.PimsPropertyAcquisitionFiles.ToList()); var propertyRepository = this._helper.GetService>(); - propertyRepository.Setup(x => x.TransferFileProperty(It.IsAny(), It.IsAny())); + propertyRepository.Setup(x => x.TransferFileProperty(It.IsAny(), It.IsAny(), It.IsAny())); var lookupRepository = this._helper.GetService>(); lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); @@ -526,11 +505,35 @@ public void Update_Success_PropertyOfInterest_UserOverride() // Assert repository.Verify(x => x.Update(It.IsAny()), Times.Once); - propertyRepository.Verify(x => x.TransferFileProperty(It.IsAny(), It.IsAny()), Times.Once); - } + propertyRepository.Verify(x => x.TransferFileProperty(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + public static object[] takesTestParameters = new List() { + new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true }, new PimsTake() { IsNewLicenseToConstruct = true } }, true, false }, + new object[] { new List() { new PimsTake() { IsNewLandAct = true }, new PimsTake() { IsNewLicenseToConstruct = true } }, true, false }, // core inventory takes priority over other interest + new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActEndDt = DateTime.UtcNow.AddDays(-1) }, new PimsTake() { IsNewLicenseToConstruct = true } }, false, false }, // should ignore any expired takes + new object[] { new List(), false, true }, // No takes should be core inventory + new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActEndDt = DateTime.UtcNow.AddDays(-1) } }, true, false }, // only expired takes is the same as no takes + new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true }, new PimsTake() { IsNewLicenseToConstruct = true } }, true, false }, + new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true }, new PimsTake() { IsNewLicenseToConstruct = true } }, true, false }, + new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true }, new PimsTake() { IsNewLicenseToConstruct = true } }, true, false }, + new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Section 15" } }, false, false }, + new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Section 16" } }, true, false }, + new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Section 17" } }, false, false }, + new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "NOI" } }, false, false }, + new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Section 66" } }, false, false }, + new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Crown Grant (New)" } }, true, false }, + new object[] { new List() { new PimsTake() { IsNewInterestInSrw = true } }, false, false }, + new object[] { new List() { new PimsTake() { IsNewLicenseToConstruct = true } }, false, false }, + new object[] { new List() { new PimsTake() { IsThereSurplus = true } }, false, false }, + new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true } }, true, false }, + new object[] { new List() { new PimsTake() { IsNewHighwayDedication = true, IsAcquiredForInventory = false } }, false, true }, + new object[] { new List() { new PimsTake() { IsNewHighwayDedication = false, IsAcquiredForInventory = true } }, true, false }, + new object[] { new List() { new PimsTake() { IsNewLandAct = true, LandActTypeCode = "Section 16", IsNewHighwayDedication = true, IsAcquiredForInventory = false } }, false, true }, + }.ToArray(); - [Theory, MemberData(nameof(takes))] - public void Update_Success_Transfer_MultipleTakes_Core(List takes, bool isOwned) + [Theory, MemberData(nameof(takesTestParameters))] + public void Update_Success_Transfer_MultipleTakes_Core(List takes, bool isOwned, bool isPropertyOfInterest) { // Arrange var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileEdit); @@ -549,7 +552,7 @@ public void Update_Success_Transfer_MultipleTakes_Core(List takes, boo var captureProperty = new PimsProperty(); var propertyRepository = this._helper.GetService>(); - propertyRepository.Setup(x => x.TransferFileProperty(captureProperty, It.IsAny())); + propertyRepository.Setup(x => x.TransferFileProperty(captureProperty, It.IsAny(), It.IsAny())); var takeRepository = this._helper.GetService>(); takeRepository.Setup(x => x.GetAllByPropertyAcquisitionFileId(It.IsAny())).Returns(takes); @@ -559,7 +562,7 @@ public void Update_Success_Transfer_MultipleTakes_Core(List takes, boo // Assert repository.Verify(x => x.Update(It.IsAny()), Times.Once); - propertyRepository.Verify(x => x.TransferFileProperty(It.IsAny(), isOwned), Times.Once); + propertyRepository.Verify(x => x.TransferFileProperty(It.IsAny(), isOwned, isPropertyOfInterest), Times.Once); } [Fact] diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx index 559127e58c..13446454d6 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx @@ -69,8 +69,8 @@ describe('TakesDetailView component', () => { props: { loading: false, takes: [ - { ...getMockApiTakes()[0], takeStatusTypeCode: 'CANCELLED', id: 1 }, - { ...getMockApiTakes()[0], takeStatusTypeCode: 'INPROGRESS' }, + { ...getMockApiTakes()[0], takeStatusTypeCode: { id: 'CANCELLED' }, id: 1 }, + { ...getMockApiTakes()[0], takeStatusTypeCode: { id: 'INPROGRESS' } }, ], }, }); @@ -85,11 +85,11 @@ describe('TakesDetailView component', () => { takes: [ { ...getMockApiTakes()[0], - isLicenseToConstruct: false, - isNewRightOfWay: false, - isLandAct: false, + isNewLicenseToConstruct: false, + isNewHighwayDedication: false, + isNewLandAct: false, isNewInterestInSrw: false, - isSurplus: false, + isThereSurplus: false, }, ], }, @@ -104,11 +104,11 @@ describe('TakesDetailView component', () => { takes: [ { ...getMockApiTakes()[0], - isLicenseToConstruct: true, - isNewRightOfWay: true, - isLandAct: true, + isNewLicenseToConstruct: true, + isNewHighwayDedication: true, + isNewLandAct: true, isNewInterestInSrw: true, - isSurplus: true, + isThereSurplus: true, }, ], }, @@ -123,7 +123,7 @@ describe('TakesDetailView component', () => { takes: [ { ...getMockApiTakes()[0], - isLicenseToConstruct: true, + isNewLicenseToConstruct: true, ltcEndDt: '2020-01-01', }, ], @@ -140,7 +140,7 @@ describe('TakesDetailView component', () => { takes: [ { ...getMockApiTakes()[0], - isLandAct: true, + isNewLandAct: true, landActEndDt: '2020-01-01', }, ], @@ -159,7 +159,7 @@ describe('TakesDetailView component', () => { takes: [ { ...getMockApiTakes()[0], - isLicenseToConstruct: true, + isNewLicenseToConstruct: true, ltcEndDt: '2020-01-01', }, ], diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.tsx b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.tsx index b579636016..05adeefe6f 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.tsx +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.tsx @@ -35,8 +35,12 @@ export const TakesDetailView: React.FunctionComponent = ( loading, onEdit, }) => { - const cancelledTakes = takes?.filter(t => t.takeStatusTypeCode === TakesStatusTypes.CANCELLED); - const nonCancelledTakes = takes?.filter(t => t.takeStatusTypeCode !== TakesStatusTypes.CANCELLED); + const cancelledTakes = takes?.filter( + t => t.takeStatusTypeCode?.id === TakesStatusTypes.CANCELLED, + ); + const nonCancelledTakes = takes?.filter( + t => t.takeStatusTypeCode?.id !== TakesStatusTypes.CANCELLED, + ); const takesNotInFile = allTakesCount - (takes?.length ?? 0); const { getCodeById } = useLookupCodeHelpers(); @@ -82,33 +86,51 @@ export const TakesDetailView: React.FunctionComponent = ( {prettyFormatUTCDate(take.appCreateTimestamp)} - {take.takeTypeCode ? getCodeById(API.TAKE_TYPES, take.takeTypeCode) : ''} + {take.takeTypeCode?.id ? getCodeById(API.TAKE_TYPES, take.takeTypeCode.id) : ''} - {take.takeStatusTypeCode - ? getCodeById(API.TAKE_STATUS_TYPES, take.takeStatusTypeCode) + {take.takeStatusTypeCode?.id + ? getCodeById(API.TAKE_STATUS_TYPES, take.takeStatusTypeCode.id) : ''} - {take.takeSiteContamTypeCode - ? getCodeById(API.TAKE_SITE_CONTAM_TYPES, take.takeSiteContamTypeCode) + {take.takeSiteContamTypeCode?.id + ? getCodeById(API.TAKE_SITE_CONTAM_TYPES, take.takeSiteContamTypeCode.id) : ''} {take.description} + + + + + + - + - {take.isNewRightOfWay && ( + {take.isNewHighwayDedication && ( - + )} @@ -120,7 +142,7 @@ export const TakesDetailView: React.FunctionComponent = ( {take.isNewInterestInSrw && ( @@ -137,9 +159,13 @@ export const TakesDetailView: React.FunctionComponent = ( - + - {take.isLandAct && ( + {take.isNewLandAct && ( <> {take.landActTypeCode @@ -165,10 +191,10 @@ export const TakesDetailView: React.FunctionComponent = ( - {take.isLicenseToConstruct && ( + {take.isNewLicenseToConstruct && ( <> @@ -184,9 +210,13 @@ export const TakesDetailView: React.FunctionComponent = ( - + - {take.isSurplus && ( + {take.isThereSurplus && ( diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakeSubForm.tsx b/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakeSubForm.tsx index 46c1cc1d5c..4e3151908a 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakeSubForm.tsx +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakeSubForm.tsx @@ -40,11 +40,14 @@ const TakeSubForm: React.FunctionComponent = ({ label: landAct.value + ' ' + landAct.label, })); - const isSurplus = getIn(values, withNameSpace(nameSpace, 'isSurplus')); - const isNewRightOfWay = getIn(values, withNameSpace(nameSpace, 'isNewRightOfWay')); + const isThereSurplus = getIn(values, withNameSpace(nameSpace, 'isThereSurplus')); + const isNewHighwayDedication = getIn(values, withNameSpace(nameSpace, 'isNewHighwayDedication')); const isNewInterestInSrw = getIn(values, withNameSpace(nameSpace, 'isNewInterestInSrw')); - const isLandAct = getIn(values, withNameSpace(nameSpace, 'isLandAct')); - const isLicenseToConstruct = getIn(values, withNameSpace(nameSpace, 'isLicenseToConstruct')); + const isNewLandAct = getIn(values, withNameSpace(nameSpace, 'isNewLandAct')); + const isNewLicenseToConstruct = getIn( + values, + withNameSpace(nameSpace, 'isNewLicenseToConstruct'), + ); const getModalWarning = (onOk: () => void) => { return (e: React.ChangeEvent) => { @@ -119,41 +122,54 @@ const TakeSubForm: React.FunctionComponent = ({ tooltip="The term new highway dedication includes municipal road or provincial public highway." > { - setFieldValue(withNameSpace(nameSpace, 'isNewRightOfWay'), 'false'); - setFieldValue(withNameSpace(nameSpace, 'newRightOfWayArea'), 0); + setFieldValue(withNameSpace(nameSpace, 'isNewHighwayDedication'), 'false'); + setFieldValue(withNameSpace(nameSpace, 'newHighwayDedicationArea'), 0); })} /> - {isNewRightOfWay === 'true' && ( + {isNewHighwayDedication === 'true' && ( <> { formikProps.setFieldValue( - withNameSpace(nameSpace, 'newRightOfWayArea'), + withNameSpace(nameSpace, 'newHighwayDedicationArea'), landArea, ); formikProps.setFieldValue( - withNameSpace(nameSpace, 'newRightOfWayAreaUnitTypeCode'), + withNameSpace(nameSpace, 'newHighwayDedicationAreaUnitTypeCode'), areaUnitTypeCode, ); }} isEditable unitCode={getIn( values, - withNameSpace(nameSpace, 'newRightOfWayAreaUnitTypeCode'), + withNameSpace(nameSpace, 'newHighwayDedicationAreaUnitTypeCode'), )} - landArea={currentTake.newRightOfWayArea} - field={withNameSpace(nameSpace, 'newRightOfWayArea')} + landArea={currentTake.newHighwayDedicationArea} + field={withNameSpace(nameSpace, 'newHighwayDedicationArea')} /> )} + + + + + = ({ { - setFieldValue(withNameSpace(nameSpace, 'isLandAct'), 'false'); + setFieldValue(withNameSpace(nameSpace, 'isNewLandAct'), 'false'); setFieldValue(withNameSpace(nameSpace, 'landActArea'), 0); setFieldValue(withNameSpace(nameSpace, 'landActEndDt'), ''); setFieldValue(withNameSpace(nameSpace, 'landActTypeCode'), ''); })} /> - {isLandAct === 'true' && ( + {isNewLandAct === 'true' && ( <> @@ -700,16 +700,16 @@ exports[`TakesUpdateForm component renders as expected 1`] = ` > @@ -841,6 +841,108 @@ exports[`TakesUpdateForm component renders as expected 1`] = ` +
+
+
+
+ +
+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+
@@ -1123,16 +1225,16 @@ exports[`TakesUpdateForm component renders as expected 1`] = `
@@ -1145,16 +1247,16 @@ exports[`TakesUpdateForm component renders as expected 1`] = ` > @@ -1436,16 +1538,16 @@ exports[`TakesUpdateForm component renders as expected 1`] = ` @@ -1458,16 +1560,16 @@ exports[`TakesUpdateForm component renders as expected 1`] = ` > @@ -1703,16 +1805,16 @@ exports[`TakesUpdateForm component renders as expected 1`] = ` @@ -1725,16 +1827,16 @@ exports[`TakesUpdateForm component renders as expected 1`] = ` > diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/update/models.test.tsx b/source/frontend/src/features/mapSideBar/property/tabs/takes/update/models.test.tsx index 5e619d0508..54d2e77b34 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/update/models.test.tsx +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/update/models.test.tsx @@ -7,48 +7,52 @@ describe('take model tests', () => { it("converts all false it values to 'false'", () => { const apiTake: Api_Take = { ...emptyTake, - isLicenseToConstruct: false, - isNewRightOfWay: false, - isLandAct: false, + isAcquiredForInventory: false, + isNewLicenseToConstruct: false, + isNewHighwayDedication: false, + isNewLandAct: false, isNewInterestInSrw: false, - isSurplus: false, + isThereSurplus: false, }; const takeModel = new TakeModel(apiTake); - expect(takeModel.isLicenseToConstruct).toBe('false'); - expect(takeModel.isNewRightOfWay).toBe('false'); - expect(takeModel.isLandAct).toBe('false'); + expect(takeModel.isAcquiredForInventory).toBe('false'); + expect(takeModel.isNewLicenseToConstruct).toBe('false'); + expect(takeModel.isNewHighwayDedication).toBe('false'); + expect(takeModel.isNewLandAct).toBe('false'); expect(takeModel.isNewInterestInSrw).toBe('false'); - expect(takeModel.isSurplus).toBe('false'); + expect(takeModel.isThereSurplus).toBe('false'); }); it("converts all true it values to 'true'", () => { const apiTake: Api_Take = { ...emptyTake, - isLicenseToConstruct: true, - isNewRightOfWay: true, - isLandAct: true, + isAcquiredForInventory: true, + isNewLicenseToConstruct: true, + isNewHighwayDedication: true, + isNewLandAct: true, isNewInterestInSrw: true, - isSurplus: true, + isThereSurplus: true, }; const takeModel = new TakeModel(apiTake); - expect(takeModel.isLicenseToConstruct).toBe('true'); - expect(takeModel.isNewRightOfWay).toBe('true'); - expect(takeModel.isLandAct).toBe('true'); + expect(takeModel.isAcquiredForInventory).toBe('true'); + expect(takeModel.isNewLicenseToConstruct).toBe('true'); + expect(takeModel.isNewHighwayDedication).toBe('true'); + expect(takeModel.isNewLandAct).toBe('true'); expect(takeModel.isNewInterestInSrw).toBe('true'); - expect(takeModel.isSurplus).toBe('true'); + expect(takeModel.isThereSurplus).toBe('true'); }); it('sets all undefined areas to 0', () => { const apiTake: Api_Take = { ...emptyTake, landActArea: null, - newRightOfWayArea: null, + newHighwayDedicationArea: null, surplusArea: null, statutoryRightOfWayArea: null, licenseToConstructArea: null, }; const takeModel = new TakeModel(apiTake); expect(takeModel.landActArea).toBe(0); - expect(takeModel.newRightOfWayArea).toBe(0); + expect(takeModel.newHighwayDedicationArea).toBe(0); expect(takeModel.surplusArea).toBe(0); expect(takeModel.statutoryRightOfWayArea).toBe(0); expect(takeModel.licenseToConstructArea).toBe(0); @@ -57,11 +61,11 @@ describe('take model tests', () => { it('sets all area units to the unit from the backend', () => { const apiTake: Api_Take = { ...emptyTake, - areaUnitTypeCode: 'FEET2', + areaUnitTypeCode: { id: 'FEET2' }, }; const takeModel = new TakeModel(apiTake); expect(takeModel.landActAreaUnitTypeCode).toBe('FEET2'); - expect(takeModel.newRightOfWayAreaUnitTypeCode).toBe('FEET2'); + expect(takeModel.newHighwayDedicationAreaUnitTypeCode).toBe('FEET2'); expect(takeModel.surplusAreaUnitTypeCode).toBe('FEET2'); expect(takeModel.statutoryRightOfWayAreaUnitTypeCode).toBe('FEET2'); expect(takeModel.licenseToConstructAreaUnitTypeCode).toBe('FEET2'); @@ -72,22 +76,22 @@ describe('take model tests', () => { const apiTake: Api_Take = { ...emptyTake, landActArea: 1, - newRightOfWayArea: 2, + newHighwayDedicationArea: 2, surplusArea: 3, statutoryRightOfWayArea: 4, licenseToConstructArea: 5, }; const takeModel = new TakeModel(apiTake); takeModel.landActAreaUnitTypeCode = 'M2'; - takeModel.newRightOfWayAreaUnitTypeCode = 'FEET2'; + takeModel.newHighwayDedicationAreaUnitTypeCode = 'FEET2'; takeModel.surplusAreaUnitTypeCode = 'HA'; takeModel.statutoryRightOfWayAreaUnitTypeCode = 'ACRE'; takeModel.licenseToConstructAreaUnitTypeCode = 'ACRE'; const actualApiTake = takeModel.toApi(); - expect(actualApiTake.areaUnitTypeCode).toBe('M2'); + expect(actualApiTake.areaUnitTypeCode?.id).toBe('M2'); expect(actualApiTake.landActArea).toBe(1); - expect(actualApiTake.newRightOfWayArea).toBe(0.18580608); + expect(actualApiTake.newHighwayDedicationArea).toBe(0.18580608); expect(actualApiTake.surplusArea).toBe(30000); expect(actualApiTake.statutoryRightOfWayArea).toBe(16187.4256896); expect(actualApiTake.licenseToConstructArea).toBe(20234.282112); diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/update/models.ts b/source/frontend/src/features/mapSideBar/property/tabs/takes/update/models.ts index 57eecc84e1..08dbd175ea 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/update/models.ts +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/update/models.ts @@ -3,30 +3,30 @@ import * as Yup from 'yup'; import { AreaUnitTypes } from '@/constants/areaUnitTypes'; import { Api_Take } from '@/models/api/Take'; import { convertArea } from '@/utils/convertUtils'; -/* eslint-disable no-template-curly-in-string */ -import { stringToUndefined, toTypeCode } from '@/utils/formUtils'; +import { fromTypeCodeNullable, stringToUndefined, toTypeCodeNullable } from '@/utils/formUtils'; +/* eslint-disable no-template-curly-in-string */ export const TakesYupSchema = Yup.object().shape({ takes: Yup.array().of( Yup.object().shape({ description: Yup.string().max(4000, 'Description must be at most ${max} characters'), takeTypeCode: Yup.string().required('Take type is required').nullable(), takeStatusTypeCode: Yup.string().required('Take status type is required.'), - isSurplus: Yup.bool().required('Surplus flag required'), - isNewRightOfWay: Yup.bool().required('New highway dedication flag required'), - isLandAct: Yup.bool().required('Section 16 flag required'), + isThereSurplus: Yup.bool().required('Surplus flag required'), + isNewHighwayDedication: Yup.bool().required('New highway dedication flag required'), + isNewLandAct: Yup.bool().required('Section 16 flag required'), isNewInterestInSrw: Yup.bool().required('Statutory right of way (SRW) flag required'), - isLicenseToConstruct: Yup.bool().required('License to construct flag required'), - ltcEndDt: Yup.string().when('isLicenseToConstruct', { - is: (isLicenseToConstruct: boolean) => isLicenseToConstruct, + isNewLicenseToConstruct: Yup.bool().required('License to construct flag required'), + ltcEndDt: Yup.string().when('isNewLicenseToConstruct', { + is: (isNewLicenseToConstruct: boolean) => isNewLicenseToConstruct, then: Yup.string().required('End Date is required'), }), - landActEndDt: Yup.string().when('isLandAct', { - is: (isLandAct: boolean) => isLandAct, + landActEndDt: Yup.string().when('isNewLandAct', { + is: (isNewLandAct: boolean) => isNewLandAct, then: Yup.string().required('End Date is required'), }), - landActTypeCode: Yup.string().when('isLandAct', { - is: (isLandAct: boolean) => isLandAct, + landActTypeCode: Yup.string().when('isNewLandAct', { + is: (isNewLandAct: boolean) => isNewLandAct, then: Yup.string().required('Land Act is required'), }), }), @@ -36,16 +36,14 @@ export const TakesYupSchema = Yup.object().shape({ export class TakeModel { id?: number; description: string; - isSurplus: 'false' | 'true'; - isNewRightOfWay: 'false' | 'true'; - isLandAct: 'false' | 'true'; + isThereSurplus: 'false' | 'true'; + isNewHighwayDedication: 'false' | 'true'; + isNewLandAct: 'false' | 'true'; isNewInterestInSrw: 'false' | 'true'; - isLicenseToConstruct: 'false' | 'true'; + isNewLicenseToConstruct: 'false' | 'true'; ltcEndDt: string; licenseToConstructArea: number; licenseToConstructAreaUnitTypeCode: string; - newRightOfWayArea: number; - newRightOfWayAreaUnitTypeCode: string; landActArea: number; landActAreaUnitTypeCode: string; landActEndDt: string; @@ -60,58 +58,72 @@ export class TakeModel { takeSiteContamTypeCode: string | null = 'UNK'; takeTypeCode: string | null; takeStatusTypeCode: string | null; + isAcquiredForInventory: 'false' | 'true'; + newHighwayDedicationArea: number; + newHighwayDedicationAreaUnitTypeCode: string; rowVersion?: number; constructor(base: Api_Take) { this.id = base.id; this.rowVersion = base.rowVersion; this.description = base.description; - this.isSurplus = base.isSurplus ? 'true' : 'false'; - this.isNewRightOfWay = base.isNewRightOfWay ? 'true' : 'false'; - this.isLandAct = base.isLandAct ? 'true' : 'false'; - this.isLicenseToConstruct = base.isLicenseToConstruct ? 'true' : 'false'; + this.isThereSurplus = base.isThereSurplus ? 'true' : 'false'; + this.isNewHighwayDedication = base.isNewHighwayDedication ? 'true' : 'false'; + this.isNewLandAct = base.isNewLandAct ? 'true' : 'false'; + this.isNewLicenseToConstruct = base.isNewLicenseToConstruct ? 'true' : 'false'; this.isNewInterestInSrw = base.isNewInterestInSrw ? 'true' : 'false'; this.licenseToConstructArea = base.licenseToConstructArea ?? 0; this.licenseToConstructAreaUnitTypeCode = - base.areaUnitTypeCode ?? AreaUnitTypes.SquareMeters.toString(); - this.newRightOfWayArea = base.newRightOfWayArea ?? 0; - this.newRightOfWayAreaUnitTypeCode = - base.areaUnitTypeCode ?? AreaUnitTypes.SquareMeters.toString(); + fromTypeCodeNullable(base.areaUnitTypeCode) ?? AreaUnitTypes.SquareMeters.toString(); this.landActArea = base.landActArea ?? 0; - this.landActAreaUnitTypeCode = base.areaUnitTypeCode ?? AreaUnitTypes.SquareMeters.toString(); + this.landActAreaUnitTypeCode = + fromTypeCodeNullable(base.areaUnitTypeCode) ?? AreaUnitTypes.SquareMeters.toString(); this.surplusArea = base.surplusArea ?? 0; - this.surplusAreaUnitTypeCode = base.areaUnitTypeCode ?? AreaUnitTypes.SquareMeters.toString(); + this.surplusAreaUnitTypeCode = + fromTypeCodeNullable(base.areaUnitTypeCode) ?? AreaUnitTypes.SquareMeters.toString(); this.statutoryRightOfWayArea = base.statutoryRightOfWayArea ?? 0; this.statutoryRightOfWayAreaUnitTypeCode = - base.areaUnitTypeCode ?? AreaUnitTypes.SquareMeters.toString(); - this.takeTypeCode = base.takeTypeCode; - this.takeStatusTypeCode = base.takeStatusTypeCode; - this.takeSiteContamTypeCode = base.takeSiteContamTypeCode ? base.takeSiteContamTypeCode : 'UNK'; + fromTypeCodeNullable(base.areaUnitTypeCode) ?? AreaUnitTypes.SquareMeters.toString(); + this.takeTypeCode = fromTypeCodeNullable(base.takeTypeCode); + this.takeStatusTypeCode = fromTypeCodeNullable(base.takeStatusTypeCode); + this.takeSiteContamTypeCode = base.takeSiteContamTypeCode + ? fromTypeCodeNullable(base.takeSiteContamTypeCode) + : 'UNK'; this.propertyAcquisitionFileId = base.propertyAcquisitionFileId; this.landActEndDt = base.landActEndDt ?? ''; this.ltcEndDt = base.ltcEndDt ?? ''; this.srwEndDt = base.srwEndDt ?? ''; this.landActDescription = base.landActTypeCode?.description ?? ''; this.landActTypeCode = base.landActTypeCode?.id ?? ''; + + this.isAcquiredForInventory = base.isAcquiredForInventory ? 'true' : 'false'; + this.newHighwayDedicationArea = base.newHighwayDedicationArea ?? 0; + this.newHighwayDedicationAreaUnitTypeCode = + fromTypeCodeNullable(base.areaUnitTypeCode) ?? AreaUnitTypes.SquareMeters.toString(); } toApi(): Api_Take { return { - ...this, - takeSiteContamTypeCode: this.takeSiteContamTypeCode || null, - areaUnitTypeCode: AreaUnitTypes.SquareMeters.toString(), - takeTypeCode: this.takeTypeCode || null, - takeStatusTypeCode: this.takeStatusTypeCode || null, - licenseToConstructArea: + id: this.id || 0, + propertyAcquisitionFileId: this.propertyAcquisitionFileId || 0, + propertyAcquisitionFile: null, + description: this.description, + isNewHighwayDedication: this.isNewHighwayDedication === 'true', + newHighwayDedicationArea: convertArea( - parseFloat(this.licenseToConstructArea.toString()), - this.licenseToConstructAreaUnitTypeCode, + parseFloat(this.newHighwayDedicationArea.toString()), + this.newHighwayDedicationAreaUnitTypeCode, AreaUnitTypes.SquareMeters.toString(), ) || null, - newRightOfWayArea: + isAcquiredForInventory: this.isAcquiredForInventory === 'true', + takeSiteContamTypeCode: toTypeCodeNullable(this.takeSiteContamTypeCode), + areaUnitTypeCode: toTypeCodeNullable(AreaUnitTypes.SquareMeters.toString()), + takeTypeCode: toTypeCodeNullable(this.takeTypeCode), + takeStatusTypeCode: toTypeCodeNullable(this.takeStatusTypeCode), + licenseToConstructArea: convertArea( - parseFloat(this.newRightOfWayArea.toString()), - this.newRightOfWayAreaUnitTypeCode, + parseFloat(this.licenseToConstructArea.toString()), + this.licenseToConstructAreaUnitTypeCode, AreaUnitTypes.SquareMeters.toString(), ) || null, landActArea: @@ -135,12 +147,12 @@ export class TakeModel { srwEndDt: stringToUndefined(this.srwEndDt), ltcEndDt: stringToUndefined(this.ltcEndDt), landActEndDt: stringToUndefined(this.landActEndDt), - landActTypeCode: toTypeCode(this.landActTypeCode), - isSurplus: this.isSurplus === 'true', - isNewRightOfWay: this.isNewRightOfWay === 'true', - isLandAct: this.isLandAct === 'true', - isLicenseToConstruct: this.isLicenseToConstruct === 'true', + landActTypeCode: toTypeCodeNullable(this.landActTypeCode), + isThereSurplus: this.isThereSurplus === 'true', + isNewLandAct: this.isNewLandAct === 'true', + isNewLicenseToConstruct: this.isNewLicenseToConstruct === 'true', isNewInterestInSrw: this.isNewInterestInSrw === 'true', + rowVersion: this.rowVersion, }; } } diff --git a/source/frontend/src/mocks/takes.mock.ts b/source/frontend/src/mocks/takes.mock.ts index 6432ea20ca..63b88e6539 100644 --- a/source/frontend/src/mocks/takes.mock.ts +++ b/source/frontend/src/mocks/takes.mock.ts @@ -3,27 +3,29 @@ export const getMockApiTakes = (): Api_Take[] => [ { id: 4, description: '', - isSurplus: true, - isLicenseToConstruct: true, - isNewRightOfWay: true, - isLandAct: true, + newHighwayDedicationArea: 4046.8564, + isAcquiredForInventory: null, + isThereSurplus: true, + isNewLicenseToConstruct: true, + isNewHighwayDedication: true, + isNewLandAct: true, isNewInterestInSrw: true, licenseToConstructArea: 16187.426, - newRightOfWayArea: 4046.8564, landActArea: 12140.569, + propertyAcquisitionFile: null, propertyAcquisitionFileId: 1, statutoryRightOfWayArea: 8093.713, surplusArea: 20234.281, - takeSiteContamTypeCode: 'UNK', - takeTypeCode: 'PARTIAL', - takeStatusTypeCode: 'INPROGRESS', + takeSiteContamTypeCode: { id: 'UNK' }, + takeTypeCode: { id: 'PARTIAL' }, + takeStatusTypeCode: { id: 'INPROGRESS' }, appCreateTimestamp: '2023-03-08T04:15:56.273', appLastUpdateTimestamp: '2023-03-08T05:51:09.953', appLastUpdateUserid: 'DESMITH', appCreateUserid: 'DESMITH', appLastUpdateUserGuid: '7db28007-0d47-4ef0-bb46-c365a4b95a73', appCreateUserGuid: '7db28007-0d47-4ef0-bb46-c365a4b95a73', - areaUnitTypeCode: 'M2', + areaUnitTypeCode: { id: 'M2' }, ltcEndDt: '2020-01-01', landActEndDt: '2020-01-01', srwEndDt: '2022-11-20', diff --git a/source/frontend/src/models/api/Take.ts b/source/frontend/src/models/api/Take.ts index 474c132fb5..23a9a1a663 100644 --- a/source/frontend/src/models/api/Take.ts +++ b/source/frontend/src/models/api/Take.ts @@ -1,27 +1,31 @@ +import { Api_AcquisitionFile } from './AcquisitionFile'; import { Api_AuditFields } from './AuditFields'; import { Api_ConcurrentVersion } from './ConcurrentVersion'; import Api_TypeCode from './TypeCode'; +// LINK @backend/api/Models/Concepts/Take/TakeModel.cs export interface Api_Take extends Api_ConcurrentVersion, Api_AuditFields { - id?: number; + id: number; description: string; - areaUnitTypeCode: string; - isSurplus: boolean; - isLandAct: boolean; - isNewInterestInSrw: boolean; - isNewRightOfWay: boolean; - isLicenseToConstruct: boolean; + newHighwayDedicationArea: number | null; + areaUnitTypeCode: Api_TypeCode | null; + isAcquiredForInventory: boolean | null; + isThereSurplus: boolean | null; + isNewLicenseToConstruct: boolean | null; + isNewHighwayDedication: boolean | null; + isNewLandAct: boolean | null; + isNewInterestInSrw: boolean | null; licenseToConstructArea: number | null; ltcEndDt: string | null; - newRightOfWayArea: number | null; landActArea: number | null; landActEndDt: string | null; - landActTypeCode: Api_TypeCode | null; + propertyAcquisitionFile: Api_AcquisitionFile | null; + propertyAcquisitionFileId: number; statutoryRightOfWayArea: number | null; srwEndDt: string | null; surplusArea: number | null; - propertyAcquisitionFileId: number | null; - takeSiteContamTypeCode: string | null; - takeTypeCode: string | null; - takeStatusTypeCode: string | null; + takeSiteContamTypeCode: Api_TypeCode | null; + takeTypeCode: Api_TypeCode | null; + takeStatusTypeCode: Api_TypeCode | null; + landActTypeCode: Api_TypeCode | null; } diff --git a/source/frontend/src/utils/formUtils.ts b/source/frontend/src/utils/formUtils.ts index 59a6e84fc9..6bf0993d0d 100644 --- a/source/frontend/src/utils/formUtils.ts +++ b/source/frontend/src/utils/formUtils.ts @@ -65,10 +65,18 @@ export function toTypeCode(value?: T | null): Api_TypeCode | unde return !!value ? { id: value } : undefined; } +export function toTypeCodeNullable(value?: T | null): Api_TypeCode | null { + return !!value ? { id: value } : null; +} + export function fromTypeCode(value?: Api_TypeCode | null): T | undefined { return value?.id; } +export function fromTypeCodeNullable(value?: Api_TypeCode | null): T | null { + return value?.id ?? null; +} + export function stringToBoolean(value: string | boolean): boolean { if (typeof value === 'string') { return value === 'true'; From ce0ee3b69372d6a86790789a376fe900f98167b1 Mon Sep 17 00:00:00 2001 From: Manuel Rodriguez Date: Tue, 7 Nov 2023 16:30:58 -0800 Subject: [PATCH 2/2] Fixed tests --- .../property/tabs/takes/detail/TakesDetailView.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx index f95a9eff57..f9003eaf83 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx @@ -69,8 +69,8 @@ describe('TakesDetailView component', () => { props: { loading: false, takes: [ - { ...getMockApiTakes()[0], takeStatusTypeCode: 'CANCELLED', id: 1 }, - { ...getMockApiTakes()[0], takeStatusTypeCode: 'INPROGRESS' }, + { ...getMockApiTakes()[0], takeStatusTypeCode: { id: 'CANCELLED' }, id: 1 }, + { ...getMockApiTakes()[0], takeStatusTypeCode: { id: 'INPROGRESS' } }, ], allTakesCount: 10, },