Skip to content

Commit

Permalink
Merge pull request #1034 from dimagi/sk/versions-rollout
Browse files Browse the repository at this point in the history
Versioning rollout
  • Loading branch information
snopoke authored Jan 14, 2025
2 parents 20b8d30 + 1915833 commit ea3d481
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 119 deletions.
52 changes: 0 additions & 52 deletions apps/experiments/management/commands/enable_versioning_for_team.py

This file was deleted.

1 change: 0 additions & 1 deletion apps/experiments/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def test_create_experiment_success(client, team_with_users):
experiment.tools == [AgentTools.ONE_OFF_REMINDER]


@override_flag("experiment_versions", active=True)
@override_settings(CELERY_TASK_ALWAYS_EAGER=True)
@pytest.mark.django_db()
def test_create_experiment_creates_first_version(client, team_with_users):
Expand Down
19 changes: 7 additions & 12 deletions apps/experiments/views/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,6 @@ def extra_context(self):
if self.object:
team_participant_identifiers.extend(self.object.participant_allowlist)
team_participant_identifiers = set(team_participant_identifiers)
fields_changed = self.object.compare_with_latest()
else:
fields_changed = []

return {
**{
Expand All @@ -389,7 +386,7 @@ def extra_context(self):
"experiment_type": experiment_type,
"available_tools": AgentTools.choices,
"team_participant_identifiers": team_participant_identifiers,
"disable_version_button": (not bool(fields_changed)) or self.object.create_version_task_id,
"disable_version_button": self.object.create_version_task_id,
},
**_get_voice_provider_alpine_context(self.request),
}
Expand Down Expand Up @@ -468,12 +465,11 @@ def form_valid(self, form, file_formset):
files = file_formset.save(self.request)
self.object.files.set(files)

if flag_is_active(self.request, "experiment_versions"):
task_id = async_create_experiment_version.delay(
experiment_id=self.object.id, version_description="", make_default=True
)
self.object.create_version_task_id = task_id
self.object.save(update_fields=["create_version_task_id"])
task_id = async_create_experiment_version.delay(
experiment_id=self.object.id, version_description="", make_default=True
)
self.object.create_version_task_id = task_id
self.object.save(update_fields=["create_version_task_id"])

return HttpResponseRedirect(self.get_success_url())

Expand Down Expand Up @@ -553,9 +549,8 @@ class DeleteFileFromExperiment(BaseDeleteFileView):
pass


# TODO: complete form
class ExperimentVersionForm(forms.ModelForm):
version_description = forms.CharField(widget=forms.Textarea(attrs={"rows": 2}))
version_description = forms.CharField(widget=forms.Textarea(attrs={"rows": 2}), required=False)
is_default_version = forms.BooleanField(required=False, label="Set as Published Version")

class Meta:
Expand Down
5 changes: 5 additions & 0 deletions templates/experiments/create_version_button.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
</button>
</div>
</div>
<div id="version-status-badge" hx-swap-oob="innerHTML">
<div class="tooltip" data-tip="Version build in progress">
<div class="badge badge-warning badge-sm">Building new version</div>
</div>
</div>
{% else %}
<a class="btn btn-sm btn-outline btn-success" href="{% url 'experiments:create_version' experiment.team.slug experiment.id %}"
{% if trigger_refresh %}x-init='htmx.trigger(".watchVersionChange", "version-changed")'{% endif %}
Expand Down
42 changes: 23 additions & 19 deletions templates/experiments/create_version_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@
{% block app %}
<div class="app-card">
<h1 class="pg-title">Create New Version</h1>
{% if not version_details.instance.has_versions or version_details.fields_changed %}
<form method="post">
{% csrf_token %}
{% render_form_fields form %}
<div class="form-actions">
<p class="buttons my-3">
<button type="submit" class="btn btn-primary">Create</button>
</p>
</div>
</form>
{% endif %}
{% if version_details.instance.has_versions %}
{% if version_details.fields_changed %}
<h1 class="pg-subtitle pb-5">Changes since version {{ version_details.previous_instance.version_number }}</h1>
<div class="p-5 border border-white rounded-lg">
{% include 'experiments/components/versions/compare.html' %}
</div>
{% else %}
<h1 class="pg-subtitle pb-5">No changes since version {{ version_details.previous_instance.version_number }}</h1>
{% if experiment.create_version_task_id %}
<h2 class="pg-subtitle pb-5">A new version being created. Please wait until it is complete before making another version.</h2>
{% else %}
{% if not version_details.instance.has_versions or version_details.fields_changed %}
<form method="post">
{% csrf_token %}
{% render_form_fields form %}
<div class="form-actions">
<p class="buttons my-3">
<button type="submit" class="btn btn-primary">Create</button>
</p>
</div>
</form>
{% endif %}
{% if version_details.instance.has_versions %}
{% if version_details.fields_changed %}
<h1 class="pg-subtitle pb-5">Changes since version {{ version_details.previous_instance.version_number }}</h1>
<div class="p-5 border border-white rounded-lg">
{% include 'experiments/components/versions/compare.html' %}
</div>
{% else %}
<h2 class="pg-subtitle pb-5">No changes since version {{ version_details.previous_instance.version_number }}</h2>
{% endif %}
{% endif %}
{% endif %}
</div>
Expand Down
4 changes: 1 addition & 3 deletions templates/experiments/experiment_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ <h3 class="text-md font-bold">{% translate "Please note" %}</h3>
<div class="mt-2">
<input type="submit" class="pg-button-primary" value="{{ button_text }}">
{% if experiment.id %}
{% flag "experiment_versions" %}
<button type="submit" class="pg-button-secondary" name="action" {% if disable_version_button %}disabled="True"{% endif %} value="save_and_version">Save & Create new version</button>
{% endflag %}
<button type="submit" class="pg-button-secondary" name="action" {% if disable_version_button %}disabled="True"{% endif %} value="save_and_version">Save & Create new version</button>
<button type="submit" class="pg-button-danger" name="action" value="save_and_archive" onclick="return confirm('Are you sure you want to archive this experiment?');">Archive</button>
{% endif %}
</div>
Expand Down
61 changes: 29 additions & 32 deletions templates/experiments/single_experiment_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@
<div class="flex">
<div class="flex-1 flex flex-row gap-2">
<h1 class="pg-title">{{ experiment.name }}</h1>
{% flag "experiment_versions" %}
{% if experiment.is_archived %}
<div class="badge badge-warning badge-sm">
Archived
{% if experiment.is_archived %}
<div class="badge badge-warning badge-sm">
Archived
</div>
{% elif deployed_version %}
<div class="flex flex-row gap-2">
<div class="tooltip" data-tip="Current published version">
<a class="badge badge-success badge-sm"
href="#versions">
v{{ deployed_version }}
</a>
</div>
{% elif deployed_version %}
<div class="flex flex-row gap-2">
<div class="tooltip" data-tip="Current published version">
<a class="badge badge-success badge-sm"
href="#versions">
v{{ deployed_version }}
</a>
</div>
<div
class="watchVersionChange"
hx-get="{% url 'experiments:get_release_status_badge' experiment.team.slug experiment.id %}"
hx-trigger="load, version-changed"
hx-swap="innerHTML">
</div>
<div
id="version-status-badge"
class="watchVersionChange"
hx-get="{% url 'experiments:get_release_status_badge' experiment.team.slug experiment.id %}"
hx-trigger="load, version-changed"
hx-swap="innerHTML">
</div>
{% endif %}
{% endflag %}
</div>
{% endif %}
</div>
<div class="justify-self-end">
<div class="join">
Expand Down Expand Up @@ -299,20 +298,18 @@ <h3 class="font-bold text-lg">Parent Experiments:
</div>
</div>

{% flag "experiment_versions" %}
<input type="radio" name="tab_group" role="tab" class="tab" aria-label="Versions" id="tab-versions" />
<div role="tabpanel" class="tab-content" id="content-versions">
<div class="app-card">
<div id="versions-table"
class="watchVersionChange"
hx-trigger="load, version-changed"
hx-target="this"
hx-get="{% url 'experiments:versions-list' request.team.slug experiment.id %}"
hx-swap="innerHTML">
</div>
<input type="radio" name="tab_group" role="tab" class="tab" aria-label="Versions" id="tab-versions" />
<div role="tabpanel" class="tab-content" id="content-versions">
<div class="app-card">
<div id="versions-table"
class="watchVersionChange"
hx-trigger="load, version-changed"
hx-target="this"
hx-get="{% url 'experiments:versions-list' request.team.slug experiment.id %}"
hx-swap="innerHTML">
</div>
</div>
{% endflag %}
</div>

{% flag "events" %}
<input type="radio" name="tab_group" role="tab" class="tab" aria-label="Events" id="tab-events" />
Expand Down

0 comments on commit ea3d481

Please sign in to comment.