feature/IO-3725-RPS-Changes - List formatter
This commit is contained in:
@@ -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>{text}</Text>;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{orderedListParts.prefix && <Text>{orderedListParts.prefix}</Text>}
|
||||
<ol
|
||||
style={{
|
||||
margin: orderedListParts.prefix ? "8px 0 0 20px" : "0 0 0 20px",
|
||||
paddingLeft: 16
|
||||
}}
|
||||
>
|
||||
{orderedListParts.items.map((item, index) => (
|
||||
<li key={`${index}-${item}`}>
|
||||
<Text>{item}</Text>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 style={{}}>{text}</Text>
|
||||
render: (text) => <ScrubberDescription text={text} />
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user