diff --git a/app/components/my/access_token/access_token_created_dialog_component.html.erb b/app/components/my/access_token/access_token_created_dialog_component.html.erb index 89ea8ac967d..6b78f49d4fb 100644 --- a/app/components/my/access_token/access_token_created_dialog_component.html.erb +++ b/app/components/my/access_token/access_token_created_dialog_component.html.erb @@ -67,7 +67,7 @@ See COPYRIGHT and LICENSE files for more details. end flex.with_row do render(Primer::Alpha::Banner.new(scheme: :warning, icon: :alert)) do - I18n.t(:warning, scope: i18n_scope) + I18n.t("my.access_token.created_dialog.one_time_warning") end end end diff --git a/app/components/my/access_token/api/row_component.rb b/app/components/my/access_token/api/row_component.rb index ab642047b93..8b40cf1403d 100644 --- a/app/components/my/access_token/api/row_component.rb +++ b/app/components/my/access_token/api/row_component.rb @@ -23,7 +23,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # See COPYRIGHT and LICENSE files for more details. #++ @@ -31,14 +31,14 @@ module My module AccessToken module API - class RowComponent < ::RowComponent + class RowComponent < OpPrimer::BorderBoxRowComponent def api_token model end def token_name - if api_token.token_name.nil? - t("my_account.access_tokens.api.static_token_name") + if !api_token.respond_to?(:token_name) || api_token.token_name.nil? + t(:static_token_name, scope: i18n_token_scope) else api_token.token_name end @@ -57,27 +57,33 @@ module My end def delete_link - link_to "", - { - action: delete_action, - access_token_id: api_token.id - }, - data: { - turbo_method: :delete, - turbo_confirm: t("my_account.access_tokens.simple_revoke_confirmation"), - test_selector: "api-token-revoke" - }, - class: "icon icon-delete" + render(Primer::Beta::IconButton.new( + icon: :trash, + scheme: :danger, + tag: :a, + href: delete_path, + "aria-label": t(:button_delete), + test_selector: "api-token-revoke", + data: { + turbo_method: :delete, + turbo_confirm: t("my_account.access_tokens.simple_revoke_confirmation") + } + )) end private - def delete_action + def delete_path case model - when Token::API then :revoke_api_key - when Token::ICalMeeting then :revoke_ical_meeting_token + when Token::API then my_access_token_revoke_api_key_path(api_token.id) + when Token::ICalMeeting then my_access_token_revoke_ical_meeting_token_path(api_token.id) + when Token::RSS then revoke_rss_key_my_access_tokens_path(api_token.id) end end + + def i18n_token_scope + [:my_account, :access_tokens, api_token.class.model_name.i18n_key] + end end end end diff --git a/app/components/my/access_token/api/table_component.rb b/app/components/my/access_token/api/table_component.rb index dc0cd690e53..8be1c034073 100644 --- a/app/components/my/access_token/api/table_component.rb +++ b/app/components/my/access_token/api/table_component.rb @@ -31,25 +31,54 @@ module My module AccessToken module API - class TableComponent < ::TableComponent - def initial_sort - %i[id asc] - end + class TableComponent < OpPrimer::BorderBoxTableComponent + columns :token_name, :created_at, :expires_on + main_column :token_name + mobile_labels :created_at, :expires_on - def sortable? - false + def initialize(title:, token_type:, **) + super(**) + + @title = title + @token_type = token_type end def headers [ - ["token_name", { caption: I18n.t("attributes.name") }], - ["created_at", { caption: User.human_attribute_name(:created_at) }], - ["expires_on", { caption: I18n.t("my_account.access_tokens.headers.expiration") }] + [:token_name, { caption: I18n.t("attributes.name") }], + [:created_at, { caption: User.human_attribute_name(:created_at) }], + [:expires_on, { caption: I18n.t("my_account.access_tokens.headers.expiration") }] ] end - def columns - headers.map(&:first) + def mobile_title + @title + end + + def row_class + RowComponent + end + + def has_actions? + true + end + + def blank_title + I18n.t(:blank_title, scope: i18n_token_scope) + end + + def blank_description + I18n.t(:blank_description, scope: i18n_token_scope) + end + + def blank_icon + nil + end + + private + + def i18n_token_scope + [:my_account, :access_tokens, @token_type.model_name.i18n_key] end end end diff --git a/app/components/my/access_token/api_tokens_section_component.html.erb b/app/components/my/access_token/api_tokens_section_component.html.erb index dd69977ae57..d41c3d518bb 100644 --- a/app/components/my/access_token/api_tokens_section_component.html.erb +++ b/app/components/my/access_token/api_tokens_section_component.html.erb @@ -38,25 +38,25 @@ See COPYRIGHT and LICENSE files for more details. end %> <% if token_available? %> - <% if @tokens.any? %> - <%= render My::AccessToken::API::TableComponent.new(rows: @tokens) %> + <%= render My::AccessToken::API::TableComponent.new(rows: @tokens, title: t(:table_title, scope: i18n_scope), token_type:) %> + <% if show_add_button? %> + <%= render( + Primer::Beta::Button.new( + tag: :a, + mt: 3, + scheme: :secondary, + test_selector: "#{token_type.model_name.element}-token-add", + href: add_button_path, + data: { turbo_stream: true, turbo_method: add_button_method }, + aria: { label: t(:add_button, scope: i18n_scope) }, + role: "button", + title: t(:add_button, scope: i18n_scope) + ) + ) do |button| + button.with_leading_visual_icon(icon: add_button_icon) + t(:add_button, scope: i18n_scope) + end %> <% end %> - <%= render( - Primer::Beta::Button.new( - tag: :a, - mt: 3, - scheme: :secondary, - test_selector: "#{token_type.model_name.element}-token-add", - href: dialog_my_access_tokens_path(token_type: token_type.model_name.element), - data: { turbo_stream: true }, - aria: { label: t(:add_button, scope: i18n_scope) }, - role: "button", - title: t(:add_button, scope: i18n_scope) - ) - ) do |button| - button.with_leading_visual_icon(icon: add_button_icon) - t(:add_button, scope: i18n_scope) - end %> <% else %>