Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve transaction filters and transaction focus across page visits #1733

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lint fixes
  • Loading branch information
zachgoll committed Jan 29, 2025
commit 63e9161d85246b5ca9b7026bab509990b6d17950
4 changes: 2 additions & 2 deletions app/controllers/concerns/accountable_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def show
if params[:focused_entry_id].present?
@focused_entry = entries.find_by(id: params[:focused_entry_id])
position = entries.pluck(:id).index(params[:focused_entry_id])

if position.present?
focused_page = (position / (params[:per_page] || 10)) + 1
if params[:page]&.to_i != focused_page
return redirect_to account_path(@account, page: focused_page, focused_entry_id: params[:focused_entry_id])
return redirect_to account_path(@account, page: focused_page, focused_entry_id: params[:focused_entry_id])
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index
if params[:focused_entry_id].present?
@focused_entry = search_query.find_by(id: params[:focused_entry_id])
position = search_query.pluck(:id).index(params[:focused_entry_id])

if position.present?
focused_page = (position / (params[:per_page] || 10).to_i) + 1
if params[:page]&.to_i != focused_page
Expand Down Expand Up @@ -47,7 +47,7 @@ def clear_filter

param_key = params[:param_key]
param_value = params[:param_value]

if q_params[param_key].is_a?(Array)
q_params[param_key].delete(param_value)
q_params.delete(param_key) if q_params[param_key].empty?
Expand All @@ -71,7 +71,7 @@ def search_params
)
.to_h
.compact_blank

cleaned_params.delete(:amount_operator) unless cleaned_params[:amount].present?

cleaned_params
Expand All @@ -84,7 +84,7 @@ def store_params!
params_to_restore[:q] = stored_params["q"].presence || default_params[:q]
params_to_restore[:page] = stored_params["page"].presence || default_params[:page]
params_to_restore[:per_page] = stored_params["per_page"].presence || default_params[:per_page]

redirect_to transactions_path(params_to_restore)
else
Current.session.update!(
Expand All @@ -103,7 +103,7 @@ def should_restore_params?

def stored_params
Current.session.prev_transaction_page_params
end
end

def default_params
{
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/transactions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def get_transaction_search_filter_partial_path(filter)

def get_default_transaction_search_filter
transaction_search_filters[0]
end
end
end
4 changes: 2 additions & 2 deletions app/views/application/_pagination.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
</div>
</div>
<div class="flex items-center gap-4">
<%= select_tag :per_page,
options_for_select(["10", "20", "30", "50"], pagy.limit),
<%= select_tag :per_page,
options_for_select(["10", "20", "30", "50"], pagy.limit),
data: { controller: "selectable-link" },
class: "py-1.5 pr-8 text-sm text-gray-900 font-medium border border-gray-200 rounded-lg focus:border-gray-900 focus:ring-gray-900 focus-visible:ring-gray-900" %>
</div>
Expand Down
Loading