From ba0aeaa50fd0e687d3eae2b107af4dd41b65c12e Mon Sep 17 00:00:00 2001 From: Antonio Ventilii Date: Fri, 15 Nov 2024 13:41:28 +0100 Subject: [PATCH] feat(frontend): add Activity to navigation menu --- .../src/lib/components/core/Menu.svelte | 21 ++++++++++++-- .../icons/iconly/IconActivity.svelte | 29 +++++++++++++++++++ .../navigation/NavigationMenu.svelte | 13 +++++++++ .../src/lib/constants/test-ids.constants.ts | 1 + src/frontend/src/lib/i18n/en.json | 2 ++ src/frontend/src/lib/types/i18n.d.ts | 2 ++ src/frontend/src/lib/utils/nav.utils.ts | 3 ++ .../src/tests/lib/utils/nav.utils.spec.ts | 17 +++++++++++ 8 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/frontend/src/lib/components/icons/iconly/IconActivity.svelte diff --git a/src/frontend/src/lib/components/core/Menu.svelte b/src/frontend/src/lib/components/core/Menu.svelte index b6f2620316..0181fcb0b1 100644 --- a/src/frontend/src/lib/components/core/Menu.svelte +++ b/src/frontend/src/lib/components/core/Menu.svelte @@ -1,5 +1,5 @@ @@ -61,6 +71,13 @@ {/if} + {#if !activityRoute && !settingsRoute} + + + {$i18n.navigation.text.activity} + + {/if} + {#if !dAppExplorerRoute && !settingsRoute} diff --git a/src/frontend/src/lib/components/icons/iconly/IconActivity.svelte b/src/frontend/src/lib/components/icons/iconly/IconActivity.svelte new file mode 100644 index 0000000000..afd89abdd8 --- /dev/null +++ b/src/frontend/src/lib/components/icons/iconly/IconActivity.svelte @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/src/frontend/src/lib/components/navigation/NavigationMenu.svelte b/src/frontend/src/lib/components/navigation/NavigationMenu.svelte index f9b6e77073..fef5904bee 100644 --- a/src/frontend/src/lib/components/navigation/NavigationMenu.svelte +++ b/src/frontend/src/lib/components/navigation/NavigationMenu.svelte @@ -8,6 +8,7 @@ import NavigationItem from '$lib/components/navigation/NavigationItem.svelte'; import { AppPath } from '$lib/constants/routes.constants'; import { + NAVIGATION_ITEM_ACTIVITY, NAVIGATION_ITEM_EXPLORER, NAVIGATION_ITEM_SETTINGS, NAVIGATION_ITEM_TOKENS @@ -15,12 +16,14 @@ import { networkId } from '$lib/derived/network.derived'; import { i18n } from '$lib/stores/i18n.store'; import { + isRouteActivity, isRouteDappExplorer, isRouteSettings, isRouteTokens, isRouteTransactions, networkParam } from '$lib/utils/nav.utils.js'; + import IconActivity from '$lib/components/icons/iconly/IconActivity.svelte'; // If we pass $page directly, we get a type error: for some reason (I cannot find any // documentation on it), the type of $page is not `Page`, but `unknown`. So we need to manually @@ -41,6 +44,16 @@ {$i18n.navigation.text.tokens} + + + {$i18n.navigation.text.activity} + + export const isRouteDappExplorer = ({ route: { id } }: Page): boolean => id === `${ROUTE_ID_GROUP_APP}${AppPath.Explore}`; +export const isRouteActivity = ({ route: { id } }: Page): boolean => + id === `${ROUTE_ID_GROUP_APP}${AppPath.Activity}`; + export const isRouteTokens = ({ route: { id } }: Page): boolean => id === ROUTE_ID_GROUP_APP; const tokenUrl = ({ diff --git a/src/frontend/src/tests/lib/utils/nav.utils.spec.ts b/src/frontend/src/tests/lib/utils/nav.utils.spec.ts index 1441926d89..8bec9a63de 100644 --- a/src/frontend/src/tests/lib/utils/nav.utils.spec.ts +++ b/src/frontend/src/tests/lib/utils/nav.utils.spec.ts @@ -1,5 +1,6 @@ import { AppPath, ROUTE_ID_GROUP_APP } from '$lib/constants/routes.constants'; import { + isRouteActivity, isRouteDappExplorer, isRouteSettings, isRouteTokens, @@ -82,6 +83,22 @@ describe('Route Check Functions', () => { }); }); + describe('isRouteActivity', () => { + it('should return true when route id matches Activity path', () => { + expect(isRouteActivity(mockPage(`${ROUTE_ID_GROUP_APP}${AppPath.Activity}`))).toBe(true); + }); + + it('should return false when route id does not match Activity path', () => { + expect(isRouteActivity(mockPage(`${ROUTE_ID_GROUP_APP}/wrongPath`))).toBe(false); + + expect(isRouteActivity(mockPage(`${ROUTE_ID_GROUP_APP}${AppPath.Settings}`))).toBe(false); + + expect(isRouteActivity(mockPage(`${ROUTE_ID_GROUP_APP}`))).toBe(false); + + expect(isRouteActivity(mockPage(`/anotherGroup/${AppPath.Activity}`))).toBe(false); + }); + }); + describe('isRouteTokens', () => { it('should return true when route id matches ROUTE_ID_GROUP_APP exactly', () => { expect(isRouteTokens(mockPage(ROUTE_ID_GROUP_APP))).toBe(true);