mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-18 23:54:54 +08:00
This list is stored on publish and will also allow to revert to specific version as a draft that you can then publish. <img width="1087" height="496" alt="Screenshot 2026-06-17 at 13 39 41" src="https://github.com/user-attachments/assets/5266c07f-cb85-4e8b-9518-d852f77141d3" />
34 lines
1 KiB
Ruby
Vendored
34 lines
1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscourseWorkflows
|
|
module Pagination
|
|
DEFAULT_LIMIT = 25
|
|
MAX_LIMIT = 100
|
|
|
|
Page = Data.define(:records, :total_rows, :load_more_url)
|
|
|
|
def self.normalize_limit(limit)
|
|
(limit || DEFAULT_LIMIT).clamp(1, MAX_LIMIT)
|
|
end
|
|
|
|
def self.cursor_page(scope:, cursor:, limit:, path:, query: {}, column: :id)
|
|
paginated_scope = cursor ? scope.where("#{column} < ?", cursor) : scope
|
|
records = paginated_scope.limit(limit + 1).to_a
|
|
has_more = records.size > limit
|
|
records = records.first(limit) if has_more
|
|
|
|
Page.new(
|
|
records: records,
|
|
total_rows: scope.count,
|
|
load_more_url: build_load_more_url(path, records, limit, query, has_more, column),
|
|
)
|
|
end
|
|
|
|
def self.build_load_more_url(path, records, limit, query, has_more, column = :id)
|
|
return if !has_more || records.empty?
|
|
|
|
cursor = records.last.public_send(column)
|
|
"#{path}?#{query.merge(cursor: cursor, limit: limit).compact_blank.to_query}"
|
|
end
|
|
end
|
|
end
|