Skip to content

Commit 025ebbb

Browse files
feat(nimbus): Add opt-in integration with nimbus-devtools
Because: - nimbus-devtools needs DOM controls to add opt-in support; and - the pretty-formatted recipe JSON is not actually valid JSON this commit: - adds those elements; and - removes the pretty formatting for recipe JSON. Fixes #13330
1 parent bfc78e5 commit 025ebbb

3 files changed

Lines changed: 38 additions & 28 deletions

File tree

experimenter/experimenter/experiments/models.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,14 +2185,10 @@ def conclusion_recommendation_labels(self):
21852185
def recipe_json(self):
21862186
from experimenter.experiments.api.v6.serializers import NimbusExperimentSerializer
21872187

2188-
return (
2189-
json.dumps(
2190-
self.published_dto or NimbusExperimentSerializer(self).data,
2191-
indent=2,
2192-
sort_keys=True,
2193-
)
2194-
.replace("&&", "\n&&") # Add helpful newlines to targeting
2195-
.replace("\\n", "\n") # Handle hard coded newlines in targeting
2188+
return json.dumps(
2189+
self.published_dto or NimbusExperimentSerializer(self).data,
2190+
indent=2,
2191+
sort_keys=True,
21962192
)
21972193

21982194
@property

experimenter/experimenter/nimbus_ui/templates/nimbus_experiments/detail_card_audience.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ <h4 class="mb-0">
136136
</td>
137137
</tr>
138138
<tr>
139-
<th id="recipe-json" class="border-bottom-0">Recipe JSON</th>
140-
<td colspan="3" class="border-bottom-0">
139+
<th class="border-bottom-0">Recipe JSON</th>
140+
<td colspan="3" class="border-bottom-0" data-nimbus-devtools-recipe-json>
141141
{% include "common/readonly_json.html" with json_content=experiment.recipe_json %}
142142

143143
</td>

experimenter/experimenter/nimbus_ui/templates/nimbus_experiments/launch_controls.html

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,24 +193,38 @@
193193
</div>
194194
{% if experiment.is_desktop %}
195195
<div class="alert alert-light border my-3">
196-
<h5 class="mb-2">Preview URL</h5>
197-
<p class="mb-1">
198-
<strong> Click the <code>about:studies</code> link below to copy</strong> then paste it in your browser. Ensure you enable <code>nimbus.debug</code> in <code>about:config</code> first.
199-
</p>
200-
<label for="branch-selector" class="form-label mt-2">Select Branch</label>
201-
<select id="branch-selector"
202-
class="form-select mb-3"
203-
onchange="updatePreviewURL()">
204-
{% for branch in experiment.branches.all %}
205-
<option value="{{ branch.slug }}"
206-
{% if branch == experiment.reference_branch %}selected{% endif %}>{{ branch.name }}</option>
207-
{% endfor %}
208-
</select>
209-
<button class="btn btn-sm" type="button">
210-
<code id="preview-url" class="d-block text-danger user-select-all">
211-
about:studies?optin_slug={{ experiment.slug }}&optin_branch={{ experiment.reference_branch.slug }}&optin_collection=nimbus-preview
212-
</code>
213-
</button>
196+
<div data-nimbus-devtools-preview-url-pane>
197+
<h5 class="mb-2">Preview URL</h5>
198+
<p class="mb-1">
199+
<strong> Click the <code>about:studies</code> link below to copy</strong> then paste it in your browser. Ensure you enable <code>nimbus.debug</code> in <code>about:config</code> first.
200+
</p>
201+
<label for="branch-selector" class="form-label mt-2">Select Branch</label>
202+
<select id="branch-selector"
203+
class="form-select mb-3"
204+
onchange="updatePreviewURL()">
205+
{% for branch in experiment.branches.all %}
206+
<option value="{{ branch.slug }}"
207+
{% if branch == experiment.reference_branch %}selected{% endif %}>{{ branch.name }}</option>
208+
{% endfor %}
209+
</select>
210+
<button class="btn btn-sm" type="button">
211+
<code id="preview-url" class="d-block text-danger user-select-all">
212+
about:studies?optin_slug={{ experiment.slug }}&optin_branch={{ experiment.reference_branch.slug }}&optin_collection=nimbus-preview
213+
</code>
214+
</button>
215+
</div>
216+
<div class="d-none" data-nimbus-devtools-opt-in-pane>
217+
<h5 class="mb-2">Opt-In for Testing</h5>
218+
<select class="form-select mb-3" name="branch">
219+
{% for branch in experiment.branches.all %}
220+
<option value="{{ branch.slug }}"
221+
{% if branch == experiment.reference_branch %}selected{% endif %}>{{ branch.name }}</option>
222+
{% endfor %}
223+
</select>
224+
<button class="btn btn-primary"
225+
type="button"
226+
data-nimbus-devtools-enroll-button>Enroll</button>
227+
</div>
214228
</div>
215229
{% endif %}
216230
<!-- Review Mode Controls -->

0 commit comments

Comments
 (0)