Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psp 7081 cancellation status and note. #3596

Merged
merged 4 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/backend/api/Controllers/LookupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public IActionResult GetAll()
var acqChecklistSectionTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllAcquisitionChecklistSectionTypes());
var acqChecklistItemStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllAcquisitionChecklistItemStatusTypes());
var agreementTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllAgreementTypes());
var agreementStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllAgreementStatusTypes());
var interestHolderInterestTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllInterestHolderInterestTypes());
var expropriationPaymentItemTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllExpropriationPaymentItemTypes());
var mgmtActivityStatusTypes = _mapper.Map<Model.LookupModel[]>(_lookupRepository.GetAllPropMgmtActivityStatusTypes());
Expand Down Expand Up @@ -189,6 +190,7 @@ public IActionResult GetAll()
codes.AddRange(acqChecklistSectionTypes);
codes.AddRange(acqChecklistItemStatusTypes);
codes.AddRange(agreementTypes);
codes.AddRange(agreementStatusTypes);
codes.AddRange(interestHolderInterestTypes);
codes.AddRange(expropriationPaymentItemTypes);
codes.AddRange(mgmtActivityStatusTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.AgreementId, src => src.AgreementId)
.Map(dest => dest.AcquisitionFileId, src => src.AcquisitionFileId)
.Map(dest => dest.AgreementType, src => src.AgreementTypeCodeNavigation)
.Map(dest => dest.AgreementStatusType, src => src.AgreementStatusTypeCodeNavigation)
.Map(dest => dest.AgreementDate, src => src.AgreementDate)
//.Map(dest => dest.IsDraft, src => src.IsDraft) TODO: Fix this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed now that the status covers is draft

.Map(dest => dest.CompletionDate, src => src.CompletionDate)
Expand All @@ -25,12 +26,14 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.ExpiryDateTime, src => src.ExpiryTs)
.Map(dest => dest.SignedDate, src => src.SignedDate)
.Map(dest => dest.InspectionDate, src => src.InspectionDate)
.Map(dest => dest.CancellationNote, src => src.CancellationNote)
.Inherits<Entity.IBaseAppEntity, BaseAppModel>();

config.NewConfig<AgreementModel, Entity.PimsAgreement>()
.Map(dest => dest.AgreementId, src => src.AgreementId)
.Map(dest => dest.AcquisitionFileId, src => src.AcquisitionFileId)
.Map(dest => dest.AgreementTypeCode, src => src.AgreementType.Id)
.Map(dest => dest.AgreementStatusTypeCode, src => src.AgreementStatusType.Id)
.Map(dest => dest.AgreementDate, src => src.AgreementDate)
//.Map(dest => dest.IsDraft, src => src.IsDraft) TODO: Fix this
.Map(dest => dest.CompletionDate, src => src.CompletionDate)
Expand All @@ -45,6 +48,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.ExpiryTs, src => src.ExpiryDateTime)
.Map(dest => dest.SignedDate, src => src.SignedDate)
.Map(dest => dest.InspectionDate, src => src.InspectionDate)
.Map(dest => dest.CancellationNote, src => src.CancellationNote)
.Inherits<BaseAppModel, Entity.IBaseAppEntity>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class AgreementModel : BaseAppModel

public TypeModel<string> AgreementType { get; set; }

public TypeModel<string> AgreementStatusType { get; set; }

public DateTime? AgreementDate { get; set; }

public bool? IsDraft { get; set; }
Expand Down Expand Up @@ -37,5 +39,7 @@ public class AgreementModel : BaseAppModel
public DateTime? SignedDate { get; set; }

public DateTime? InspectionDate { get; set; }

public string CancellationNote { get; set; }
}
}
1 change: 1 addition & 0 deletions source/backend/dal/Repositories/AgreementRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
return Context.PimsAgreements
.Where(ci => ci.AcquisitionFileId == acquisitionFileId)
.Include(ci => ci.AgreementTypeCodeNavigation)
.Include(ci => ci.AgreementStatusTypeCodeNavigation)

Check warning on line 42 in source/backend/dal/Repositories/AgreementRepository.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/dal/Repositories/AgreementRepository.cs#L42

Added line #L42 was not covered by tests
.AsNoTracking()
.ToList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,7 @@ public interface ILookupRepository : IRepository
IEnumerable<PimsPropMgmtActivitySubtype> GetAllPropMgmtActivitySubtypes();

IEnumerable<PimsPropMgmtActivityType> GetAllPropMgmtActivityTypes();

IEnumerable<PimsAgreementStatusType> GetAllAgreementStatusTypes();
}
}
5 changes: 5 additions & 0 deletions source/backend/dal/Repositories/LookupRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@
return Context.PimsPropMgmtActivityTypes.AsNoTracking().ToArray();
}

public IEnumerable<PimsAgreementStatusType> GetAllAgreementStatusTypes()
{
return Context.PimsAgreementStatusTypes.AsNoTracking().ToArray();
}

Check warning on line 379 in source/backend/dal/Repositories/LookupRepository.cs

View check run for this annotation

Codecov / codecov/patch

source/backend/dal/Repositories/LookupRepository.cs#L377-L379

Added lines #L377 - L379 were not covered by tests

#endregion
}
}
19 changes: 19 additions & 0 deletions source/backend/entities/Partials/AgreementStatusType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace Pims.Dal.Entities
{
/// <summary>
/// PimsAgreementStatusType class, provides an entity for the datamodel to manage agreement status types.
/// </summary>
public partial class PimsAgreementStatusType : ITypeEntity<string>
{
#region Properties

/// <summary>
/// get/set - Primary key to identify agreement status type.
/// </summary>
[NotMapped]
public string Id { get => AgreementStatusTypeCode; set => AgreementStatusTypeCode = value; }
#endregion
}
}
1 change: 1 addition & 0 deletions source/frontend/src/constants/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const PAYMENT_ITEM_TYPES = 'PimsPaymentItemType';
export const PROP_MGMT_ACTIVITY_STATUS_TYPES = 'PimsPropMgmtActivityStatusType';
export const PROP_MGMT_ACTIVITY_SUBTYPES_TYPES = 'PimsPropMgmtActivitySubtype';
export const PROP_MGMT_ACTIVITY_TYPES = 'PimsPropMgmtActivityType';
export const AGREEMENT_STATUS_TYPES = 'PimsAgreementStatusType';

// TODO: PSP-4395 This should all be removed from this and moved to the useApi* hooks.
// Auth Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { StyledAddButton } from '@/components/common/styles';
import Claims from '@/constants/claims';
import useKeycloakWrapper from '@/hooks/useKeycloakWrapper';
import { Api_Agreement } from '@/models/api/Agreement';
import { AgreementStatusTypes, Api_Agreement } from '@/models/api/Agreement';
import { formatMoney, prettyFormatDate } from '@/utils';

import { StyledSectionSubheader } from '../styles';
Expand Down Expand Up @@ -73,8 +73,13 @@
>
<StyledSectionSubheader>Agreement details</StyledSectionSubheader>
<SectionField labelWidth="5" label="Agreement status">
{agreement.isDraft === true ? 'Draft' : 'Final'}
{agreement.agreementStatusType?.description ?? ''}
</SectionField>
{agreement.agreementStatusType?.id === AgreementStatusTypes.CANCELLED && (
<SectionField labelWidth="5" label="Cancellation reason">
{agreement.cancellationNote ?? ''}

Check warning on line 80 in source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/detail/AgreementView.tsx

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/detail/AgreementView.tsx#L79-L80

Added lines #L79 - L80 were not covered by tests
</SectionField>
)}
<SectionField labelWidth="5" label="Legal survey plan">
{agreement.legalSurveyPlanNum}
</SectionField>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { FormikProps } from 'formik';
import React from 'react';
import { FormikProps, getIn } from 'formik';
import React, { useEffect } from 'react';
import styled from 'styled-components';

import {
FastCurrencyInput,
FastDatePicker,
Input,
Select,
SelectOption,
TextArea,
} from '@/components/common/form';
import { SectionField, StyledFieldLabel } from '@/components/common/Section/SectionField';
import * as API from '@/constants/API';
import useLookupCodeHelpers from '@/hooks/useLookupCodeHelpers';
import { useModalContext } from '@/hooks/useModalContext';
import { AgreementStatusTypes } from '@/models/api/Agreement';
import { ILookupCode } from '@/store/slices/lookupCodes';
import { mapLookupCode } from '@/utils';
import { withNameSpace } from '@/utils/formUtils';
Expand All @@ -32,16 +35,53 @@
agreementTypes,
}) => {
const H0074Type = 'H0074';
const options: SelectOption[] = [
{ label: 'Draft', value: 'true' },
{ label: 'Final', value: 'false' },
];
const { getOptionsByType } = useLookupCodeHelpers();

const agreementStatusOptions = getOptionsByType(API.AGREEMENT_STATUS_TYPES);
const agreement = getIn(formikProps.values, nameSpace);

const { setDisplayModal, setModalContent } = useModalContext();
const setFieldValue = formikProps.setFieldValue;
useEffect(() => {
if (
agreement.agreementStatusTypeCode !== AgreementStatusTypes.CANCELLED &&
!!agreement.cancellationNote
) {
setModalContent({
okButtonText: 'Yes',
cancelButtonText: 'No',
message:
'Changing status to a status other than "Cancelled" will remove your "Cancellation reason". Are you sure you want to continue?',
title: 'Warning',
handleCancel: () => {
setFieldValue(

Check warning on line 57 in source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/AgreementSubForm.tsx

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/AgreementSubForm.tsx#L56-L57

Added lines #L56 - L57 were not covered by tests
withNameSpace(nameSpace, 'agreementStatusTypeCode'),
AgreementStatusTypes.CANCELLED,
);
setDisplayModal(false);

Check warning on line 61 in source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/AgreementSubForm.tsx

View check run for this annotation

Codecov / codecov/patch

source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/AgreementSubForm.tsx#L61

Added line #L61 was not covered by tests
},
handleOk: () => {
setFieldValue(withNameSpace(nameSpace, 'cancellationNote'), '');
setDisplayModal(false);
},
});
setDisplayModal(true);
}
}, [agreement, setFieldValue, nameSpace, setDisplayModal, setModalContent]);
return (
<>
<StyledSectionSubheader>Agreement details</StyledSectionSubheader>
<SectionField labelWidth="5" label="Agreement status">
<Select options={options} field={withNameSpace(nameSpace, 'isDraft')} />
<Select
options={agreementStatusOptions}
field={withNameSpace(nameSpace, 'agreementStatusTypeCode')}
/>
</SectionField>
{agreement.agreementStatusTypeCode === AgreementStatusTypes.CANCELLED && (
<SectionField labelWidth="5" label="Cancellation reason">
<Input field={withNameSpace(nameSpace, 'cancellationNote')} />
</SectionField>
)}
<SectionField labelWidth="5" label="Legal survey plan">
<Input field={withNameSpace(nameSpace, 'legalSurveyPlanNum')} />
</SectionField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { useApiUsers } from '@/hooks/pims-api/useApiUsers';
import { mockAgreementsResponse } from '@/mocks/agreements.mock';
import { mockLookups } from '@/mocks/index.mock';
import { ILookupCode, lookupCodesSlice } from '@/store/slices/lookupCodes';
import { act, render, RenderOptions } from '@/utils/test-utils';
import {
act,
fillInput,
render,
RenderOptions,
selectOptions,
userEvent,
} from '@/utils/test-utils';

import { AgreementsFormModel } from './models';
import { IUpdateAgreementsFormProps, UpdateAgreementsForm } from './UpdateAgreementsForm';
Expand Down Expand Up @@ -79,4 +86,48 @@ describe('UpdateAgreementsForm component', () => {
});
expect(mockViewProps.onSave).toHaveBeenCalled();
});

it('does not display cancellation note by default', async () => {
const { queryByText } = setup();

expect(queryByText(/Cancellation reason/i)).toBeNull();
});

it('displays cancellation note if status is cancelled', async () => {
const { getByText } = setup();

await act(async () => {
await act(() => selectOptions('agreements.0.agreementStatusTypeCode', 'CANCELLED'));
});
expect(getByText(/Cancellation reason/i)).toBeVisible();
});

it('displays a popup if status is changed from cancelled and there is a cancellation note', async () => {
const { getByText, container } = setup();

await act(async () => selectOptions('agreements.0.agreementStatusTypeCode', 'CANCELLED'));
await act(async () =>
fillInput(container, 'agreements.0.cancellationNote', 'this is a test cancellation note'),
);
await act(async () => selectOptions('agreements.0.agreementStatusTypeCode', 'DRAFT'));
expect(
getByText(
'Changing status to a status other than "Cancelled" will remove your "Cancellation reason". Are you sure you want to continue?',
),
).toBeVisible();
});

it('hides cancellation note if status is changed from cancelled and there is a cancellation note, and the displayed popup is confirmed', async () => {
const { container, getByText, formikRef, queryByText } = setup();

await act(async () => selectOptions('agreements.0.agreementStatusTypeCode', 'CANCELLED'));
await act(async () =>
fillInput(container, 'agreements.0.cancellationNote', 'this is a test cancellation note'),
);
await act(async () => selectOptions('agreements.0.agreementStatusTypeCode', 'DRAFT'));
await act(async () => userEvent.click(getByText('Yes')));

expect(queryByText(/Cancellation reason/i)).toBeNull();
expect(formikRef.current?.values.agreements[0].cancellationNote).toBe('');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -394,23 +394,30 @@ exports[`UpdateAgreementsForm component renders as expected 1`] = `
>
<select
class="form-select form-control"
id="input-agreements.0.isDraft"
name="agreements.0.isDraft"
id="input-agreements.0.agreementStatusTypeCode"
name="agreements.0.agreementStatusTypeCode"
>
<option
class="option"
data-testid="select-option-true"
value="true"
data-testid="select-option-DRAFT"
value="DRAFT"
>
Draft
</option>
<option
class="option"
data-testid="select-option-false"
value="false"
data-testid="select-option-FINAL"
value="FINAL"
>
Final
</option>
<option
class="option"
data-testid="select-option-CANCELLED"
value="CANCELLED"
>
Cancelled
</option>
</select>
</div>
</div>
Expand Down Expand Up @@ -977,23 +984,30 @@ exports[`UpdateAgreementsForm component renders as expected 1`] = `
>
<select
class="form-select form-control"
id="input-agreements.1.isDraft"
name="agreements.1.isDraft"
id="input-agreements.1.agreementStatusTypeCode"
name="agreements.1.agreementStatusTypeCode"
>
<option
class="option"
data-testid="select-option-true"
value="true"
data-testid="select-option-DRAFT"
value="DRAFT"
>
Draft
</option>
<option
class="option"
data-testid="select-option-false"
value="false"
data-testid="select-option-FINAL"
value="FINAL"
>
Final
</option>
<option
class="option"
data-testid="select-option-CANCELLED"
value="CANCELLED"
>
Cancelled
</option>
</select>
</div>
</div>
Expand Down
Loading
Loading