p-q and limitations to processing only 200 items

This commit is contained in:
Roman Krček
2025-07-30 16:06:44 +02:00
parent dc1edaae84
commit 1aa6cd53fa
3 changed files with 69 additions and 26 deletions

35
package-lock.json generated
View File

@@ -19,6 +19,7 @@
"fontkit": "^2.0.4", "fontkit": "^2.0.4",
"heic-convert": "^2.1.0", "heic-convert": "^2.1.0",
"idb": "^8.0.3", "idb": "^8.0.3",
"p-queue": "^8.1.0",
"pdf-lib": "^1.17.1", "pdf-lib": "^1.17.1",
"uuid": "^11.1.0" "uuid": "^11.1.0"
}, },
@@ -1013,6 +1014,12 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/eventemitter3": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz",
"integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==",
"license": "MIT"
},
"node_modules/fast-deep-equal": { "node_modules/fast-deep-equal": {
"version": "3.1.3", "version": "3.1.3",
"license": "MIT" "license": "MIT"
@@ -1443,6 +1450,34 @@
} }
} }
}, },
"node_modules/p-queue": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/p-queue/-/p-queue-8.1.0.tgz",
"integrity": "sha512-mxLDbbGIBEXTJL0zEx8JIylaj3xQ7Z/7eEVjcF9fJX4DBiH9oqe+oahYnlKKxm0Ci9TlWTyhSHgygxMxjIB2jw==",
"license": "MIT",
"dependencies": {
"eventemitter3": "^5.0.1",
"p-timeout": "^6.1.2"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/p-timeout": {
"version": "6.1.4",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-6.1.4.tgz",
"integrity": "sha512-MyIV3ZA/PmyBN/ud8vV9XzwTrNtR4jFrObymZYnZqMmW0zA8Z17vnT0rBgFE/TlohB+YCHqXMgZzb3Csp49vqg==",
"license": "MIT",
"engines": {
"node": ">=14.16"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/pako": { "node_modules/pako": {
"version": "1.0.11", "version": "1.0.11",
"license": "(MIT AND Zlib)" "license": "(MIT AND Zlib)"

View File

@@ -40,6 +40,7 @@
"fontkit": "^2.0.4", "fontkit": "^2.0.4",
"heic-convert": "^2.1.0", "heic-convert": "^2.1.0",
"idb": "^8.0.3", "idb": "^8.0.3",
"p-queue": "^8.1.0",
"pdf-lib": "^1.17.1", "pdf-lib": "^1.17.1",
"uuid": "^11.1.0" "uuid": "^11.1.0"
} }

View File

@@ -107,25 +107,19 @@
return processedRow; return processedRow;
}); });
// Initially select rows based on validity and "Already Printed" status // Initially select rows based on validity and "Already Printed" status, up to 200
selectedRows = new Set( const rowsToConsider = processedData.filter((row) => {
processedData if (!row._isValid) return false;
.filter((row) => { const alreadyPrinted = row.alreadyPrinted;
if (!row._isValid) return false; if (alreadyPrinted) {
const value = String(alreadyPrinted).toLowerCase().trim();
return !(value === 'true' || value === 'yes' || value === '1' || value === 'x');
}
return true;
});
// Check "Already Printed" column value const initialSelection = rowsToConsider.slice(0, 200).map((row) => row._rowIndex);
const alreadyPrinted = row.alreadyPrinted; selectedRows = new Set(initialSelection);
if (alreadyPrinted) {
const value = String(alreadyPrinted).toLowerCase().trim();
// If the value is "true", "yes", "1", or any truthy value, don't select
return !(value === 'true' || value === 'yes' || value === '1' || value === 'x');
}
// If empty or falsy, select the row
return true;
})
.map((row) => row._rowIndex)
);
updateSelectAllState(); updateSelectAllState();
} finally { } finally {
@@ -137,6 +131,10 @@
if (selectedRows.has(rowIndex)) { if (selectedRows.has(rowIndex)) {
selectedRows.delete(rowIndex); selectedRows.delete(rowIndex);
} else { } else {
if (selectedRows.size >= 200) {
alert('You can only select a maximum of 200 rows at a time.');
return;
}
selectedRows.add(rowIndex); selectedRows.add(rowIndex);
} }
selectedRows = new Set(selectedRows); // Trigger reactivity selectedRows = new Set(selectedRows); // Trigger reactivity
@@ -145,19 +143,28 @@
function toggleSelectAll() { function toggleSelectAll() {
if (selectAll) { if (selectAll) {
// Deselect all visible valid rows that aren't already printed // Deselect all visible valid rows
filteredData.forEach((row) => { filteredData.forEach((row) => {
if (row._isValid && !isRowAlreadyPrinted(row)) { if (row._isValid) {
selectedRows.delete(row._rowIndex); selectedRows.delete(row._rowIndex);
} }
}); });
} else { } else {
// Select all visible valid rows that aren't already printed // Select all visible valid rows that aren't already printed, up to the limit
filteredData.forEach((row) => { const rowsToSelect = filteredData.filter(
if (row._isValid && !isRowAlreadyPrinted(row)) { (row) => row._isValid && !isRowAlreadyPrinted(row) && !selectedRows.has(row._rowIndex)
selectedRows.add(row._rowIndex); );
}
}); const availableSlots = 200 - selectedRows.size;
if (rowsToSelect.length > availableSlots) {
alert(
`You can only select up to 200 rows. Only the first ${availableSlots} available rows will be selected.`
);
}
for (let i = 0; i < Math.min(rowsToSelect.length, availableSlots); i++) {
selectedRows.add(rowsToSelect[i]._rowIndex);
}
} }
selectedRows = new Set(selectedRows); selectedRows = new Set(selectedRows);
updateSelectAllState(); updateSelectAllState();