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-7884 add take completion date. #3927

Merged
merged 7 commits into from
Apr 9, 2024
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
5 changes: 5 additions & 0 deletions source/backend/api/Services/TakeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Security.Claims;
using Microsoft.Extensions.Logging;
using Pims.Api.Constants;
using Pims.Api.Models.CodeTypes;
using Pims.Core.Exceptions;
using Pims.Dal.Entities;
Expand Down Expand Up @@ -70,6 +71,10 @@ public IEnumerable<PimsTake> UpdateAcquisitionPropertyTakes(long acquisitionFile
{
throw new BusinessRuleViolationException("Retired records are referenced for historical purposes only and cannot be edited or deleted. If the take has been added in error, contact your system administrator to re-open the file, which will allow take deletion.");
}
else if (takes.Any(t => t.TakeStatusTypeCode == AcquisitionTakeStatusTypes.COMPLETE.ToString() && t.CompletionDt == null))
{
throw new BusinessRuleViolationException("A completed take must have a completion date.");
}
else
{
// Complete Takes can only be deleted or set to InProgress by Admins when File is Active/Draft
Expand Down
2 changes: 2 additions & 0 deletions source/backend/apimodels/Models/Concepts/Take/TakeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void Register(TypeAdapterConfig config)
.Map(dest => dest.TakeTypeCode, src => src.TakeTypeCodeNavigation)
.Map(dest => dest.TakeStatusTypeCode, src => src.TakeStatusTypeCodeNavigation)
.Map(dest => dest.LandActTypeCode, src => src.LandActTypeCodeNavigation)
.Map(dest => dest.CompletionDt, src => src.CompletionDt)
.Inherits<Entity.IBaseAppEntity, BaseAuditModel>();

config.NewConfig<TakeModel, Entity.PimsTake>()
Expand All @@ -58,6 +59,7 @@ public void Register(TypeAdapterConfig config)
.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.CompletionDt, src => src.CompletionDt)
.Inherits<BaseAuditModel, Entity.IBaseAppEntity>();
}
}
Expand Down
2 changes: 2 additions & 0 deletions source/backend/apimodels/Models/Concepts/Take/TakeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class TakeModel : BaseAuditModel

public DateOnly? LandActEndDt { get; set; }

public DateOnly? CompletionDt { get; set; }

public AcquisitionFileModel PropertyAcquisitionFile { get; set; }

public long PropertyAcquisitionFileId { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions source/frontend/src/components/common/form/FastDatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type OptionalAttributes = {
innerClassName?: string;
/** The minimum data allowable to be chosen in the datepicker */
minDate?: Date;
/** The maximum date allowable to be chosen in the datepicker */
maxDate?: Date;
/** form label */
label?: string;
/** Whether the field is required. Makes the field border blue. */
Expand All @@ -48,6 +50,7 @@ const FormikDatePicker: FunctionComponent<React.PropsWithChildren<FastDatePicker
className,
innerClassName,
minDate,
maxDate,
label,
required,
popperModifiers,
Expand Down Expand Up @@ -100,6 +103,7 @@ const FormikDatePicker: FunctionComponent<React.PropsWithChildren<FastDatePicker
selected={(value && new Date(value)) || null}
disabled={disabled}
minDate={minDate ? moment(minDate, 'YYYY-MM-DD').toDate() : undefined}
maxDate={maxDate}
{...rest}
popperModifiers={popperModifiers}
onBlur={() => {
Expand Down
5 changes: 0 additions & 5 deletions source/frontend/src/constants/takesStatusTypes.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import TooltipIcon from '@/components/common/TooltipIcon';
import AreaContainer from '@/components/measurements/AreaContainer';
import * as API from '@/constants/API';
import { Claims } from '@/constants/claims';
import { TakesStatusTypes } from '@/constants/takesStatusTypes';
import { isAcquisitionFile } from '@/features/mapSideBar/acquisition/add/models';
import StatusUpdateSolver from '@/features/mapSideBar/acquisition/tabs/fileDetails/detail/statusUpdateSolver';
import useKeycloakWrapper from '@/hooks/useKeycloakWrapper';
import useLookupCodeHelpers from '@/hooks/useLookupCodeHelpers';
import { ApiGen_CodeTypes_AcquisitionTakeStatusTypes } from '@/models/api/generated/ApiGen_CodeTypes_AcquisitionTakeStatusTypes';
import { ApiGen_Concepts_FileProperty } from '@/models/api/generated/ApiGen_Concepts_FileProperty';
import { ApiGen_Concepts_Take } from '@/models/api/generated/ApiGen_Concepts_Take';
import { getApiPropertyName, prettyFormatDate, prettyFormatUTCDate } from '@/utils';
Expand All @@ -39,10 +39,10 @@ export const TakesDetailView: React.FunctionComponent<ITakesDetailViewProps> = (
onEdit,
}) => {
const cancelledTakes = takes?.filter(
t => t.takeStatusTypeCode?.id === TakesStatusTypes.CANCELLED,
t => t.takeStatusTypeCode?.id === ApiGen_CodeTypes_AcquisitionTakeStatusTypes.CANCELLED,
);
const nonCancelledTakes = takes?.filter(
t => t.takeStatusTypeCode?.id !== TakesStatusTypes.CANCELLED,
t => t.takeStatusTypeCode?.id !== ApiGen_CodeTypes_AcquisitionTakeStatusTypes.CANCELLED,
);
const takesNotInFile = allTakesCount - (takes?.length ?? 0);

Expand Down Expand Up @@ -114,6 +114,11 @@ export const TakesDetailView: React.FunctionComponent<ITakesDetailViewProps> = (
? getCodeById(API.TAKE_STATUS_TYPES, take.takeStatusTypeCode.id)
: ''}
</SectionField>
{take.completionDt && (
<SectionField label="Completion date *">
{prettyFormatDate(take.completionDt)}
</SectionField>
)}
<SectionField label="Site contamination">
{take.takeSiteContamTypeCode?.id
? getCodeById(API.TAKE_SITE_CONTAM_TYPES, take.takeSiteContamTypeCode.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const useTakesRepository = () => {
requestName: 'UpdateTakesByAcquisitionPropertyId',
onSuccess: useAxiosSuccessHandler(),
onError: useAxiosErrorHandler(),
throwError: true,
});

return useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ const TakeSubForm: React.FunctionComponent<ITakeSubFormProps> = ({
);
const takeStatusTypeCode = getIn(values, withNameSpace(nameSpace, 'takeStatusTypeCode'));

React.useEffect(() => {
if (
currentTake.completionDt &&
currentTake.takeStatusTypeCode !== ApiGen_CodeTypes_AcquisitionTakeStatusTypes.COMPLETE
) {
setFieldValue(withNameSpace(nameSpace, 'completionDt'), '');
}
}, [currentTake.completionDt, currentTake.takeStatusTypeCode, nameSpace, setFieldValue]);

const getModalWarning = (onOk: () => void) => {
return (e: React.ChangeEvent<any>) => {
if (e.target.value === 'false') {
Expand Down Expand Up @@ -121,6 +130,24 @@ const TakeSubForm: React.FunctionComponent<ITakeSubFormProps> = ({
disabled={!canEditTake}
/>
</SectionField>
<SectionField
label="Completion date"
required={
currentTake.takeStatusTypeCode === ApiGen_CodeTypes_AcquisitionTakeStatusTypes.COMPLETE
}
tooltip={`This will be enabled when the file status is set to "Completed"`}
Copy link
Collaborator

@eddherrera eddherrera Apr 5, 2024

Choose a reason for hiding this comment

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

nit: no need for brackets

labelWidth="4"
contentWidth="5"
>
<FastDatePicker
formikProps={formikProps}
field={withNameSpace(nameSpace, 'completionDt')}
maxDate={new Date()}
disabled={
currentTake.takeStatusTypeCode !== ApiGen_CodeTypes_AcquisitionTakeStatusTypes.COMPLETE
}
/>
</SectionField>
<SectionField label="Site contamination" labelWidth="4" contentWidth="5">
<Select
field={withNameSpace(nameSpace, 'takeSiteContamTypeCode')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export const TakesUpdateContainer = React.forwardRef<FormikProps<any>, ITakesDet
t.propertyAcquisitionFileId = fileProperty.id ?? 0;
return t.toApi();
});
fileProperty.id && (await updateTakesByPropertyFile(fileProperty.id, takes));
onSuccess();
if (fileProperty.id) {
await updateTakesByPropertyFile(fileProperty.id, takes);
onSuccess();
}
} finally {
formikHelpers.setSubmitting(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const emptyTake: ApiGen_Concepts_Take = {
takeTypeCode: null,
takeStatusTypeCode: toTypeCode('INPROGRESS'),
landActTypeCode: null,
completionDt: null,
...getEmptyBaseAudit(),
};

Expand Down
Loading
Loading