Last active
September 14, 2023 17:47
-
-
Save joshstrange/a962dd8615016870923a83cedc8d2b3f to your computer and use it in GitHub Desktop.
Get total of time estimates for subtasks in ClickUp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* By default, ClickUp shows the total time estimate for a list of subtasks | |
* but does not filter out "Completed" tasks (or any other status you might | |
* want to not count, such as "Ready for QA"). This script will find the total | |
* time estimate for all subtasks that are not "Completed" or "Ready for QA". | |
* | |
* The "Ready for QA" status is a custom status that we use to indicate that | |
* a task is ready for QA. It is not a default status. We are filtering it out | |
* based on it's color 'rgb(175, 126, 46)`, if you don't use custom statuses | |
* then you can probably use this script as-is since it will never match. If you | |
* use custom statuses, you will need to update the color to match your custom | |
* status that you want to ignore or make sure it doesn't match any of your | |
* custom statuses that you want to include. | |
*/ | |
/** | |
* Given a time estimate element, find the row that contains it | |
* @param el {HTMLElement} | |
* @returns {HTMLElement|null} | |
*/ | |
const findRow = (el) => { | |
while(el.parentElement) { | |
el = el.parentElement; | |
if(el.parentElement.classList.contains('lv-subtask__outer')) { | |
return el.parentElement; | |
} | |
} | |
return null; | |
}; | |
// Get all the timeEstimates on the page (NOTE: You might need to scroll to load all the subtasks) | |
const timeEstimates = Array.from(document.querySelectorAll('.cu-time-estimates-view__value')); | |
// Remove the first 2, they are the "totals" | |
timeEstimates.splice(0, 2); | |
let totalTime = 0; | |
// Find tasks that aren't ready for QA | |
for(const timeEstimate of timeEstimates) { | |
const row = findRow(timeEstimate); | |
if(row) { | |
// Find status indicator | |
const statusWrapper = row.querySelector('.task-todo-item__status-container'); | |
const colorBlock = statusWrapper.querySelector('.cu-dropdown__toggle'); | |
// Completed are hidden by default but we have a "Ready for QA" that we also | |
// want to ignore | |
if(colorBlock.style.color !== 'var(--cu-status-brown)') { | |
// This is a keeper | |
const time = Number(timeEstimate.textContent.replace('h', '')); | |
totalTime += time; | |
} | |
} else { | |
console.log('No row found: ', timeEstimate); | |
} | |
} | |
console.log('Total time: ', totalTime); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment