From d84fd709ea6007c30f8ea8971b5644d26cb04bbb Mon Sep 17 00:00:00 2001 From: Eduardo Rosendo Date: Wed, 18 Sep 2024 20:22:21 -0400 Subject: [PATCH] fix(district): Refine generateFileName method for large documents The generateFileName method has been refined to accurately compute zip file names, even for cases where the first document exceeds 30 pages. Previously, the logic lead to an error in such cases. This update addresses the issue by employing a more robust approach to compute the file name. --- CHANGES.md | 1 + src/content_delegate.js | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0f7e246d..b12b845e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Changes: Fixes: - Corrected typo in build script, ensuring correct favicon path for Firefox releases([379](https://github.com/freelawproject/recap/issues/379), [397](https://github.com/freelawproject/recap-chrome/pull/397)) + - Refines the generateFileName method to accurately compute zip file names ([366](https://github.com/freelawproject/recap/issues/366), [399](https://github.com/freelawproject/recap-chrome/pull/399)). For developers: - Nothing yet diff --git a/src/content_delegate.js b/src/content_delegate.js index 39b949f2..4c886cdd 100644 --- a/src/content_delegate.js +++ b/src/content_delegate.js @@ -662,9 +662,34 @@ ContentDelegate.prototype.onDownloadAllSubmit = async function (event) { .concat('.zip'); } else if (options.lawyer_style_filenames) { const firstTable = document.getElementsByTagName('table')[0]; + // The download page's tables typically display transaction details. + // However, only certain rows contain relevant information: + // + // 1. Table Title. + // 2. Subtitle. + // 3. Date of Transaction + // 4. Pacer Login Data: Includes the Pacer login username and client code. + // 5. Description and Case Number. + // 6. Billable Pages and Cost. + // + // Additionally, if the document has more than 30 pages, an extra row is + // added to inform the user that they will only be billed for 30 pages. const firstTableRows = firstTable.querySelectorAll('tr'); - // 4th from bottom - const matchedRow = firstTableRows[firstTableRows.length - 4]; + // Remove rows from the querySelectorAll result that have no visible + // content. + const rowsWithContent = Array.from(firstTableRows).filter((row) => + row.hasChildNodes() + ); + const lastRow = rowsWithContent[rowsWithContent.length -1]; + let matchedRow; + // Find the row containing the Description and Case Number. If the last + // row contains the billing message for documents exceeding 30 pages, + // adjusts the index accordingly. + if (lastRow.innerHTML.includes('You will only be billed for 30 pages')){ + matchedRow = rowsWithContent[rowsWithContent.length - 3]; + } else { + matchedRow = rowsWithContent[rowsWithContent.length - 2]; + } const cells = matchedRow.querySelectorAll('td'); const document_number = cells[0].innerText.match(/\d+(?=\-)/)[0]; const docket_number = cells[1].innerText;