-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from dimak1/feat/breadcrumb
Add Breadcrumb Across the App
- Loading branch information
Showing
21 changed files
with
307 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script setup lang="ts"> | ||
const { getBreadcrumbLinks, isDashboardButtonDisabled, isBreadcrumbVisible, dashboardButtonLink } = useBreadcrumb() | ||
</script> | ||
|
||
<template> | ||
<div | ||
v-if="isBreadcrumbVisible" | ||
class="flex justify-center min-h-[52px] bg-bcGovColor-nonClickable" | ||
data-test-id="breadcrumb-trail" | ||
> | ||
<div class="flex max-w-[1360px] grow px-4 items-center gap-3"> | ||
<router-link | ||
:to="isDashboardButtonDisabled ? '' : dashboardButtonLink" | ||
class="flex" | ||
:class="{ 'pointer-events-none': isDashboardButtonDisabled }" | ||
> | ||
<UIcon | ||
name="i-mdi-arrow-left-circle" | ||
class="size-7" | ||
:class="isDashboardButtonDisabled ? 'text-blue-200' : 'text-white'" | ||
/> | ||
</router-link> | ||
<UDivider orientation="vertical" class="h-6" /> | ||
<UBreadcrumb :links="getBreadcrumbLinks" class="flex" /> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { | ||
hostBreadcrumbs, | ||
examinerBreadcrumbs | ||
} from '~/page-data/breadcrumbs' | ||
|
||
export const useBreadcrumb = () => { | ||
const route = useRoute() | ||
const strrStore = useStrrStore() | ||
const { getApplicationId, getApplicationNickname, getRegistrationNumber } = storeToRefs(strrStore) | ||
const { isExaminer } = useBcrosKeycloak() | ||
const { t } = useTranslation() | ||
|
||
const { setApplicationId, setApplicationNickname, setRegistrationNumber } = useStrrStore() | ||
|
||
const NO_BREADCRUMB_ROUTES = [ | ||
RouteNamesE.TERMS_OF_SERVICE, | ||
RouteNamesE.FINALIZATION, | ||
RouteNamesE.ACCOUNT_SELECT, | ||
RouteNamesE.APPLICATION_SUBMITTED | ||
] | ||
|
||
// set store values for breadcrumb | ||
const setupBreadcrumbData = (application: ApplicationI) => { | ||
setApplicationId(application?.header.id.toString()) | ||
setApplicationNickname(application?.registration.unitAddress.nickname) | ||
setRegistrationNumber(application?.header.registrationNumber) | ||
} | ||
|
||
// Remove '-id' suffix and language codes (e.g., '___en') from route names to match RouteNamesE enum values | ||
const cleanupRoute = (routeName: string) => { | ||
return routeName?.replace(/(-id|___\w{2}$)/g, '') as RouteNamesE | ||
} | ||
|
||
/** | ||
* Create breadcrumb links for the current route, including dynamic labels based on | ||
* application or registration details. | ||
* | ||
* @returns {BreadcrumbI[]} An array of breadcrumb objects for the current route | ||
*/ | ||
const getBreadcrumbLinks = computed((): BreadcrumbI[] => { | ||
const routeName = route.name?.toString() | ||
|
||
// cleanup route from locale and id suffix | ||
const currentRouteName = cleanupRoute(routeName as RouteNamesE) | ||
|
||
// get nickname or set as empty string | ||
const nickname = getApplicationNickname.value ? `${getApplicationNickname.value}, ` : '' | ||
|
||
// set base Breadcrumb based on role | ||
const breadcrumbLinks = isExaminer | ||
? [...(examinerBreadcrumbs[currentRouteName] || [])] | ||
: [...(hostBreadcrumbs[currentRouteName] || [])] | ||
|
||
// add custom Breadcrumb info based on current route | ||
switch (currentRouteName) { | ||
case RouteNamesE.APPLICATION_DETAILS: | ||
breadcrumbLinks[1] = { | ||
label: `${nickname}Application #${getApplicationId.value}` | ||
} | ||
break | ||
case RouteNamesE.APPLICATION_DETAILS_LTSA: | ||
case RouteNamesE.APPLICATION_DETAILS_AUTO_APPROVAL: | ||
breadcrumbLinks[1] = { | ||
label: `${nickname}Application #${getApplicationId.value}`, | ||
to: `/${RouteNamesE.APPLICATION_DETAILS}/${getApplicationId.value}` | ||
} | ||
breadcrumbLinks[2] = { | ||
label: | ||
currentRouteName === RouteNamesE.APPLICATION_DETAILS_LTSA | ||
? t('ltsa.ltsaDetails') | ||
: t('autoApproval.automaticDetails') | ||
} | ||
break | ||
case RouteNamesE.REGISTRATION_DETAILS: | ||
breadcrumbLinks[1] = { | ||
label: `${nickname}Registration #${getRegistrationNumber.value}` | ||
} | ||
break | ||
} | ||
|
||
return breadcrumbLinks | ||
}) | ||
|
||
// Disable Dashboard Back Button when already at top route (eg Dashboard route) | ||
const isDashboardButtonDisabled = computed((): boolean => { | ||
return [RouteNamesE.REGISTRY_DASHBOARD, RouteNamesE.APPLICATION_STATUS].includes( | ||
cleanupRoute(route.name?.toString() ?? '') | ||
) | ||
}) | ||
|
||
// Check if breadcrumbs should be visible on certain routes | ||
const isBreadcrumbVisible = computed((): boolean => | ||
NO_BREADCRUMB_ROUTES.every(routeName => !route.name?.toString().startsWith(routeName)) | ||
) | ||
|
||
// Set the back button link to navigate one level up in breadcrumb | ||
const dashboardButtonLink = computed(():string => { | ||
const breadcrumbLinks = getBreadcrumbLinks.value | ||
// return second to last link for one level up | ||
return breadcrumbLinks[breadcrumbLinks.length - 2]?.to || '' | ||
}) | ||
|
||
return { | ||
setupBreadcrumbData, | ||
getBreadcrumbLinks, | ||
isDashboardButtonDisabled, | ||
dashboardButtonLink, | ||
isBreadcrumbVisible | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export enum RouteNamesE { | ||
CREATE_ACCOUNT = 'create-account', | ||
APPLICATION_DETAILS = 'application-details', | ||
APPLICATION_STATUS = 'application-status', | ||
REGISTRY_DASHBOARD = 'registry-dashboard', | ||
REGISTRATION_DETAILS = 'registration-details', | ||
APPLICATION_DETAILS_LTSA = 'application-details-ltsa', | ||
APPLICATION_DETAILS_AUTO_APPROVAL = 'application-details-auto-approval', | ||
|
||
// No Breadcrumb routes | ||
ACCOUNT_SELECT = 'account-select', | ||
TERMS_OF_SERVICE = 'terms-of-service', | ||
FINALIZATION = 'finalization', | ||
APPLICATION_SUBMITTED = 'success' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface BreadcrumbI { | ||
label: string | ||
to?: string | ||
} | ||
|
||
export type BreadcrumbsI = { | ||
[key in RouteNamesE]: BreadcrumbI[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { RouteNamesE } from '~/enums/route-names-e' | ||
import { BreadcrumbsI } from '~/interfaces/breadcrumb-i' | ||
|
||
export const hostDashboardBreadcrumb: Array<BreadcrumbI> = [ | ||
{ | ||
label: 'My STR Registry Dashboard' | ||
} | ||
] | ||
|
||
export const examinerDashboardBreadcrumb: Array<BreadcrumbI> = [ | ||
{ | ||
label: 'My CEU STR Registry Dashboard' | ||
} | ||
] | ||
|
||
export const strRegistrationBreadcrumb: Array<BreadcrumbI> = [ | ||
{ | ||
label: 'My STR Registry Dashboard', | ||
to: '/' + RouteNamesE.APPLICATION_STATUS | ||
}, | ||
{ | ||
label: 'Short-Term Rental Registration' | ||
} | ||
] | ||
|
||
export const applicationDetailsBreadcrumb: Array<BreadcrumbI> = [ | ||
{ | ||
label: 'My STR Registry Dashboard', | ||
to: '/' + RouteNamesE.APPLICATION_STATUS | ||
} | ||
] | ||
|
||
export const examinerApplicationDetailsBreadcrumb: Array<BreadcrumbI> = [ | ||
{ | ||
label: 'My CEU STR Registry Dashboard', | ||
to: '/' + RouteNamesE.REGISTRY_DASHBOARD | ||
} | ||
] | ||
|
||
export const examinerStrRegistrationBreadcrumb: Array<BreadcrumbI> = [ | ||
{ | ||
label: 'My CEU STR Registry Dashboard', | ||
to: '/' + RouteNamesE.REGISTRY_DASHBOARD | ||
}, | ||
{ | ||
label: 'Short-Term Rental Registration' | ||
} | ||
] | ||
|
||
export const hostBreadcrumbs: Partial<BreadcrumbsI> = { | ||
[RouteNamesE.APPLICATION_STATUS]: hostDashboardBreadcrumb, | ||
[RouteNamesE.APPLICATION_DETAILS]: applicationDetailsBreadcrumb, | ||
[RouteNamesE.CREATE_ACCOUNT]: strRegistrationBreadcrumb, | ||
[RouteNamesE.REGISTRATION_DETAILS]: applicationDetailsBreadcrumb | ||
} | ||
|
||
export const examinerBreadcrumbs: Partial<BreadcrumbsI> = { | ||
[RouteNamesE.APPLICATION_STATUS]: examinerDashboardBreadcrumb, | ||
[RouteNamesE.REGISTRY_DASHBOARD]: examinerDashboardBreadcrumb, | ||
[RouteNamesE.APPLICATION_DETAILS]: examinerApplicationDetailsBreadcrumb, | ||
[RouteNamesE.APPLICATION_DETAILS_LTSA]: examinerApplicationDetailsBreadcrumb, | ||
[RouteNamesE.APPLICATION_DETAILS_AUTO_APPROVAL]: examinerApplicationDetailsBreadcrumb, | ||
[RouteNamesE.CREATE_ACCOUNT]: examinerStrRegistrationBreadcrumb, | ||
[RouteNamesE.REGISTRATION_DETAILS]: examinerDashboardBreadcrumb | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.