diff --git a/frontend/src/components/common/Link.stories.tsx b/frontend/src/components/common/Link.stories.tsx
index 54dfdf80b5a..905fa67338a 100644
--- a/frontend/src/components/common/Link.stories.tsx
+++ b/frontend/src/components/common/Link.stories.tsx
@@ -1,15 +1,23 @@
import { Meta, StoryFn } from '@storybook/react';
+import React from 'react';
+import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
+import { createStore } from 'redux';
+import reducers from '../../redux/reducers/reducers';
import Link, { LinkProps } from './Link';
+const store = createStore(reducers);
+
export default {
title: 'Link',
component: Link,
decorators: [
Story => (
-
-
-
+
+
+
+
+
),
],
} as Meta;
diff --git a/frontend/src/components/common/Link.tsx b/frontend/src/components/common/Link.tsx
index 69f1155a73c..abcc0fcf827 100644
--- a/frontend/src/components/common/Link.tsx
+++ b/frontend/src/components/common/Link.tsx
@@ -1,10 +1,14 @@
import MuiLink from '@mui/material/Link';
import { useQueryClient } from '@tanstack/react-query';
import React from 'react';
+import { useDispatch } from 'react-redux';
import { Link as RouterLink } from 'react-router-dom';
+import helpers from '../../helpers';
import { kubeObjectQueryKey, useEndpoints } from '../../lib/k8s/api/v2/hooks';
import { KubeObject } from '../../lib/k8s/KubeObject';
import { createRouteURL, RouteURLProps } from '../../lib/router';
+import { setSelectedResource } from '../../redux/drawerModeSlice';
+import { useTypedSelector } from '../../redux/reducers/reducers';
import { LightTooltip } from './Tooltip';
export interface LinkBaseProps {
@@ -23,6 +27,7 @@ export interface LinkProps extends LinkBaseProps {
state?: {
[prop: string]: any;
};
+ drawerEnabled?: boolean;
}
export interface LinkObjectProps extends LinkBaseProps {
@@ -66,8 +71,8 @@ function PureLink(props: React.PropsWithChildren) {
const { kubeObject, ...otherProps } = props as LinkObjectProps;
return ;
}
+ const { routeName, params = {}, search, state, ...otherProps } = props as LinkObjectProps;
- const { routeName, params = {}, search, state, ...otherProps } = props as LinkProps;
return (
) {
}
export default function Link(props: React.PropsWithChildren) {
- const { tooltip, ...otherProps } = props;
+ const drawerEnabled = useTypedSelector(state => state.drawerMode.isDetailDrawerEnabled);
+ const dispatch = useDispatch();
+
+ const { tooltip, kubeObject, ...otherProps } = props as LinkObjectProps;
+
if (tooltip) {
let tooltipText = '';
if (typeof tooltip === 'string') {
@@ -106,5 +115,42 @@ export default function Link(props: React.PropsWithChildren {
+ if (drawerEnabled) {
+ dispatch(setSelectedResource(kubeJSON!));
+ /**
+ * NOTE: we are using window.history.pushState to update the URL without causing a page reload.
+ * currently there is no way to update the URL without navigation to the details page which would make the drawer redundant.
+ *
+ * also note that this currently only works in the browser, not in electron.
+ */
+ if (!helpers.isElectron()) {
+ window.history.pushState(
+ { path: kubeObject.getDetailsLink() },
+ '',
+ kubeObject.getDetailsLink()
+ );
+ }
+ }
+ }}
+ >
+ {props.children || kubeObject.getName()}
+
+ );
+ } else {
+ return (
+
+ {props.children || kubeObject.getName()}
+
+ );
+ }
+ }
+
return ;
}