From 0107cbe83c75edcf5ca2dc1980933b8086873642 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 29 May 2026 14:45:22 -0400 Subject: [PATCH] feature/IO-3725-RPS-Changes - List formatter --- .../estimate-scrubber-results.molecule.jsx | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/src/components/molecules/estimate-scruber-results/estimate-scrubber-results.molecule.jsx b/src/components/molecules/estimate-scruber-results/estimate-scrubber-results.molecule.jsx index bceff62..236251c 100644 --- a/src/components/molecules/estimate-scruber-results/estimate-scrubber-results.molecule.jsx +++ b/src/components/molecules/estimate-scruber-results/estimate-scrubber-results.molecule.jsx @@ -20,6 +20,81 @@ export default connect(mapStateToProps, mapDispatchToProps)(EstimateScrubberResu const { Title, Text, Link } = Typography; +function getOrderedListParts(text) { + if (typeof text !== "string") return null; + + const matches = []; + const markerPattern = /(\d{1,2})\.\s+/g; + let match; + + while ((match = markerPattern.exec(text)) !== null) { + const markerStart = match.index; + const previousCharacter = text[markerStart - 1]; + + if (markerStart > 0 && !/\s/.test(previousCharacter)) continue; + + matches.push({ + number: Number(match[1]), + markerStart, + contentStart: markerPattern.lastIndex + }); + } + + if (matches.length < 2) return null; + + const listStartIndex = matches.findIndex((item, index) => { + const nextItem = matches[index + 1]; + return item.number === 1 && nextItem?.number === 2; + }); + + if (listStartIndex === -1) return null; + + const listMatches = matches.slice(listStartIndex); + const sequentialEndIndex = listMatches.findIndex((item, index) => item.number !== index + 1); + const orderedMatches = sequentialEndIndex === -1 ? listMatches : listMatches.slice(0, sequentialEndIndex); + const orderedListEnd = sequentialEndIndex === -1 ? text.length : listMatches[sequentialEndIndex].markerStart; + + if (orderedMatches.length < 2) return null; + + const items = orderedMatches + .map((item, index) => { + const nextMarkerStart = orderedMatches[index + 1]?.markerStart ?? orderedListEnd; + return text.slice(item.contentStart, nextMarkerStart).trim(); + }) + .filter(Boolean); + + if (items.length < 2) return null; + + return { + prefix: text.slice(0, orderedMatches[0].markerStart).trim(), + items + }; +} + +function ScrubberDescription({ text }) { + const orderedListParts = getOrderedListParts(text); + + if (!orderedListParts) return {text}; + + return ( +
+ {orderedListParts.prefix && {orderedListParts.prefix}} +
    + {orderedListParts.items.map((item, index) => ( +
  1. + {item} +
  2. + ))} +
+
+ ); +} + export function EstimateScrubberResults({ bodyshop, jobid, job, esResults }) { const [searchText, setSearchText] = useState(""); const buttonDisabled = job?.g_bett_amt == null; @@ -91,7 +166,7 @@ export function EstimateScrubberResults({ bodyshop, jobid, job, esResults }) { dataIndex: "R", key: "description", width: "75%", - render: (text) => {text} + render: (text) => } ];