Skip to content

Commit

Permalink
feat: split start/end dates into separate columns on main list
Browse files Browse the repository at this point in the history
  • Loading branch information
mikewilli committed Jan 3, 2025
1 parent fa0060c commit bc57535
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 12 deletions.
6 changes: 4 additions & 2 deletions experimenter/experimenter/nimbus_ui_new/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ class SortChoices(models.TextChoices):
FEATURES_DOWN = "-feature_configs__slug"
VERSIONS_UP = "firefox_min_version"
VERSIONS_DOWN = "-firefox_min_version"
DATES_UP = "_start_date"
DATES_DOWN = "-_start_date"
START_DATE_UP = "_start_date"
START_DATE_DOWN = "-_start_date"
END_DATE_UP = "sort_end_date"
END_DATE_DOWN = "-sort_end_date"


class IconMultiSelectWidget(MultiSelectWidget):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ <h1 class="modal-title fs-5" id="createModalLabel">
{% include "nimbus_experiments/table_header.html" with field="Size" up=sort_choices.SIZE_UP down=sort_choices.SIZE_DOWN %}
{% include "nimbus_experiments/table_header.html" with field="Features" up=sort_choices.FEATURES_UP down=sort_choices.FEATURES_DOWN %}
{% include "nimbus_experiments/table_header.html" with field="Versions" up=sort_choices.VERSIONS_UP down=sort_choices.VERSIONS_DOWN %}
{% include "nimbus_experiments/table_header.html" with field="Dates" up=sort_choices.DATES_UP down=sort_choices.DATES_DOWN %}
{% include "nimbus_experiments/table_header.html" with field="Start" up=sort_choices.START_DATE_UP down=sort_choices.START_DATE_DOWN %}
{% include "nimbus_experiments/table_header.html" with field="End" up=sort_choices.END_DATE_UP down=sort_choices.END_DATE_DOWN %}

</tr>
</thead>
Expand Down Expand Up @@ -109,11 +110,16 @@ <h1 class="modal-title fs-5" id="createModalLabel">
</td>
<td>
{% if experiment.start_date %}
{{ experiment.start_date|date:"Y-m-d" }} -
<br>
{{ experiment.computed_end_date|date:"Y-m-d" }}
<br>
({{ experiment.computed_duration_days }} days)
{{ experiment.start_date|date:"Y-m-d" }}
{% else %}
N/A
{% endif %}
</td>
<td>
{% if experiment.end_date %}
{{ experiment.end_date|date:"Y-m-d" }} ({{ experiment.computed_duration_days }} days)
{% elif experiment.proposed_end_date %}
<i>{{ experiment.proposed_end_date|date:"Y-m-d" }} ({{ experiment.computed_duration_days }} days)</i>
{% else %}
N/A
{% endif %}
Expand Down
78 changes: 75 additions & 3 deletions experimenter/experimenter/nimbus_ui_new/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def test_sort_by_versions(self):
[experiment2.slug, experiment1.slug],
)

def test_sort_by_dates(self):
def test_sort_by_start_date(self):
experiment1 = NimbusExperimentFactory.create_with_lifecycle(
NimbusExperimentFactory.Lifecycles.LIVE_ENROLLING,
start_date=datetime.date(2024, 1, 1),
Expand All @@ -860,7 +860,7 @@ def test_sort_by_dates(self):
response = self.client.get(
reverse("nimbus-list"),
{
"sort": SortChoices.DATES_UP,
"sort": SortChoices.START_DATE_UP,
},
)

Expand All @@ -872,7 +872,79 @@ def test_sort_by_dates(self):
response = self.client.get(
reverse("nimbus-list"),
{
"sort": SortChoices.DATES_DOWN,
"sort": SortChoices.START_DATE_DOWN,
},
)

self.assertEqual(
[e.slug for e in response.context["experiments"]],
[experiment2.slug, experiment1.slug],
)

def test_sort_by_end_date(self):
experiment1 = NimbusExperimentFactory.create_with_lifecycle(
NimbusExperimentFactory.Lifecycles.ENDING_APPROVE_APPROVE,
start_date=datetime.date(2024, 1, 1),
end_date=datetime.date(2024, 2, 1),
)
experiment2 = NimbusExperimentFactory.create_with_lifecycle(
NimbusExperimentFactory.Lifecycles.ENDING_APPROVE_APPROVE,
start_date=datetime.date(2024, 1, 2),
end_date=datetime.date(2024, 2, 2),
)

response = self.client.get(
reverse("nimbus-list"),
{
"sort": SortChoices.END_DATE_UP,
},
)

self.assertEqual(
[e.slug for e in response.context["experiments"]],
[experiment1.slug, experiment2.slug],
)

response = self.client.get(
reverse("nimbus-list"),
{
"sort": SortChoices.END_DATE_DOWN,
},
)

self.assertEqual(
[e.slug for e in response.context["experiments"]],
[experiment2.slug, experiment1.slug],
)

def test_sort_by_proposed_end_date(self):
experiment1 = NimbusExperimentFactory.create_with_lifecycle(
NimbusExperimentFactory.Lifecycles.LIVE_ENROLLING,
start_date=datetime.date(2024, 1, 1),
proposed_duration=10,
)
experiment2 = NimbusExperimentFactory.create_with_lifecycle(
NimbusExperimentFactory.Lifecycles.LIVE_ENROLLING,
start_date=datetime.date(2024, 1, 2),
proposed_duration=10,
)

response = self.client.get(
reverse("nimbus-list"),
{
"sort": SortChoices.END_DATE_UP,
},
)

self.assertEqual(
[e.slug for e in response.context["experiments"]],
[experiment1.slug, experiment2.slug],
)

response = self.client.get(
reverse("nimbus-list"),
{
"sort": SortChoices.END_DATE_DOWN,
},
)

Expand Down
14 changes: 13 additions & 1 deletion experimenter/experimenter/nimbus_ui_new/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.conf import settings
from django.db.models import DateField, ExpressionWrapper, F
from django.db.models.functions import Coalesce
from django.http import HttpResponse
from django.urls import reverse
from django.views.generic import CreateView, DetailView
Expand Down Expand Up @@ -62,7 +64,17 @@ class NimbusChangeLogsView(NimbusExperimentViewMixin, DetailView):

class NimbusExperimentsListView(NimbusExperimentViewMixin, FilterView):
queryset = (
NimbusExperiment.objects.all()
NimbusExperiment.objects.annotate(
sort_end_date=Coalesce(
F("_end_date"),
ExpressionWrapper(
Coalesce(F("proposed_release_date"), F("_start_date"))
+ F("proposed_duration"),
output_field=DateField(),
),
)
)
.all()
.order_by("-_updated_date_time")
.prefetch_related("feature_configs")
)
Expand Down

0 comments on commit bc57535

Please sign in to comment.