Skip to content

Commit

Permalink
refactor flow querying for nwi table to only submit single queries pe…
Browse files Browse the repository at this point in the history
…r reach
  • Loading branch information
ngottlieb committed Jun 3, 2024
1 parent 719b031 commit 6d9112d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 58 deletions.
6 changes: 3 additions & 3 deletions src/app/assets/scss/abstracts/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ $flow-medium: #59E78D;
$high-runnable: lighten($flow-medium, 15%);
$med-runnable: $flow-medium;
$low-runnable: darken($flow-medium, 15%);
$stale: #ffcc00;
$flow-warning: #ffcc00;

// maps flow classes to their color
$flow-map: (
"above-recommended": $flow-high,
"high-runnable": $high-runnable,
"runnable": $med-runnable,
"medium-runnable": $med-runnable,
"low-runnable": $low-runnable,
"below-recommended": $flow-low,
"stale": $stale
"stale": #dfe3e6 // use ui-03 for unknown/stale
);

// high contrast/accessibility flow colors
Expand Down
92 changes: 42 additions & 50 deletions src/app/views/river-index/components/nwi-rivers-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<template v-if="searchLoading">
<utility-block state="loading" />
</template>
<template v-else-if="reachesInTable && reachesInTable.length > 0">
<template v-else-if="reaches && reaches.length > 0">
<div class="bx--data-table-container river-index">
<table class="bx--data-table river-table">
<thead>
Expand All @@ -17,24 +17,19 @@
</tr>
</thead>
<tbody>
<template v-if="reachesInTable && reachesInTable.length > 0">
<template v-if="reaches && reaches.length > 0">
<tr
v-for="reach in reachesInTable"
v-for="reach in reaches"
:key="reach.id"
:ref="`reach-${reach.id}`"
:class="[
mouseoveredFeature && reach.id === mouseoveredFeature.properties.id ? 'active' : '',
classForGaugeCorrelation(reach.correlation)
classForGaugeCorrelation(reachFlows[reach.id].correlation)
]"
@mouseover="debouncedMouseover(reach.feature)"
@mouseleave="debouncedMouseover()"
>
<td
:class="[
`${classForGaugeCorrelation(reach.correlation)}`,
'river-name-section',
]"
>
<td class="river-name-section">
<router-link :to="`/river-detail/${reach.id}/main`">
<strong>{{ displayReachTitle(reach) }}</strong>
<br >
Expand All @@ -43,17 +38,17 @@
</router-link>
</td>
<td class="level">
<template v-if="reach.loading">
<template v-if="reachFlows[reach.id].loading">
<cv-inline-loading
small
state="loading"
loading-text=""
/>
</template>
<template v-else-if="reach.correlation && reach.correlation.status">
{{ reach.correlation.status.latestReading.value }} {{ correlationMetrics[reach.correlation.status.metric].unit }}
<template v-else-if="reachFlows[reach.id].correlation && reachFlows[reach.id].correlation.status">
{{ reachFlows[reach.id].correlation.status.latestReading.value }} {{ correlationMetrics[reachFlows[reach.id].correlation.status.metric].unit }}
<cv-tooltip
v-if="reach.correlation.status.status === 'stale'"
v-if="reachFlows[reach.id].correlation.status.status === 'stale'"
tip="reading is out of date"
direction="left"
>
Expand Down Expand Up @@ -121,7 +116,7 @@ export default {
data: () => ({
windowWidth: 0,
mq: Breakpoints,
reachesInTable: []
reachFlows: {}
}),
computed: {
...mapState({
Expand Down Expand Up @@ -217,20 +212,19 @@ export default {
},
// update reactive data property with map or search results whenever they change
reaches(newReaches) {
this.reachesInTable = [...newReaches];
},
// retrieve flow information for table reaches
reachesInTable(newReaches) {
// TODO: use new query that retrieves correlation data with batch of IDs
newReaches.forEach(async r => {
r.loading = true;
try {
r.correlation = await reachClient.primaryGaugeStub.query({ reachID: `${r.id}` });
} finally {
r.loading = false;
if (!this.reachFlows[r.id]) {
this.reachFlows[r.id] = {
loading: true
};
try {
this.reachFlows[r.id].correlation = await reachClient.primaryGaugeStub.query({ reachID: `${r.id}` });
} finally {
this.reachFlows[r.id].loading = false;
}
}
})
}
},
},
methods: {
displayReachTitle(reach) {
Expand Down Expand Up @@ -313,36 +307,34 @@ export default {
cursor: pointer;
}
&.river-table {
tr.stale button.cv-tooltip {
background-color: $stale;
padding: 0 0.47rem;
border-radius: 1rem;
}
tr.stale button.cv-tooltip {
background-color: $flow-warning;
padding: 0 0.47rem;
border-radius: 1rem;
}
tr {
@include ease;
// lines up header background with borders from the rows
border-left: 0.5rem solid $ui-03;
tr {
@include ease;
// lines up header background with borders from the rows
border-left: 0.5rem solid $ui-03;
.level {
white-space: nowrap;
}
.level {
white-space: nowrap;
}
td {
padding: 0.5rem 0;
&:first-child {
@each $class, $color in $flow-map {
&.#{$class} {
border-left: 0.5rem solid $color;
}
}
@each $class, $color in $flow-map {
&.#{$class} {
td:first-child {
border-left: 0.5rem solid $color;
}
}
}
td {
padding: 0.5rem 0;
}
&.active, &.active td {
background: #e5e5e5;
}
&.active, &.active td {
background: #e5e5e5;
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/app/views/river-index/rivers-by-state.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ export default {
</script>
<style lang="scss">
.bx--tag--stale {
background-color: #dfe3e6;
:hover > & {
background-color: $stale;
}
background-color: $flow-warning;
}
#rivers-by-state {
Expand Down

0 comments on commit 6d9112d

Please sign in to comment.