function resolveToggleOperation(toggledTaskUuid, allDescendantsCollapsed, allChildrenExpanded,
  uiCollapseOperationsByUuid) {
  let resolvedOperation;
  if (allDescendantsCollapsed) {
    const collapsedByExistingOp = _.some(
      _.get(uiCollapseOperationsByUuid, toggledTaskUuid, []),
      op => op.operation === 'collapse' && _.isEqual(op.targets, ['descendants']),
    );
    if (collapsedByExistingOp) {
      resolvedOperation = {
        uuids: [toggledTaskUuid],
        operation: 'clear',
        target: 'descendants',
      };
    } else {
      // descendants collapsed by default, expand all.
      // TODO: is this a safe assumption?
      resolvedOperation = {
        uuids: [toggledTaskUuid],
        operation: 'expand',
        target: 'descendants',
      };
    }
  } else if (allChildrenExpanded) {
    const uuidsExpandedFromDefaultByParent = _.keys(_.pickBy(
      uiCollapseOperationsByUuid,
      ops => _.some(ops, op => op.sourceTaskUuid === toggledTaskUuid
        && _.isEqual(op.targets, ['self'])
        && op.operation === 'expand'),
    ));
    if (!_.isEmpty(uuidsExpandedFromDefaultByParent)) {
      resolvedOperation = {
        uuids: uuidsExpandedFromDefaultByParent,
        operation: 'clear',
        target: 'self',
      };
    } else {
      const expandedByExistingOp = _.some(
        _.get(uiCollapseOperationsByUuid, toggledTaskUuid, []),
        op => op.operation === 'expand' && _.isEqual(op.targets, ['descendants']),
      );
      if (expandedByExistingOp) {
        // All expanded without any default ops to restore, so just collapse everything.
        resolvedOperation = {
          uuids: [toggledTaskUuid],
          operation: 'clear',
          target: 'descendants',
        };
      } else {
        // All expanded without any default ops to restore, so just collapse everything.
        resolvedOperation = {
          uuids: [toggledTaskUuid],
          operation: 'collapse',
          target: 'descendants',
        };
      }
    }
  } else {
    // Neither all collapsed nor all expanded -- default collapsed, some expanded.
    resolvedOperation = {
      uuids: [toggledTaskUuid],
      operation: 'collapse',
      target: 'descendants',
    };
  }
  return resolvedOperation;
}
//  operation to the core collapse resolution algorithm, then sending simpler operations from here.
operation to the core collapse resolution algorithm, then sending simpler operations from here.
operation to the core collapse resolution algorithm then sending simpler operations from here .
function resolveToggleOperation(toggledTaskUuid, allDescendantsCollapsed, allChildrenExpanded,
  uiCollapseOperationsByUuid) {
  let resolvedOperation;
  if (allDescendantsCollapsed) {
    const collapsedByExistingOp = _.some(
      _.get(uiCollapseOperationsByUuid, toggledTaskUuid, []),
      op => op.operation === 'collapse' && _.isEqual(op.targets, ['descendants']),
    );
    if (collapsedByExistingOp) {
      resolvedOperation = {
        uuids: [toggledTaskUuid],
        operation: 'clear',
        target: 'descendants',
      };
    } else {
      resolvedOperation = {
        uuids: [toggledTaskUuid],
        operation: 'expand',
        target: 'descendants',
      };
    }
  } else if (allChildrenExpanded) {
    const uuidsExpandedFromDefaultByParent = _.keys(_.pickBy(
      uiCollapseOperationsByUuid,
      ops => _.some(ops, op => op.sourceTaskUuid === toggledTaskUuid
        && _.isEqual(op.targets, ['self'])
        && op.operation === 'expand'),
    ));
    if (!_.isEmpty(uuidsExpandedFromDefaultByParent)) {
      resolvedOperation = {
        uuids: uuidsExpandedFromDefaultByParent,
        operation: 'clear',
        target: 'self',
      };
    } else {
      const expandedByExistingOp = _.some(
        _.get(uiCollapseOperationsByUuid, toggledTaskUuid, []),
        op => op.operation === 'expand' && _.isEqual(op.targets, ['descendants']),
      );
      if (expandedByExistingOp) {
        resolvedOperation = {
          uuids: [toggledTaskUuid],
          operation: 'clear',
          target: 'descendants',
        };
      } else {
        resolvedOperation = {
          uuids: [toggledTaskUuid],
          operation: 'collapse',
          target: 'descendants',
        };
      }
    }
  } else {
    resolvedOperation = {
      uuids: [toggledTaskUuid],
      operation: 'collapse',
      target: 'descendants',
    };
  }
  return resolvedOperation;
}
function resolveToggleOperation ( toggledTaskUuid , allDescendantsCollapsed , allChildrenExpanded , uiCollapseOperationsByUuid ) { let resolvedOperation ; if ( allDescendantsCollapsed ) { const collapsedByExistingOp = _ . some ( _ . get ( uiCollapseOperationsByUuid , toggledTaskUuid , [ ] ) , op => op . operation === 'collapse' && _ . isEqual ( op . targets , [ 'descendants' ] ) , ) ; if ( collapsedByExistingOp ) { resolvedOperation = { uuids : [ toggledTaskUuid ] , operation : 'clear' , target : 'descendants' , } ; } else { resolvedOperation = { uuids : [ toggledTaskUuid ] , operation : 'expand' , target : 'descendants' , } ; } } else if ( allChildrenExpanded ) { const uuidsExpandedFromDefaultByParent = _ . keys ( _ . pickBy ( uiCollapseOperationsByUuid , ops => _ . some ( ops , op => op . sourceTaskUuid === toggledTaskUuid && _ . isEqual ( op . targets , [ 'self' ] ) && op . operation === 'expand' ) , ) ) ; if ( ! _ . isEmpty ( uuidsExpandedFromDefaultByParent ) ) { resolvedOperation = { uuids : uuidsExpandedFromDefaultByParent , operation : 'clear' , target : 'self' , } ; } else { const expandedByExistingOp = _ . some ( _ . get ( uiCollapseOperationsByUuid , toggledTaskUuid , [ ] ) , op => op . operation === 'expand' && _ . isEqual ( op . targets , [ 'descendants' ] ) , ) ; if ( expandedByExistingOp ) { resolvedOperation = { uuids : [ toggledTaskUuid ] , operation : 'clear' , target : 'descendants' , } ; } else { resolvedOperation = { uuids : [ toggledTaskUuid ] , operation : 'collapse' , target : 'descendants' , } ; } } } else { resolvedOperation = { uuids : [ toggledTaskUuid ] , operation : 'collapse' , target : 'descendants' , } ; } return resolvedOperation ; }
operation to the core collapse resolution algorithm, then sending simpler operations from here.
operation to the core collapse resolution algorithm then sending simpler operations from here .
// descendants collapsed by default, expand all. // TODO: is this a safe assumption? // All expanded without any default ops to restore, so just collapse everything. // All expanded without any default ops to restore, so just collapse everything. // Neither all collapsed nor all expanded -- default collapsed, some expanded.