mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Extract filter_keywords
helper method for listing filter keyword groups
This commit is contained in:
parent
4180f754d0
commit
3b9befc955
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module FiltersHelper
|
module FiltersHelper
|
||||||
|
KEYWORDS_LIMIT = 5
|
||||||
|
|
||||||
def filter_action_label(action)
|
def filter_action_label(action)
|
||||||
safe_join(
|
safe_join(
|
||||||
[
|
[
|
||||||
|
@ -9,4 +11,10 @@ module FiltersHelper
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filter_keywords(filter)
|
||||||
|
filter.keywords.map(&:keyword).take(KEYWORDS_LIMIT).tap do |list|
|
||||||
|
list << '…' if filter.keywords.size > KEYWORDS_LIMIT
|
||||||
|
end.join(', ')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,9 +19,7 @@
|
||||||
.permissions-list__item__text__title
|
.permissions-list__item__text__title
|
||||||
= t('filters.index.keywords', count: filter.keywords.size)
|
= t('filters.index.keywords', count: filter.keywords.size)
|
||||||
.permissions-list__item__text__type
|
.permissions-list__item__text__type
|
||||||
- keywords = filter.keywords.map(&:keyword)
|
= filter_keywords(filter)
|
||||||
- keywords = keywords.take(5) + ['…'] if keywords.size > 5 # TODO
|
|
||||||
= keywords.join(', ')
|
|
||||||
- unless filter.statuses.empty?
|
- unless filter.statuses.empty?
|
||||||
%li.permissions-list__item
|
%li.permissions-list__item
|
||||||
.permissions-list__item__icon
|
.permissions-list__item__icon
|
||||||
|
|
24
spec/helpers/filters_helper_spec.rb
Normal file
24
spec/helpers/filters_helper_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe FiltersHelper do
|
||||||
|
describe '#filter_keywords' do
|
||||||
|
subject { helper.filter_keywords(filter) }
|
||||||
|
|
||||||
|
let(:filter) { Fabricate.build :custom_filter, keywords: }
|
||||||
|
let(:keywords) { words.map { |keyword| Fabricate.build(:custom_filter_keyword, keyword:) } }
|
||||||
|
|
||||||
|
context 'with few keywords' do
|
||||||
|
let(:words) { %w(One) }
|
||||||
|
|
||||||
|
it { is_expected.to eq('One') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with many keywords' do
|
||||||
|
let(:words) { %w(One Two Three Four Five Six Seven Eight Nine Ten) }
|
||||||
|
|
||||||
|
it { is_expected.to eq('One, Two, Three, Four, Five, …') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user