Skip to content

Commit a0237aa

Browse files
committed
feat: add rewards chart filters
See: BEDS-875
1 parent bb7e7c7 commit a0237aa

File tree

8 files changed

+597
-262
lines changed

8 files changed

+597
-262
lines changed

frontend/assets/css/prime.scss

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,122 @@ div.p-accordion {
626626
}
627627
}
628628

629+
div.p-datepicker-input {
630+
max-width: min-content;
631+
}
632+
633+
div.p-datepicker-panel {
634+
background: var(--input-background);
635+
width: 268px;
636+
margin-top: var(--padding-tiny);
637+
padding: var(--padding-small);
638+
border-radius: var(--border-radius);
639+
border: 1px solid var(--input-border-color);
640+
641+
.p-datepicker-header {
642+
padding: var(--padding-small);
643+
padding-bottom: var(--padding);
644+
border-bottom: 1px solid var(--light-grey-7);
645+
646+
.p-datepicker-prev-button,
647+
.p-datepicker-next-button {
648+
height: 30px;
649+
}
650+
651+
.p-datepicker-title {
652+
gap: var(--padding);
653+
654+
.p-datepicker-select-month,
655+
.p-datepicker-select-year {
656+
font-size: 1rem
657+
}
658+
}
659+
}
660+
661+
.p-datepicker-day-view {
662+
margin-top: var(--padding-small);
663+
664+
.p-datepicker-weekday-cell {
665+
padding: var(--padding-tiny);
666+
}
667+
668+
.p-datepicker-day-cell {
669+
padding: var(--padding-tiny);
670+
671+
&.p-datepicker-other-month {
672+
color: var(--text-color-disabled);
673+
}
674+
675+
&.p-datepicker-today > .p-datepicker-day {
676+
background-color: var(--grey);
677+
}
678+
679+
.p-datepicker-day {
680+
border-radius: 50%;
681+
width: 30px;
682+
height: 30px;
683+
transition: background-color 0.2s, color 0.2s, border-color 0.2s;
684+
685+
&.p-datepicker-day-selected {
686+
background-color: var(--primary-color);
687+
}
688+
689+
&:not(.p-datepicker-day-selected):not(.p-disabled):hover {
690+
background-color: var(--grey);
691+
}
692+
}
693+
694+
.p-disabled {
695+
color: var(--text-color-disabled);
696+
}
697+
}
698+
}
699+
700+
.p-datepicker-month-view {
701+
margin-top: var(--padding-small);
702+
703+
.p-datepicker-month {
704+
padding: var(--padding-small);
705+
border-radius: var(--border-radius);
706+
transition: background-color 0.2s, color 0.2s, border-color 0.2s;
707+
708+
&.p-datepicker-month-selected {
709+
background-color: var(--primary-color);
710+
}
711+
712+
&:not(.p-datepicker-month-selected):not(.p-disabled):hover {
713+
background-color: var(--grey);
714+
}
715+
}
716+
717+
.p-disabled {
718+
color: var(--text-color-disabled);
719+
}
720+
}
721+
722+
.p-datepicker-year-view {
723+
margin-top: var(--padding-small);
724+
725+
.p-datepicker-year {
726+
padding: var(--padding-small);
727+
border-radius: var(--border-radius);
728+
transition: background-color 0.2s, color 0.2s, border-color 0.2s;
729+
730+
&.p-datepicker-year-selected {
731+
background-color: var(--primary-color);
732+
}
733+
734+
&:not(.p-datepicker-year-selected):not(.p-disabled):hover {
735+
background-color: var(--grey);
736+
}
737+
}
738+
739+
.p-disabled {
740+
color: var(--text-color-disabled);
741+
}
742+
}
743+
}
744+
629745

630746
/**
631747
* TODO: remove the .p-overflow-hidden and .p-overlay-mask class when PrimeVue is updated.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<script setup lang="ts">
2+
const {
3+
dateFormat = 'dd/mm/yy',
4+
label,
5+
} = defineProps<{
6+
dateFormat?: string,
7+
id: string,
8+
label: string,
9+
maxDate: Date,
10+
minDate: Date,
11+
}>()
12+
13+
const modelValue = defineModel<Date>({
14+
15+
required: true,
16+
})
17+
</script>
18+
19+
<template>
20+
<label
21+
:id
22+
class="datepicker__label"
23+
>
24+
<span>{{ label }}</span>
25+
<Datepicker
26+
:id
27+
v-model="modelValue"
28+
:date-format
29+
:min-date
30+
:max-date
31+
/>
32+
</label>
33+
</template>
34+
35+
<style lang="scss" scoped>
36+
.datepicker__label {
37+
display: flex;
38+
flex-direction: column;
39+
font-size: 0.8rem;
40+
color: var(--text-color-discreet);
41+
}
42+
</style>

frontend/components/dashboard/chart/DashboardChartRewards.vue

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,26 @@ import {
1616
TransformComponent,
1717
} from 'echarts/components'
1818
import VChart from 'vue-echarts'
19-
2019
import type {
2120
BarSeriesOption,
2221
EChartsOption,
2322
EChartsType,
2423
} from 'echarts'
24+
import type { RewardsChartFilter } from '../chart/DashboardChartRewardsFilter.vue'
25+
2526
import {
2627
getChartTextColor,
2728
getChartTooltipBackgroundColor,
2829
getRewardChartColors,
2930
getRewardsChartLineColor,
3031
} from '~/utils/colors'
3132
import type { GetValidatorDashboardRewardsChartResponse } from '~/types/api/validator_dashboard'
32-
import type {
33-
ChartData, ChartSeries,
34-
} from '~/types/api/common'
33+
import type { ChartSeries } from '~/types/api/common'
3534
import { DashboardChartRewardsTooltip } from '#components'
3635
37-
const {
38-
getTimestampFromEpoch,
39-
} = useNetworkStore()
36+
const { filter } = defineProps<{
37+
filter: RewardsChartFilter,
38+
}>()
4039
4140
use([
4241
GridComponent,
@@ -55,26 +54,33 @@ const {
5554
dashboardKey,
5655
} = useDashboardKey()
5756
58-
const data = ref<ChartData<number, string> | undefined>()
59-
60-
const { status } = useAsyncData(
57+
const {
58+
data,
59+
status,
60+
} = useAsyncData(
6161
'validator_dashboard_rewards_chart',
6262
async () => {
6363
if (dashboardKey.value === undefined) {
64-
data.value = undefined
6564
return
6665
}
67-
const res = await fetch<GetValidatorDashboardRewardsChartResponse>(
66+
return await fetch<GetValidatorDashboardRewardsChartResponse>(
6867
'DASHBOARD_VALIDATOR_REWARDS_CHART',
69-
undefined,
68+
{
69+
query: {
70+
...filter,
71+
group_ids: filter.group_ids.join(','),
72+
},
73+
},
7074
{ dashboardKey: dashboardKey.value },
7175
)
72-
data.value = res.data
7376
},
7477
{
7578
immediate: true,
7679
server: false,
77-
watch: [ dashboardKey ],
80+
watch: [
81+
dashboardKey,
82+
filter,
83+
],
7884
},
7985
)
8086
@@ -106,7 +112,7 @@ const {
106112
selectedCurrencyMain,
107113
} = useCurrency()
108114
109-
const categoryCount = computed(() => data.value?.categories?.length ?? 0)
115+
const categoryCount = computed(() => data.value?.data.categories?.length ?? 0)
110116
111117
const isGwei = ref(false)
112118
@@ -153,7 +159,7 @@ const autoFormatAmount = (values: string[], {
153159
return result
154160
}
155161
156-
const clSeries = computed(() => data.value?.series?.filter(series => series.property === 'cl') ?? [])
162+
const clSeries = computed(() => data.value?.data.series?.filter(series => series.property === 'cl') ?? [])
157163
const clSeriesGroupTotal = computed(() => {
158164
let total = Array(categoryCount.value).fill('0')
159165
clSeries.value.forEach((group) => {
@@ -170,7 +176,7 @@ const clSeriesGroupTotal = computed(() => {
170176
})
171177
const clSeriesGroupTotalFormatted = computed(() => autoFormatAmount(clSeriesGroupTotal.value))
172178
173-
const elSeries = computed(() => data.value?.series?.filter(series => series.property === 'el') ?? [])
179+
const elSeries = computed(() => data.value?.data.series?.filter(series => series.property === 'el') ?? [])
174180
const elSeriesGroupTotal = computed(() => {
175181
let total = Array(categoryCount.value).fill('0')
176182
elSeries.value.forEach((group) => {
@@ -230,7 +236,7 @@ type DataZoomEvent = {
230236
start: number,
231237
type: 'datazoom',
232238
}
233-
const dataZoomStart = ref(60)
239+
const dataZoomStart = ref(0)
234240
const dataZoomEnd = ref(100)
235241
// position of tooltip get's lost due to rerendering of `options` (> computed > currency recalculations > latest-state)
236242
const onDatazoom = ({
@@ -318,8 +324,7 @@ const option = computed<EChartsOption>(() => {
318324
},
319325
end: dataZoomEnd.value,
320326
labelFormatter: (_value: number, valueStr: string) => {
321-
const unixTimestamp = getTimestampFromEpoch(Number(valueStr))
322-
return getDateTime(unixTimestamp, { hasTime: false })
327+
return getDateTime(Number(valueStr), { hasTime: false })
323328
},
324329
start: dataZoomStart.value,
325330
type: 'slider',
@@ -360,10 +365,9 @@ const option = computed<EChartsOption>(() => {
360365
const paramsConsensusLayer = params.find(param => param.seriesId === seriesId.cl)
361366
const paramsExecutionLayer = params.find(param => param.seriesId === seriesId.el)
362367
const currentIndex = params[0].dataIndex
363-
const currentTimestamp = getTimestampFromEpoch(Number(params[0].name))
364368
const currentEpoch = {
365369
index: params[0].name,
366-
timestamp: currentTimestamp,
370+
timestamp: Number(params[0].name),
367371
}
368372
const currentGroupTotalCl = clSeriesGroupTotal.value[currentIndex]
369373
const currentGroupTotalEl = elSeriesGroupTotal.value[currentIndex]
@@ -418,14 +422,13 @@ const option = computed<EChartsOption>(() => {
418422
axisLabel: {
419423
fontSize: textSize,
420424
fontWeight: fontWeightMedium,
421-
formatter: (epoch: number) => {
422-
const unixTimestamp = getTimestampFromEpoch(epoch)
423-
const date = getDateTime(unixTimestamp, { hasTime: false })
424-
return `${date}\n${$t('common.epoch')} ${epoch}`
425+
formatter: (timestamp: number) => {
426+
const date = getDateTime(timestamp, { hasTime: false })
427+
return date
425428
},
426429
lineHeight: 20,
427430
},
428-
data: data.value?.categories,
431+
data: data.value?.data.categories,
429432
type: 'category',
430433
},
431434
yAxis: {
@@ -446,6 +449,8 @@ const option = computed<EChartsOption>(() => {
446449
},
447450
}
448451
})
452+
453+
onUpdated(() => hideTooltip())
449454
</script>
450455

451456
<template>
@@ -473,14 +478,14 @@ const option = computed<EChartsOption>(() => {
473478
class="no-data"
474479
alignment="center"
475480
>
476-
{{ $t("dashboard.validator.summary.chart.error") }}
481+
{{ $t("dashboard.validator.rewards.chart.error") }}
477482
</div>
478483
<div
479484
v-if="status === 'success' && !clSeries.length"
480485
class="no-data"
481486
alignment="center"
482487
>
483-
{{ $t("dashboard.validator.summary.chart.no_data") }}
488+
{{ $t("dashboard.validator.rewards.chart.no_data") }}
484489
</div>
485490
</div>
486491
</template>

0 commit comments

Comments
 (0)