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

feat(PUI): Make header tabs links to simpilfy new tab behaviour #8779

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/frontend/src/components/buttons/AdminButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function AdminButton(props: Readonly<AdminButtonProps>) {
`${server.server.django_admin}${modelDef.admin_url}${props.id}/`
);

if (event?.ctrlKey || event?.shiftKey) {
if (event?.ctrlKey || event?.shiftKey || event?.metaKey) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is used over and over again, maybe it makes sense to extract this into a custom function?

Copy link
Member Author

Choose a reason for hiding this comment

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

As those are seperate functions/interactions I would keep them seperate for now

// Open the link in a new tab
window.open(url, '_blank');
} else {
Expand Down
18 changes: 16 additions & 2 deletions src/frontend/src/components/nav/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { ActionIcon, Container, Group, Indicator, Tabs } from '@mantine/core';
import {
ActionIcon,
Container,
Group,
Indicator,
Tabs,
UnstyledButton
} from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import { IconBell, IconSearch } from '@tabler/icons-react';
import { useQuery } from '@tanstack/react-query';
Expand All @@ -9,6 +16,8 @@ import { api } from '../../App';
import { navTabs as mainNavTabs } from '../../defaults/links';
import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { navigateToLink } from '../../functions/navigation';
import { generateUrl } from '../../functions/urls';
import { base_url } from '../../main';
import * as classes from '../../main.css';
import { apiUrl } from '../../states/ApiState';
import { useLocalState } from '../../states/LocalState';
Expand Down Expand Up @@ -161,7 +170,12 @@ function NavTabs() {
navigateToLink(`/${tab.name}`, navigate, event)
}
>
{tab.text}
<UnstyledButton
component={'a'}
href={generateUrl(`${base_url}/${tab.name}`)}
>
{tab.text}
</UnstyledButton>
</Tabs.Tab>
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/nav/SearchDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export function SearchDrawer({
return;
}

if (event?.ctrlKey || event?.shiftKey) {
if (event?.ctrlKey || event?.shiftKey || event?.metaKey) {
// Keep the drawer open in this condition
} else {
closeDrawer();
Expand Down
16 changes: 13 additions & 3 deletions src/frontend/src/components/panels/PanelGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
Paper,
Stack,
Tabs,
Tooltip
Tooltip,
UnstyledButton
} from '@mantine/core';
import {
IconLayoutSidebarLeftCollapse,
Expand All @@ -30,7 +31,9 @@ import type { ModelType } from '../../enums/ModelType';
import { identifierString } from '../../functions/conversion';
import { cancelEvent } from '../../functions/events';
import { navigateToLink } from '../../functions/navigation';
import { generateUrl } from '../../functions/urls';
import { usePluginPanels } from '../../hooks/UsePluginPanels';
import { base_url } from '../../main';
import { useLocalState } from '../../states/LocalState';
import { Boundary } from '../Boundary';
import { StylishText } from '../items/StylishText';
Expand Down Expand Up @@ -117,7 +120,7 @@ function BasePanelGroup({
// Callback when the active panel changes
const handlePanelChange = useCallback(
(panel: string, event?: any) => {
if (event && (event?.ctrlKey || event?.shiftKey)) {
if (event && (event?.ctrlKey || event?.shiftKey || event?.metaKey)) {
const url = `${location.pathname}/../${panel}`;
cancelEvent(event);
navigateToLink(url, navigate, event);
Expand Down Expand Up @@ -182,7 +185,14 @@ function BasePanelGroup({
handlePanelChange(panel.name, event)
}
>
{expanded && panel.label}
<UnstyledButton
component={'a'}
href={generateUrl(
`${base_url}${location.pathname}/${panel.name}`
)}
>
{expanded && panel.label}
</UnstyledButton>
</Tabs.Tab>
</Tooltip>
)
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/functions/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { cancelEvent } from './events';
export const navigateToLink = (link: string, navigate: any, event: any) => {
cancelEvent(event);

if (event?.ctrlKey || event?.shiftKey) {
if (event?.ctrlKey || event?.shiftKey || event?.metaKey) {
// Open the link in a new tab
const url = `/${base_url}${link}`;
window.open(url, '_blank');
Expand Down
Loading