From e5fd44a6cb56fef9a88440674d2dc2d33b3a4987 Mon Sep 17 00:00:00 2001 From: aptmac Date: Mon, 10 Feb 2025 12:10:53 -0500 Subject: [PATCH] fix(links): update CryostatLink to handle partial paths (#1567) (cherry picked from commit cce817305859a710c7291d574a61f4769aa1dad4) --- src/app/Shared/Components/CryostatLink.tsx | 27 ++++++++++++++++++---- src/app/Topology/Entity/EntityDetails.tsx | 6 ++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/app/Shared/Components/CryostatLink.tsx b/src/app/Shared/Components/CryostatLink.tsx index a7efc1e22..675f51b4a 100644 --- a/src/app/Shared/Components/CryostatLink.tsx +++ b/src/app/Shared/Components/CryostatLink.tsx @@ -14,10 +14,29 @@ * limitations under the License. */ -import { toPath } from '@app/utils/utils'; +import { BASEPATH, toPath } from '@app/utils/utils'; import React from 'react'; -import { Link } from 'react-router-dom-v5-compat'; +import { Link, LinkProps, Path, To } from 'react-router-dom-v5-compat'; -export const CryostatLink: React.FC<{ to: string; onClick? }> = ({ to, onClick, ...props }) => { - return ; +export interface CryostatLinkProps extends LinkProps {} + +/** + * Formats a To (string | Partial\) by prepending a basepath if necessary + * @param {string | Partial} destination - the target destination + */ +const toDestination = (destination: To) => { + if (BASEPATH) { + if (typeof destination === 'string') { + return toPath(destination); + } else { + (destination as Partial).pathname = `/${BASEPATH}${(destination as Partial).pathname}`; + return destination as Partial; + } + } else { + return destination; + } +}; + +export const CryostatLink: React.FC = ({ to, onClick, ...props }) => { + return ; }; diff --git a/src/app/Topology/Entity/EntityDetails.tsx b/src/app/Topology/Entity/EntityDetails.tsx index 008c061e5..710b4958a 100644 --- a/src/app/Topology/Entity/EntityDetails.tsx +++ b/src/app/Topology/Entity/EntityDetails.tsx @@ -14,6 +14,7 @@ * limitations under the License. */ +import { CryostatLink } from '@app/Shared/Components/CryostatLink'; import { LinearDotSpinner } from '@app/Shared/Components/LinearDotSpinner'; import { EnvironmentNode, MBeanMetrics, MBeanMetricsResponse, TargetNode } from '@app/Shared/Services/api.types'; import { isTargetNode } from '@app/Shared/Services/api.utils'; @@ -50,7 +51,6 @@ import { css } from '@patternfly/react-styles'; import { ExpandableRowContent, Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'; import { GraphElement, NodeStatus } from '@patternfly/react-topology'; import * as React from 'react'; -import { Link } from 'react-router-dom-v5-compat'; import { catchError, concatMap, map, of } from 'rxjs'; import { EmptyText } from '../../Shared/Components/EmptyText'; import { NodeAction } from '../Actions/types'; @@ -555,9 +555,9 @@ export const TargetResourceItem: React.FC<{ /> { - + {splitWordsOnUppercase(resourceType, true).join(' ')} - + }