Skip to content

Commit 8e7027e

Browse files
feature: external link on records (#3501)
* feature: external link on records * remove rails 8 gemfile github lock * wip * Revert "remove rails 8 gemfile github lock" and "wip" This reverts commit d12fb14 and 94ae45d. * fix new records * test * locales --------- Co-authored-by: Paul Bob <[email protected]> Co-authored-by: Paul Bob <[email protected]>
1 parent cbad870 commit 8e7027e

31 files changed

+89
-3
lines changed

app/components/avo/items/panel_component.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def args
3434
index: 0,
3535
data: {panel_id: "main"},
3636
cover_photo: @resource.cover_photo,
37-
profile_photo: @resource.profile_photo
37+
profile_photo: @resource.profile_photo,
38+
external_link: @resource.get_external_link
3839
}
3940
else
4041
{name: @item.name, description: @item.description, index: @index}

app/components/avo/panel_component.html.erb

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
name: @name,
55
description: @description,
66
display_breadcrumbs: @display_breadcrumbs,
7-
profile_photo: @profile_photo
7+
profile_photo: @profile_photo,
8+
external_link: @external_link
89
) do |header| %>
910
<% if name_slot.present? %>
1011
<% header.with_name_slot do %>

app/components/avo/panel_component.rb

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Avo::PanelComponent < Avo::BaseComponent
2828
def after_initialize
2929
@name = @args.dig(:name) || @args.dig(:title)
3030
end
31+
prop :external_link
3132

3233
def classes
3334
class_names(@classes, "has-cover-photo": @cover_photo.present?, "has-profile-photo": @profile_photo.present?)

app/components/avo/panel_header_component.html.erb

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
<% if name_slot? %>
1313
<%= name_slot %>
1414
<% else %>
15-
<%= render Avo::PanelNameComponent.new name: @name %>
15+
<%= render Avo::PanelNameComponent.new name: @name do |panel_name_component| %>
16+
<% panel_name_component.with_body do %>
17+
<% if @external_link.present? %>
18+
<%= link_to @external_link, class: "text-gray-600 hover:text-gray-900 mt-1", title: helpers.t("avo.visit_record_on_external_path"), data: {tippy: :tooltip}, target: :_blank do %>
19+
<%= svg "heroicons/outline/arrow-top-right-on-square", class: "ml-2 text-2xl h-4" %>
20+
<% end %>
21+
<% end %>
22+
<% end %>
23+
<% end %>
1624
<% end %>
1725
<% if @description.present? %>
1826
<div class="text-sm tracking-normal font-medium text-gray-600 text-center sm:text-left" data-target="description">

app/components/avo/panel_header_component.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Avo::PanelHeaderComponent < Avo::BaseComponent
77
renders_one :tools
88

99
prop :name
10+
prop :external_link
1011
prop :description
1112
prop :display_breadcrumbs, default: false
1213
prop :profile_photo

lib/avo/resources/base.rb

+7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def current_user
8080
class_attribute :default_sort_column, default: :created_at
8181
class_attribute :default_sort_direction, default: :desc
8282
class_attribute :controls_placement, default: nil
83+
class_attribute :external_link, default: nil
8384

8485
# EXTRACT:
8586
class_attribute :ordering
@@ -644,6 +645,12 @@ def resolve_component(original_component)
644645
custom_components.dig(original_component.to_s)&.to_s&.safe_constantize || original_component
645646
end
646647

648+
def get_external_link
649+
return unless record.persisted?
650+
651+
Avo::ExecutionContext.new(target: external_link, resource: self, record: record).handle
652+
end
653+
647654
private
648655

649656
def flatten_keys(array)

lib/generators/avo/templates/locales/avo.ar.yml

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ ar:
122122
undo: تراجع
123123
view: عرض
124124
view_item: عرض %{item}
125+
visit_record_on_external_path: زيارة السجل على الرابط الخارجي
125126
was_successfully_created: تم إنشاؤه بنجاح
126127
was_successfully_updated: تم تحديثه بنجاح
127128
x_items_more:

lib/generators/avo/templates/locales/avo.de.yml

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ de:
112112
undo: Rückgängig machen
113113
view: Anzeigen
114114
view_item: "%{item} anzeigen"
115+
visit_record_on_external_path: Datensatz über externen Link besuchen
115116
was_successfully_created: wurde erfolgreich erstellt
116117
was_successfully_updated: wurde erfolgreich aktualisiert
117118
x_items_more:

lib/generators/avo/templates/locales/avo.en.yml

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ en:
112112
undo: undo
113113
view: View
114114
view_item: view %{item}
115+
visit_record_on_external_path: Visit record on external path
115116
was_successfully_created: was successfully created
116117
was_successfully_updated: was successfully updated
117118
x_items_more:

lib/generators/avo/templates/locales/avo.es.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ es:
114114
undo: deshacer
115115
view: Vista
116116
view_item: ver %{item}
117+
visit_record_on_external_path: Visitar registro en enlace externo
117118
was_successfully_created: se ha creado con éxito
118119
was_successfully_updated: se ha actualizado con éxito
119120
x_items_more:

lib/generators/avo/templates/locales/avo.fr.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ fr:
114114
undo: annuler
115115
view: Vue
116116
view_item: voir %{item}
117+
visit_record_on_external_path: Consulter l'enregistrement via un lien externe
117118
was_successfully_created: a été créé avec succès
118119
was_successfully_updated: a été mis à jour avec succès
119120
x_items_more:

lib/generators/avo/templates/locales/avo.it.yml

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ it:
112112
undo: Annulla
113113
view: Visualizza
114114
view_item: Visualizza %{item}
115+
visit_record_on_external_path: Visita il record tramite link esterno
115116
was_successfully_created: è stato creato con successo
116117
was_successfully_updated: è stato aggiornato con successo
117118
x_items_more:

lib/generators/avo/templates/locales/avo.ja.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ ja:
114114
undo: 元に戻す
115115
view: ビュー
116116
view_item: "%{item}を表示"
117+
visit_record_on_external_path: 外部リンクで記録を確認する
117118
was_successfully_created: は正常に作成されました
118119
was_successfully_updated: は正常に更新されました
119120
x_items_more:

lib/generators/avo/templates/locales/avo.nb.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ nb:
114114
undo: angre
115115
view: Vis
116116
view_item: vis %{item}
117+
visit_record_on_external_path: Besøk posten via en ekstern lenke
117118
was_successfully_created: ble opprettet
118119
was_successfully_updated: ble oppdatert
119120
x_items_more:

lib/generators/avo/templates/locales/avo.nl.yml

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ nl:
112112
undo: Ongedaan maken
113113
view: Bekijken
114114
view_item: "%{item} bekijken"
115+
visit_record_on_external_path: Bezoek record via een externe link
115116
was_successfully_created: is succesvol aangemaakt
116117
was_successfully_updated: is succesvol bijgewerkt
117118
x_items_more:

lib/generators/avo/templates/locales/avo.nn.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ nn:
114114
undo: angre
115115
view: Vis
116116
view_item: vis %{item}
117+
visit_record_on_external_path: Besøk posten via ein ekstern lenke
117118
was_successfully_created: vart oppretta
118119
was_successfully_updated: vart oppdatert
119120
x_items_more:

lib/generators/avo/templates/locales/avo.pl.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pl:
114114
undo: Cofnij
115115
view: Widok
116116
view_item: Wyświetl %{item}
117+
visit_record_on_external_path: Odwiedź rekord za pomocą zewnętrznego linku
117118
was_successfully_created: został pomyślnie utworzony
118119
was_successfully_updated: został pomyślnie zaktualizowany
119120
x_items_more:

lib/generators/avo/templates/locales/avo.pt-BR.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pt-BR:
114114
undo: desfazer
115115
view: Visualizar
116116
view_item: visualizar %{item}
117+
visit_record_on_external_path: Visitar registro através de link externo
117118
was_successfully_created: foi criado com sucesso
118119
was_successfully_updated: foi atualizado com sucesso
119120
x_items_more:

lib/generators/avo/templates/locales/avo.pt.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pt:
114114
undo: desfazer
115115
view: Ver
116116
view_item: ver %{item}
117+
visit_record_on_external_path: Visitar registro através de link externo
117118
was_successfully_created: foi criado com sucesso
118119
was_successfully_updated: foi atualizado com sucesso
119120
x_items_more:

lib/generators/avo/templates/locales/avo.ro.yml

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ ro:
116116
undo: Anulează
117117
view: vezi
118118
view_item: vezi %{item}
119+
visit_record_on_external_path: Vizitați înregistrarea printr-un link extern
119120
was_successfully_created: a fost creat
120121
was_successfully_updated: a fost actualizat
121122
x_items_more:

lib/generators/avo/templates/locales/avo.ru.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ ru:
114114
undo: Отменить
115115
view: Просмотр
116116
view_item: Просмотр %{item}
117+
visit_record_on_external_path: Перейти к записи через внешнюю ссылку
117118
was_successfully_created: успешно создана
118119
was_successfully_updated: успешно обновлена
119120
x_items_more:

lib/generators/avo/templates/locales/avo.tr.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ tr:
114114
undo: geri al
115115
view: Görünüm
116116
view_item: "%{item} öğresini görüntüle"
117+
visit_record_on_external_path: Harici bağlantı yoluyla kaydı ziyaret et
117118
was_successfully_created: başarıyla oluşturuldu
118119
was_successfully_updated: başarıyla güncellendi
119120
x_items_more:

lib/generators/avo/templates/locales/avo.uk.yml

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ uk:
114114
undo: Скасувати
115115
view: Перегляд
116116
view_item: Перегляд %{item}
117+
visit_record_on_external_path: Перейти до запису через зовнішнє посилання
117118
was_successfully_created: успішно створено
118119
was_successfully_updated: успішно оновлено
119120
x_items_more:

lib/generators/avo/templates/locales/avo.zh.yml

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ zh:
112112
undo: 撤销
113113
view: 查看
114114
view_item: 查看 %{item}
115+
visit_record_on_external_path: 通过外部链接访问记录
115116
was_successfully_created: 创建成功
116117
was_successfully_updated: 更新成功
117118
x_items_more:

spec/dummy/app/avo/resources/post.rb

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class Avo::Resources::Post < Avo::BaseResource
2828
end
2929
}
3030
self.view_types = [:grid, :table]
31+
# Show a link to the post outside Avo
32+
self.external_link = -> {
33+
main_app.post_path(record)
34+
}
3135

3236
def fields
3337
field :id, as: :id
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class PostsController < ApplicationController
2+
def index
3+
@posts = Post.all
4+
end
5+
6+
def show
7+
@post = Post.find(params[:id])
8+
end
9+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h1>Posts#index</h1>
2+
<p>Find me in app/views/posts/index.html.erb</p>
3+
4+
<%= @posts.count %>
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h1>Posts#show</h1>
2+
<p>Find me in app/views/posts/show.html.erb</p>
3+
4+
<%= @post.inspect %>

spec/dummy/config/locales/avo.en.yml

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ en:
110110
undo: undo
111111
view: View
112112
view_item: view %{item}
113+
visit_record_on_external_path: Visit record on external path
113114
was_successfully_created: was successfully created
114115
was_successfully_updated: was successfully updated
115116
x_items_more:

spec/dummy/config/routes.rb

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
get "hey", to: "home#index"
77

8+
resources :posts
9+
810
authenticate :user, ->(user) { user.is_admin? } do
911
scope :admin do
1012
get "custom_tool", to: "avo/tools#custom_tool", as: :custom_tool
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require "rails_helper"
2+
3+
RSpec.feature "external_link", type: :feature do
4+
let!(:post) { create :post }
5+
6+
describe "external_link" do
7+
it "on show" do
8+
visit avo.resources_post_path(post)
9+
10+
find("[target='_blank'][href='/posts/#{post.to_param}']").click
11+
12+
expect(current_path).to eq "/posts/#{post.to_param}"
13+
expect(page).to have_text("Find me in app/views/posts/show.html.erb")
14+
end
15+
16+
it "on edit" do
17+
visit avo.edit_resources_post_path(post)
18+
19+
find("[target='_blank'][href='/posts/#{post.to_param}']").click
20+
21+
expect(current_path).to eq "/posts/#{post.to_param}"
22+
expect(page).to have_text("Find me in app/views/posts/show.html.erb")
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)