Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notifications): implement notifications table, use backend types… #679

Merged
merged 8 commits into from
Aug 12, 2024
1 change: 1 addition & 0 deletions frontend/components/bc/table/TablePager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ watch(
position: absolute;
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
.left-info {
margin-right: auto;
Expand Down
96 changes: 47 additions & 49 deletions frontend/components/notifications/DashboardsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import { faArrowUpRightFromSquare } from '@fortawesome/pro-solid-svg-icons'
import IconValidator from '../icon/IconValidator.vue'
import IconAccount from '../icon/IconAccount.vue'
import type { Cursor } from '~/types/datatable'
import { getGroupLabel } from '~/utils/dashboard/group'
import type { DashboardType } from '~/types/dashboard'
import { useUserDashboardStore } from '~/stores/dashboard/useUserDashboardStore'
import type { ChainIDs } from '~/types/network'

defineEmits<{ (e: 'openDialog'): void }>()

const cursor = ref<Cursor>()
const pageSize = ref<number>(10)
const { t: $t } = useTranslation()

// TODO: replace currentNetwork with selection from NETWORK_SWITCHER_COMPONENT that has yet to be implemented
const { currentNetwork } = useNetworkStore()
const networkId = ref<ChainIDs>(currentNetwork.value ?? 1)

const {
isLoading,
notificationsDashboards,
Expand All @@ -20,9 +26,9 @@ const {
setCursor,
setPageSize,
setSearch,
} = useNotificationsDashboardStore()
} = useNotificationsDashboardStore(networkId)

const { groups } = useValidatorDashboardGroups()
const { getDashboardLabel } = useUserDashboardStore()

const { width } = useWindowSize()
const colsVisible = computed(() => {
Expand All @@ -33,29 +39,12 @@ const colsVisible = computed(() => {
}
})

const groupNameLabel = (groupId?: number) => {
return getGroupLabel($t, groupId, groups.value, 'Σ')
}

const openDialog = () => {
// TODO: implement dialog
alert('not implemented yet 😪')
}

const notificationsDashboardsWithUniqueIdentifier = computed(() => {
if (!notificationsDashboards.value) {
return
}
return {
// TODO: set unique identifier after backend is ready
data: notificationsDashboards.value.data.map((item, index) => ({
...item,
identifier: index,
})),
paging: notificationsDashboards.value.paging,
// .filter(() => false) // comment in to test empty table
}
})
const getDashboardType = (isAccount: boolean): DashboardType => isAccount ? 'account' : 'validator'
</script>

<template>
Expand All @@ -71,8 +60,8 @@ const notificationsDashboardsWithUniqueIdentifier = computed(() => {
<template #table>
<ClientOnly fallback-tag="span">
<BcTable
:data="notificationsDashboardsWithUniqueIdentifier"
data-key="dashboardId"
:data="notificationsDashboards"
data-key="notification_id"
:expandable="!colsVisible.notifications"
:cursor
:page-size
Expand All @@ -83,7 +72,7 @@ const notificationsDashboardsWithUniqueIdentifier = computed(() => {
@set-page-size="setPageSize"
>
<Column
field="network"
field="chain_id"
sortable
header-class="col-header-network"
body-class="col-network"
Expand All @@ -92,14 +81,14 @@ const notificationsDashboardsWithUniqueIdentifier = computed(() => {
<div class="icon-wrapper">
<IconNetwork
colored
:chain-id="slotProps.data.dashboardNetwork"
:chain-id="slotProps.data.chain_id"
class="icon-network"
/>
</div>
</template>
</Column>
<Column
field="age"
field="timestamp"
sortable
header-class="col-age"
body-class="col-age"
Expand All @@ -116,62 +105,64 @@ const notificationsDashboardsWithUniqueIdentifier = computed(() => {
</Column>
<Column
v-if="colsVisible.dashboard"
field="dashboard"
field="dashboard_id"
:sortable="true"
header-class="col-dashboard"
body-class="col-dashboard"
:header="$t('notifications.col.dashboard')"
>
<template #body="slotProps">
<NotificationsDashboardsTableItemDashboard
:type="slotProps.data.entity.type"
:dashboard-id="slotProps.data.dashboardId"
:dashboard-name="slotProps.data.dashboardName"
:type="getDashboardType(slotProps.data.is_account_dashboard)"
:dashboard-id="slotProps.data.dashboard_id"
:dashboard-name="getDashboardLabel(
`${slotProps.data.dashboard_id}`,
getDashboardType(slotProps.data.is_account_dashboard),
)"
/>
</template>
</Column>
<Column
v-if="colsVisible.groups"
field="group_id"
field="group_name"
body-class="col-group"
header-class="col-group"
:header="$t('notifications.col.group')"
>
<template #body="slotProps">
<span>
{{ groupNameLabel(slotProps.data.group_id) }}
{{ slotProps.data.group_name }}
</span>
</template>
</Column>
<Column
field="entity"
sortable
field="entity_count"
header-class="col-entity"
body-class="col-entity"
:header="$t('notifications.dashboards.col.entity')"
>
<template #body="slotProps">
<div class="entity">
<template v-if="slotProps.data.entity.type === 'validator'">
<template v-if="!slotProps.data.is_account_dashboard">
<IconValidator class="icon-dashboard-type" />
{{ slotProps.data.entity.count }}
{{ slotProps.data.entity_count }}
<span>
{{
$t(
"notifications.dashboards.entity.validators",
slotProps.data.entity.count,
slotProps.data.entity_count,
)
}}
</span>
</template>
<template v-if="slotProps.data.entity.type === 'account'">
<template v-else>
<IconAccount class="icon-dashboard-type" />
{{ slotProps.data.entity.count }}
{{ slotProps.data.entity_count }}
<span>
{{
$t(
"notifications.dashboards.entity.accounts",
slotProps.data.entity.count,
slotProps.data.entity_count,
)
}}
</span>
Expand All @@ -188,12 +179,12 @@ const notificationsDashboardsWithUniqueIdentifier = computed(() => {
<Column
v-if="colsVisible.notifications"
field="notification"
body-class="notification"
header-class="notification"
body-class="col-notification"
header-class="col-notification"
:header="$t('notifications.dashboards.col.notification')"
>
<template #body="slotProps">
{{ slotProps.data.notification.join(", ") }}
{{ slotProps.data.event_types.join(", ") }}
</template>
</Column>
<template #expansion="slotProps">
Expand All @@ -202,29 +193,32 @@ const notificationsDashboardsWithUniqueIdentifier = computed(() => {
{{ $t("notifications.dashboards.expansion.label-dashboard") }}
</div>
<NotificationsDashboardsTableItemDashboard
:type="slotProps.data.entity.type"
:dashboard-id="slotProps.data.dashboardId"
:dashboard-name="slotProps.data.dashboardName"
:type="getDashboardType(slotProps.data.is_account_dashboard)"
:dashboard-id="slotProps.data.dashboard_id"
:dashboard-name="getDashboardLabel(
`${slotProps.data.dashboard_id}`,
getDashboardType(slotProps.data.is_account_dashboard),
)"
/>
<div class="label-group">
{{ $t("notifications.dashboards.expansion.label-group") }}
</div>
<div class="group">
{{ groupNameLabel(slotProps.data.group_id) }}
{{ slotProps.data.group_name }}
</div>
<div class="label-notification">
{{
$t("notifications.dashboards.expansion.label-notification")
}}
</div>
<div class="notification">
{{ slotProps.data.notification.join(", ") }}
{{ slotProps.data.event_types.join(", ") }}
</div>
</div>
</template>
<template #empty>
<NotificationsDashboardsTableEmpty
v-if="!notificationsDashboardsWithUniqueIdentifier?.data.length"
v-if="!notificationsDashboards?.data.length"
@open-dialog="$emit('openDialog')"
/>
</template>
Expand Down Expand Up @@ -327,6 +321,10 @@ $breakpoint-lg: 1024px;
@include utils.truncate-text;
}
}
:deep(.col-notification) {
@include utils.set-all-width(240px);
@include utils.truncate-text;
}

:deep(.bc-table-header) {
.h1 {
Expand Down
Loading
Loading