Skip to content

Commit

Permalink
Add panels to create test form and view
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonatan-lopes authored and Stormheg committed Mar 22, 2024
1 parent 91d0e0c commit e631af6
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion wagtail_ab_testing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
permission_classes,
)
from rest_framework.response import Response
from wagtail.admin import messages
from wagtail.admin import messages, panels
from wagtail.admin.action_menu import ActionMenuItem
from wagtail.admin.filters import DateRangePickerWidget, WagtailFilterSet
from wagtail.admin.views.reports import ReportView
Expand Down Expand Up @@ -53,6 +53,40 @@ class Meta:
model = AbTest
fields = ["name", "hypothesis", "goal_event", "goal_page", "sample_size"]

panels = [
panels.MultiFieldPanel(
[
panels.FieldPanel("name"),
panels.FieldPanel("hypothesis"),
],
heading=_("Enter test details"),
),
panels.MultiFieldPanel(
[
# A dummy help panel to mount the react component:
panels.HelpPanel(attrs={"data-component": "goal-selector"}),
],
heading=_("Choose a goal"),
),
panels.MultiFieldPanel(
[
panels.FieldPanel("sample_size"),
panels.HelpPanel(
_(
"Need help calculating sample size for A/B tests? "
'Try <a href="https://www.optimizely.com/uk/sample-size-calculator/" '
'target="_blank">Optimisely</a>, '
'<a href="https://www.evanmiller.org/ab-testing/sample-size.html" '
'target="_blank">Evan Miller</a>, or '
'<a href="https://www.abtasty.com/sample-size-calculator/" '
'target="_blank">AB Tasty</a>.'
)
),
],
heading=_("Sample size"),
),
]


def add_ab_test_checks(request, page):
# User must have permission to edit the page
Expand Down Expand Up @@ -150,6 +184,11 @@ def add_form(request, page_id):

event_types = get_event_types().items()

panel = panels.ObjectList(form.panels).bind_to_model(AbTest)
bound_panel = panel.get_bound_panel(
instance=form.instance, form=form, request=request
)

"""
Template: wagtail_ab_testing/add_form.html is rendered here
Expand All @@ -163,6 +202,7 @@ def add_form(request, page_id):
{
"page": page,
"form": form,
"panel": bound_panel,
"goal_selector_props": json.dumps(
{
"goalTypesByPageType": {
Expand Down

0 comments on commit e631af6

Please sign in to comment.