diff --git a/app/components/viral/data_table/column_component.rb b/app/components/viral/data_table/column_component.rb index 78a55d9318..f75c5c0487 100644 --- a/app/components/viral/data_table/column_component.rb +++ b/app/components/viral/data_table/column_component.rb @@ -2,7 +2,7 @@ module Viral module DataTable - # Component responsible for specific column attributes of DataTableComponent + # Component responsible for specific column data of DataTableComponent class ColumnComponent < Viral::Component attr_reader :title diff --git a/app/components/viral/data_table_component.rb b/app/components/viral/data_table_component.rb index 073f6a193b..b986699b74 100644 --- a/app/components/viral/data_table_component.rb +++ b/app/components/viral/data_table_component.rb @@ -9,19 +9,19 @@ class DataTableComponent < Viral::Component } def initialize( data, - row_actions: {}, + id: '', **system_arguments ) @data = data - @row_actions = row_actions - @render_row_actions = @row_actions.select { |_key, value| value }.count.positive? + @id = id @system_arguments = system_arguments end def system_arguments { tag: 'div' }.deep_merge(@system_arguments).tap do |args| - args[:id] = "#{@type}_table" + args[:id] = @id args[:classes] = class_names(args[:classes], 'overflow-auto scrollbar') + # possibly to be used once implemented into tables with selection # if @abilities[:select] # args[:data] ||= {} # args[:data][:controller] = 'selection' diff --git a/app/views/profiles/personal_access_tokens/_table.html.erb b/app/views/profiles/personal_access_tokens/_table.html.erb index 65197d2cd3..818aa2afa1 100644 --- a/app/views/profiles/personal_access_tokens/_table.html.erb +++ b/app/views/profiles/personal_access_tokens/_table.html.erb @@ -1,52 +1,50 @@ <%= turbo_frame_tag "personal_access_tokens" do %> -<% if @active_access_tokens.count.positive? %> -<%= viral_data_table(@active_access_tokens) do |table| %> - <% table.with_column(t("activerecord.attributes.personal_access_token.name")) do |row| %> - <%= row[:name] %> - <% end %> - <% table.with_column(t("activerecord.attributes.personal_access_token.scopes")) do |row| %> - <%= row[:scopes].join(", ") %> - <% end %> - <% table.with_column(t("activerecord.attributes.personal_access_token.created_at")) do |row| %> - <%= local_time(row[:created_at], :full_date) %> - <% end %> - <% table.with_column(t("activerecord.attributes.personal_access_token.last_used_at")) do |row| %> - <% if row[:last_used_at].present? %> - <%= local_time(row[:last_used_at], :full_date) %> - <% else %> - <%= t(".never") %> - <% end %> - <% end %> - <% table.with_column(t(".expires_at")) do |row| %> - <% if row[:expires_at].present? %> - <%= local_time(row[:expires_at], :full_date) %> - <% else %> - <%= t(".never") %> + <% if @active_access_tokens.count.positive? %> + <%= viral_data_table(@active_access_tokens, id: "personal-access-tokens-table") do |table| %> + <% table.with_column(t("activerecord.attributes.personal_access_token.name")) do |row| %> + <%= row[:name] %> + <% end %> + <% table.with_column(t("activerecord.attributes.personal_access_token.scopes")) do |row| %> + <%= row[:scopes].join(", ") %> + <% end %> + <% table.with_column(t("activerecord.attributes.personal_access_token.created_at")) do |row| %> + <%= local_time(row[:created_at], :full_date) %> + <% end %> + <% table.with_column(t("activerecord.attributes.personal_access_token.last_used_at")) do |row| %> + <% if row[:last_used_at].present? %> + <%= local_time(row[:last_used_at], :full_date) %> + <% else %> + <%= t(".never") %> + <% end %> + <% end %> + <% table.with_column(t(".expires_at")) do |row| %> + <% if row[:expires_at].present? %> + <%= local_time(row[:expires_at], :full_date) %> + <% else %> + <%= t(".never") %> + <% end %> + <% end %> + <% table.with_column(t(".action")) do |row| %> + <%= link_to( + t(".revoke_button"), + revoke_profile_personal_access_token_path(id: row.id), + data: { + turbo_frame: "personal-access-tokens", + turbo_method: :delete, + turbo_confirm: t(".revoke_confirm") + }, + class: + "font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer" + ) %> + <% end %> <% end %> + <% else %> +
<% end %> - <% table.with_column(t(".action")) do |row| %> - <%= link_to( - t(".revoke_button"), - revoke_profile_personal_access_token_path(id: row.id), - data: { - turbo_frame: "personal-access-tokens", - turbo_method: :delete, - turbo_confirm: t(".revoke_confirm") - }, - class: - "font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer" - ) %> - <% end %> - -<% end %> - -<% else %> - -<% end %> <% end %> diff --git a/test/system/profile_test.rb b/test/system/profile_test.rb index a5bf5059ac..f53eccbf10 100644 --- a/test/system/profile_test.rb +++ b/test/system/profile_test.rb @@ -104,21 +104,36 @@ def setup assert_text I18n.t(:'profiles.personal_access_tokens.index.active_personal_access_tokens', count: @active_token_count) - assert_text token_to_revoke.name - + within('#personal-access-tokens-table') do + assert_text token_to_revoke.name + end within %(tr[id=#{token_to_revoke.id}]) do - click_link I18n.t(:'profiles.personal_access_tokens.personal_access_token.revoke_button') + click_link I18n.t(:'profiles.personal_access_tokens.table.revoke_button') end within('#turbo-confirm[open]') do click_button I18n.t(:'components.confirmation.confirm') end - - assert_no_text token_to_revoke.name + within('#personal-access-tokens-table') do + assert_no_text token_to_revoke.name + end assert_text I18n.t(:'profiles.personal_access_tokens.index.active_personal_access_tokens', count: @active_token_count - 1) end + test 'empty personal access tokens state' do + login_as users(:empty_doe) + visit profile_path + click_link I18n.t(:'profiles.sidebar.access_tokens') + + assert_text I18n.t(:'profiles.personal_access_tokens.index.active_personal_access_tokens', + count: 0) + assert_no_selector 'table#personal-access-tokens-table' + + assert_text I18n.t('profiles.personal_access_tokens.table.empty_state.title') + assert_text I18n.t('profiles.personal_access_tokens.table.empty_state.description') + end + test 'can view language selection' do visit profile_preferences_path