Skip to content

Commit

Permalink
get rid of cached unsaved filters when a query is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
as-op committed Nov 27, 2024
1 parent 2708e0f commit 7b7233f
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions modules/reporting/app/controllers/cost_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,20 @@ def index
def perform
respond_to do |format|
format.html do
session[report_engine.name.underscore.to_sym].try(:delete, :name)
session[session_name].try(:delete, :name)
# get rid of unsaved filters and grouping
store_query(@query) if @query&.id != session[session_name].try(:id)
render locals: { menu_name: project_or_global_menu }
end
format.xls { export(:xls) }
format.pdf { export(:pdf) }
end
end

Check notice on line 94 in modules/reporting/app/controllers/cost_reports_controller.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] modules/reporting/app/controllers/cost_reports_controller.rb#L83-L94 <Metrics/AbcSize>

Assignment Branch Condition size for perform is too high. [<1, 18, 3> 18.28/17]
Raw output
modules/reporting/app/controllers/cost_reports_controller.rb:83:3: C: Metrics/AbcSize: Assignment Branch Condition size for perform is too high. [<1, 18, 3> 18.28/17]

def session_name
report_engine.name.underscore.to_sym
end

def export(format)
job_id = ::CostQuery::ScheduleExportService
.new(user: current_user)
Expand Down Expand Up @@ -255,7 +261,7 @@ def default_filter_parameters
# Get the filter params with an optional project context
def filter_params
filters = http_filter_parameters if set_filter?
filters ||= session[report_engine.name.underscore.to_sym].try(:[], :filters)
filters ||= session[session_name].try(:[], :filters)
filters ||= default_filter_parameters

update_project_context!(filters)
Expand All @@ -267,7 +273,7 @@ def filter_params
# Return the active group bys
def group_params
groups = http_group_parameters if set_filter?
groups ||= session[report_engine.name.underscore.to_sym].try(:[], :groups)
groups ||= session[session_name].try(:[], :groups)
groups || default_group_parameters
end

Expand Down Expand Up @@ -495,8 +501,8 @@ def force_default?
# Prepare the query from the request
def prepare_query
determine_settings
@query = build_query(session[report_engine.name.underscore.to_sym][:filters],
session[report_engine.name.underscore.to_sym][:groups])
@query = build_query(session[session_name][:filters],
session[session_name][:groups])

set_cost_type if @unit_id.present?
end
Expand All @@ -507,14 +513,14 @@ def prepare_query
def determine_settings
if force_default?
filters = default_filter_parameters
groups = default_group_parameters
session[report_engine.name.underscore.to_sym].try :delete, :name
groups = default_group_parameters
session[session_name].try :delete, :name
else
filters = filter_params
groups = group_params
groups = group_params
end
cookie = session[report_engine.name.underscore.to_sym] || {}
session[report_engine.name.underscore.to_sym] = cookie.merge(filters:, groups:)
cookie = session[session_name] || {}
session[session_name] = cookie.merge(filters:, groups:)
end

Check notice on line 524 in modules/reporting/app/controllers/cost_reports_controller.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] modules/reporting/app/controllers/cost_reports_controller.rb#L513-L524 <Metrics/AbcSize>

Assignment Branch Condition size for determine_settings is too high. [<6, 16, 3> 17.35/17]
Raw output
modules/reporting/app/controllers/cost_reports_controller.rb:513:3: C: Metrics/AbcSize: Assignment Branch Condition size for determine_settings is too high. [<6, 16, 3> 17.35/17]

##
Expand Down Expand Up @@ -549,7 +555,8 @@ def store_query(_query)
h
end
cookie[:name] = @query.name if @query.name
session[report_engine.name.underscore.to_sym] = cookie
cookie[:id] = @query.id
session[session_name] = cookie
end

Check notice on line 560 in modules/reporting/app/controllers/cost_reports_controller.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] modules/reporting/app/controllers/cost_reports_controller.rb#L547-L560 <Metrics/AbcSize>

Assignment Branch Condition size for store_query is too high. [<13, 30, 5> 33.08/17]
Raw output
modules/reporting/app/controllers/cost_reports_controller.rb:547:3: C: Metrics/AbcSize: Assignment Branch Condition size for store_query is too high. [<13, 30, 5> 33.08/17]

##
Expand Down

0 comments on commit 7b7233f

Please sign in to comment.