Skip to content

Commit

Permalink
Merge branch 'dev' into PSP-8708
Browse files Browse the repository at this point in the history
  • Loading branch information
asanchezr authored Jul 12, 2024
2 parents 48ec6b7 + fa59c26 commit 09ed155
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 98 deletions.
4 changes: 2 additions & 2 deletions source/backend/api/Pims.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<UserSecretsId>0ef6255f-9ea0-49ec-8c65-c172304b4926</UserSecretsId>
<Version>5.4.0-84.30</Version>
<Version>5.4.0-84.30</Version>
<Version>5.4.0-84.31</Version>
<Version>5.4.0-84.31</Version>
<AssemblyVersion>5.4.0.84</AssemblyVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProjectGuid>16BC0468-78F6-4C91-87DA-7403C919E646</ProjectGuid>
Expand Down
2 changes: 1 addition & 1 deletion source/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "5.4.0-84.30",
"version": "5.4.0-84.31",
"private": true,
"dependencies": {
"@bcgov/bc-sans": "1.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ describe('AddLeaseContainer component', () => {
it('cancels the form', async () => {
const { getByTitle, getCloseButton } = await setup({});

await act(async () => selectOptions('regionId', '1'));
await act(async () => userEvent.click(getCloseButton()));
await act(async () => userEvent.click(getByTitle('ok-modal')));

Expand Down Expand Up @@ -211,7 +212,7 @@ describe('AddLeaseContainer component', () => {

const leaseData: ApiGen_Concepts_Lease = {
...getEmptyLease(),
rowVersion: 0,
rowVersion: null,
startDate: '2020-01-01',
amount: 0,
paymentReceivableType: toTypeCodeNullable(ApiGen_CodeTypes_LeaseAccountTypes.RCVBL),
Expand Down
10 changes: 8 additions & 2 deletions source/frontend/src/features/leases/add/AddLeaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Formik, FormikHelpers, FormikProps } from 'formik';
import styled from 'styled-components';

import { IMapProperty } from '@/components/propertySelector/models';
import * as API from '@/constants/API';
import useLookupCodeHelpers from '@/hooks/useLookupCodeHelpers';

import { FormLeaseProperty, getDefaultFormLease, LeaseFormModel } from '../models';
import LeasePropertySelector from '../shared/propertyPicker/LeasePropertySelector';
import { AddLeaseYupSchema } from './AddLeaseYupSchema';
import AdministrationSubForm from './AdministrationSubForm';
import ConsultationSubForm from './ConsultationSubForm';
import ConsultationSubForm, { getConsultations } from './ConsultationSubForm';
import LeaseDetailSubForm from './LeaseDetailSubForm';
import DocumentationSubForm from './ReferenceSubForm';

Expand All @@ -26,6 +28,10 @@ const AddLeaseForm: React.FunctionComponent<React.PropsWithChildren<IAddLeaseFor
propertyInfo,
}) => {
const defaultFormLease = getDefaultFormLease();
const apiFormLease = LeaseFormModel.toApi(defaultFormLease);
const { getByType } = useLookupCodeHelpers();
const consultationTypes = getByType(API.CONSULTATION_TYPES);
apiFormLease.consultations = getConsultations(apiFormLease, consultationTypes);
if (propertyInfo) {
defaultFormLease.properties = [];
defaultFormLease.properties.push(FormLeaseProperty.fromMapProperty(propertyInfo));
Expand All @@ -44,7 +50,7 @@ const AddLeaseForm: React.FunctionComponent<React.PropsWithChildren<IAddLeaseFor
<Formik<LeaseFormModel>
enableReinitialize
innerRef={formikRef}
initialValues={defaultFormLease}
initialValues={LeaseFormModel.fromApi(apiFormLease)}
validationSchema={AddLeaseYupSchema}
onSubmit={handleSubmit}
>
Expand Down
80 changes: 46 additions & 34 deletions source/frontend/src/features/leases/add/ConsultationSubForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { Section } from '@/components/common/Section/Section';
import { SectionField } from '@/components/common/Section/SectionField';
import * as API from '@/constants/API';
import useLookupCodeHelpers from '@/hooks/useLookupCodeHelpers';
import useDeepCompareEffect from '@/hooks/util/useDeepCompareEffect';
import { ApiGen_Concepts_ConsultationLease } from '@/models/api/generated/ApiGen_Concepts_ConsultationLease';
import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Lease';
import { getEmptyBaseAudit } from '@/models/defaultInitializers';

import { FormLeaseConsultation, LeaseFormModel } from '../models';
import { LeaseFormModel } from '../models';

export interface IConsultationSubFormProps {
formikProps: FormikProps<LeaseFormModel>;
Expand All @@ -17,40 +19,10 @@ export interface IConsultationSubFormProps {
const ConsultationSubForm: React.FunctionComponent<
React.PropsWithChildren<IConsultationSubFormProps>
> = ({ formikProps }) => {
const { values, setFieldValue } = formikProps;
const { consultations } = values;
const { getOptionsByType, getByType } = useLookupCodeHelpers();
const consultationTypes = getByType(API.CONSULTATION_TYPES);
const { values } = formikProps;
const { getOptionsByType } = useLookupCodeHelpers();
const consultationStatusTypes = getOptionsByType(API.CONSULTATION_STATUS_TYPES);

useDeepCompareEffect(() => {
// Not all consultations might be coming from the backend. Add the ones missing.
if (consultations.length !== consultationTypes.length) {
const newConsultations: FormLeaseConsultation[] = [];

consultationTypes.forEach(consultationType => {
const newConsultation = FormLeaseConsultation.fromApiLookup(
values.id || 0,
consultationType,
);

// If there is a consultation with the type, set the status to the existing one
const existingConsultation = consultations.find(
consultation => consultation.consultationType === consultationType.id,
);
if (existingConsultation !== undefined) {
newConsultation.id = existingConsultation.id;
newConsultation.consultationStatusType = existingConsultation.consultationStatusType;
newConsultation.consultationStatusTypeDescription =
existingConsultation.consultationStatusTypeDescription;
newConsultation.rowVersion = existingConsultation.rowVersion;
}
newConsultations.push(newConsultation);
});
setFieldValue('consultations', newConsultations);
}
}, [consultationTypes, consultations, setFieldValue, values.id]);

return (
<Section header="Consultation" isCollapsable initiallyExpanded>
{values.consultations.map((consultation, i) => (
Expand Down Expand Up @@ -84,4 +56,44 @@ const ConsultationSubForm: React.FunctionComponent<
);
};

export const getConsultations = (lease: ApiGen_Concepts_Lease, consultationTypes) => {
if (lease.consultations?.length !== consultationTypes.length) {
const newConsultations: ApiGen_Concepts_ConsultationLease[] = [];

consultationTypes.forEach(consultationType => {
const newConsultation: ApiGen_Concepts_ConsultationLease = {
id: 0,
parentLeaseId: lease.id || 0,
consultationType: {
id: consultationType.id.toString(),
description: consultationType.name,
displayOrder: null,
isDisabled: false,
},
consultationStatusType: {
id: 'UNKNOWN',
description: 'Unknown',
displayOrder: null,
isDisabled: false,
},
otherDescription: null,
...getEmptyBaseAudit(0),
};

// If there is a consultation with the type, set the status to the existing one
const existingConsultation = lease.consultations?.find(
consultation => consultation.consultationType?.id === consultationType.id,
);
if (existingConsultation !== undefined) {
newConsultation.id = existingConsultation.id;
newConsultation.consultationStatusType = existingConsultation.consultationStatusType;
newConsultation.rowVersion = existingConsultation.rowVersion;
}
newConsultations.push(newConsultation);
});
return newConsultations;
}
return [];
};

export default ConsultationSubForm;
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { useFormikContext } from 'formik';

import { Section } from '@/components/common/Section/Section';
import { SectionField } from '@/components/common/Section/SectionField';
import * as API from '@/constants/API';
import useLookupCodeHelpers from '@/hooks/useLookupCodeHelpers';
import { ApiGen_Concepts_ConsultationLease } from '@/models/api/generated/ApiGen_Concepts_ConsultationLease';
import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Lease';
import { getEmptyBaseAudit } from '@/models/defaultInitializers';
import { exists } from '@/utils/utils';

export interface IDetailConsultationProps {
Expand All @@ -20,48 +17,7 @@ export interface IDetailConsultationProps {
export const DetailConsultation: React.FunctionComponent<
React.PropsWithChildren<IDetailConsultationProps>
> = () => {
const { values, setFieldValue } = useFormikContext<ApiGen_Concepts_Lease>();

const { getByType } = useLookupCodeHelpers();
const consultationTypes = getByType(API.CONSULTATION_TYPES);

// Not all consultations might be coming from the backend. Add the ones missing.
if (values.consultations?.length !== consultationTypes.length) {
const newConsultations: ApiGen_Concepts_ConsultationLease[] = [];

consultationTypes.forEach(consultationType => {
const newConsultation: ApiGen_Concepts_ConsultationLease = {
id: 0,
parentLeaseId: values.id || 0,
consultationType: {
id: consultationType.id.toString(),
description: consultationType.name,
displayOrder: null,
isDisabled: false,
},
consultationStatusType: {
id: 'UNKNOWN',
description: 'Unknown',
displayOrder: null,
isDisabled: false,
},
otherDescription: null,
...getEmptyBaseAudit(0),
};

// If there is a consultation with the type, set the status to the existing one
const existingConsultation = values.consultations?.find(
consultation => consultation.consultationType?.id === consultationType.id,
);
if (existingConsultation !== undefined) {
newConsultation.id = existingConsultation.id;
newConsultation.consultationStatusType = existingConsultation.consultationStatusType;
newConsultation.rowVersion = existingConsultation.rowVersion;
}
newConsultations.push(newConsultation);
});
setFieldValue('consultations', newConsultations);
}
const { values } = useFormikContext<ApiGen_Concepts_Lease>();

const generateLabel = (consultation: ApiGen_Concepts_ConsultationLease): string => {
let label = consultation.consultationType?.description || '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,5 @@ const expectedLease: ApiGen_Concepts_Lease = {
isExpired: false,
project: null,
id: 0,
rowVersion: 0,
rowVersion: null,
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { AxiosError } from 'axios';
import { FormikProps } from 'formik/dist/types';
import { useCallback, useContext, useEffect } from 'react';
import { useCallback, useContext } from 'react';

import LoadingBackdrop from '@/components/common/LoadingBackdrop';
import { useMapStateMachine } from '@/components/common/mapFSM/MapStateMachineContext';
import * as API from '@/constants/API';
import { getConsultations } from '@/features/leases/add/ConsultationSubForm';
import { LeaseStateContext } from '@/features/leases/context/LeaseContext';
import { useLeaseDetail } from '@/features/leases/hooks/useLeaseDetail';
import { useUpdateLease } from '@/features/leases/hooks/useUpdateLease';
import { LeaseFormModel } from '@/features/leases/models';
import useApiUserOverride from '@/hooks/useApiUserOverride';
import useLookupCodeHelpers from '@/hooks/useLookupCodeHelpers';
import { useModalContext } from '@/hooks/useModalContext';
import useDeepCompareEffect from '@/hooks/util/useDeepCompareEffect';
import { IApiError } from '@/interfaces/IApiError';
import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Lease';
import { UserOverrideCode } from '@/models/api/UserOverrideCode';
Expand Down Expand Up @@ -39,16 +43,22 @@ export const UpdateLeaseContainer: React.FunctionComponent<UpdateLeaseContainerP

const mapMachine = useMapStateMachine();

const { getByType } = useLookupCodeHelpers();
const consultationTypes = getByType(API.CONSULTATION_TYPES);

// Not all consultations might be coming from the backend. Add the ones missing.

const leaseId = lease?.id;
useEffect(() => {
useDeepCompareEffect(() => {
const exec = async () => {
if (leaseId) {
const lease = await getCompleteLease();
lease.consultations = getConsultations(lease, consultationTypes);
formikRef?.current?.resetForm({ values: LeaseFormModel.fromApi(lease) });
}
};
exec();
}, [getCompleteLease, leaseId, formikRef]);
}, [getCompleteLease, leaseId, formikRef, consultationTypes]);

const afterSubmit = useCallback(
async (updatedLease?: ApiGen_Concepts_Lease) => {
Expand Down
2 changes: 1 addition & 1 deletion source/frontend/src/features/leases/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class LeaseFormModel {
leaseDetail.isResidential = apiModel?.isResidential || false;
leaseDetail.isCommercialBuilding = apiModel?.isCommercialBuilding || false;
leaseDetail.isOtherImprovement = apiModel?.isOtherImprovement || false;
leaseDetail.rowVersion = apiModel?.rowVersion || 0;
leaseDetail.rowVersion = apiModel?.rowVersion || null;
leaseDetail.description = apiModel?.description || '';
leaseDetail.otherCategoryTypeDescription = apiModel?.otherCategoryType || '';
leaseDetail.otherProgramTypeDescription = apiModel?.otherProgramType || '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ describe('useGenerateH120 functions', () => {
beforeEach(() => {
findElectoralDistrictFn.mockResolvedValue({ properties: { ED_NAME: 'MOCK DISTRICT' } });
getAcquisitionPropertiesFn.mockResolvedValue(mockAcquisitionFileResponse().fileProperties);
getCompensationRequisitionPropertiesFn.mockResolvedValue(mockAcquisitionFileResponse().fileProperties);
getCompensationRequisitionPropertiesFn.mockResolvedValue(
mockAcquisitionFileResponse().fileProperties,
);
getInterestHoldersFn.mockResolvedValue([]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
mockApiAcquisitionFileTeamOrganization,
mockApiAcquisitionFileTeamPerson,
} from '@/mocks/acquisitionFiles.mock';
import { getMockApiDefaultCompensation, getMockCompensationPropertiesReq } from '@/mocks/compensations.mock';
import {
getMockApiDefaultCompensation,
getMockCompensationPropertiesReq,
} from '@/mocks/compensations.mock';
import { getEmptyPerson } from '@/mocks/contacts.mock';
import { emptyApiInterestHolder } from '@/mocks/interestHolder.mock';
import { getEmptyOrganization, getMockOrganization } from '@/mocks/organization.mock';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ describe('Compensation Detail View Component', () => {
<CompensationRequisitionDetailView
acquisitionFile={renderOptions?.props?.acquisitionFile ?? mockAcquisitionFileResponse()}
compensation={renderOptions?.props?.compensation ?? getMockApiDefaultCompensation()}
compensationProperties={renderOptions?.props?.compensationProperties ?? getMockCompensationPropertiesReq()}
compensationProperties={
renderOptions?.props?.compensationProperties ?? getMockCompensationPropertiesReq()
}
loading={renderOptions.props?.loading ?? false}
setEditMode={setEditMode}
clientConstant={renderOptions.props?.clientConstant ?? '034'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('compensation list view container', () => {
propertyAcquisitionFileId: 2,
acquisitionFileProperty: null,
},
]
],
};
expect(mockPostApi.execute).toHaveBeenCalledWith(1, mockNewCompensationRequisition);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ describe('Compensation Requisition UpdateForm component', () => {
claims: [Claims.COMPENSATION_REQUISITION_EDIT],
});

expect(await findByTestId("selectrow-1")).not.toBeChecked();
expect(await findByTestId('selectrow-1')).not.toBeChecked();
expect(await findByText(/PID: 023-214-937/)).toBeVisible();

expect(await findByTestId("selectrow-2")).not.toBeChecked();
expect(await findByTestId('selectrow-2')).not.toBeChecked();
expect(await findByText(/PID: 024-996-777/)).toBeVisible();
});

Expand Down
4 changes: 2 additions & 2 deletions source/frontend/src/models/defaultInitializers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import moment from 'moment';

import { prettyFormatDate } from '@/utils';
import { isValidId, prettyFormatDate } from '@/utils';

import { ApiGen_Base_BaseAudit } from './api/generated/ApiGen_Base_BaseAudit';
import { ApiGen_Concepts_AcquisitionFile } from './api/generated/ApiGen_Concepts_AcquisitionFile';
Expand All @@ -17,7 +17,7 @@ export const getEmptyBaseAudit = (rowVersion?: number | null): ApiGen_Base_BaseA
appCreateUserid: null,
appLastUpdateUserGuid: null,
appCreateUserGuid: null,
rowVersion: rowVersion ?? null,
rowVersion: isValidId(rowVersion) ? rowVersion : null,
});

/**
Expand Down

0 comments on commit 09ed155

Please sign in to comment.