From 7a0dba69d865bcd20e6e8da3d8c8696e6be7c167 Mon Sep 17 00:00:00 2001 From: Lucca Dukic <109136188+LuccaBitfly@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:08:26 +0100 Subject: [PATCH] refactor: use better terminology for dashboard types - replaces all mentions of "public" dashboards with "guest" dashboards, as this is the correct internal terminology. - replaces all mentions of "hash" regarding guest dashboards with "key", as guest dashboard keys are NOT hashes. - unifies some misc. function and variable naming --- .../dashboard/DashboardControls.vue | 32 +++++----- .../components/dashboard/DashboardHeader.vue | 18 +++--- .../dashboard/DashboardShareCodeModal.vue | 10 ++-- .../DashboardValidatorManagementModal.vue | 15 +++-- ...ashboardValidatorManagementModalSearch.vue | 4 +- .../dashboard/GroupManagementModal.vue | 9 +-- .../dashboard/SharedDashboardModal.vue | 4 +- .../dashboard/chart/RewardsChart.vue | 2 +- .../creation/DashboardCreationController.vue | 4 +- .../dashboard/table/DashboardTableBlocks.vue | 5 +- .../dashboard/table/DashboardTableRewards.vue | 5 +- .../dashboard/table/DashboardTableSummary.vue | 5 +- frontend/composables/useDashboardKey.ts | 12 ++-- .../composables/useDashboardKeyProvider.ts | 20 +++---- frontend/pages/dashboard/[[id]]/index.vue | 36 ++++++------ .../stores/dashboard/useUserDashboardStore.ts | 58 +++++++++---------- .../dashboard/useValidatorSlotVizStore.ts | 2 +- frontend/types/dashboard/index.ts | 10 ++-- frontend/utils/dashboard/key.ts | 4 +- 19 files changed, 129 insertions(+), 126 deletions(-) diff --git a/frontend/components/dashboard/DashboardControls.vue b/frontend/components/dashboard/DashboardControls.vue index 48c74b14d..721dbfe5a 100644 --- a/frontend/components/dashboard/DashboardControls.vue +++ b/frontend/components/dashboard/DashboardControls.vue @@ -37,15 +37,15 @@ const { isLoggedIn } = useUserStore() const { dashboardKey, dashboardType, - isPrivate, - isPublic, - isShared, + isGuestDashboard, + isPrivateDashboard, + isSharedDashboard, publicEntities, setDashboardKey, } = useDashboardKey() const { refreshOverview } = useValidatorDashboardOverviewStore() const { - dashboards, getDashboardLabel, refreshDashboards, updateHash, + dashboards, getDashboardLabel, refreshDashboards, updateGuestDashboardKey, } = useUserDashboardStore() @@ -59,7 +59,7 @@ const manageGroupsModalVisisble = ref(false) const manageValidatorsModalVisisble = ref(false) const manageButtons = computed(() => { - if (isShared.value) { + if (isSharedDashboard.value) { return undefined } @@ -108,7 +108,7 @@ const shareDashboard = computed(() => { }) const shareButtonOptions = computed(() => { - const edit = isPrivate.value && !shareDashboard.value?.public_ids?.length + const edit = isPrivateDashboard.value && !shareDashboard.value?.public_ids?.length const label = isMobile.value ? '' @@ -116,7 +116,7 @@ const shareButtonOptions = computed(() => { ? $t('dashboard.shared') : $t('dashboard.share') const icon = !edit ? faUsers : faShare - const disabled = isShared.value || !dashboardKey.value + const disabled = isSharedDashboard.value || !dashboardKey.value return { disabled, edit, @@ -130,7 +130,7 @@ const editButtons = computed(() => { buttons.push({ component: RocketpoolToggle }) - if (isPrivate.value) { + if (isPrivateDashboard.value) { buttons.push({ command: editDashboard, faIcon: faEdit, @@ -148,7 +148,7 @@ const editButtons = computed(() => { }) } - if (!isShared.value && dashboardKey.value) { + if (!isSharedDashboard.value && dashboardKey.value) { buttons.push({ command: onDelete, faIcon: faTrash, @@ -172,7 +172,7 @@ const shareView = () => { }, onClose: (options?: DynamicDialogCloseOptions) => { if (options?.data === 'DELETE') { - if (isShared.value && dashboardId) { + if (isSharedDashboard.value && dashboardId) { setDashboardKey(`${dashboardId}`) } } @@ -202,12 +202,12 @@ const share = () => { } const deleteButtonOptions = computed(() => { - const visible = !isShared.value + const visible = !isSharedDashboard.value - const disabled = isPublic.value && publicEntities.value?.length === 0 + const disabled = isGuestDashboard.value && publicEntities.value?.length === 0 - // private dashboards always get deleted, public dashboards only get cleared - const deleteDashboard = isPrivate.value + // private dashboards always get deleted, guest dashboards only get cleared + const deleteDashboard = isPrivateDashboard.value // we can only forward if there is something to forward to after a potential deletion const privateDashboardsCount = isLoggedIn.value @@ -281,8 +281,8 @@ const deleteAction = async ( await refreshDashboards() } else if (!isLoggedIn.value) { - // simply clear the public dashboard by emptying the hash - updateHash(dashboardType.value, '') + // simply clear the guest dashboard by emptying the key + updateGuestDashboardKey(dashboardType.value, '') setDashboardKey('') return } diff --git a/frontend/components/dashboard/DashboardHeader.vue b/frontend/components/dashboard/DashboardHeader.vue index 273853394..13a9da04d 100644 --- a/frontend/components/dashboard/DashboardHeader.vue +++ b/frontend/components/dashboard/DashboardHeader.vue @@ -4,7 +4,7 @@ import type { } from '~/types/menuBar' import { useUserDashboardStore } from '~/stores/dashboard/useUserDashboardStore' import { - COOKIE_DASHBOARD_ID, type CookieDashboard, type Dashboard, type DashboardKey, type DashboardType, + type Dashboard, type DashboardKey, type DashboardType, GUEST_DASHBOARD_ID, type GuestDashboard, } from '~/types/dashboard' const { t: $t } = useTranslation() @@ -16,7 +16,7 @@ const { has } = useFeatureFlag() const { isLoggedIn } = useUserStore() const { dashboards } = useUserDashboardStore() const { - dashboardKey, dashboardType, isShared, setDashboardKey, + dashboardKey, dashboardType, isSharedDashboard, setDashboardKey, } = useDashboardKey() const emit = defineEmits<{ (e: 'showCreation'): void }>() @@ -26,14 +26,14 @@ const getDashboardName = (db: Dashboard): string => { return db.name || `${$t('dashboard.title')} ${db.id}` // Just to be sure, we should not have dashboards without a name in prod } else { - return db.id === COOKIE_DASHBOARD_ID.ACCOUNT + return db.id === GUEST_DASHBOARD_ID.ACCOUNT ? $t('dashboard.account_dashboard') : $t('dashboard.validator_dashboard') } } const items = computed(() => { - if (dashboards.value === undefined || isShared.value) { + if (dashboards.value === undefined || isSharedDashboard.value) { return [] } @@ -87,13 +87,13 @@ const items = computed(() => { } } addToSortedItems($t('dashboard.header.validator'), dashboards.value?.validator_dashboards?.map((db) => { - const cd = db as CookieDashboard - return createMenuBarButton('validator', getDashboardName(cd), `${cd.hash !== undefined ? cd.hash : cd.id}`) + const gd = db as GuestDashboard + return createMenuBarButton('validator', getDashboardName(gd), `${gd.key !== undefined ? gd.key : gd.id}`) })) if (has('feature-account_dashboards')) { addToSortedItems($t('dashboard.header.account'), dashboards.value?.validator_dashboards?.slice(0, 1).map((db) => { - const cd = db as CookieDashboard - return createMenuBarButton('account', getDashboardName(cd), `${cd.hash ?? cd.id}`) + const gd = db as GuestDashboard + return createMenuBarButton('account', getDashboardName(gd), `${gd.key ?? gd.id}`) })) } const disabledTooltip = !has('feature-notifications') ? $t('common.coming_soon') : undefined @@ -115,7 +115,7 @@ const items = computed(() => { :buttons="items" /> : props.value?.dashboardKey, ) -const isShared = computed(() => isSharedKey(sharedKey.value)) +const isShared = computed(() => isSharedDashboardKey(sharedKey.value)) const path = computed(() => { const newRoute = router.resolve({ @@ -41,7 +41,7 @@ const path = computed(() => { const edit = () => { if (isReadonly.value) { - warn('cannot edit public dashboard share') + warn('cannot edit guest dashboard share') return } dialogRef?.value?.close('EDIT') @@ -49,7 +49,7 @@ const edit = () => { const unpublish = async () => { if (isReadonly.value) { - warn('cannot delete public dashboard share') + warn('cannot delete guest dashboard share') return } if (isUpdating.value) { diff --git a/frontend/components/dashboard/DashboardValidatorManagementModal.vue b/frontend/components/dashboard/DashboardValidatorManagementModal.vue index a2562bacf..547e21983 100644 --- a/frontend/components/dashboard/DashboardValidatorManagementModal.vue +++ b/frontend/components/dashboard/DashboardValidatorManagementModal.vue @@ -44,10 +44,9 @@ const selectedGroup = ref(-1) const { addEntities, dashboardKey, - isPublic: isPublicDashboard, + isGuestDashboard, removeEntities, -} - = useDashboardKey() +} = useDashboardKey() const { user, } = useUserStore() @@ -136,7 +135,7 @@ const removeValidators = async (validators?: NumberOrString[]) => { warn('no validators selected to change group') return } - if (isPublicDashboard.value) { + if (isGuestDashboard.value) { removeEntities(validators.map(v => v.toString())) return } @@ -275,7 +274,7 @@ const removeRow = (row: VDBManageValidatorsTableRow) => { const totalValidators = computed(() => addUpValues(overview.value?.validators)) const maxValidatorsPerDashboard = computed(() => - isPublicDashboard.value || !user.value?.premium_perks?.validators_per_dashboard + isGuestDashboard.value || !user.value?.premium_perks?.validators_per_dashboard ? 20 : user.value.premium_perks.validators_per_dashboard, ) @@ -312,7 +311,7 @@ const handleSubmit = (item: InternalPostSearchResponse['data'][number] | undefin handleInvalidSubmit() return } - if (isPublicDashboard.value) { + if (isGuestDashboard.value) { if (item.type === 'validator') { addEntities([ `${item.value.index}` ]) resetInput() @@ -360,7 +359,7 @@ const inputValidator = ref('') diff --git a/frontend/components/dashboard/DashboardValidatorManagementModalSearch.vue b/frontend/components/dashboard/DashboardValidatorManagementModalSearch.vue index 14e4215fe..776a4b326 100644 --- a/frontend/components/dashboard/DashboardValidatorManagementModalSearch.vue +++ b/frontend/components/dashboard/DashboardValidatorManagementModalSearch.vue @@ -6,7 +6,7 @@ import { API_PATH } from '~/types/customFetch' const props = defineProps<{ hasPremiumPerkBulkAdding: boolean, - isPublicDashboard: boolean, + isGuestDashboard: boolean, maxValidatorsPerDashboard: number, totalValidators: number, }>() @@ -67,7 +67,7 @@ const isDisabled = (type: InternalPostSearchResponse['data'][number]['type'], va return true } if ( - props.isPublicDashboard + props.isGuestDashboard && ((type !== 'validator' && type !== 'validator_list')) ) { return true diff --git a/frontend/components/dashboard/GroupManagementModal.vue b/frontend/components/dashboard/GroupManagementModal.vue index fbc8a9770..7c7b24cf6 100644 --- a/frontend/components/dashboard/GroupManagementModal.vue +++ b/frontend/components/dashboard/GroupManagementModal.vue @@ -22,7 +22,8 @@ const { fetch } = useCustomFetch() const dialog = useDialog() const { - dashboardKey, isPublic, + dashboardKey, + isGuestDashboard, } = useDashboardKey() const { @@ -186,7 +187,7 @@ const dashboardName = computed(() => { }) const maxGroupsPerDashboard = computed(() => - isPublic.value || !user.value?.premium_perks?.validator_groups_per_dashboard + isGuestDashboard.value || !user.value?.premium_perks?.validator_groups_per_dashboard ? 1 : user.value.premium_perks.validator_groups_per_dashboard, ) @@ -222,7 +223,7 @@ const isMobile = computed(() => { :search-placeholder=" $t('dashboard.validator.group_management.search_placeholder') " - :disabled-filter="isPublic" + :disabled-filter="isGuestDashboard" @set-search="setSearch" >