-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1657 from tactilenews/955_filter_contributors_by_tag
- Loading branch information
Showing
21 changed files
with
359 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.ContributorsIndex-filterSection { | ||
padding: 0; | ||
} | ||
|
||
.ContributorsIndex-filterSectionLabel { | ||
font-size: 1.25rem; | ||
line-height: 1.25; | ||
font-weight: 700; | ||
} | ||
|
||
.ContributorsIndex-filterSection .TagsInput { | ||
margin: var(--spacing-unit-s) 0; | ||
} | ||
|
||
.ContributorsIndex-filterSection .Button { | ||
margin-right: var(--spacing-unit-s); | ||
} |
86 changes: 86 additions & 0 deletions
86
app/components/contributors_index/contributors_index.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<%= c 'main', data: { controller: 'contributors-index' } do %> | ||
<%= c 'page_header', styles: [:lightGrayBackground, :spaceBetween, :largeMarginBottom] do |header| %> | ||
<div> | ||
<%= c 'heading' do %> | ||
<%= I18n.t 'contributor.contributor', count: :other %> | ||
<% end %> | ||
<p><%= t('contributor.subheading') %></p> | ||
</div> | ||
|
||
<%= c 'copy_button', | ||
label: I18n.t('contributor.actions.copy_invite'), | ||
styles: [:colorNavBar, :customIcon], | ||
url: invites_url, | ||
key: 'url', | ||
custom_icon: 'onboarding-ticket' | ||
%> | ||
|
||
<% header.tab_bar do %> | ||
<%= c('tab_bar', items: [ | ||
{ | ||
url: contributors_path(state: :active, tag_list: tag_list.present? ? @tag_list : nil), | ||
label: "Aktiv", | ||
active: state == :active, | ||
count: active_contributors_count, | ||
}, | ||
{ | ||
url: contributors_path(state: :inactive, tag_list: tag_list.present? ? @tag_list : nil), | ||
label: "Inaktiv", | ||
active: state == :inactive, | ||
count: inactive_contributors_count, | ||
}, | ||
{ | ||
label: I18n.t('contributor.filter_section.submit_button'), | ||
icon: "filter-tool", | ||
data: { action: 'contributors-index#toggleFilterSection' } | ||
} | ||
]) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= c('section', | ||
class: 'ContributorsIndex-filterSection', | ||
data: { contributors_index_target: 'filterSection' }, | ||
hidden: true | ||
) do %> | ||
<%= c('form', | ||
url: contributors_path, | ||
method: 'get', | ||
multiple: true | ||
) do %> | ||
<%= hidden_field_tag :state, state %> | ||
|
||
<label class="ContributorsIndex-filterSectionLabel"> | ||
<%= t('contributor.filter_section.heading') %> | ||
<%= c 'tags_input', | ||
id: 'ContributorsIndex-filterTagsInput', | ||
available_tags: available_tags, | ||
allow_new: false, name: 'tag_list[]', | ||
value: tag_list | ||
%> | ||
</label> | ||
<%= c 'submit_button', | ||
styles: [:secondary], | ||
label: t('contributor.filter_section.submit_button') | ||
%> | ||
<%= c 'button', | ||
styles: [:secondary, :warning], | ||
label: t('contributor.filter_section.clear_button'), | ||
data: { action: 'contributors-index#clearTags' } | ||
%> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= c 'section' do %> | ||
<% if contributors.present? && tag_list.present? %> | ||
<p><%= t('.filter_active_text', count: tag_list.size).html_safe %> | ||
<strong> | ||
<% tag_list.map do |tag| %> | ||
<%= " (#{tag})" %> | ||
<% end %> | ||
</strong> | ||
</p> | ||
<% end %> | ||
<%= c 'contributors_list', contributors: contributors, filter_active: tag_list.present? %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
|
||
export default class extends Controller { | ||
static targets = ['filterSection']; | ||
|
||
connect() { | ||
const searchParams = new URL(document.location).searchParams; | ||
const tagList = searchParams.get('tag_list[]'); | ||
const showFilter = !(tagList && tagList.length > 0); | ||
this.filterSectionTarget.hidden = showFilter; | ||
} | ||
|
||
toggleFilterSection() { | ||
this.filterSectionTarget.hidden = !this.filterSectionTarget.hidden; | ||
} | ||
|
||
clearTags() { | ||
this.dispatch('clearTags', { bubbles: true }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module ContributorsIndex | ||
class ContributorsIndex < ApplicationComponent | ||
def initialize(contributors:, state:, active_count:, inactive_count:, filter_count:, tag_list: nil) | ||
super | ||
|
||
@contributors = contributors | ||
@tag_list = tag_list | ||
@state = state | ||
@active_count = active_count | ||
@inactive_count = inactive_count | ||
@filter_count = filter_count | ||
end | ||
|
||
private | ||
|
||
attr_reader :contributors, :tag_list, :state, :active_count, :inactive_count, :filter_count | ||
|
||
def available_tags | ||
Contributor.all_tags_with_count.to_json | ||
end | ||
|
||
def active_contributors_count | ||
tag_list.present? && state == :active ? filter_count : active_count | ||
end | ||
|
||
def inactive_contributors_count | ||
tag_list.present? && state == :inactive ? filter_count : inactive_count | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
app/components/contributors_list/contributors_list.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<% if contributors.empty? %> | ||
<%= c 'empty_state', custom_icon: 'community' do %> | ||
<% if filter_active %> | ||
<p><%= t('.empty_state.filter_active') %></p> | ||
<% else %> | ||
<p><%= t('.empty_state.no_contributors') %></p> | ||
<% end %> | ||
<% end %> | ||
<% else %> | ||
<% contributors.each do |contributor| %> | ||
<%= c 'contributor_row', contributor: contributor %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module ContributorsList | ||
class ContributorsList < ApplicationComponent | ||
def initialize(contributors:, filter_active: false) | ||
super | ||
|
||
@contributors = contributors | ||
@filter_active = filter_active | ||
end | ||
|
||
private | ||
|
||
attr_reader :contributors, :filter_active | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
<nav class="TabBar"> | ||
<ul> | ||
<% items.each do |url, options| %> | ||
<nav class="TabBar" data-controller="tab-bar"> | ||
<ul class="TabBar-list"> | ||
<% items.each do |options| %> | ||
<li class="TabBar-item <%= 'TabBar-item--active' if options.dig(:active) %>"> | ||
<a href="<%= url %>"> | ||
<%= options.dig(:label) %> | ||
|
||
<%= c('button', | ||
link: options.dig(:url), | ||
styles: [:inline], | ||
data: options.dig(:data) | ||
) do %> | ||
<% if options.key?(:label) %> | ||
<%= options.dig(:label) %> | ||
<% end %> | ||
<% if options.key?(:count) %> | ||
<span class="TabBar-count"> | ||
<%= options[:count] %> | ||
<%= options.dig(:count) %> | ||
</span> | ||
<% end %> | ||
</a> | ||
<% if options.key?(:icon) %> | ||
<%= c 'icon', icon: options.dig(:icon), styles: [:inline] %> | ||
<% end %> | ||
<% end %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<%= content %> | ||
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.