Skip to content

Commit

Permalink
fix: added better evaluation for the reduce function that handles the…
Browse files Browse the repository at this point in the history
… sum of Total Updates (#7).
  • Loading branch information
Daryn St. Pierre committed Jan 17, 2020
1 parent 84bbf24 commit 785e4f1
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/views/Entities/EntityDataplanes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,22 @@ export default {
}
})
// get the sum of total updates (if there is a numerical value set)
if (totalUpdates !== placeholder) {
totalUpdates = totalUpdates.reduce((a, b) => a + b)
// get the sum of total updates (with some precautions)
if (totalUpdates.length > 0) {
totalUpdates = totalUpdates.reduce((a, b) => {
if (a === placeholder) {
return b
} else if (b === placeholder) {
return a
} else if (a === placeholder && b === placeholder) {
return placeholder
}
return a + b
})
} else {
// fallback to a general placeholder if there are no items
totalUpdates = placeholder
}
// select the most recent LAST CONNECTED timestamp
Expand Down Expand Up @@ -163,11 +176,15 @@ export default {
// formatted time for LAST CONNECTED (if there is a value present)
if (selectedTime && !isNaN(selectedTimeAsDate)) {
lastConnected = humanReadableDate(selectedTimeAsDate)
} else {
lastConnected = 'never'
}
// formatted time for LAST UPDATED (if there is a value present)
if (selectedUpdateTime && !isNaN(selectedUpdateTimeAsDate)) {
lastUpdated = humanReadableDate(selectedUpdateTimeAsDate)
} else {
lastUpdated = 'never'
}
} else {
// if there are no subscriptions, set them all to a fallback
Expand Down

0 comments on commit 785e4f1

Please sign in to comment.