Problem/Motivation

As seen in #2869316: Add column count filter for the layouts in overview page, adding additional filters to the Grid layouts and Styles overview pages results in cluttered JavaScript code.

Proposed resolution

Refactor overview.admin.js so that only the render array (PHP code) has to be adjusted, when adding additional subjects to filter by.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

VladimirMarko created an issue. See original summary.

VladimirMarko’s picture

Status: Active » Needs review
FileSize
10.16 KB
Primsi’s picture

+++ b/js/overview.admin.js
@@ -8,57 +8,216 @@
+        _.each(object, function ($select, subject) {

Do we need to add a lib dependency on uderscore then?

Also it would be great if someone with frontend expertise could look at this js.

VladimirMarko’s picture

FileSize
4.26 KB
12.03 KB

Added a library dependency to Underscore.js.

Made the text search a bit more selective by using arrays as its haystacks instead of combining all the the source values from a row into a single big string.

Fixed some bugs and some documentation.

VladimirMarko’s picture

FileSize
16.14 KB
11.86 KB

Reduced the nesting level of all the helper functions. They are all directly in the IIFE now.

Made having multiple tables with their separate filters on a single page possible.

miro_dietiker’s picture

I see 35 leaving lines of code replaced with 250+ new ones due to better abstraction.
That's not really a healthy balance. Didn't find too much time yet for looking deeper into it. Let's try to keep complexity as low as possible, this is just an overview.

VladimirMarko’s picture

The functions Drupal.behaviors.tableFilters and singleTableFilter are analogous (both in structure and function) to the original code. The rest are helper pure functions that mostly do the obvious thing and whose docblocks are as large as the function code itself.

I originally tried to do it without those functions in a procedural style. That was much shorter but resulted in horrible, long variable names in a badly-readable mess.