From 133b708dbd52b791ac883abae6a12af1247d4dc9 Mon Sep 17 00:00:00 2001 From: devinleighsmith Date: Fri, 19 Jan 2024 13:15:03 -0800 Subject: [PATCH] lint correction. --- .../acquisition/common/constants.ts | 2 ++ .../update/UpdateAgreementsForm.test.tsx | 3 ++- .../agreement/update/UpdateAgreementsForm.tsx | 4 +-- .../tabs/agreement/update/models.ts | 4 +++ ...CompensationRequisitionDetailView.test.tsx | 4 ++- .../CompensationRequisitionDetailView.tsx | 4 +-- .../detail/AcquisitionSummaryView.test.tsx | 23 +++++++++++++++- .../detail/AcquisitionSummaryView.tsx | 4 +-- .../takes/detail/TakesDetailView.test.tsx | 19 ++++++++++++++ .../tabs/takes/detail/TakesDetailView.tsx | 26 +++++++++++++++++-- source/frontend/src/mocks/properties.mock.ts | 5 +++- 11 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 source/frontend/src/features/mapSideBar/acquisition/common/constants.ts diff --git a/source/frontend/src/features/mapSideBar/acquisition/common/constants.ts b/source/frontend/src/features/mapSideBar/acquisition/common/constants.ts new file mode 100644 index 0000000000..a1d67e7854 --- /dev/null +++ b/source/frontend/src/features/mapSideBar/acquisition/common/constants.ts @@ -0,0 +1,2 @@ +export const cannotEditMessage = + 'This section of the file is in a non-editable state. Contact a System administrator to change it to an editable state'; diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/UpdateAgreementsForm.test.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/UpdateAgreementsForm.test.tsx index 1a9b488193..1b7e3a49d0 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/UpdateAgreementsForm.test.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/UpdateAgreementsForm.test.tsx @@ -144,12 +144,13 @@ describe('UpdateAgreementsForm component', () => { it('Cannot edit if not allowed', async () => { organizerMock.canEditOrDeleteAgreement.mockReturnValue(false); - setup(); + const { getByTestId } = setup(); const element: HTMLSelectElement | null = document.querySelector( `select[name="agreements.0.agreementStatusTypeCode"]`, ); expect(element).toHaveAttribute('disabled'); + expect(getByTestId('tooltip-icon-1-agreement-cannot-edit-tooltip')).toBeVisible(); }); }); diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/UpdateAgreementsForm.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/UpdateAgreementsForm.tsx index 4fcc9395f1..8165015691 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/UpdateAgreementsForm.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/UpdateAgreementsForm.tsx @@ -13,6 +13,7 @@ import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile'; import { Api_Agreement } from '@/models/api/Agreement'; import { ILookupCode } from '@/store/slices/lookupCodes'; +import { cannotEditMessage } from '../../../common/constants'; import StatusUpdateSolver from '../../fileDetails/detail/statusUpdateSolver'; import AgreementSubForm from './AgreementSubForm'; import { AgreementsFormModel, SingleAgreementFormModel } from './models'; @@ -45,9 +46,6 @@ export const UpdateAgreementsForm: React.FC = ({ const statusSolver = new StatusUpdateSolver(acquistionFile); - const cannotEditMessage = - 'The file you are viewing is in a non-editable state. Change the file status to active or draft to allow editing.'; - return ( diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/models.ts b/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/models.ts index ac1fb0563d..81f37418ad 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/models.ts +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/update/models.ts @@ -1,3 +1,4 @@ +import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile'; import { Api_Agreement } from '@/models/api/Agreement'; import { stringToUndefined, toTypeCode } from '@/utils/formUtils'; @@ -95,3 +96,6 @@ export class AgreementsFormModel { return this.agreements.map(x => x.toApi(this.acquisitionFileId)); } } + +export const isAcquisitionFile = (file: unknown): file is Api_AcquisitionFile => + !!file && Object.prototype.hasOwnProperty.call(file, 'acquisitionTypeCode'); diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/compensation/detail/CompensationRequisitionDetailView.test.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/compensation/detail/CompensationRequisitionDetailView.test.tsx index 6fd0540994..13d8e79fa2 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/compensation/detail/CompensationRequisitionDetailView.test.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/compensation/detail/CompensationRequisitionDetailView.test.tsx @@ -158,7 +158,7 @@ describe('Compensation Detail View Component', () => { it('User does not have the option to Edit Compensation when is in "FINAL" status', async () => { const acquistionFile = mockAcquisitionFileResponse(); const mockFinalCompensation = getMockApiDefaultCompensation(); - const { queryByTitle } = await setup({ + const { queryByTitle, getByTestId } = await setup({ claims: [Claims.COMPENSATION_REQUISITION_EDIT], props: { acquisitionFile: { @@ -171,6 +171,8 @@ describe('Compensation Detail View Component', () => { const editButton = queryByTitle('Edit compensation requisition'); expect(editButton).not.toBeInTheDocument(); + const warningIcon = getByTestId(`tooltip-icon-1-compensation-cannot-edit-tooltip`); + expect(warningIcon).toBeVisible(); }); it('Admin user should be able to Edit Compensation when is in "FINAL" status', async () => { diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/compensation/detail/CompensationRequisitionDetailView.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/compensation/detail/CompensationRequisitionDetailView.tsx index 04b0c4392e..25efc947da 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/compensation/detail/CompensationRequisitionDetailView.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/compensation/detail/CompensationRequisitionDetailView.tsx @@ -21,6 +21,7 @@ import { Api_Person } from '@/models/api/Person'; import { formatMoney, prettyFormatDate } from '@/utils'; import { formatApiPersonNames } from '@/utils/personUtils'; +import { cannotEditMessage } from '../../../common/constants'; import { DetailAcquisitionFileOwner } from '../../../models/DetailAcquisitionFileOwner'; import StatusUpdateSolver from '../../fileDetails/detail/statusUpdateSolver'; @@ -144,9 +145,6 @@ export const CompensationRequisitionDetailView: React.FunctionComponent< return false; }; - const cannotEditMessage = - 'The file you are viewing is in a non-editable state. Change the file status to active or draft to allow editing.'; - const editButtonBlock = ( { it('does not render the edit button for users that do not have acquisition edit permissions', async () => { const { queryByTitle } = setup( - { acquisitionFile: mockAcquisitionFileResponse() }, + { + acquisitionFile: { + ...mockAcquisitionFileResponse(), + }, + }, { claims: [] }, ); await waitForEffects(); @@ -91,6 +95,23 @@ describe('AcquisitionSummaryView component', () => { expect(editButton).toBeNull(); }); + it('does not render the edit button for non-admin users when the file is finalized', async () => { + const { queryByTitle, getByTestId } = setup( + { + acquisitionFile: { + ...mockAcquisitionFileResponse(), + fileStatusTypeCode: { id: 'COMPLETE' }, + }, + }, + { claims: [Claims.ACQUISITION_EDIT] }, + ); + await waitForEffects(); + const editButton = queryByTitle('Edit acquisition file'); + expect(editButton).toBeNull(); + const editWarningText = getByTestId('tooltip-icon-1-summary-cannot-edit-tooltip'); + expect(editWarningText).toBeVisible(); + }); + it('renders historical file number', async () => { const mockResponse = mockAcquisitionFileResponse(); const { getByText } = setup({ acquisitionFile: mockResponse }, { claims: [] }); diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/AcquisitionSummaryView.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/AcquisitionSummaryView.tsx index fddc1a8852..faf9cb5870 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/AcquisitionSummaryView.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/AcquisitionSummaryView.tsx @@ -16,6 +16,7 @@ import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile'; import { prettyFormatDate } from '@/utils'; import { formatApiPersonNames } from '@/utils/personUtils'; +import { cannotEditMessage } from '../../../common/constants'; import AcquisitionOwnersSummaryContainer from './AcquisitionOwnersSummaryContainer'; import AcquisitionOwnersSummaryView from './AcquisitionOwnersSummaryView'; import { DetailAcquisitionFile } from './models'; @@ -65,9 +66,6 @@ const AcquisitionSummaryView: React.FC = ({ const statusSolver = new StatusUpdateSolver(acquisitionFile); - const cannotEditMessage = - 'The file you are viewing is in a non-editable state. Change the file status to active or draft to allow editing.'; - const canEditDetails = () => { if (hasRole(Roles.SYSTEM_ADMINISTRATOR) || statusSolver.canEditDetails()) { return true; 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 f9003eaf83..4414e7826e 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 @@ -1,5 +1,6 @@ import { createMemoryHistory } from 'history'; +import { AcquisitionStatus } from '@/constants/acquisitionFileStatus'; import { Claims } from '@/constants/claims'; import { mockLookups } from '@/mocks/lookups.mock'; import { getMockApiPropertyFiles } from '@/mocks/properties.mock'; @@ -64,6 +65,24 @@ describe('TakesDetailView component', () => { expect(onEdit).toHaveBeenCalled(); }); + it('hides the edit button when the file has been completed', () => { + const fileProperty = getMockApiPropertyFiles()[0]; + const { queryByTitle, getByTestId } = setup({ + props: { + loading: true, + fileProperty: { + ...fileProperty, + file: { ...fileProperty.file, fileStatusTypeCode: { id: AcquisitionStatus.Complete } }, + }, + }, + claims: [Claims.PROPERTY_EDIT], + }); + const editButton = queryByTitle('Edit takes'); + expect(editButton).toBeNull(); + const tooltip = getByTestId('tooltip-icon-1-summary-cannot-edit-tooltip'); + expect(tooltip).toBeVisible(); + }); + it('displays the number of takes in other files', () => { setup({ props: { 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 f5006961f8..2116babe46 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 @@ -8,10 +8,15 @@ import { Section } from '@/components/common/Section/Section'; import { SectionField } from '@/components/common/Section/SectionField'; import { StyledEditWrapper, StyledSummarySection } from '@/components/common/Section/SectionStyles'; import { H2 } from '@/components/common/styles'; +import TooltipIcon from '@/components/common/TooltipIcon'; import AreaContainer from '@/components/measurements/AreaContainer'; import * as API from '@/constants/API'; import { Claims } from '@/constants/claims'; +import Roles from '@/constants/roles'; import { TakesStatusTypes } from '@/constants/takesStatusTypes'; +import { cannotEditMessage } from '@/features/mapSideBar/acquisition/common/constants'; +import { isAcquisitionFile } from '@/features/mapSideBar/acquisition/tabs/agreement/update/models'; +import StatusUpdateSolver from '@/features/mapSideBar/acquisition/tabs/fileDetails/detail/statusUpdateSolver'; import useKeycloakWrapper from '@/hooks/useKeycloakWrapper'; import useLookupCodeHelpers from '@/hooks/useLookupCodeHelpers'; import { Api_PropertyFile } from '@/models/api/PropertyFile'; @@ -44,19 +49,36 @@ export const TakesDetailView: React.FunctionComponent = ( const takesNotInFile = allTakesCount - (takes?.length ?? 0); const { getCodeById } = useLookupCodeHelpers(); - const { hasClaim } = useKeycloakWrapper(); + const { hasClaim, hasRole } = useKeycloakWrapper(); + + const file = fileProperty.file; + + const statusSolver = new StatusUpdateSolver(isAcquisitionFile(file) ? file : null); + + const canEditDetails = () => { + if (hasRole(Roles.SYSTEM_ADMINISTRATOR) || statusSolver.canEditDetails()) { + return true; + } + return false; + }; return ( - {onEdit !== undefined && hasClaim(Claims.PROPERTY_EDIT) && ( + {onEdit !== undefined && hasClaim(Claims.PROPERTY_EDIT) && canEditDetails() ? ( { onEdit(true); }} /> + ) : null} + {!canEditDetails() && ( + )}
diff --git a/source/frontend/src/mocks/properties.mock.ts b/source/frontend/src/mocks/properties.mock.ts index d4e75ca7cc..6072a33da4 100644 --- a/source/frontend/src/mocks/properties.mock.ts +++ b/source/frontend/src/mocks/properties.mock.ts @@ -3,7 +3,7 @@ import { PropertyDataSourceTypes } from '@/constants/propertyDataSourceTypes'; import { PropertyStatusTypes } from '@/constants/propertyStatusTypes'; import { PropertyTenureTypes } from '@/constants/propertyTenureTypes'; import { IProperty } from '@/interfaces'; -import { mockAddress } from '@/mocks/index.mock'; +import { mockAcquisitionFileResponse, mockAddress } from '@/mocks/index.mock'; import { Api_Property } from '@/models/api/Property'; import { Api_PropertyFile } from '../models/api/PropertyFile'; @@ -170,6 +170,7 @@ export const getMockApiPropertyFiles = (): Api_PropertyFile[] => [ { id: 1, fileId: 1, + file: mockAcquisitionFileResponse(), propertyName: 'test property name', propertyId: 1, property: { @@ -209,6 +210,8 @@ export const getMockApiPropertyFiles = (): Api_PropertyFile[] => [ { id: 2, propertyId: 2, + fileId: 2, + file: mockAcquisitionFileResponse(), property: { id: 2, anomalies: [],