Skip to content

Commit

Permalink
Add buttons into each variant at final step
Browse files Browse the repository at this point in the history
  • Loading branch information
kaedroho committed Dec 16, 2020
1 parent 2132aed commit c61fcd4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
4 changes: 4 additions & 0 deletions wagtail_ab_testing/static_src/style/progress.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ $charcoal-grey: #333;
font-weight: bold;
font-size: 20px;
}

.button span {
font-weight: bold;
}
}

&__variant-stats {
Expand Down
14 changes: 14 additions & 0 deletions wagtail_ab_testing/templates/wagtail_ab_testing/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ <h3>{% trans "Control" %} <a href="{% pageurl page %}" target="_blank">{% icon n
</div>
</li>
</ul>

{% if ab_test.status == 'finished' %}
<form method="post">
{% csrf_token %}
<button type="submit" name="action-select-control" value="{% trans 'Keep and end test' %}" class="button">{% trans "<span>Keep</span> and end test" %}</button>
</form>
{% endif %}
</div>
</div>
<div class="abtest-results__variant abtest-results__variant--treatment">
Expand Down Expand Up @@ -96,6 +103,13 @@ <h3>{% trans "Treatment" %} <a href="{% url 'wagtailadmin_pages:view_draft' page
</div>
</li>
</ul>

{% if ab_test.status == 'finished' %}
<form method="post">
{% csrf_token %}
<button type="submit" name="action-select-treatment" value="{% trans 'Publish and end test' %}" class="button">{% trans "<span>Publish</span> and end test" %}</button>
</form>
{% endif %}
</div>
</div>
</div>
Expand Down
24 changes: 5 additions & 19 deletions wagtail_ab_testing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def is_shown(self, request, context):
if not context['user_page_permissions'].for_page(context['ab_test'].page).can_publish():
return False

return context['ab_test'].status in [AbTest.Status.DRAFT, AbTest.Status.RUNNING, AbTest.Status.PAUSED, AbTest.Status.FINISHED]
return context['ab_test'].status in [AbTest.Status.DRAFT, AbTest.Status.RUNNING, AbTest.Status.PAUSED]


class PauseAbTestMenuItem(ActionMenuItem):
Expand All @@ -185,22 +185,6 @@ def is_shown(self, request, context):
return context['ab_test'].status == AbTest.Status.RUNNING


class SelectControlMenuItem(ActionMenuItem):
name = 'action-select-control'
label = _("Revert to control")

def is_shown(self, request, context):
return context['ab_test'].status == AbTest.Status.FINISHED


class SelectTreatmentMenuItem(ActionMenuItem):
name = 'action-select-treatment'
label = _("Publish treatment")

def is_shown(self, request, context):
return context['ab_test'].status == AbTest.Status.FINISHED


class AbTestActionMenu:
template = 'wagtailadmin/pages/action_menu/menu.html'

Expand All @@ -214,8 +198,6 @@ def __init__(self, request, **kwargs):
RestartAbTestMenuItem(order=1),
EndAbTestMenuItem(order=2),
PauseAbTestMenuItem(order=3),
SelectControlMenuItem(order=4),
SelectTreatmentMenuItem(order=5),
]

self.menu_items = [
Expand Down Expand Up @@ -368,6 +350,8 @@ def progress(request, page, ab_test):
if ab_test.status == AbTest.Status.FINISHED:
ab_test.complete(AbTest.CompletionAction.REVERT, user=request.user)

messages.success(request, _("The page has been reverted back to the control version."))

else:
messages.error(request, _("The A/B test cannot be paused because it is not running."))

Expand All @@ -376,6 +360,8 @@ def progress(request, page, ab_test):
# TODO Permission check?
ab_test.complete(AbTest.CompletionAction.PUBLISH, user=request.user)

messages.success(request, _("The treatment version has been published."))

else:
messages.error(request, _("The A/B test cannot be paused because it is not running."))

Expand Down

0 comments on commit c61fcd4

Please sign in to comment.