chore: Improve search in super admin panel (#7952)
Co-authored-by: Vishnu Narayanan <vishnu@chatwoot.com> Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -76,6 +76,7 @@ gem 'pundit'
|
|||||||
# super admin
|
# super admin
|
||||||
gem 'administrate', '>= 0.19.0'
|
gem 'administrate', '>= 0.19.0'
|
||||||
gem 'administrate-field-active_storage'
|
gem 'administrate-field-active_storage'
|
||||||
|
gem 'administrate-field-belongs_to_search'
|
||||||
|
|
||||||
##--- gems for pubsub service ---##
|
##--- gems for pubsub service ---##
|
||||||
# https://karolgalanciak.com/blog/2019/11/30/from-activerecord-callbacks-to-publish-slash-subscribe-pattern-and-event-driven-design/
|
# https://karolgalanciak.com/blog/2019/11/30/from-activerecord-callbacks-to-publish-slash-subscribe-pattern-and-event-driven-design/
|
||||||
|
|||||||
@@ -116,6 +116,11 @@ GEM
|
|||||||
administrate-field-active_storage (0.4.2)
|
administrate-field-active_storage (0.4.2)
|
||||||
administrate (>= 0.2.2)
|
administrate (>= 0.2.2)
|
||||||
rails (>= 7.0)
|
rails (>= 7.0)
|
||||||
|
administrate-field-belongs_to_search (0.8.0)
|
||||||
|
administrate (>= 0.3, < 1.0)
|
||||||
|
jbuilder (~> 2)
|
||||||
|
rails (>= 4.2, < 7.1)
|
||||||
|
selectize-rails (~> 0.6)
|
||||||
annotate (3.2.0)
|
annotate (3.2.0)
|
||||||
activerecord (>= 3.2, < 8.0)
|
activerecord (>= 3.2, < 8.0)
|
||||||
rake (>= 10.4, < 14.0)
|
rake (>= 10.4, < 14.0)
|
||||||
@@ -831,6 +836,7 @@ DEPENDENCIES
|
|||||||
acts-as-taggable-on
|
acts-as-taggable-on
|
||||||
administrate (>= 0.19.0)
|
administrate (>= 0.19.0)
|
||||||
administrate-field-active_storage
|
administrate-field-active_storage
|
||||||
|
administrate-field-belongs_to_search
|
||||||
annotate
|
annotate
|
||||||
attr_extras
|
attr_extras
|
||||||
audited (~> 5.3)
|
audited (~> 5.3)
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ class AccountDashboard < Administrate::BaseDashboard
|
|||||||
end
|
end
|
||||||
|
|
||||||
ATTRIBUTE_TYPES = {
|
ATTRIBUTE_TYPES = {
|
||||||
id: Field::Number,
|
id: Field::Number.with_options(searchable: true),
|
||||||
name: Field::String,
|
name: Field::String.with_options(searchable: true),
|
||||||
created_at: Field::DateTime,
|
created_at: Field::DateTime,
|
||||||
updated_at: Field::DateTime,
|
updated_at: Field::DateTime,
|
||||||
users: CountField,
|
users: CountField,
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ class AccountUserDashboard < Administrate::BaseDashboard
|
|||||||
# which determines how the attribute is displayed
|
# which determines how the attribute is displayed
|
||||||
# on pages throughout the dashboard.
|
# on pages throughout the dashboard.
|
||||||
ATTRIBUTE_TYPES = {
|
ATTRIBUTE_TYPES = {
|
||||||
account: Field::BelongsTo.with_options(searchable: true, searchable_field: 'name', order: 'id DESC'),
|
account: Field::BelongsToSearch.with_options(class_name: 'Account', searchable: true, searchable_field: [:name, :id], order: 'id DESC'),
|
||||||
user: Field::BelongsTo.with_options(searchable: true, searchable_field: 'name', order: 'id DESC'),
|
user: Field::BelongsToSearch.with_options(class_name: 'User', searchable: true, searchable_field: [:name, :email, :id], order: 'id DESC'),
|
||||||
inviter: Field::BelongsTo.with_options(class_name: 'User', searchable: true, searchable_field: 'name'),
|
inviter: Field::BelongsToSearch.with_options(class_name: 'User', searchable: true, searchable_field: [:name, :email, :id], order: 'id DESC'),
|
||||||
id: Field::Number,
|
id: Field::Number,
|
||||||
role: Field::Select.with_options(collection: AccountUser.roles.keys),
|
role: Field::Select.with_options(collection: AccountUser.roles.keys),
|
||||||
created_at: Field::DateTime,
|
created_at: Field::DateTime,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class UserDashboard < Administrate::BaseDashboard
|
|||||||
# on pages throughout the dashboard.
|
# on pages throughout the dashboard.
|
||||||
ATTRIBUTE_TYPES = {
|
ATTRIBUTE_TYPES = {
|
||||||
account_users: Field::HasMany,
|
account_users: Field::HasMany,
|
||||||
id: Field::Number,
|
id: Field::Number.with_options(searchable: true),
|
||||||
avatar_url: AvatarField,
|
avatar_url: AvatarField,
|
||||||
avatar: Field::ActiveStorage.with_options(
|
avatar: Field::ActiveStorage.with_options(
|
||||||
destroy_url: proc do |_namespace, _resource, attachment|
|
destroy_url: proc do |_namespace, _resource, attachment|
|
||||||
@@ -28,9 +28,9 @@ class UserDashboard < Administrate::BaseDashboard
|
|||||||
confirmed_at: Field::DateTime,
|
confirmed_at: Field::DateTime,
|
||||||
confirmation_sent_at: Field::DateTime,
|
confirmation_sent_at: Field::DateTime,
|
||||||
unconfirmed_email: Field::String,
|
unconfirmed_email: Field::String,
|
||||||
name: Field::String,
|
name: Field::String.with_options(searchable: true),
|
||||||
display_name: Field::String,
|
display_name: Field::String,
|
||||||
email: Field::String,
|
email: Field::String.with_options(searchable: true),
|
||||||
tokens: Field::String.with_options(searchable: false),
|
tokens: Field::String.with_options(searchable: false),
|
||||||
created_at: Field::DateTime,
|
created_at: Field::DateTime,
|
||||||
updated_at: Field::DateTime,
|
updated_at: Field::DateTime,
|
||||||
|
|||||||
28
app/views/fields/belongs_to_search/_index.html.erb
Normal file
28
app/views/fields/belongs_to_search/_index.html.erb
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<%#
|
||||||
|
# BelongsToSearch Index Partial
|
||||||
|
|
||||||
|
This partial renders a belongs_to relationship,
|
||||||
|
to be displayed on a resource's index page.
|
||||||
|
|
||||||
|
By default, the relationship is rendered as a link to the associated object.
|
||||||
|
|
||||||
|
## Local variables:
|
||||||
|
|
||||||
|
- `field`:
|
||||||
|
An instance of Administrate::Field::BelongsToSearch.
|
||||||
|
A wrapper around the belongs_to relationship pulled from the database.
|
||||||
|
%>
|
||||||
|
|
||||||
|
<% if field.data %>
|
||||||
|
<% if field.data.is_a? User %>
|
||||||
|
<%= link_to(
|
||||||
|
field.display_associated_resource,
|
||||||
|
super_admin_user_path(field.data),
|
||||||
|
) %>
|
||||||
|
<% elsif existing_action?(field.associated_class, :show) %>
|
||||||
|
<%= link_to(
|
||||||
|
field.display_associated_resource,
|
||||||
|
[namespace, field.data],
|
||||||
|
) %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
Reference in New Issue
Block a user