diff --git a/source/frontend/src/components/common/ExpandableTextList.tsx b/source/frontend/src/components/common/ExpandableTextList.tsx index 644164889d..36851be951 100644 --- a/source/frontend/src/components/common/ExpandableTextList.tsx +++ b/source/frontend/src/components/common/ExpandableTextList.tsx @@ -1,4 +1,4 @@ -import { Fragment, ReactElement, useState } from 'react'; +import { Fragment, ReactElement, useEffect, useState } from 'react'; import { exists } from '@/utils/utils'; @@ -10,6 +10,7 @@ export interface IExpandableTextListProps { keyFunction: (item: T, index: number) => string; delimiter?: ReactElement | string; maxCollapsedLength?: number; + maxExpandedLength?: number; className?: string; moreText?: string; hideText?: string; @@ -25,12 +26,39 @@ export function ExpandableTextList({ renderFunction, delimiter, maxCollapsedLength, + maxExpandedLength, moreText, hideText, }: IExpandableTextListProps) { const [isExpanded, setIsExpanded] = useState(false); - const displayedItemsLength = !isExpanded ? maxCollapsedLength ?? items.length : items.length; + const [displayedItemsLength, setDisplayedItemsLength] = useState( + !isExpanded ? maxCollapsedLength ?? items.length : maxExpandedLength ?? items.length, + ); const displayedItems = items.slice(0, displayedItemsLength); + + const updateDisplayedItemsLength = () => { + if (maxExpandedLength !== undefined && displayedItemsLength < items.length) { + const remainingItems = items.length - displayedItemsLength; + if (remainingItems >= maxExpandedLength) { + setDisplayedItemsLength(displayedItemsLength + maxExpandedLength); + } else { + setDisplayedItemsLength(displayedItemsLength + remainingItems); + } + } else { + setIsExpanded(prevState => !prevState); + } + }; + + useEffect(() => { + setDisplayedItemsLength(!isExpanded ? maxCollapsedLength ?? items.length : items.length); + }, [isExpanded, items.length, maxCollapsedLength]); + + useEffect(() => { + if (displayedItemsLength === items.length) { + setIsExpanded(true); + } + }, [displayedItemsLength, items.length]); + return ( {displayedItems.map((item: T, index: number) => ( @@ -40,7 +68,7 @@ export function ExpandableTextList({ ))} {exists(maxCollapsedLength) && maxCollapsedLength < items.length && ( - setIsExpanded(collapse => !collapse)}> + updateDisplayedItemsLength()}> {isExpanded ? hideText ?? 'hide' : `[+${items.length - displayedItemsLength} ${moreText ?? 'more...'}]`} diff --git a/source/frontend/src/features/mapSideBar/property/MotiInventoryHeader.tsx b/source/frontend/src/features/mapSideBar/property/MotiInventoryHeader.tsx index 0fa76e15c9..53ae96e7be 100644 --- a/source/frontend/src/features/mapSideBar/property/MotiInventoryHeader.tsx +++ b/source/frontend/src/features/mapSideBar/property/MotiInventoryHeader.tsx @@ -77,7 +77,7 @@ export const MotiInventoryHeader: React.FunctionComponent + @@ -134,7 +134,7 @@ export const MotiInventoryHeader: React.FunctionComponent - + ); }; @@ -145,6 +145,12 @@ const StyledDivider = styled.div` border-bottom-width: 0.1rem; `; +const HeaderMaxWidthHeight = styled.div` + overflow-y: auto; + overflow-x: hidden; + max-height: 50rem; +`; + export const PropertyStyleStatus = styled(InlineFlexDiv)` text-transform: uppercase; color: ${props => props.theme.css.textWarningColor}; diff --git a/source/frontend/src/features/mapSideBar/property/__snapshots__/MotiInventoryHeader.test.tsx.snap b/source/frontend/src/features/mapSideBar/property/__snapshots__/MotiInventoryHeader.test.tsx.snap index 59e716f4d8..d10f16470d 100644 --- a/source/frontend/src/features/mapSideBar/property/__snapshots__/MotiInventoryHeader.test.tsx.snap +++ b/source/frontend/src/features/mapSideBar/property/__snapshots__/MotiInventoryHeader.test.tsx.snap @@ -6,12 +6,12 @@ exports[`MotiInventoryHeader component > renders as expected 1`] = ` class="Toastify" />
- .c0 { + .c1 { font-weight: bold; white-space: nowrap; } -.c1 { +.c2 { height: 100%; display: -webkit-box; display: -webkit-flex; @@ -22,118 +22,128 @@ exports[`MotiInventoryHeader component > renders as expected 1`] = ` flex-direction: column; } +.c3 { + margin-top: 0.5rem; + border-bottom-style: solid; + border-bottom-color: grey; + border-bottom-width: 0.1rem; +} + +.c0 { + overflow-y: auto; + overflow-x: hidden; + max-height: 50rem; +} +
- -
-
-
- +
+
+
- PIN #: - -
-
- + PIN #: + +
+
- - - + + - + +
-
-
- -
-
- - + +
+
+ - +
-
-
- + +
+
-
-
-
- + +
+
-
+
- .c0 { - margin-top: 0.5rem; - border-bottom-style: solid; - border-bottom-color: grey; - border-bottom-width: 0.1rem; -} - -
`; diff --git a/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberFieldView.tsx b/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberFieldView.tsx index 859b0ff21e..c2969d39c2 100644 --- a/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberFieldView.tsx +++ b/source/frontend/src/features/mapSideBar/shared/header/HistoricalNumberFieldView.tsx @@ -76,6 +76,7 @@ export const HistoricalNumberFieldView: React.FC = renderFunction={p => <>{p.historicalFileNumber}} delimiter={'; '} maxCollapsedLength={3} + maxExpandedLength={10} className="d-flex flex-wrap" />