Skip to content

Commit

Permalink
Merge pull request #430 from gobitfly/BIDS-2900/SharedDasbhoardsView
Browse files Browse the repository at this point in the history
Bids 2900/shared dasbhoards view
  • Loading branch information
D13ce authored Jun 11, 2024
2 parents e5e5d98 + 3f15619 commit d395955
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
15 changes: 11 additions & 4 deletions frontend/components/dashboard/DashboardControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const manageGroupsModalVisisble = ref(false)
const manageValidatorsModalVisisble = ref(false)
const manageButtons = computed<MenuBarEntry[] | undefined>(() => {
if (isShared.value) {
return undefined
}
const buttons: MenuBarEntry[] = []
buttons.push({
Expand Down Expand Up @@ -67,7 +71,8 @@ const shareButtonOptions = computed(() => {
const label = !edit ? $t('dashboard.shared') : $t('dashboard.share')
const icon = !edit ? faUsers : faShare
return { label, icon, edit }
const disabled = isShared.value || !dashboardKey.value
return { label, icon, edit, disabled }
})
const shareView = () => {
Expand Down Expand Up @@ -99,6 +104,8 @@ const share = () => {
}
const deleteButtonOptions = computed(() => {
const visible = !isShared.value
const disabled = isPublic.value && publicEntities.value?.length === 0
// private dashboards always get deleted, public dashboards only get cleared
Expand All @@ -108,7 +115,7 @@ const deleteButtonOptions = computed(() => {
const privateDashboardsCount = isLoggedIn.value ? ((dashboards.value?.validator_dashboards?.length ?? 0) + (dashboards.value?.account_dashboards?.length ?? 0)) : 0
const forward = deleteDashboard ? (privateDashboardsCount > 1) : (privateDashboardsCount > 0)
return { disabled, deleteDashboard, forward }
return { visible, disabled, deleteDashboard, forward }
})
const onDelete = () => {
Expand Down Expand Up @@ -173,10 +180,10 @@ const deleteAction = async (key: DashboardKey, deleteDashboard: boolean, forward
<DashboardValidatorManagementModal v-if="dashboardType=='validator'" v-model="manageValidatorsModalVisisble" />
<div class="header-row">
<div class="action-button-container">
<Button class="share-button" :disabled="!dashboardKey" @click="share()">
<Button class="share-button" :disabled="shareButtonOptions.disabled" @click="share()">
{{ shareButtonOptions.label }}<FontAwesomeIcon :icon="shareButtonOptions.icon" />
</Button>
<Button class="p-button-icon-only" :disabled="deleteButtonOptions.disabled" @click="onDelete()">
<Button v-if="deleteButtonOptions.visible" class="p-button-icon-only" :disabled="deleteButtonOptions.disabled" @click="onDelete()">
<FontAwesomeIcon :icon="faTrash" />
</Button>
</div>
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/dashboard/DashboardHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const showInDevelopment = Boolean(useRuntimeConfig().public.showInDevelopment)
const { isLoggedIn } = useUserStore()
const { refreshOverview } = useValidatorDashboardOverviewStore()
const { dashboards, getDashboardLabel, refreshDashboards } = useUserDashboardStore()
const { dashboardKey, dashboardType, setDashboardKey, isPrivate } = useDashboardKey()
const { dashboardKey, dashboardType, setDashboardKey, isPrivate, isShared } = useDashboardKey()
const emit = defineEmits<{(e: 'showCreation'): void }>()
Expand Down Expand Up @@ -56,7 +56,7 @@ const getDashboardName = (db: Dashboard): string => {
}
const items = computed<MenuBarEntry[]>(() => {
if (dashboards.value === undefined) {
if (dashboards.value === undefined || isShared.value) {
return []
}
Expand Down Expand Up @@ -167,7 +167,7 @@ const editDashboard = () => {
</span>
</template>
</Menubar>
<Button class="p-button-icon-only" @click="emit('showCreation')">
<Button v-if="!isShared" class="p-button-icon-only" @click="emit('showCreation')">
<IconPlus alt="Plus icon" width="100%" height="100%" />
</Button>
</div>
Expand Down
43 changes: 43 additions & 0 deletions frontend/components/dashboard/SharedDashboardModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script lang="ts" setup>
import { COOKIE_KEY, type CookiesPreference } from '~/types/cookie'
const cookiePreference = useCookie<CookiesPreference>(COOKIE_KEY.COOKIES_PREFERENCE, { default: () => undefined })
const { isShared } = useDashboardKey()
const { t: $t } = useI18n()
const route = useRoute()
const visible = computed(() => isShared.value && cookiePreference.value !== undefined)
</script>

<template>
<Dialog
v-model:visible="visible"
:dismissable-mask="false"
:draggable="false"
:close-on-escape="false"
position="bottom"
>
<div class="dialog-container">
{{ $t('dashboard.shared_modal.text') }}
<BcLink :to="`/dashboard`" :replace="route.path.startsWith('/dashboard')">
<Button class="get-started">
{{ $t('dashboard.shared_modal.get_started') }}
</Button>
</BcLink>
</div>
</Dialog>
</template>

<style lang="scss" scoped>
@use "~/assets/css/fonts.scss";
.dialog-container {
display: flex;
align-items: center;
gap: var(--padding-large);
.get-started {
min-width: 120px;
}
}
</style>
2 changes: 1 addition & 1 deletion frontend/composables/useDashboardKeyProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function useDashboardKeyProvider (type: DashboardType = 'validator', mock
}
// only use the dashboard cookie key as default if you are not logged in and it's not private
if (!isLoggedIn.value && isPublicKey(dashboardKeyCookie.value)) {
setDashboardKey(dashboardKeyCookie.value)
setDashboardKey(`${dashboardKeyCookie.value}`)
}
return
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@
}
}
},
"shared_modal": {
"text": "Create your own dashboard to get the most out of beaconcha.in",
"get_started": "Get started"
},
"group": {
"selection": {
"all": "All groups",
Expand Down
1 change: 1 addition & 0 deletions frontend/pages/dashboard/[[id]]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ watch([dashboardKey, isLoggedIn], ([newKey, newLoggedIn], [oldKey]) => {
<DashboardHeader :dashboard-title="overview?.name" @show-creation="showDashboardCreationDialog()" />
<DashboardValidatorOverview class="overview" />
</template>
<DashboardSharedDashboardModal />
<DashboardControls />
<div>
<DashboardValidatorSlotViz />
Expand Down

0 comments on commit d395955

Please sign in to comment.