Skip to content

Commit

Permalink
fix(links): update CryostatLink to handle partial paths (#1567)
Browse files Browse the repository at this point in the history
(cherry picked from commit cce8173)
  • Loading branch information
aptmac authored and mergify[bot] committed Feb 10, 2025
1 parent 82fe4ad commit e5fd44a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
27 changes: 23 additions & 4 deletions src/app/Shared/Components/CryostatLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Link to={toPath(to)} onClick={onClick} {...props}></Link>;
export interface CryostatLinkProps extends LinkProps {}

/**
* Formats a To (string | Partial\<Path\>) by prepending a basepath if necessary
* @param {string | Partial<Path>} destination - the target destination
*/
const toDestination = (destination: To) => {
if (BASEPATH) {
if (typeof destination === 'string') {
return toPath(destination);
} else {
(destination as Partial<Path>).pathname = `/${BASEPATH}${(destination as Partial<Path>).pathname}`;
return destination as Partial<Path>;
}
} else {
return destination;
}
};

export const CryostatLink: React.FC<CryostatLinkProps> = ({ to, onClick, ...props }) => {
return <Link to={toDestination(to)} onClick={onClick} {...props}></Link>;
};
6 changes: 3 additions & 3 deletions src/app/Topology/Entity/EntityDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -555,9 +555,9 @@ export const TargetResourceItem: React.FC<{
/>
<Td key={`${resourceType}-resource-name`} dataLabel={'Resource'}>
{
<Link {...getLinkPropsForTargetResource(resourceType)} onClick={switchTarget}>
<CryostatLink {...getLinkPropsForTargetResource(resourceType)} onClick={switchTarget}>
{splitWordsOnUppercase(resourceType, true).join(' ')}
</Link>
</CryostatLink>
}
</Td>
<Td key={`${resourceType}-resource-count`} dataLabel={'Total'} textCenter>
Expand Down

0 comments on commit e5fd44a

Please sign in to comment.