[PATCH 5/5] patch-list: added inline dropdown changes functionality

Raxel Gutierrez raxel at google.com
Tue Jul 20 09:34:28 AEST 2021


Added dropdown for the row values of the Delegate and State columns for
each individual patch to make one-off changes to patches. Changed the
generic_list method to pass the list of states and maintainers in patch
list view context to populate the dropdown options. The static
patch-list.js file now uses the modularity of the fetch request and
update/error messages handling of utils.js.

Signed-off-by: Raxel Gutierrez <raxel at google.com>
---
 htdocs/css/style.css                          |  2 +-
 htdocs/js/patch-list.js                       | 34 +++++++++++++++++++
 htdocs/js/utils.js                            |  2 +-
 .../patchwork/partials/patch-list.html        | 31 +++++++++++++++--
 patchwork/views/__init__.py                   |  3 ++
 templates/base.html                           |  2 +-
 6 files changed, 68 insertions(+), 6 deletions(-)

diff --git a/htdocs/css/style.css b/htdocs/css/style.css
index 8746083..2a45ec7 100644
--- a/htdocs/css/style.css
+++ b/htdocs/css/style.css
@@ -366,7 +366,7 @@ div.patchform {
     align-items: center;
 }
 
-.change-property, .archive-patch, .add-bundle {
+.change-property, select[class^="change-property-"], .archive-patch, .add-bundle {
     padding: 4px;
     margin-right: 8px;
     box-sizing: border-box;
diff --git a/htdocs/js/patch-list.js b/htdocs/js/patch-list.js
index 8c7640f..b88bad5 100644
--- a/htdocs/js/patch-list.js
+++ b/htdocs/js/patch-list.js
@@ -1,4 +1,17 @@
+import { updateProperty } from "./utils.js";
+
 $( document ).ready(function() {
+    // Change listener for dropdowns that change an individual patch's delegate and state properties
+    $("select[class^='change-property-']").change((event) => {
+        const property = event.target.getAttribute("value");
+        const { url, data } = getPatchProperties(event.target, property);
+        const updateMessage = {
+            'none': "No patches updated",
+            'some': "1 patch updated",
+        };
+        updateProperty(url, data, updateMessage);
+    });
+
     $("#patchlist").stickyTableHeaders();
 
     $("#check-all").change(function(e) {
@@ -9,4 +22,25 @@ $( document ).ready(function() {
         }
         e.preventDefault();
     });
+
+    /**
+     * Returns the data to make property changes to a patch through fetch request.
+     * @param {Element} propertySelect Property select element modified.
+     * @param {string} property Patch property modified (e.g. "state", "delegate")
+     * @return {{property: string, value: string}}
+     *     property: Property field to be modified in request.
+     *     value: New value for property to be modified to in request.
+     */
+    function getPatchProperties(propertySelect, property) {
+        const selectedOption = propertySelect.options[propertySelect.selectedIndex];
+        const patchId = propertySelect.parentElement.parentElement.dataset.patchId;
+        const propertyValue = (property === "state") ? selectedOption.text
+                            : (selectedOption.value === "*") ? null : selectedOption.value
+        const data = {};
+        data[property] = propertyValue;
+        return {
+            "url": "/api/patches/" + patchId + "/",
+            "data": data,
+        };
+    }
 });
\ No newline at end of file
diff --git a/htdocs/js/utils.js b/htdocs/js/utils.js
index 34d41f5..254b5ae 100644
--- a/htdocs/js/utils.js
+++ b/htdocs/js/utils.js
@@ -68,4 +68,4 @@ function handleErrorMessages(errorMessage) {
     container.prepend(errorHeader);
 }
 
-export { updateProperty, handleUpdateMessages, handleUpdateMessages};
\ No newline at end of file
+export { updateProperty };
\ No newline at end of file
diff --git a/patchwork/templates/patchwork/partials/patch-list.html b/patchwork/templates/patchwork/partials/patch-list.html
index 629922c..48b47db 100644
--- a/patchwork/templates/patchwork/partials/patch-list.html
+++ b/patchwork/templates/patchwork/partials/patch-list.html
@@ -5,7 +5,7 @@
 {% load static %}
 
 {% block headers %}
-  <script src="{% static "js/patch-list.js" %}"></script>
+  <script type="module" src="{% static "js/patch-list.js" %}"></script>
 {% endblock %}
 
 {% include "patchwork/partials/filters.html" %}
@@ -238,8 +238,33 @@
    <td id="patch-checks" class="text-nowrap">{{ patch|patch_checks }}</td>
    <td id="patch-date" class="text-nowrap">{{ patch.date|date:"Y-m-d" }}</td>
    <td id="patch-submitter">{{ patch.submitter|personify:project }}</td>
-   <td id="patch-delegate">{{ patch.delegate.username }}</td>
-   <td id="patch-state">{{ patch.state }}</td>
+   <td id="patch-delegate">
+      <select class="change-property-delegate" value="delegate">
+        {% if not patch.delegate.username %}
+          <option value="*" selected>No delegate</option>
+        {% else %}
+          <option value="*">No delegate</option>
+        {% endif %}
+        {% for maintainer in maintainers %}
+          {% if maintainer.name == patch.delegate.username %}
+            <option value="{{ patch.delegate.username.id }}" selected>{{ patch.delegate.username }}</option>
+          {% else %}
+            <option value="{{ maintainer.id }}">{{ maintainer.name }}</option>
+          {% endif %}
+        {% endfor %}
+      </select>
+    </td>
+   <td id="patch-state">
+    <select class="change-property-state" value="state">
+      {% for state in states %}
+        {% if state.name == patch.state.name %}
+          <option value="{{ patch.state.ordering }}" selected>{{ patch.state }}</option>
+        {% else %}
+          <option value="{{ state.ordering  }}">{{ state.name }}</option>
+        {% endif %}
+      {% endfor %}
+    </select>
+  </td>
   </tr>
  {% empty %}
   <tr>
diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py
index 6c30f0b..cdd6f55 100644
--- a/patchwork/views/__init__.py
+++ b/patchwork/views/__init__.py
@@ -13,6 +13,7 @@ from patchwork.models import Bundle
 from patchwork.models import BundlePatch
 from patchwork.models import Patch
 from patchwork.models import Project
+from patchwork.models import State
 from patchwork.models import Check
 from patchwork.paginator import Paginator
 
@@ -177,6 +178,8 @@ def generic_list(request, project, view, view_args=None, filter_settings=None,
         'project': project,
         'projects': Project.objects.all(),
         'filters': filters,
+        'maintainers': project.maintainer_project.all(),
+        'states': State.objects.all(),
     }
 
     # pagination
diff --git a/templates/base.html b/templates/base.html
index e1fac82..9bdb35f 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -114,7 +114,7 @@
   {% endfor %}
   </div>
 {% endif %}
-  <div class="container-fluid">
+  <div id="main-content" class="container-fluid">
 {% block body %}
 {% endblock %}
   </div>
-- 
2.32.0.402.g57bb445576-goog



More information about the Patchwork mailing list