MDL-68977 user: Do not refresh participants table on load
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 9 Jun 2020 02:57:06 +0000 (10:57 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 9 Jun 2020 06:35:39 +0000 (14:35 +0800)
user/amd/build/participantsfilter.min.js
user/amd/build/participantsfilter.min.js.map
user/amd/src/participantsfilter.js

index 0e6d74a..2a5efd0 100644 (file)
Binary files a/user/amd/build/participantsfilter.min.js and b/user/amd/build/participantsfilter.min.js differ
index 4f67ea5..ae59874 100644 (file)
Binary files a/user/amd/build/participantsfilter.min.js.map and b/user/amd/build/participantsfilter.min.js.map differ
index 3808753..482466e 100644 (file)
@@ -165,6 +165,9 @@ export const init = participantsRegionId => {
      * @param {HTMLElement} filterRow
      */
     const removeFilterRow = async filterRow => {
+        const filterType = filterRow.querySelector(Selectors.filter.fields.type);
+        const hasFilterValue = !!filterType.value;
+
         // Remove the filter object.
         removeFilterObject(filterRow.dataset.filterType);
 
@@ -174,8 +177,10 @@ export const init = participantsRegionId => {
         // Update the list of available filter types.
         updateFiltersOptions();
 
-        // Refresh the table.
-        updateTableFromFilter();
+        if (hasFilterValue) {
+            // Refresh the table if there was any content in this row.
+            updateTableFromFilter();
+        }
 
         // Update filter fieldset legends.
         const filterLegends = await getAvailableFilterLegends();
@@ -337,7 +342,7 @@ export const init = participantsRegionId => {
         const filterPromises = filterConfig.map(([filterType, filterData]) => {
             if (filterType === 'courseid') {
                 // The courseid is a special case.
-                return Promise.resolve();
+                return false;
             }
 
             const filterValues = filterData.values;
@@ -345,11 +350,15 @@ export const init = participantsRegionId => {
             if (!filterValues.length) {
                 // There are no values for this filter.
                 // Skip it.
-                return Promise.resolve();
+                return false;
             }
 
             return addFilterRow().then(([filterRow]) => addFilter(filterRow, filterType, filterValues));
-        });
+        }).filter(promise => promise);
+
+        if (!filterPromises.length) {
+            return;
+        }
 
         Promise.all(filterPromises).then(() => {
             return removeEmptyFilters();