diff --git a/source/frontend/src/features/leases/list/LeaseFilter/LeaseFilter.tsx b/source/frontend/src/features/leases/list/LeaseFilter/LeaseFilter.tsx index f4d286efa9..787b609dd4 100644 --- a/source/frontend/src/features/leases/list/LeaseFilter/LeaseFilter.tsx +++ b/source/frontend/src/features/leases/list/LeaseFilter/LeaseFilter.tsx @@ -130,7 +130,7 @@ export const LeaseFilter: React.FunctionComponent { }), ); - expect(await findByText(/0309-001;/i)).toBeInTheDocument(); + expect(await findByText(/0309-001/i)).toBeInTheDocument(); }); it('searches historical file number for PS', async () => { @@ -253,7 +253,7 @@ describe('Lease and License List View', () => { 123, '0309-000', ApiGen_CodeTypes_HistoricalFileNumberTypes.PSNO.toString(), - 'PS #', + 'PS', ), ], }, @@ -275,7 +275,7 @@ describe('Lease and License List View', () => { }), ); - expect(await findByText(/0309-000;/i)).toBeInTheDocument(); + expect(await findByText(/0309-000/i)).toBeInTheDocument(); }); it('searches historical file number for OTHER', async () => { diff --git a/source/frontend/src/features/leases/list/LeaseSearchResults/LeaseSearchResults.tsx b/source/frontend/src/features/leases/list/LeaseSearchResults/LeaseSearchResults.tsx index 2047ff7ad7..1f556965c7 100644 --- a/source/frontend/src/features/leases/list/LeaseSearchResults/LeaseSearchResults.tsx +++ b/source/frontend/src/features/leases/list/LeaseSearchResults/LeaseSearchResults.tsx @@ -1,4 +1,3 @@ -import { groupBy } from 'lodash'; import moment from 'moment'; import { useCallback } from 'react'; import { Tooltip } from 'react-bootstrap'; @@ -10,8 +9,7 @@ import styled from 'styled-components'; import TooltipIcon from '@/components/common/TooltipIcon'; import { ColumnWithProps, renderTypeCode, Table } from '@/components/Table'; import { TableSort } from '@/components/Table/TableSort'; -import { ApiGen_CodeTypes_HistoricalFileNumberTypes } from '@/models/api/generated/ApiGen_CodeTypes_HistoricalFileNumberTypes'; -import { ApiGen_Concepts_HistoricalFileNumber } from '@/models/api/generated/ApiGen_Concepts_HistoricalFileNumber'; +import { HistoricalNumberFieldView } from '@/features/mapSideBar/shared/header/HistoricalNumberFieldView'; import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Lease'; import { exists, prettyFormatDate } from '@/utils'; import { formatApiPersonNames } from '@/utils/personUtils'; @@ -117,79 +115,16 @@ const columns: ColumnWithProps[] = [ align: 'left', clickable: false, sortable: false, - width: 10, - maxWidth: 20, + width: 30, + maxWidth: 30, Cell: (props: CellProps) => { - // File numbers types to display - const numberTypes: string[] = [ - ApiGen_CodeTypes_HistoricalFileNumberTypes.LISNO.toString(), - ApiGen_CodeTypes_HistoricalFileNumberTypes.PSNO.toString(), - ApiGen_CodeTypes_HistoricalFileNumberTypes.OTHER.toString(), - ]; - // Get unique file numbers from lease properties - const fileNumbers: ApiGen_Concepts_HistoricalFileNumber[] = []; - props.row.original.fileProperties?.forEach(fl => { - fl.property.historicalFileNumbers?.forEach(number => { - if (numberTypes.includes(number.historicalFileNumberTypeCode.id)) { - if ( - !fileNumbers.find( - x => - x.historicalFileNumber === number.historicalFileNumber && - x.historicalFileNumberTypeCode.id === number.historicalFileNumberTypeCode.id, - ) - ) { - fileNumbers.push(number); - } - } - }); - }); - - const groupByType = groupBy(fileNumbers, x => x.historicalFileNumberTypeCode.id); - - let lisNumbers = ''; - let psNumbers = ''; - let otherNumbers = ''; - if (groupByType[ApiGen_CodeTypes_HistoricalFileNumberTypes.LISNO.toString()]?.length) { - lisNumbers = groupByType[ApiGen_CodeTypes_HistoricalFileNumberTypes.LISNO.toString()] - .map(x => x.historicalFileNumber) - .join(', '); - } - - if (groupByType[ApiGen_CodeTypes_HistoricalFileNumberTypes.PSNO.toString()]?.length) { - psNumbers = groupByType[ApiGen_CodeTypes_HistoricalFileNumberTypes.PSNO.toString()] - .map(x => x.historicalFileNumber) - .join(', '); - } + const fileNumbers = + props.row.original?.fileProperties + ?.flatMap(fl => fl?.property?.historicalFileNumbers) + .filter(exists) ?? []; - if (groupByType[ApiGen_CodeTypes_HistoricalFileNumberTypes.OTHER.toString()]?.length) { - otherNumbers = groupByType[ApiGen_CodeTypes_HistoricalFileNumberTypes.OTHER.toString()] - .map(x => x.historicalFileNumber) - .join(', '); - } - - return ( - - {lisNumbers ? ( - - ) : null} - {psNumbers ? ( - - ) : null} - {otherNumbers ? ( - - ) : null} - - ); + return ; }, }, { @@ -240,16 +175,6 @@ export function LeaseSearchResults(props: ILeaseSearchResultsProps) { ); } -const FileNumbersDiv = styled('div')` - label { - display: inline-block; - - span { - font-weight: bold; - } - } -`; - const ExpiredIcon = styled('span')` color: ${props => props.theme.bcTokens.surfaceColorPrimaryDangerButtonDefault}; `; diff --git a/source/frontend/src/features/leases/list/LeaseSearchResults/__snapshots__/LeaseSearchResults.test.tsx.snap b/source/frontend/src/features/leases/list/LeaseSearchResults/__snapshots__/LeaseSearchResults.test.tsx.snap index 7839e1badf..7dc540810a 100644 --- a/source/frontend/src/features/leases/list/LeaseSearchResults/__snapshots__/LeaseSearchResults.test.tsx.snap +++ b/source/frontend/src/features/leases/list/LeaseSearchResults/__snapshots__/LeaseSearchResults.test.tsx.snap @@ -39,14 +39,6 @@ exports[`Lease Search Results Table > matches snapshot 1`] = ` border-radius: 0.4rem; } -.c4 label { - display: inline-block; -} - -.c4 label span { - font-weight: bold; -} -
matches snapshot 1`] = ` class="th" colspan="1" role="columnheader" - style="box-sizing: border-box; flex: 20 0 auto; min-width: 30px; width: 20px; justify-content: left; text-align: left; flex-wrap: wrap; align-items: center; display: flex;" + style="box-sizing: border-box; flex: 30 0 auto; min-width: 30px; width: 30px; justify-content: left; text-align: left; flex-wrap: wrap; align-items: center; display: flex;" >
matches snapshot 1`] = `
-
+
matches snapshot 1`] = `
-
+
matches snapshot 1`] = ` class="th" colspan="1" role="columnheader" - style="box-sizing: border-box; flex: 20 0 auto; min-width: 30px; width: 20px; justify-content: left; text-align: left; flex-wrap: wrap; align-items: center; display: flex;" + style="box-sizing: border-box; flex: 30 0 auto; min-width: 30px; width: 30px; justify-content: left; text-align: left; flex-wrap: wrap; align-items: center; display: flex;" >
)} - + diff --git a/source/frontend/src/features/mapSideBar/disposition/common/DispositionHeader.tsx b/source/frontend/src/features/mapSideBar/disposition/common/DispositionHeader.tsx index 7becefde18..ae5dd14dc1 100644 --- a/source/frontend/src/features/mapSideBar/disposition/common/DispositionHeader.tsx +++ b/source/frontend/src/features/mapSideBar/disposition/common/DispositionHeader.tsx @@ -10,7 +10,7 @@ import { ApiGen_Concepts_DispositionFile } from '@/models/api/generated/ApiGen_C import { exists } from '@/utils'; import HistoricalNumbersContainer from '../../shared/header/HistoricalNumberContainer'; -import HistoricalNumberFieldView from '../../shared/header/HistoricalNumberSectionView'; +import { HistoricalNumberSectionView } from '../../shared/header/HistoricalNumberSectionView'; export interface IDispositionHeaderProps { dispositionFile?: ApiGen_Concepts_DispositionFile; @@ -32,11 +32,7 @@ export const DispositionHeader: React.FunctionComponent< D-{dispositionFile?.fileNumber} - + diff --git a/source/frontend/src/features/mapSideBar/lease/common/LeaseHeader.tsx b/source/frontend/src/features/mapSideBar/lease/common/LeaseHeader.tsx index b00010b9af..ee1b05ab81 100644 --- a/source/frontend/src/features/mapSideBar/lease/common/LeaseHeader.tsx +++ b/source/frontend/src/features/mapSideBar/lease/common/LeaseHeader.tsx @@ -19,7 +19,7 @@ import { ApiGen_Concepts_Lease } from '@/models/api/generated/ApiGen_Concepts_Le import { exists, prettyFormatDate } from '@/utils'; import HistoricalNumbersContainer from '../../shared/header/HistoricalNumberContainer'; -import HistoricalNumberFieldView from '../../shared/header/HistoricalNumberSectionView'; +import { HistoricalNumberSectionView } from '../../shared/header/HistoricalNumberSectionView'; import { LeaseHeaderTenants } from './LeaseHeaderTenants'; export interface ILeaseHeaderProps { @@ -74,8 +74,7 @@ export const LeaseHeader: React.FC = ({ lease, lastUpdatedBy diff --git a/source/frontend/src/features/mapSideBar/property/MotiInventoryHeader.tsx b/source/frontend/src/features/mapSideBar/property/MotiInventoryHeader.tsx index e5a2cce772..c42f541377 100644 --- a/source/frontend/src/features/mapSideBar/property/MotiInventoryHeader.tsx +++ b/source/frontend/src/features/mapSideBar/property/MotiInventoryHeader.tsx @@ -16,7 +16,7 @@ import { exists, formatApiAddress, pidFormatter } from '@/utils'; import { mapFeatureToProperty } from '@/utils/mapPropertyUtils'; import HistoricalNumbersContainer from '../shared/header/HistoricalNumberContainer'; -import HistoricalNumberFieldView from '../shared/header/HistoricalNumberSectionView'; +import { HistoricalNumberSectionView } from '../shared/header/HistoricalNumberSectionView'; export interface IMotiInventoryHeaderProps { isLoading: boolean; @@ -69,8 +69,7 @@ export const MotiInventoryHeader: React.FunctionComponent {exists(apiProperty) && ( )} diff --git a/source/frontend/src/features/mapSideBar/research/common/ResearchHeader.tsx b/source/frontend/src/features/mapSideBar/research/common/ResearchHeader.tsx index 494bdcf1e9..8b00abf10f 100644 --- a/source/frontend/src/features/mapSideBar/research/common/ResearchHeader.tsx +++ b/source/frontend/src/features/mapSideBar/research/common/ResearchHeader.tsx @@ -10,7 +10,7 @@ import { ApiGen_Concepts_ResearchFile } from '@/models/api/generated/ApiGen_Conc import { exists } from '@/utils'; import HistoricalNumbersContainer from '../../shared/header/HistoricalNumberContainer'; -import HistoricalNumberFieldView from '../../shared/header/HistoricalNumberSectionView'; +import { HistoricalNumberSectionView } from '../../shared/header/HistoricalNumberSectionView'; export interface IResearchHeaderProps { researchFile?: ApiGen_Concepts_ResearchFile; @@ -64,11 +64,7 @@ const ResearchHeader: React.FunctionComponent< {districts} - + diff --git a/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberContainer.tsx b/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberContainer.tsx index 33ea68bcfe..451f9e2830 100644 --- a/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberContainer.tsx +++ b/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberContainer.tsx @@ -7,12 +7,10 @@ import { IHistoricalNumbersViewProps } from './HistoricalNumberSectionView'; export interface IHistoricalNumbersContainerProps { propertyIds: number[]; - displayValuesOnly: boolean; View: React.FunctionComponent; } const HistoricalNumbersContainer: React.FC = ({ propertyIds, - displayValuesOnly, View, }) => { const [historicalNumbers, setHistoricalNumbers] = useState< @@ -36,6 +34,6 @@ const HistoricalNumbersContainer: React.FC = ( }); }, [propertyIds, getHistoricalExecute]); - return ; + return ; }; export default HistoricalNumbersContainer; diff --git a/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberFieldView.tsx b/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberFieldView.tsx new file mode 100644 index 0000000000..ecd7c648f8 --- /dev/null +++ b/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberFieldView.tsx @@ -0,0 +1,87 @@ +import { useMemo } from 'react'; +import styled from 'styled-components'; + +import ExpandableTextList from '@/components/common/ExpandableTextList'; +import { Dictionary } from '@/interfaces/Dictionary'; +import { ApiGen_Base_CodeType } from '@/models/api/generated/ApiGen_Base_CodeType'; +import { ApiGen_CodeTypes_HistoricalFileNumberTypes } from '@/models/api/generated/ApiGen_CodeTypes_HistoricalFileNumberTypes'; +import { ApiGen_Concepts_HistoricalFileNumber } from '@/models/api/generated/ApiGen_Concepts_HistoricalFileNumber'; +import { exists } from '@/utils'; + +export interface IHistoricalNumbersViewProps { + historicalNumbers: ApiGen_Concepts_HistoricalFileNumber[]; +} + +interface HistoricalGroup { + historicalType: ApiGen_Base_CodeType; + historicalValues: Dictionary; + otherDescription: string; + propertyKey: string; +} + +export const HistoricalNumberFieldView: React.FC = ({ + historicalNumbers, +}) => { + const uniqueNumbers = useMemo(() => { + const flatNumberDictionary: Dictionary = historicalNumbers + .filter(exists) + .reduce((accumulator, h) => { + const historicalTypeKey = `[${h.historicalFileNumberTypeCode.id}-${h.otherHistFileNumberTypeCode}]`; + if (!(historicalTypeKey in accumulator)) { + accumulator[historicalTypeKey] = { + historicalType: h.historicalFileNumberTypeCode, + historicalValues: {}, + otherDescription: h.otherHistFileNumberTypeCode, + key: '', + }; + } + + const historicalValueKey = `[${h.historicalFileNumber}][${h.historicalFileNumberTypeCode.id}][${h.otherHistFileNumberTypeCode}]`; + if (!(historicalValueKey in accumulator[historicalTypeKey])) { + accumulator[historicalTypeKey].historicalValues[historicalValueKey] = h; + accumulator[historicalTypeKey].key += h.propertyId; + } + return accumulator; + }, {}); + + const flatNumberArray = Object.values(flatNumberDictionary); + + return flatNumberArray.sort( + (a, b) => a.historicalType.displayOrder - b.historicalType.displayOrder, + ); + }, [historicalNumbers]); + + return ( + + items={uniqueNumbers} + keyFunction={(p, index: number) => + `historical-group-${p.historicalType.id}-${p.propertyKey}-${index}` + } + renderFunction={p => ( + <> + + {p.historicalType.id === ApiGen_CodeTypes_HistoricalFileNumberTypes.OTHER + ? p.otherDescription + : p.historicalType.description} + : + + + {Object.values(p.historicalValues).map((historicalValue, index) => { + return ( + + {historicalValue.historicalFileNumber} + {index + 1 < Object.values(p.historicalValues).length && , } + + ); + })} + + )} + delimiter={'; '} + maxCollapsedLength={2} + /> + ); +}; + +export const StyledLabel = styled.label` + font-weight: bold; +`; diff --git a/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberSectionView.tsx b/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberSectionView.tsx index b2adcd22f6..677b85591b 100644 --- a/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberSectionView.tsx +++ b/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberSectionView.tsx @@ -1,106 +1,18 @@ -import { useMemo } from 'react'; -import styled from 'styled-components'; - -import ExpandableTextList from '@/components/common/ExpandableTextList'; import { HeaderField } from '@/components/common/HeaderField/HeaderField'; -import { Dictionary } from '@/interfaces/Dictionary'; -import { ApiGen_Base_CodeType } from '@/models/api/generated/ApiGen_Base_CodeType'; import { ApiGen_Concepts_HistoricalFileNumber } from '@/models/api/generated/ApiGen_Concepts_HistoricalFileNumber'; -import { exists } from '@/utils'; + +import { HistoricalNumberFieldView } from './HistoricalNumberFieldView'; export interface IHistoricalNumbersViewProps { - valuesOnly: boolean; historicalNumbers: ApiGen_Concepts_HistoricalFileNumber[]; } -interface HistoricalGroup { - historicalType: ApiGen_Base_CodeType; - historicalValues: Dictionary; -} - -const HistoricalNumberFieldView: React.FC = ({ +export const HistoricalNumberSectionView: React.FC = ({ historicalNumbers, - valuesOnly, }) => { - const uniqueNumbers = useMemo(() => { - const flatNumberArray: Dictionary = historicalNumbers - .filter(exists) - .reduce((accumulator, h) => { - const historicalTypeKey = `[${h.historicalFileNumberTypeCode.description}]`; - if (!(historicalTypeKey in accumulator)) { - accumulator[historicalTypeKey] = { - historicalType: h.historicalFileNumberTypeCode, - historicalValues: {}, - }; - } - - const historicalValueKey = `[${h.historicalFileNumberTypeCode.description}][${h.historicalFileNumber}]`; - accumulator[historicalTypeKey].historicalValues[historicalValueKey] = h; - return accumulator; - }, {} as Dictionary); - - return Object.values(flatNumberArray).sort(p => p.historicalType.displayOrder); - }, [historicalNumbers]); - - if (valuesOnly) { - return ( - - items={uniqueNumbers} - keyFunction={(p, index: number) => `historical-number-${p.historicalType.id}-${index}`} - renderFunction={p => ( - <> - - {p.historicalType.description}: - - - {Object.values(p.historicalValues).map((historicalValue, index) => { - return ( - - {historicalValue.historicalFileNumber} - {index + 1 < Object.values(p.historicalValues).length && , } - - ); - })} - - )} - delimiter={'; '} - maxCollapsedLength={2} - /> - ); - } - return ( - <> - - items={uniqueNumbers} - keyFunction={(p, index: number) => `historical-number-${p.historicalType.id}-${index}`} - renderFunction={p => ( - <> - - {p.historicalType.description}: - - - {Object.values(p.historicalValues).map((historicalValue, index) => { - return ( - - {historicalValue.historicalFileNumber} - {index + 1 < Object.values(p.historicalValues).length && , } - - ); - })} - - )} - delimiter={'; '} - maxCollapsedLength={2} - /> - + ); }; - -export default HistoricalNumberFieldView; - -export const StyledLabel = styled.label` - font-weight: bold; -`; diff --git a/source/frontend/src/features/properties/filter/PropertyFilter.tsx b/source/frontend/src/features/properties/filter/PropertyFilter.tsx index 2c69e45ec5..1deb060204 100644 --- a/source/frontend/src/features/properties/filter/PropertyFilter.tsx +++ b/source/frontend/src/features/properties/filter/PropertyFilter.tsx @@ -155,7 +155,10 @@ export const PropertyFilter: React.FC )} {values.searchBy === 'historical' && ( - + )} diff --git a/source/frontend/src/features/properties/list/PropertyListView.test.tsx b/source/frontend/src/features/properties/list/PropertyListView.test.tsx index b12fb4cb0c..2492bede1b 100644 --- a/source/frontend/src/features/properties/list/PropertyListView.test.tsx +++ b/source/frontend/src/features/properties/list/PropertyListView.test.tsx @@ -29,6 +29,7 @@ import { ApiGen_Concepts_PropertyView } from '@/models/api/generated/ApiGen_Conc import { useApiHistoricalNumbers } from '@/hooks/pims-api/useApiHistoricalNumbers'; import { ApiGen_Concepts_HistoricalFileNumber } from '@/models/api/generated/ApiGen_Concepts_HistoricalFileNumber'; import { ApiGen_CodeTypes_HistoricalFileNumberTypes } from '@/models/api/generated/ApiGen_CodeTypes_HistoricalFileNumberTypes'; +import { useHistoricalNumberRepository } from '@/hooks/repositories/useHistoricalNumberRepository'; // Set all module functions to vi.fn @@ -50,12 +51,25 @@ vi.mocked(useApiGeocoder).mockReturnValue({ ) => Promise>, } as unknown as ReturnType); -const mockApiGetHistoricalFileNumbersApi = vi.fn(); -vi.mocked(useApiHistoricalNumbers).mockReturnValue({ - getByPropertyId: mockApiGetHistoricalFileNumbersApi as ( - propertyId: number, - ) => Promise>, -} as unknown as ReturnType); +const mockGetPropertyHistoricalNumbersExecute = vi.fn().mockResolvedValue([]); + +vi.mock('@/hooks/repositories/useHistoricalNumberRepository'); +vi.mocked(useHistoricalNumberRepository).mockReturnValue({ + getPropertyHistoricalNumbers: { + error: null, + response: [], + execute: mockGetPropertyHistoricalNumbersExecute, + loading: false, + status: 200, + }, + updatePropertyHistoricalNumbers: { + error: null, + response: [], + execute: vi.fn().mockResolvedValue([]), + loading: false, + status: 200, + }, +}); const mockAxios = new MockAdapter(axios); const history = createMemoryHistory(); @@ -97,15 +111,15 @@ const setupMockApi = (properties?: ApiGen_Concepts_PropertyView[]) => { }, } as any); - mockApiGetHistoricalFileNumbersApi.mockResolvedValue({ - data: [ + for (let i = 0; i < mockProperties.length; i++) { + mockGetPropertyHistoricalNumbersExecute.mockResolvedValueOnce([ { - id: 100, - propertyId: 1, + id: mockProperties[i].id * 100, + propertyId: mockProperties[i].id, property: null, historicalFileNumberTypeCode: { id: ApiGen_CodeTypes_HistoricalFileNumberTypes.LISNO.toString(), - description: 'LIS #', + description: 'LIS', isDisabled: false, displayOrder: 1, }, @@ -120,8 +134,8 @@ const setupMockApi = (properties?: ApiGen_Concepts_PropertyView[]) => { appCreateUserGuid: null, rowVersion: 1, }, - ], - }); + ]); + } }; describe('Property list view', () => { @@ -131,7 +145,7 @@ describe('Property list view', () => { mockAxios.onAny().reply(200, {}); mockApiGetPropertiesPagedApi.mockClear(); - mockApiGetHistoricalFileNumbersApi.mockClear(); + mockGetPropertyHistoricalNumbersExecute.mockClear(); }); afterEach(() => { diff --git a/source/frontend/src/features/properties/list/columns.tsx b/source/frontend/src/features/properties/list/columns.tsx index 059912da5a..6c61f349d3 100644 --- a/source/frontend/src/features/properties/list/columns.tsx +++ b/source/frontend/src/features/properties/list/columns.tsx @@ -11,7 +11,7 @@ import TooltipIcon from '@/components/common/TooltipIcon'; import { ColumnWithProps } from '@/components/Table'; import { AreaUnitTypes, Claims } from '@/constants/index'; import HistoricalNumbersContainer from '@/features/mapSideBar/shared/header/HistoricalNumberContainer'; -import HistoricalNumberFieldView from '@/features/mapSideBar/shared/header/HistoricalNumberSectionView'; +import { HistoricalNumberFieldView } from '@/features/mapSideBar/shared/header/HistoricalNumberFieldView'; import useKeycloakWrapper from '@/hooks/useKeycloakWrapper'; import { ApiGen_Concepts_PropertyView } from '@/models/api/generated/ApiGen_Concepts_PropertyView'; import { ILookupCode } from '@/store/slices/lookupCodes'; @@ -70,7 +70,6 @@ export const columns = ({ return ( );