Created
July 5, 2018 21:47
-
-
Save mturley/d5012951f18adc249f83a2c063844bdd to your computer and use it in GitHub Desktop.
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
const getActivePlaybook = task => { | |
if (!task || !task.options || !task.options.playbooks) return {}; | |
const { options: { playbooks } } = task; | |
if (playbooks.pre.status === 'Active') return playbooks.pre; | |
if (playbooks.post.status === 'Active') return playbooks.post; | |
return {}; | |
}; | |
const playbooksByTaskId = mostRecentTasks.reduce( | |
(map, task) => ({ | |
...map, | |
[task.id]: task.options.playbooks | |
}), | |
{} | |
); | |
const tasksWithActivePlaybooks = mostRecentTasks.filter(task => { | |
const playbooks = playbooksByTaskId[task.id]; | |
return playbooks.pre.status === 'Active' || playbooks.post.status === 'Active'; | |
}); | |
const isSomePlaybookActive = tasksWithActivePlaybooks.length > 0; | |
const activePlaybook = getActivePlaybook(tasksWithActivePlaybooks[0]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment