Repository: cisagov/manage.get.gov

Issue:
Admin: make `submission date` the default sort for domain requests list page
### Issue description

### Problem:
In the domain requests list page, currently, this `Submission Date` column is far to the right and requires horizontal scrolling to see it. In order to help the analyst prioritize incoming requests, they would prefer to see the Submission Date more easily. 

Also, analysts would prefer that the most recent submissions appear at the top of this list, so they may easily see which tickets have not been triaged and assigned to an analyst for review. This means that the oldest requests would be at the bottom of the list.

### Solution:
We will move the submission date column right next to the domain name column in the view. The default view for this page will then be sorted in reverse chronological order by submission date.

The second level sort will be by domain name, in ascending alphabetical order.


### Acceptance criteria

- [ ] On the /admin/registrar/domainrequest/ page, the default view is sorted by `Submission Date`, in reverse chronological order.
- [ ] In that same view, the `Submission Date` column appears in the second position, preceded by `Requested Domain` and followed by `Status` columns.

### Additional context

Request came from the 3/27/24 Product Huddle, [with Bookmark to notes here](https://docs.google.com/document/d/1jatolB9YaQLITwqx25y0B1u5J23S_J19PawXtIaov8o/edit#bookmark=id.3lxagvi8bl8u).

This issue has come up several times, and should be considered a priority.

### Links to other issues

Relates to: #1838. This ticket has been inspired by that work.


Discussion:

Resolving patch:
diff --git a/src/registrar/admin.py b/src/registrar/admin.py
--- a/src/registrar/admin.py
+++ b/src/registrar/admin.py
@@ -1056,6 +1056,7 @@ def queryset(self, request, queryset):
     # Columns
     list_display = [
         "requested_domain",
+        "submission_date",
         "status",
         "generic_org_type",
         "federal_type",
@@ -1064,7 +1065,6 @@ def queryset(self, request, queryset):
         "custom_election_board",
         "city",
         "state_territory",
-        "submission_date",
         "submitter",
         "investigator",
     ]
@@ -1192,7 +1192,9 @@ def custom_election_board(self, obj):
     filter_horizontal = ("current_websites", "alternative_domains", "other_contacts")
 
     # Table ordering
-    ordering = ["requested_domain__name"]
+    # NOTE: This impacts the select2 dropdowns (combobox)
+    # Currentl, there's only one for requests on DomainInfo
+    ordering = ["-submission_date", "requested_domain__name"]
 
     change_form_template = "django/admin/domain_request_change_form.html"
 


Test patch:
diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py
--- a/src/registrar/tests/test_admin.py
+++ b/src/registrar/tests/test_admin.py
@@ -1,4 +1,6 @@
-from datetime import date
+from datetime import date, datetime
+from django.utils import timezone
+import re
 from django.test import TestCase, RequestFactory, Client, override_settings
 from django.contrib.admin.sites import AdminSite
 from contextlib import ExitStack
@@ -716,7 +718,7 @@ def test_domain_sortable(self):
             self.test_helper.assert_table_sorted("-1", ("-requested_domain__name",))
 
     def test_submitter_sortable(self):
-        """Tests if the DomainRequest sorts by domain correctly"""
+        """Tests if the DomainRequest sorts by submitter correctly"""
         with less_console_noise():
             p = "adminpass"
             self.client.login(username="superuser", password=p)
@@ -747,7 +749,7 @@ def test_submitter_sortable(self):
             )
 
     def test_investigator_sortable(self):
-        """Tests if the DomainRequest sorts by domain correctly"""
+        """Tests if the DomainRequest sorts by investigator correctly"""
         with less_console_noise():
             p = "adminpass"
             self.client.login(username="superuser", password=p)
@@ -760,7 +762,7 @@ def test_investigator_sortable(self):
 
             # Assert that our sort works correctly
             self.test_helper.assert_table_sorted(
-                "6",
+                "12",
                 (
                     "investigator__first_name",
                     "investigator__last_name",
@@ -769,13 +771,77 @@ def test_investigator_sortable(self):
 
             # Assert that sorting in reverse works correctly
             self.test_helper.assert_table_sorted(
-                "-6",
+                "-12",
                 (
                     "-investigator__first_name",
                     "-investigator__last_name",
                 ),
             )
 
+    @less_console_noise_decorator
+    def test_default_sorting_in_domain_requests_list(self):
+        """
+        Make sure the default sortin in on the domain requests list page is reverse submission_date
+        then alphabetical requested_domain
+        """
+
+        # Create domain requests with different names
+        domain_requests = [
+            completed_domain_request(status=DomainRequest.DomainRequestStatus.SUBMITTED, name=name)
+            for name in ["ccc.gov", "bbb.gov", "eee.gov", "aaa.gov", "zzz.gov", "ddd.gov"]
+        ]
+
+        domain_requests[0].submission_date = timezone.make_aware(datetime(2024, 10, 16))
+        domain_requests[1].submission_date = timezone.make_aware(datetime(2001, 10, 16))
+        domain_requests[2].submission_date = timezone.make_aware(datetime(1980, 10, 16))
+        domain_requests[3].submission_date = timezone.make_aware(datetime(1998, 10, 16))
+        domain_requests[4].submission_date = timezone.make_aware(datetime(2013, 10, 16))
+        domain_requests[5].submission_date = timezone.make_aware(datetime(1980, 10, 16))
+
+        # Save the modified domain requests to update their attributes in the database
+        for domain_request in domain_requests:
+            domain_request.save()
+
+        # Refresh domain request objects from the database to reflect the changes
+        domain_requests = [DomainRequest.objects.get(pk=domain_request.pk) for domain_request in domain_requests]
+
+        # Login as superuser and retrieve the domain request list page
+        self.client.force_login(self.superuser)
+        response = self.client.get("/admin/registrar/domainrequest/")
+
+        # Check that the response is successful
+        self.assertEqual(response.status_code, 200)
+
+        # Extract the domain names from the response content using regex
+        domain_names_match = re.findall(r"(\w+\.gov)</a>", response.content.decode("utf-8"))
+
+        logger.info(f"domain_names_match {domain_names_match}")
+
+        # Verify that domain names are found
+        self.assertTrue(domain_names_match)
+
+        # Extract the domain names
+        domain_names = [match for match in domain_names_match]
+
+        # Verify that the domain names are displayed in the expected order
+        expected_order = [
+            "ccc.gov",
+            "zzz.gov",
+            "bbb.gov",
+            "aaa.gov",
+            "ddd.gov",
+            "eee.gov",
+        ]
+
+        # Remove duplicates
+        # Remove duplicates from domain_names list while preserving order
+        unique_domain_names = []
+        for domain_name in domain_names:
+            if domain_name not in unique_domain_names:
+                unique_domain_names.append(domain_name)
+
+        self.assertEqual(unique_domain_names, expected_order)
+
     def test_short_org_name_in_domain_requests_list(self):
         """
         Make sure the short name is displaying in admin on the list page