<commit_before>module Perspective {

  /**
   * Returns the top level tabs for the given perspective
   */
  export function topLevelTabs($location, workspace) {
    var perspective = $location.search()["_p"];
    if (!perspective) {
      perspective = Perspective.choosePerspective($location, workspace);
    }
    console.log("perspective: " + perspective);
    var data = perspective ? Perspective.metadata[perspective] : null;
    var answer = [];
    if (!data) {
      answer = workspace.topLevelTabs;
    } else {
      // lets iterate through the available tabs in the perspective
      var topLevelTabs = data.topLevelTabs;
      var list = topLevelTabs.includes || topLevelTabs.excludes;
      angular.forEach(list, (tabSpec) => {
        var href = tabSpec.href;
        if (href) {
          var tab = workspace.topLevelTabs.find((t) => {
            var thref = t.href();
            return thref && thref.startsWith(href);
          });
          if (tab) {
            answer.push(tab);
          }
        }
      });
      if (!topLevelTabs.includes) {
        // lets exclude the matched tabs
        answer = workspace.topLevelTabs.subtract(answer);
      }
    }
    return answer;
  }

  /**
   * Returns the perspective we should be using right now since none is specified
   */
  export function choosePerspective($location, workspace) {
    return null;
  }

  /**
   * Returns the default page after figuring out what the current perspective is
   */
  export function defaultPage($location, workspace) {
    console.log("====== HEY - function with " + $location + " and workspace " + workspace);
    if ($location && workspace) {
      var topLevelTabs = Perspective.topLevelTabs($location, workspace);
      if (topLevelTabs && topLevelTabs.length) {
        var tab = topLevelTabs[0];
        var href = tab.href();
        if (href) {
          return Core.trimLeading(href, "#");
        }
      }
    }
    return '/help/index';
  }
}<commit_msg>#529 default to the first valid tab<commit_after>module Perspective {

  /**
   * Returns the top level tabs for the given perspective
   */
  export function topLevelTabs($location, workspace) {
    var perspective = $location.search()["_p"];
    if (!perspective) {
      perspective = Perspective.choosePerspective($location, workspace);
    }
    console.log("perspective: " + perspective);
    var data = perspective ? Perspective.metadata[perspective] : null;
    var answer = [];
    if (!data) {
      answer = workspace.topLevelTabs;
    } else {
      // lets iterate through the available tabs in the perspective
      var topLevelTabs = data.topLevelTabs;
      var list = topLevelTabs.includes || topLevelTabs.excludes;
      angular.forEach(list, (tabSpec) => {
        var href = tabSpec.href;
        if (href) {
          var tab = workspace.topLevelTabs.find((t) => {
            var thref = t.href();
            return thref && thref.startsWith(href);
          });
          if (tab) {
            answer.push(tab);
          }
        }
      });
      if (!topLevelTabs.includes) {
        // lets exclude the matched tabs
        answer = workspace.topLevelTabs.subtract(answer);
      }
    }
    return answer;
  }

  /**
   * Returns the perspective we should be using right now since none is specified
   */
  export function choosePerspective($location, workspace) {
    return null;
  }

  /**
   * Returns the default page after figuring out what the current perspective is
   */
  export function defaultPage($location, workspace) {
    var answer = null;
    console.log("====== HEY - function with " + $location + " and workspace " + workspace);
    if ($location && workspace) {
      var topLevelTabs = Perspective.topLevelTabs($location, workspace);
      angular.forEach(topLevelTabs, (tab) => {
        var href = tab.href();
        if (href && !answer) {
          // exclude invalid tabs
          var validFn = tab.isValid;
          if (!validFn || validFn(workspace)) {
            answer =  Core.trimLeading(href, "#");
          }
        }
      });
    }
    return answer || '/help/index';
  }
}
{'fraction_non_alphanumeric': 0.11908804268736357, 'fraction_numerical': 0.0009701673538685423, 'mean_word_length': 2.328490718321227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4820324', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1145, 'n_words': 312}