Skip to content

Commit 0182c8b

Browse files
committed
Add admin page to show current test track assignments
For longer running experiments with a specific audience in my mind (like preferred beta testers) it's useful to use the bulk assignments capability to enable those features. However if there are mulitple instances of "adding users to the beta", one doesn't have visibility into what assignments may already be present. This view is intended to give admins more confidence that the intended assignments are in place.
1 parent 4395a7b commit 0182c8b

File tree

8 files changed

+96
-2
lines changed

8 files changed

+96
-2
lines changed

app/assets/stylesheets/components/_tables.scss

+10
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ mixin for generating a standard table
129129
@include standard-table(100%, 15%, 45%);
130130
}
131131

132+
.FormulaTable {
133+
@include standard-table(100%, 15%, 45%);
134+
thead tr:first-child:not(tr:last-child) th {
135+
border-bottom: none
136+
}
137+
tr td:last-child, th:last-child {
138+
border-left: 4px double var(--color-border-default);
139+
}
140+
}
141+
132142
.EmptyTable {
133143
&--centered {
134144
text-align: center;

app/components/flash_component.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def banner_args(type)
2323
end
2424

2525
def flash_types
26-
%i(error success)
26+
%i(error success warning)
2727
end
2828

2929
def scheme_types
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Admin::SplitAssignmentsController < AuthenticatedAdminController
2+
VIEW_LIMIT = 1000
3+
4+
def index
5+
split = Split.find(params.require(:split_id))
6+
@split_name = split.name
7+
@assignments = split.assignments.includes(visitor: { identifiers: :identifier_type }).order(updated_at: :desc).limit(VIEW_LIMIT)
8+
flash.now[:warning] = "Only showing #{VIEW_LIMIT} of #{split.assignments.count} assignments" if split.assignments.count > VIEW_LIMIT
9+
end
10+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<article class="InfoCard py-5">
2+
<div class="InfoCard-titleContainer">
3+
<h1> <%= @split_name %> Assignments</h1>
4+
</div>
5+
<hr class="InfoCard-divider">
6+
<div class="InfoCard-description">
7+
<table class="FormulaTable">
8+
<thead>
9+
<tr><th colspan=2>Match visitor by</th><th>Set split to</th></tr>
10+
<tr><th>attribute</th><th>value</th><th>variant</th></tr>
11+
</thead>
12+
<tbody>
13+
<% @assignments.group_by(&:variant).each do |variant, assignments| %>
14+
<% assignments.map(&:visitor).flat_map(&:identifiers).group_by { |identifier| identifier.identifier_type }.each do |type, identifiers| %>
15+
<% identifiers.each do |identifier| %>
16+
<tr>
17+
<td ><%= type.name%></td>
18+
<td ><%= identifier.value%></td>
19+
<td><%= variant %></td>
20+
</tr>
21+
<%end %>
22+
<% end %>
23+
<% end %>
24+
</tbody>
25+
</table>
26+
</div>
27+
</article>

app/views/admin/splits/_details.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<td>Population Size</td>
1111
<td>
1212
<span class='population'>
13-
<%= @split.assignments.count %><% if @split.feature_gate? %>* [<a href="#gate_population">feature gate</a>]<% end %>
13+
<%= link_to @split.assignments.count, admin_split_assignments_path(split) %><% if @split.feature_gate? %>* [<a href="#gate_population">feature gate</a>]<% end %>
1414
</span>
1515
</td>
1616
<td>

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
resources :splits, only: [:show] do
112112
resource :details, only: [:edit, :update], controller: 'split_details'
113113
resource :split_config, only: [:new, :create]
114+
resources :assignments, only: [:index], controller: 'split_assignments'
114115
resources :bulk_assignments, only: [:new, :create]
115116
resources :decisions, only: [:new, :create]
116117
resources :variants, only: [] do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AdminSplitAssignmentsPage < SitePrism::Page
2+
set_url "/admin/splits/{split_id}/assignments"
3+
4+
elements :assignments, ".AdminSplitAssignments--index table tbody tr"
5+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe 'bulk assign flow' do
4+
let(:split_page) { app.admin_split_show_page }
5+
let(:assignments_page) { app.admin_split_assignments_page }
6+
7+
let(:split) { FactoryBot.create(:split) }
8+
let(:assignment_count) { 3 }
9+
let!(:assignments) do
10+
Assignment.transaction do
11+
identifiers = FactoryBot.create_list(:identifier, assignment_count)
12+
identifiers.map(&:visitor).map { |visitor| FactoryBot.create(:assignment, split:, visitor:) }
13+
end
14+
end
15+
16+
before do
17+
login
18+
end
19+
20+
it 'allows admins to view assignments' do
21+
split_page.load split_id: split.id
22+
23+
expect(split_page.population_count).to have_content "3"
24+
split_page.population_count.click
25+
26+
expect(assignments_page.assignments.length).to eq 3
27+
end
28+
29+
context 'with too many assignments' do
30+
let(:assignment_count) { 1005 }
31+
32+
it 'shows a limited number of assignments' do
33+
split_page.load split_id: split.id
34+
35+
expect(split_page.population_count).to have_content "1005"
36+
split_page.population_count.click
37+
38+
expect(assignments_page.assignments.length).to eq 1000
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)