Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select all rows (include group rows) in the journal grid #1526

Merged
merged 3 commits into from
Apr 20, 2017

Conversation

mbayopanda
Copy link
Collaborator

@mbayopanda mbayopanda commented Apr 19, 2017

This PR permits to select all rows in the journal grid, this selection include the group header rows.

select_all

Closes #1512.

Copy link
Collaborator

@jniles jniles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbayopanda, I've made some comments for code clarity.

@@ -21,6 +21,7 @@ function GridGroupingService(GridAggregators, uiGridGroupingConstants, Session,
$timeout, util, uiGridConstants) {
/** @const aggregators assigned by column ids */
var DEFAULT_AGGREGATORS = GridAggregators.aggregators.tree;
var SELECTED_GROUP_HEADERS;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ALL_CAPITAL_LETTERS syntax is usually for constants. Does this variable need to be global to the entire service? It looks like it is only used in hadnleBatchSelection().

// handle deselect
if (hasSelections === false) {
angular.forEach(SELECTED_GROUP_HEADERS, function (node) {
node.isSelected = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does isSelected do? It looks like it is always set but never used. Is it an internal ui-grid thing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isSelected is responsible to set the row selected (checked) in the ui grid.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - I was wondering if that was the case 👍

if (parentRow.treeLevel === 0 && !parents[parentRow.uid]) {
parentRow.isSelected = true;
parents[parentRow.uid] = parentRow;
SELECTED_GROUP_HEADERS = parents;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to set this every loop through the gridRows? It looks like what you are really doing is:

gridRows.forEach(function (row) {
  var parentRow = row.treeNode.parentRow;
  if (parentRow.treeLevel === 0 && !parents[parentRow.uid]) {
    parentRow.isSelected = true;
    parents[parentRow.uid] = parentRow;
  }
});

SELECTED_GROUP_HEADERS = parents;

If that is true, then it is easier to read (and might be more performant) to remove the SELECTED_GROUP_HEADERS variable assignment from the loop.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the SELECTED_GROUP_HEADERS is a global variable and must be updated only when there are new parent row (enter in the if clause).

If it is out the if we cannot deselect parent rows which were previously selected because

var parents = {};

/* this code is not executed
gridRows.forEach(function (row) {
  var parentRow = row.treeNode.parentRow;
  if (parentRow.treeLevel === 0 && !parents[parentRow.uid]) {
    parentRow.isSelected = true;
    parents[parentRow.uid] = parentRow;
  }
}); */

SELECTED_GROUP_HEADERS = parents; // SELECTED_GROUP_HEADERS = {}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, that makes sense. I don't think there is a clearer way of expressing what you wrote. LGTM 👍


gridRows.forEach(function (row) {
var parentRow = row.treeNode.parentRow;
if (parentRow.treeLevel === 0 && !parents[parentRow.uid]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what this is because we've talked about it, but the code is hard to read as it is. Could you move this check into a function?

// this function identifies parent rows that we haven't seen yet
function isUnusedParentRow(row) {
  return row.treeLevel === 0 && !parents[row.uid];
}

gridRows.forEach(function (row) {
  var parentRow = row.treeNode.parentRow; 
  if (isUnusedParentRow(parentRow)) {
     // do something.
  }
});

var gridRows = gridApi.selection.getSelectedGridRows();
var parents = {};

var hasSelections = gridApi.selection.getSelectedRows().length > 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice variable assignment 👍

Copy link
Collaborator

@jniles jniles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All my comments have been addressed 👍

@jniles jniles added the Bug Fix label Apr 20, 2017
@jniles jniles merged commit 9263a28 into Third-Culture-Software:master Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants