Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PUI] Open links in new window #7354

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion src/frontend/src/components/nav/BreadcrumbList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { IconMenu2 } from '@tabler/icons-react';
import { useMemo } from 'react';
import { useNavigate } from 'react-router-dom';

import { navigateToLink } from '../../functions/navigation';

export type Breadcrumb = {
name: string;
url: string;
Expand Down Expand Up @@ -57,7 +59,10 @@ export function BreadcrumbList({
return (
<Anchor
key={index}
onClick={() => breadcrumb.url && navigate(breadcrumb.url)}
onClick={(event: any) =>
breadcrumb.url &&
navigateToLink(breadcrumb.url, navigate, event)
}
>
<Text size="sm">{breadcrumb.name}</Text>
</Anchor>
Expand Down
12 changes: 8 additions & 4 deletions src/frontend/src/components/nav/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useMatch, useNavigate } from 'react-router-dom';
import { api } from '../../App';
import { navTabs as mainNavTabs } from '../../defaults/links';
import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { navigateToLink } from '../../functions/navigation';
import * as classes from '../../main.css';
import { apiUrl } from '../../states/ApiState';
import { useLocalState } from '../../states/LocalState';
Expand Down Expand Up @@ -141,13 +142,16 @@ function NavTabs() {
tab: classes.tab
}}
value={tabValue}
onChange={(value) =>
value == '/' ? navigate('/') : navigate(`/${value}`)
}
>
<Tabs.List>
{mainNavTabs.map((tab) => (
<Tabs.Tab value={tab.name} key={tab.name}>
<Tabs.Tab
value={tab.name}
key={tab.name}
onClick={(event: any) =>
navigateToLink(`/${tab.name}`, navigate, event)
}
>
{tab.text}
</Tabs.Tab>
))}
Expand Down
42 changes: 28 additions & 14 deletions src/frontend/src/components/nav/PanelGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import {
IconLayoutSidebarLeftCollapse,
IconLayoutSidebarRightCollapse
} from '@tabler/icons-react';
import { ReactNode, useEffect, useMemo, useState } from 'react';
import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
import {
Navigate,
Route,
Routes,
useLocation,
useNavigate,
useParams
} from 'react-router-dom';

import { navigateToLink } from '../../functions/navigation';
import { useLocalState } from '../../states/LocalState';
import { Boundary } from '../Boundary';
import { PlaceholderPanel } from '../items/Placeholder';
Expand Down Expand Up @@ -52,6 +54,7 @@ function BasePanelGroup({
selectedPanel,
collapsible = true
}: Readonly<PanelProps>): ReactNode {
const location = useLocation();
const navigate = useNavigate();
const { panel } = useParams();

Expand All @@ -72,19 +75,27 @@ function BasePanelGroup({
}, [setLastUsedPanel]);

// Callback when the active panel changes
function handlePanelChange(panel: string | null) {
if (activePanels.findIndex((p) => p.name === panel) === -1) {
setLastUsedPanel('');
return navigate('../');
}

navigate(`../${panel}`);

// Optionally call external callback hook
if (panel && onPanelChange) {
onPanelChange(panel);
}
}
const handlePanelChange = useCallback(
(panel: string | null, event?: any) => {
if (activePanels.findIndex((p) => p.name === panel) === -1) {
setLastUsedPanel('');
return navigate('../');
}

if (event && (event?.ctrlKey || event?.shiftKey)) {
const url = `${location.pathname}/../${panel}`;
navigateToLink(url, navigate, event);
} else {
navigate(`../${panel}`);
}

// Optionally call external callback hook
if (panel && onPanelChange) {
onPanelChange(panel);
}
},
[activePanels, setLastUsedPanel, navigate, location, onPanelChange]
);

// if the selected panel state changes update the current panel
useEffect(() => {
Expand Down Expand Up @@ -129,6 +140,9 @@ function BasePanelGroup({
hidden={panel.hidden}
disabled={panel.disabled}
style={{ cursor: panel.disabled ? 'unset' : 'pointer' }}
onClick={(event: any) =>
handlePanelChange(panel.name, event)
}
>
{expanded && panel.label}
</Tabs.Tab>
Expand Down
Loading