Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.idea/
27 changes: 5 additions & 22 deletions src/components/Navigation/ActivityNav.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
// Copyright © 2022 Kaleido, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep this copyright - it stays from the original contributor but you can add the org you belong along side it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, updated now. :-)

//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { InsertChartOutlined } from '@mui/icons-material';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import { ApplicationContext } from '../../contexts/ApplicationContext';
import { FF_NAV_PATHS, INavItem } from '../../interfaces';
import { NavSection } from './NavSection';

export const ActivityNav = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const { selectedNamespace } = useContext(ApplicationContext);
const { pathname } = useLocation();

Expand All @@ -36,22 +19,22 @@ export const ActivityNav = () => {
const navItems: INavItem[] = [
{
name: t('timeline'),
action: () => navigate(timelinePath),
to: timelinePath,
itemIsActive: pathname === timelinePath,
},
{
name: t('events'),
action: () => navigate(eventsPath),
to: eventsPath,
itemIsActive: pathname === eventsPath,
},
{
name: t('transactions'),
action: () => navigate(txPath),
to: txPath,
itemIsActive: pathname.startsWith(txPath),
},
{
name: t('operations'),
action: () => navigate(opsPath),
to: opsPath,
itemIsActive: pathname === opsPath,
},
];
Expand Down
13 changes: 6 additions & 7 deletions src/components/Navigation/BlockchainNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import ViewInArIcon from '@mui/icons-material/ViewInAr';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import { ApplicationContext } from '../../contexts/ApplicationContext';
import { FF_NAV_PATHS, INavItem } from '../../interfaces';
import { NavSection } from './NavSection';

export const BlockchainNav = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const { selectedNamespace } = useContext(ApplicationContext);
const { pathname } = useLocation();

Expand All @@ -38,27 +37,27 @@ export const BlockchainNav = () => {
const navItems: INavItem[] = [
{
name: t('dashboard'),
action: () => navigate(blockchainPath),
to: blockchainPath,
itemIsActive: pathname === blockchainPath,
},
{
name: t('events'),
action: () => navigate(eventsPath),
to: eventsPath,
itemIsActive: pathname === eventsPath,
},
{
name: t('apis'),
action: () => navigate(apiPath),
to: apiPath,
itemIsActive: pathname === apiPath,
},
{
name: t('interfaces'),
action: () => navigate(interfacesPath),
to: interfacesPath,
itemIsActive: pathname === interfacesPath,
},
{
name: t('listeners'),
action: () => navigate(listenersPath),
to: listenersPath,
itemIsActive: pathname === listenersPath,
},
];
Expand Down
9 changes: 4 additions & 5 deletions src/components/Navigation/MyNodeNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import HexagonIcon from '@mui/icons-material/Hexagon';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import { ApplicationContext } from '../../contexts/ApplicationContext';
import { FF_NAV_PATHS, INavItem } from '../../interfaces';
import { NavSection } from './NavSection';

export const MyNodeNav = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const { selectedNamespace } = useContext(ApplicationContext);
const { pathname } = useLocation();

Expand All @@ -37,17 +36,17 @@ export const MyNodeNav = () => {
const navItems: INavItem[] = [
{
name: t('dashboard'),
action: () => navigate(myNodePath),
to: myNodePath,
itemIsActive: pathname === myNodePath,
},
{
name: t('subscriptions'),
action: () => navigate(myNodeSubscriptionsPath),
to: myNodeSubscriptionsPath,
itemIsActive: pathname === myNodeSubscriptionsPath,
},
{
name: t('websockets'),
action: () => navigate(myNodeWebsocketsPath),
to: myNodeWebsocketsPath,
itemIsActive: pathname === myNodeWebsocketsPath,
},
];
Expand Down
24 changes: 21 additions & 3 deletions src/components/Navigation/NavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,44 @@ import {
ListItemText,
Typography,
} from '@mui/material';
import { Link as RouterLink } from 'react-router-dom';

interface Props {
name: string;
action: () => void;
icon?: JSX.Element;
itemIsActive: boolean;
icon?: JSX.Element;
rightIcon?: JSX.Element;
isRoot?: boolean;
}

// NEW:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment removed. :-)

to?: string; // internal route (React Router)
href?: string; // external link
action?: () => void; // fallback click handler (legacy)
}
export const NavItem = ({
name,
action,
icon,
itemIsActive,
rightIcon,
isRoot = false,
to,
href,
}: Props) => {
const linkProps =
to != null
? { component: RouterLink, to }
: href != null
? {
component: 'a' as const,
href,
target: '_blank',
rel: 'noopener noreferrer',
}
: {};
return (
<ListItemButton
{...linkProps}
onClick={action}
sx={{
borderLeft: 6,
Expand Down
7 changes: 5 additions & 2 deletions src/components/Navigation/NavSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ export const NavSection = ({ icon, navItems, title }: Props) => {
<Collapse in={open} unmountOnExit>
{navItems.map((item) => (
<NavItem
key={item.name}
name={item.name}
action={item.action}
icon={item.icon}
itemIsActive={item.itemIsActive}
key={item.name}
to={item.to}
href={item.href}
action={item.action} // still supported as fallback
/>
))}
</Collapse>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Navigation: React.FC = () => {
<NavItem
name={t('dashboard')}
icon={<DashboardOutlined />}
action={() => navigate(FF_NAV_PATHS.homePath(selectedNamespace))}
to={FF_NAV_PATHS.homePath(selectedNamespace)} // ← use `to` instead of action
itemIsActive={pathname === FF_NAV_PATHS.homePath(selectedNamespace)}
isRoot
/>
Expand All @@ -43,7 +43,7 @@ export const Navigation: React.FC = () => {
<NavItem
name={t('docs')}
icon={<MenuBookIcon />}
action={() => window.open(FF_NAV_PATHS.docsPath, '_blank')}
href={FF_NAV_PATHS.docsPath} // ← external URL
itemIsActive={false}
rightIcon={<LaunchIcon />}
isRoot
Expand Down
13 changes: 6 additions & 7 deletions src/components/Navigation/NetworkNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import LanguageIcon from '@mui/icons-material/Language';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import { ApplicationContext } from '../../contexts/ApplicationContext';
import { FF_NAV_PATHS, INavItem } from '../../interfaces';
import { NavSection } from './NavSection';

export const NetworkNav = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const { selectedNamespace } = useContext(ApplicationContext);
const { pathname } = useLocation();

Expand All @@ -37,27 +36,27 @@ export const NetworkNav = () => {
const navItems: INavItem[] = [
{
name: t('dashboard'),
action: () => navigate(networkPath),
to: networkPath,
itemIsActive: pathname === networkPath,
},
{
name: t('organizations'),
action: () => navigate(orgPath),
to: orgPath,
itemIsActive: pathname === orgPath,
},
{
name: t('nodes'),
action: () => navigate(nodePath),
to: nodePath,
itemIsActive: pathname === nodePath,
},
{
name: t('identities'),
action: () => navigate(identitiesPath),
to: identitiesPath,
itemIsActive: pathname === identitiesPath,
},
{
name: t('namespaces'),
action: () => navigate(namespacesPath),
to: namespacesPath,
itemIsActive: pathname === namespacesPath,
},
];
Expand Down
15 changes: 7 additions & 8 deletions src/components/Navigation/OffChainNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import InventoryIcon from '@mui/icons-material/Inventory';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import { ApplicationContext } from '../../contexts/ApplicationContext';
import { FF_NAV_PATHS, INavItem } from '../../interfaces';
import { NavSection } from './NavSection';

export const OffChainNav = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const { pathname } = useLocation();
const { selectedNamespace } = useContext(ApplicationContext);

Expand All @@ -38,32 +37,32 @@ export const OffChainNav = () => {
const navItems: INavItem[] = [
{
name: t('dashboard'),
action: () => navigate(offchainPath),
to: offchainPath,
itemIsActive: pathname === offchainPath,
},
{
name: t('messages'),
action: () => navigate(messagesPath),
to: messagesPath,
itemIsActive: pathname === messagesPath,
},
{
name: t('data'),
action: () => navigate(dataPath),
to: dataPath,
itemIsActive: pathname === dataPath,
},
{
name: t('batches'),
action: () => navigate(batchesPath),
to: batchesPath,
itemIsActive: pathname === batchesPath,
},
{
name: t('datatypes'),
action: () => navigate(datatypesPath),
to: datatypesPath,
itemIsActive: pathname === datatypesPath,
},
{
name: t('groups'),
action: () => navigate(groupsPath),
to: groupsPath,
itemIsActive: pathname === groupsPath,
},
];
Expand Down
13 changes: 6 additions & 7 deletions src/components/Navigation/TokensNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import AdjustIcon from '@mui/icons-material/Adjust';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import { ApplicationContext } from '../../contexts/ApplicationContext';
import { FF_NAV_PATHS, INavItem } from '../../interfaces';
import { NavSection } from './NavSection';

export const TokensNav = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const { pathname } = useLocation();
const { selectedNamespace } = useContext(ApplicationContext);

Expand All @@ -37,27 +36,27 @@ export const TokensNav = () => {
const navItems: INavItem[] = [
{
name: t('dashboard'),
action: () => navigate(blockchainPath),
to: blockchainPath,
itemIsActive: pathname === blockchainPath,
},
{
name: t('transfers'),
action: () => navigate(transfersPath),
to: transfersPath,
itemIsActive: pathname === transfersPath,
},
{
name: t('pools'),
action: () => navigate(poolsPath),
to: poolsPath,
itemIsActive: pathname.startsWith(poolsPath),
},
{
name: t('balances'),
action: () => navigate(balancesPath),
to: balancesPath,
itemIsActive: pathname === balancesPath,
},
{
name: t('approvals'),
action: () => navigate(approvalsPath),
to: approvalsPath,
itemIsActive: pathname === approvalsPath,
},
];
Expand Down
Loading
Loading