Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/230#discussion_r23399464
--- Diff: app/addons/documents/views.js ---
@@ -564,15 +591,79 @@ function(app, FauxtonAPI, Components, Documents,
Databases, Views, QueryOptions)
this.toggleTrash();
this.maybeHighlightAllButton();
+ this.updateExpandButtonLabel();
},
perPage: function () {
return this.allDocsNumber.perPage();
+ },
+
+ // a bit dense, but necessary. It decides on what the Expand/Collapse
button label should be and takes into
+ // account the default expand/collapse state, what rows are checked
and their states
+ updateExpandButtonLabel: function () {
+
+ if (this.defaultDocsStateExpanded) {
+ this.setExpandButtonLabel(false);
+
+ // override the default label and show "Expand" if ALL checked
rows have state === collapse (false)
+ if (this.numSelectedOnPage() &&
this.allCheckedRowsHaveState(false)) {
+ this.setExpandButtonLabel(true);
+ }
+ } else {
+ this.setExpandButtonLabel(true); // default show "Expand"
+
+ // show "Collapse" if ALL checked rows have state === expanded
(true)
+ if (this.numSelectedOnPage() &&
this.allCheckedRowsHaveState(true)) {
+ this.setExpandButtonLabel(false);
+ }
+ }
+ },
--- End diff --
this one is quite complex code - it seems it has a quite high cyclomatic
complexity - i would suggest using early returns so the if / else does not get
so deeply nested:
```js
updateExpandButtonLabel: function () {
this.setExpandButtonLabel(true); // default show "Expand"
// show "Collapse" if ALL checked rows have state === expanded (true)
if (!this.defaultDocsStateExpanded && this.numSelectedOnPage() &&
this.allCheckedRowsHaveState(true)) {
this.setExpandButtonLabel(false);
return;
}
// override the default label and show "Expand" if ALL checked rows
have state === collapse (false)
if (this.numSelectedOnPage() && this.allCheckedRowsHaveState(false)) {
this.setExpandButtonLabel(true);
}
return;
this.setExpandButtonLabel(false);
},
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---