From 4a6e63b78a7ab10326a600e2994aa90a9327f158 Mon Sep 17 00:00:00 2001 From: Nitheesh T Ganesh Date: Fri, 22 Nov 2024 23:01:56 -0700 Subject: [PATCH 1/2] continuation report search fixes --- .github/workflows/web.ci.yml | 20 +++++- .../ContinuationReportTimelineEntry.tsx | 63 ++++++++++++++++--- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/.github/workflows/web.ci.yml b/.github/workflows/web.ci.yml index 7c4ccb4d..06a133ff 100644 --- a/.github/workflows/web.ci.yml +++ b/.github/workflows/web.ci.yml @@ -73,8 +73,26 @@ jobs: npx cypress run --component --headed --browser chrome - name: Generate Coverage Report + id: coverage run: | - npx nyc report --reporter=lcov --reporter=text-summary + SUMMARY=$(npx nyc report --reporter=text-summary) + echo "COVERAGE_SUMMARY<> $GITHUB_ENV + echo "$SUMMARY" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Comment PR with Coverage + uses: actions/github-script@v7 + if: github.event_name == 'pull_request' + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const summary = process.env.COVERAGE_SUMMARY; + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '### Test Coverage Summary\n```\n' + summary + '\n```' + }); build-check: needs: setup-job diff --git a/compliance-web/src/components/App/ContinuationReports/ContinuationReportTimelineEntry.tsx b/compliance-web/src/components/App/ContinuationReports/ContinuationReportTimelineEntry.tsx index 79c0ecbc..9b04647a 100644 --- a/compliance-web/src/components/App/ContinuationReports/ContinuationReportTimelineEntry.tsx +++ b/compliance-web/src/components/App/ContinuationReports/ContinuationReportTimelineEntry.tsx @@ -15,14 +15,15 @@ export default function ContinuationReportTimelineEntry({ searchText?: string; }) { const contentRef = useRef(null); - const [isExpanded, setIsExpanded] = useState(!!searchText); // if searchText is there, default should be open + const [isExpanded, setIsExpanded] = useState(false); const [showReadMore, setShowReadMore] = useState(false); useEffect(() => { if (contentRef.current && contentRef.current.scrollHeight > 170) { setShowReadMore(true); } - }, []); + setIsExpanded(!!searchText); // if searchText is there, default should be open + }, [searchText]); const handleReadMoreClick = (event: React.MouseEvent) => { event.stopPropagation(); @@ -30,12 +31,58 @@ export default function ContinuationReportTimelineEntry({ }; const getFormattedText = () => { - if (!searchText) return renderText; // If no searchText to highlight, return the original renderText - const regex = new RegExp(`(${searchText})`, "g"); // Case-insensitive regex for the word - return renderText.replace( - regex, - `${searchText}` - ); + if (!searchText) return renderText; + + // Create a temporary DOM element to parse the HTML + const tempDiv = document.createElement("div"); + tempDiv.innerHTML = renderText; + + // Function to highlight text in a text node + const highlightTextNode = (node: Text) => { + const regex = new RegExp(`(${searchText})`, "gi"); + const matches = node.textContent?.match(regex); + if (!matches) return; + + const fragment = document.createDocumentFragment(); + let lastIndex = 0; + let match; + + regex.lastIndex = 0; // Reset regex state + while ((match = regex.exec(node.textContent || "")) !== null) { + // Add text before match + fragment.appendChild( + document.createTextNode( + node.textContent?.substring(lastIndex, match.index) || "" + ) + ); + + // Add highlighted match + const highlight = document.createElement("span"); + highlight.style.backgroundColor = "yellow"; + highlight.textContent = match[0]; + fragment.appendChild(highlight); + + lastIndex = regex.lastIndex; + } + + // Add remaining text + fragment.appendChild( + document.createTextNode(node.textContent?.substring(lastIndex) || "") + ); + node.parentNode?.replaceChild(fragment, node); + }; + + // Recursive function to traverse DOM + const traverse = (node: Node) => { + if (node.nodeType === Node.TEXT_NODE) { + highlightTextNode(node as Text); + } else { + node.childNodes.forEach(traverse); + } + }; + + traverse(tempDiv); + return tempDiv.innerHTML; }; return ( From 9b72aed55744047cf4e0e70309edf0d7ad5f162d Mon Sep 17 00:00:00 2001 From: Nitheesh T Ganesh Date: Sat, 23 Nov 2024 00:10:37 -0700 Subject: [PATCH 2/2] coverage report --- .github/workflows/web.ci.yml | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/.github/workflows/web.ci.yml b/.github/workflows/web.ci.yml index 06a133ff..59516cba 100644 --- a/.github/workflows/web.ci.yml +++ b/.github/workflows/web.ci.yml @@ -72,27 +72,9 @@ jobs: run: | npx cypress run --component --headed --browser chrome - - name: Generate Coverage Report - id: coverage + - name: Coverage Report run: | - SUMMARY=$(npx nyc report --reporter=text-summary) - echo "COVERAGE_SUMMARY<> $GITHUB_ENV - echo "$SUMMARY" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - - name: Comment PR with Coverage - uses: actions/github-script@v7 - if: github.event_name == 'pull_request' - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const summary = process.env.COVERAGE_SUMMARY; - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: '### Test Coverage Summary\n```\n' + summary + '\n```' - }); + npx nyc report --reporter=lcov --reporter=text-summary build-check: needs: setup-job