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: Federation portal button link #854

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/components/federated_portal_button_component.rb
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

class FederatedPortalButtonComponent < ViewComponent::Base
attr_reader :name, :tooltip, :link, :color, :light_color
include UrlsHelper

def initialize(name:, link:, color:, tooltip:, light_color:)
@name = name
@@ -10,4 +11,8 @@ def initialize(name:, link:, color:, tooltip:, light_color:)
@color = color
@light_color = light_color
end

def internal?
!link?(@link)
Copy link
Collaborator

Choose a reason for hiding this comment

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

here it should be id.include?($REST_URL) , because logically this function does not make sense if you are unaware of the existence of ontoportal_ui_link hack.

Copy link
Collaborator Author

@Bilelkihal Bilelkihal Nov 19, 2024

Choose a reason for hiding this comment

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

I didn't got you well, what do you mean by ontoportal_ui_link hack?

Here basically, when a link is internal we pass it relative like this /ontologies/acronym and when it is external we pass it absolute like this https://data...
so the first one technically is not considered as a valid link this is why I used the function link?

Copy link
Collaborator

Choose a reason for hiding this comment

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

How do you enforce that internal we pass it relative like this /ontologies/acronym and when it is external we pass it absolute like this https://data... ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For the external, no choice it should be absolute.
And for the internal onces, this is the practice that we have in all the app.
What is the case that you have in your mind and can break this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For the external, yes.
For the internal, you did this

 def ontoportal_ui_link(id)
    if id.include?($REST_URL)
      return id.gsub($REST_URL,'')
    end

which says if I understood well, check if the given link includes the internal rest URL, and in this case remove it from it. So that you enforce that the internal link is not absolute, what I propose is to not have this code and just directly test if includes or not $REST_URL inside your new function internal?, with no need for any external expectation of absolute or relative URL.

And also I think that this function does that already https://github.com/ontoportal-lirmm/bioportal_web_ui/blob/master/app/helpers/federation_helper.rb#L65, but to test if does work in this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not substruct the $REST_URL only to use it inside the other component here.
If the url is internal the best practice is to use the relative one instead of the absolute.
And inside the component I built my logic based on that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Discussed, ok

end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%span{'data-controller': 'federation-portals-colors',
'data-federation-portals-colors-color-value': color,
'data-federation-portals-colors-portal-name-value': name.downcase}
%a{ href: link, target: '_blank', 'data-controller' => 'tooltip', title: tooltip, class: 'federation-portal-button button icon-right', style: color ? "background-color: #{light_color} !important" : '' }
%a{ href: link, target: internal? ? '_top' : '_blank', 'data-controller' => 'tooltip', title: tooltip, class: 'federation-portal-button button icon-right', style: color ? "background-color: #{light_color} !important" : '' }
= inline_svg_tag('logos/ontoportal.svg', class: "federated-icon-#{name.downcase}")
%div{ class: 'text', style: color ? "color: #{color} !important" : '' }
= name.humanize.gsub("portal", "Portal")
4 changes: 4 additions & 0 deletions app/helpers/federation_helper.rb
Original file line number Diff line number Diff line change
@@ -53,6 +53,10 @@ def ontology_portal_color(id)
end

def ontoportal_ui_link(id)
if id.include?($REST_URL)
return id.gsub($REST_URL,'')
end

portal_key, config = ontology_portal_config(id)
return nil unless portal_key