-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix external link badge display for tools hosted under the same domain (
#1192) **Related Ticket:** #1187 ### Description of Changes After discussing with @hanbyul-here during pod week, we identified two potential solutions: 1. Introduce an isExternalLink prop in the .mdx configuration files for each story, or, 2. Add logic in the card component to dynamically check the domain of the link and decide whether it is external Option 2 requires less configuration for developers/users of VEDA instances, but it's not easy to test locally especially if we want more fine-grained control over future integration tests. So the implementation here goes for Option 1. More context: https://developmentseed.slack.com/archives/C063GD0NYP8/p1728407361439379 - Add a new `isLinkExternal` prop that can be passed to the story as a configuration - The existing check for `http/https (/^https?:\/\//)` remains in place as a fallback if the new prop is not present ### Notes & Questions About Changes ### Validation / Testing - Use the new `isLinkExternal` prop in some of the stories and validate that it shows/hides the "External Link" badge in the UI - Remove the `isLinkExternal` prop that you added and see if the UI still behaves as expected (e.g if the link you added in the story .mdx file has `https`, it will be marked as `External Link` in the UI cards) - Click around the UI cards and verify that the links work as expected
- Loading branch information
Showing
11 changed files
with
53 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
import React, { MouseEventHandler } from 'react'; | ||
import { LinkProps } from 'react-router-dom'; | ||
|
||
export function isExternalLink(link: string): boolean { | ||
return /^https?:\/\//.test(link) && !link.includes(window.location.hostname); | ||
} | ||
|
||
export const getLinkProps = ( | ||
linkTo: string, | ||
as?: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>, | ||
onClick?: (() => void) | MouseEventHandler | ||
) => { | ||
// Open the link in a new tab when link is external | ||
const isExternalLink = /^https?:\/\//.test(linkTo); | ||
return isExternalLink | ||
linkTo: string, | ||
isLinkExternal?: boolean, | ||
as?: React.ForwardRefExoticComponent< | ||
LinkProps & React.RefAttributes<HTMLAnchorElement> | ||
>, | ||
onClick?: (() => void) | MouseEventHandler | ||
) => { | ||
// Open the link in a new tab when link is external | ||
const isExternalLink = isLinkExternal ?? /^https?:\/\//.test(linkTo); | ||
return isExternalLink | ||
? { | ||
href: linkTo, | ||
to: linkTo, | ||
...{target: '_blank', rel: 'noopener noreferrer'}, | ||
...(onClick ? {onClick: onClick} : {}) | ||
...{ target: '_blank', rel: 'noopener noreferrer' }, | ||
...(onClick ? { onClick: onClick } : {}) | ||
} | ||
: { | ||
...(as ? {as: as} : {}), | ||
...(as ? { as: as } : {}), | ||
to: linkTo, | ||
...(onClick ? {onClick: onClick} : {}) | ||
...(onClick ? { onClick: onClick } : {}) | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters