Skip to content

Commit

Permalink
Add check for currenltly active type filter
Browse files Browse the repository at this point in the history
  • Loading branch information
HDinger committed Nov 9, 2023
1 parent 7f58d29 commit 8a1b4af
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions app/components/work_packages/share/modal_body_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,25 @@ def type_filter_options
end

def type_filter_option_active?(_option)
# Todo
false
principal_type_filter_value = current_filter_value(params[:filters], 'principal_type')
project_member_filter_value = current_filter_value(params[:filters], 'also_project_member')

return false if principal_type_filter_value.nil? || project_member_filter_value.nil?

principal_type_checked =
_option[:value][:principal_type] == principal_type_filter_value
membership_selected =
_option[:value][:project_member] == ActiveRecord::Type::Boolean.new.cast(project_member_filter_value)

principal_type_checked && membership_selected
end

def role_filter_option_active?(option)
return false if params[:filters].nil?
def role_filter_option_active?(_option)
role_filter_value = current_filter_value(params[:filters], 'principal_type')

given_role_filters = JSON.parse(params[:filters]).find { |filter| filter.key?('role_id') }
given_role_filter_value = given_role_filters ? given_role_filters['role_id']['values'].first.to_i : nil
return false if role_filter_value.nil?

find_role_ids(option[:value]).first == given_role_filter_value unless given_role_filter_value.nil?
find_role_ids(_option[:value]).first == role_filter_value.to_i
end

def filter_url(type_option: nil, role_option: nil)
Expand All @@ -119,9 +127,6 @@ def filter_url(type_option: nil, role_option: nil)

unless role_option.nil? || role_filter_option_active?(role_option)
filter.push({ role_id: { operator: "=", values: find_role_ids(role_option[:value]) } })

filter.push({ entity_type: { operator: "=", values: [WorkPackage.name] } })
filter.push({ entity_id: { operator: "=", values: [params[:work_package_id]] } })
end

# Todo: Keep options of the other filter defined in params
Expand All @@ -130,6 +135,13 @@ def filter_url(type_option: nil, role_option: nil)

work_package_shares_path(args)
end

def current_filter_value(filters, filter_key)
return nil if filters.nil?

given_filters = JSON.parse(filters).find { |key| key.key?(filter_key) }
given_filters ? given_filters[filter_key]['values'].first : nil
end
end
end
end

0 comments on commit 8a1b4af

Please sign in to comment.