-
-
Notifications
You must be signed in to change notification settings - Fork 201
feat: add chapter status admin page #2671
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
Merged
+227
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
app/components/admin/chapter_status/table_component.html.erb
This file contains hidden or 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,45 @@ | ||
| <% if rows.any? %> | ||
| <section class="mb-5"> | ||
| <h2 class="mb-1"><%= label %> (<%= rows.size %>)</h2> | ||
| <details class="mb-3"> | ||
| <summary class="small text-muted">What does this mean?</summary> | ||
| <div class="small text-muted"> | ||
| <% if label == 'Active' %> | ||
| Chapters with ≥1 workshop in this window. The <span class="badge bg-warning text-dark">At Risk</span> badge marks chapters with no workshops in the last <%= months - 1 %> months — they may be winding down. | ||
| <% elsif label == 'Dormant' %> | ||
| Chapters that are enabled but haven't run any workshops in this window. | ||
| <% else %> | ||
| Chapters that have been disabled. | ||
| <% end %> | ||
| </div> | ||
| </details> | ||
| <div class="table-responsive"> | ||
| <table class="table table-sm"> | ||
| <thead> | ||
| <tr> | ||
| <th>Chapter</th> | ||
| <th>Workshops</th> | ||
| <th>Eligible Students</th> | ||
| <th>Eligible Coaches</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <% rows.each do |row| %> | ||
| <% at_risk = at_risk_ids&.include?(row[:chapter].id) %> | ||
| <tr class="<%= 'table-warning' if at_risk %>"> | ||
| <td> | ||
| <%= link_to row[:chapter].name, [:admin, row[:chapter]] %> | ||
| <% if at_risk %> | ||
| <span class="badge bg-warning text-dark ms-2" title="No workshops in the last <%= months - 1 %> months">At Risk</span> | ||
| <% end %> | ||
| </td> | ||
| <td><%= row[:workshops] %></td> | ||
| <td><%= row[:eligible_students] %></td> | ||
| <td><%= row[:eligible_coaches] %></td> | ||
| </tr> | ||
| <% end %> | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| </section> | ||
| <% end %> |
This file contains hidden or 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,14 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Admin::ChapterStatus::TableComponent < ViewComponent::Base | ||
| def initialize(label:, rows:, months:, at_risk_ids: nil) # rubocop:disable Lint/MissingSuper | ||
| @label = label | ||
| @rows = rows | ||
| @months = months | ||
| @at_risk_ids = at_risk_ids | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :label, :rows, :months, :at_risk_ids | ||
| end |
This file contains hidden or 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 hidden or 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,21 @@ | ||
| <% content_for :title, "Chapter Status — last #{@months} months" %> | ||
|
|
||
| <div class="container py-4 py-lg-5"> | ||
| <h1>Chapter Status</h1> | ||
|
|
||
| <p class="lead">Chapter activity overview (including workshops scheduled up to 3 months ahead). "Eligible" means subscribed, not banned, and accepted terms.</p> | ||
|
|
||
| <%= form_tag status_admin_chapters_path, method: :get, class: 'd-inline-block mb-4' do %> | ||
| <div class="btn-group" role="group"> | ||
| <% active_class = ->(m) { @months == m ? ' active' : '' } %> | ||
| <%= button_tag '6 months', name: 'months', value: 6, class: "btn btn-outline-primary#{active_class.call(6)}", data: { disable_with: '6 months' } %> | ||
| <%= button_tag '12 months', name: 'months', value: 12, class: "btn btn-outline-primary#{active_class.call(12)}", data: { disable_with: '12 months' } %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <%= render Admin::ChapterStatus::TableComponent.new(label: 'Active', rows: @active, months: @months, at_risk_ids: @at_risk_ids) %> | ||
|
|
||
| <%= render Admin::ChapterStatus::TableComponent.new(label: 'Dormant', rows: @dormant, months: @months) %> | ||
|
|
||
| <%= render Admin::ChapterStatus::TableComponent.new(label: 'Inactive', rows: @inactive, months: @months) %> | ||
| </div> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,79 @@ | ||||||
| RSpec.describe Admin::ChaptersController, type: :controller do | ||||||
| let(:admin) { Fabricate(:member) } | ||||||
|
|
||||||
| before do | ||||||
| login_as_admin(admin) | ||||||
| end | ||||||
|
|
||||||
| describe '#status' do | ||||||
| it 'renders successfully with default 6 months' do | ||||||
| get :status | ||||||
| expect(response).to be_successful | ||||||
| expect(controller.view_assigns['months']).to eq(6) | ||||||
| end | ||||||
|
|
||||||
| it 'respects months param' do | ||||||
| get :status, params: { months: '12' } | ||||||
| expect(controller.view_assigns['months']).to eq(12) | ||||||
| end | ||||||
|
|
||||||
| it 'falls back to 6 for invalid months' do | ||||||
| get :status, params: { months: '3' } | ||||||
| expect(controller.view_assigns['months']).to eq(6) | ||||||
| end | ||||||
|
|
||||||
| it 'classifies chapters correctly' do | ||||||
| get :status | ||||||
| expect(controller.view_assigns['active']).to be_a(Array) | ||||||
| expect(controller.view_assigns['dormant']).to be_a(Array) | ||||||
| expect(controller.view_assigns['inactive']).to be_a(Array) | ||||||
| end | ||||||
|
|
||||||
| it 'marks a chapter with a past workshop as active' do | ||||||
| chapter = Fabricate(:chapter_with_groups) | ||||||
| Fabricate(:workshop, chapter: chapter, date_and_time: 2.months.ago) | ||||||
|
|
||||||
| get :status | ||||||
|
|
||||||
| active_names = controller.view_assigns['active'].map { |r| r[:chapter].name } | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very minor: can always use an
Suggested change
|
||||||
| expect(active_names).to include(chapter.name) | ||||||
| end | ||||||
|
|
||||||
| it 'marks a chapter with only a future workshop as active' do | ||||||
| chapter = Fabricate(:chapter_with_groups) | ||||||
| Fabricate(:workshop, chapter: chapter, date_and_time: 2.months.from_now) | ||||||
|
|
||||||
| get :status | ||||||
|
|
||||||
| active_names = controller.view_assigns['active'].map { |r| r[:chapter].name } | ||||||
| expect(active_names).to include(chapter.name) | ||||||
| end | ||||||
|
|
||||||
| it 'marks an active:false chapter as inactive' do | ||||||
| chapter = Fabricate(:chapter_with_groups, active: false) | ||||||
|
|
||||||
| get :status | ||||||
|
|
||||||
| inactive_names = controller.view_assigns['inactive'].map { |r| r[:chapter].name } | ||||||
| expect(inactive_names).to include(chapter.name) | ||||||
| end | ||||||
|
|
||||||
| it 'flags at-risk chapters with no recent workshops' do | ||||||
| chapter = Fabricate(:chapter_with_groups) | ||||||
| Fabricate(:workshop, chapter: chapter, date_and_time: 6.months.ago + 1.week) | ||||||
|
|
||||||
| get :status, params: { months: '6' } | ||||||
|
|
||||||
| expect(controller.view_assigns['at_risk_ids']).to include(chapter.id) | ||||||
| end | ||||||
|
|
||||||
| it 'does not flag active chapters with recent workshops as at-risk' do | ||||||
| chapter = Fabricate(:chapter_with_groups) | ||||||
| Fabricate(:workshop, chapter: chapter, date_and_time: 1.month.ago) | ||||||
|
|
||||||
| get :status, params: { months: '6' } | ||||||
|
|
||||||
| expect(controller.view_assigns['at_risk_ids']).not_to include(chapter.id) | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good context in comment!