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

fix widget link issues #91

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

fix widget link issues #91

wants to merge 4 commits into from

Conversation

InsaneZein
Copy link

Description

Fixes RHCLOUD-32859

  • Prevents widget links from opening new tabs when clicked
  • makes sure /preview/ persists when link is clicked

Screenshots

After:

fixwidgetlinks


Checklist ☑️

  • PR only fixes one issue or story
  • Change reviewed for extraneous code
  • UI best practices adhered to
  • Commits squashed and meaningfully named
  • All PR checks pass locally (build, lint, test, E2E)

  • (Optional) QE: Needs QE attention (OUIA changed, perceived impact to tests, no test coverage)
  • (Optional) QE: Has been mentioned
  • (Optional) UX: Needs UX attention (end user UX modified, missing designs)
  • (Optional) UX: Has been mentioned

@InsaneZein InsaneZein requested a review from a team May 28, 2024 15:58
@@ -62,6 +64,14 @@ const GridTile = ({ widgetType, isDragging, setIsDragging, setWidgetAttribute, w
return null;
}

const widgetLink = (href: string) => {
if (href.includes('https://')) {
Copy link
Author

Choose a reason for hiding this comment

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

is there a better way to check if the href is an external link?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not reliable. We use a isExternal prop in our links to determine if a link is external. Configuration is responsible for marking external links.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not seeing an isExternal prop being passed down

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think exists yet in the widgets. But its a pattern all across the platform.

@@ -192,7 +202,8 @@ const GridTile = ({ widgetType, isDragging, setIsDragging, setWidgetAttribute, w
<Button
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use react-router-dom Links when we are not opening new tabs and staying in HCC.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@Hyperkid123
Copy link
Contributor

I think the styling is now off.

screenshot-stage foo redhat com_1337-2024 05 30-09_30_09

epwinchell
epwinchell previously approved these changes May 30, 2024
@epwinchell
Copy link
Contributor

@Hyperkid123 @InsaneZein Styling looks fine now

if (href.includes('https://')) {
return href;
} else {
return `${window.location.origin}${chrome.isBeta() ? '/preview' : ''}${href}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have to add origin or the preview partial to router links. That is handled via the component.

{headerLink.title}
</Button>
{headerLink.href && (
<Link to={widgetLink(headerLink.href)}>
Copy link
Contributor

Choose a reason for hiding this comment

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

You can't mix client-side routing with classic HTML routing. You have to pick a link component based on what the target is.

// for origin console.redhat.com

const href = https://www.google.com/

<Link to={href}>...</Link>
// actual link: console.redhat.com/https://www.google.com/

You have to decide which type of a link you are supposed to use.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure I understand. Do I pick a different routing component based on whether its external or not?

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly. For external links, you use the plain HTML tags.

@@ -62,6 +64,14 @@ const GridTile = ({ widgetType, isDragging, setIsDragging, setWidgetAttribute, w
return null;
}

const widgetLink = (href: string) => {
if (href.includes('https://')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not reliable. We use a isExternal prop in our links to determine if a link is external. Configuration is responsible for marking external links.

@Hyperkid123 Hyperkid123 dismissed epwinchell’s stale review May 31, 2024 07:27

PR has still some code issues to be addressed.

@InsaneZein
Copy link
Author

We use a isExternal prop in our links to determine if a link is external. Configuration is responsible for marking external links.

@Hyperkid123 I'm not seeing an isExternal link prop passed anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants