-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start migrating project bot accounts to use data table component * fix response for create bot * fix remaining logic after each action associated with bot table * some cleanup, fix some tests * update project bots PAT table and responses * update checkbox to use primary color * migrate groups bots to use data table * fix tests * cleanup, move pagy to table partial * fix translations * refactor PAT tables into component * refactor bot accounts table to use share component * refactor translations * finish refactoring translations * refactor PAT translations * fix translations in tests * cleanup, add rubocop disable * fix translations * run normalize * fix tests after translation change * move mb-4 from wrapper to turbo frame * remove whitespace for some classes
- Loading branch information
1 parent
2e16b32
commit 13ecb2f
Showing
52 changed files
with
534 additions
and
958 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<% if @bot_accounts.count.positive? %> | ||
<%= viral_data_table(@bot_accounts, id: "bots-table") do |table| %> | ||
<% table.with_column(t("bots.index.table.header.username")) do |row| %> | ||
<%= row.user.email %> | ||
<% end %> | ||
<% table.with_column(t("bots.index.table.header.active_tokens")) do |row| %> | ||
<% if row.user.personal_access_tokens.active.count.positive? %> | ||
<%= link_to row.user.personal_access_tokens.active.count, | ||
bot_tokens_path(row), | ||
data: { | ||
turbo_stream: true, | ||
}, | ||
class: "font-semibold text-slate-800 dark:text-slate-300 hover:underline" %> | ||
<% else %> | ||
0 | ||
<% end %> | ||
<% end %> | ||
<% table.with_column(t("bots.index.table.header.created")) do |row| %> | ||
<%= helpers.local_time_ago(row.user.created_at) %> | ||
<% end %> | ||
<% table.with_column(t("bots.index.table.header.access_level")) do |row| %> | ||
<% unless row.membership.nil? %> | ||
<%= t(:"bots.index.table.access_level.level_#{row.membership.access_level}") %> | ||
<% end %> | ||
<% end %> | ||
<% table.with_column(t("bots.index.table.header.expiration")) do |row| %> | ||
<% if !row.membership&.expires_at.nil? %> | ||
<%= helpers.local_time(row.membership.expires_at, :full_date) %> | ||
<% else %> | ||
<%= t("bots.index.table.never") %> | ||
<% end %> | ||
<% end %> | ||
<% table.with_column(t("bots.index.table.header.actions"), | ||
sticky_key: :right | ||
) do |row| %> | ||
<% if @abilities[:generate_token] %> | ||
<%= link_to( | ||
t("bots.index.table.actions.generate_new_token"), | ||
new_token_path(row), | ||
data: { | ||
turbo_stream: true, | ||
}, | ||
aria: { | ||
label: t("bots.index.table.actions.generate_new_token_aria_label"), | ||
}, | ||
class: | ||
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer", | ||
) %> | ||
<% end %> | ||
<% if @abilities[:destroy_bot] %> | ||
<%= link_to( | ||
t("bots.index.table.actions.destroy"), | ||
destroy_path(row), | ||
data: { | ||
turbo_method: :delete, | ||
turbo_confirm: t("bots.index.table.actions.destroy_confirmation"), | ||
turbo_frame: "_top", | ||
}, | ||
aria: { | ||
label: t("bots.index.table.actions.destroy_aria_label"), | ||
}, | ||
class: | ||
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer", | ||
) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<%= render Viral::Pagy::FullComponent.new(@pagy, item: t("bots.index.pagy_item")) %> | ||
<% else %> | ||
<div class="empty_state_message"> | ||
<%= viral_empty( | ||
title: t("bots.index.table.empty_state.title"), | ||
description: t("bots.index.table.empty_state.description"), | ||
icon_name: :bug_ant, | ||
) %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'ransack/helpers/form_helper' | ||
|
||
module Bots | ||
# Component for rendering the PersonalAccessTokens tables | ||
class TableComponent < Component | ||
include Ransack::Helpers::FormHelper | ||
|
||
# rubocop: disable Metrics/ParameterLists | ||
def initialize( | ||
bot_accounts, | ||
namespace, | ||
pagy, | ||
abilities: {}, | ||
empty: {}, | ||
**system_arguments | ||
) | ||
@bot_accounts = bot_accounts | ||
@namespace = namespace | ||
@pagy = pagy | ||
@abilities = abilities | ||
@empty = empty | ||
@system_arguments = system_arguments | ||
end | ||
# rubocop: enable Metrics/ParameterLists | ||
|
||
private | ||
|
||
def bot_tokens_path(bot) | ||
if @namespace.is_a?(Group) | ||
group_bot_personal_access_tokens_path(bot_id: bot.id) | ||
elsif @namespace.is_a?(Namespaces::ProjectNamespace) | ||
namespace_project_bot_personal_access_tokens_path(bot_id: bot.id) | ||
end | ||
end | ||
|
||
def new_token_path(bot) | ||
if @namespace.is_a?(Group) | ||
new_group_bot_personal_access_token_path(bot_id: bot.id) | ||
elsif @namespace.is_a?(Namespaces::ProjectNamespace) | ||
new_namespace_project_bot_personal_access_token_path(bot_id: bot.id) | ||
end | ||
end | ||
|
||
def destroy_path(bot) | ||
if @namespace.is_a?(Group) | ||
group_bot_path(id: bot.id) | ||
elsif @namespace.is_a?(Namespaces::ProjectNamespace) | ||
namespace_project_bot_path(id: bot.id) | ||
end | ||
end | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
app/components/personal_access_tokens/table_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<% if @personal_access_tokens.count.positive? %> | ||
<%= viral_data_table(@personal_access_tokens, id: "access-tokens-table") do |table| %> | ||
<% table.with_column(t("personal_access_tokens.table.header.name")) do |row| %> | ||
<%= row[:name] %> | ||
<% end %> | ||
<% table.with_column(t("personal_access_tokens.table.header.scopes")) do |row| %> | ||
<%= row[:scopes].join(", ") %> | ||
<% end %> | ||
<% table.with_column(t("personal_access_tokens.table.header.created_at")) do |row| %> | ||
<%= helpers.local_time(row[:created_at], :full_date) %> | ||
<% end %> | ||
<% table.with_column(t("personal_access_tokens.table.header.last_used_at")) do |row| %> | ||
<% if row[:last_used_at].present? %> | ||
<%= helpers.local_time(row[:last_used_at], :full_date) %> | ||
<% else %> | ||
<%= t("personal_access_tokens.table.never") %> | ||
<% end %> | ||
<% end %> | ||
<% table.with_column(t("personal_access_tokens.table.header.expires_at")) do |row| %> | ||
<% if row[:expires_at].present? %> | ||
<%= helpers.local_time(row[:expires_at], :full_date) %> | ||
<% else %> | ||
<%= t("personal_access_tokens.table.never") %> | ||
<% end %> | ||
<% end %> | ||
<% table.with_column(t("personal_access_tokens.table.header.action"), | ||
sticky_key: :right | ||
) do |row| %> | ||
<%= link_to( | ||
t("personal_access_tokens.table.revoke"), | ||
revoke_path(row), | ||
data: { | ||
turbo_method: :delete, | ||
turbo_confirm: t("personal_access_tokens.table.revoke_confirmation"), | ||
}, | ||
class: | ||
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer", | ||
) %> | ||
<% end %> | ||
<% end %> | ||
<% else %> | ||
<div class="empty_state_message"> | ||
<%= viral_empty( | ||
title: @empty[:title], | ||
description: @empty[:description], | ||
icon_name: :bug_ant, | ||
) %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'ransack/helpers/form_helper' | ||
|
||
module PersonalAccessTokens | ||
# Component for rendering the PersonalAccessTokens tables | ||
class TableComponent < Component | ||
include Ransack::Helpers::FormHelper | ||
|
||
def initialize( | ||
personal_access_tokens, | ||
namespace: nil, | ||
bot_account: nil, | ||
empty: {}, | ||
**system_arguments | ||
) | ||
@personal_access_tokens = personal_access_tokens | ||
@namespace = namespace | ||
@bot_account = bot_account | ||
@empty = empty | ||
@system_arguments = system_arguments | ||
end | ||
|
||
private | ||
|
||
def revoke_path(token) | ||
if @namespace.is_a?(Group) | ||
revoke_group_bot_personal_access_token_path( | ||
bot_id: @bot_account.id, | ||
id: token.id | ||
) | ||
elsif @namespace.is_a?(Namespaces::ProjectNamespace) | ||
revoke_namespace_project_bot_personal_access_token_path( | ||
bot_id: @bot_account.id, | ||
id: token.id | ||
) | ||
else | ||
revoke_profile_personal_access_token_path(id: token.id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.