feat(help-center): enable drag-and-drop category reordering (#13706)

This commit is contained in:
Sojan Jose
2026-03-04 23:23:38 -08:00
committed by GitHub
parent 3abe32a2c7
commit 42a244369d
33 changed files with 708 additions and 47 deletions

View File

@@ -132,11 +132,13 @@ class Article < ApplicationRecord
# rubocop:enable Rails/SkipsModelValidations
end
def self.update_positions(positions_hash)
positions_hash.each do |article_id, new_position|
# Find the article by its ID and update its position
article = Article.find(article_id)
article.update!(position: new_position)
def self.update_positions(portal:, positions_hash:)
return if positions_hash.blank?
transaction do
positions_hash.each do |article_id, new_position|
portal.articles.find(article_id).update!(position: new_position)
end
end
end

View File

@@ -73,6 +73,16 @@ class Category < ApplicationRecord
params[:page] || 1
end
def self.update_positions(portal:, positions_hash:)
return if positions_hash.blank?
transaction do
positions_hash.each do |category_id, new_position|
portal.categories.find(category_id).update!(position: new_position)
end
end
end
private
def ensure_account_id

View File

@@ -27,6 +27,8 @@
class Portal < ApplicationRecord
include Rails.application.routes.url_helpers
DEFAULT_COLOR = '#1f93ff'.freeze
belongs_to :account
has_many :categories, dependent: :destroy_async
has_many :folders, through: :categories
@@ -62,6 +64,10 @@ class Portal < ApplicationRecord
config['default_locale'] || 'en'
end
def color
self[:color].presence || DEFAULT_COLOR
end
private
def config_json_format