async componentWillMount()

in src/content/components/AllocationView/AllocationView.js [88:209]


  async componentWillMount() {
    this._isMounted = true;
    await this.context.qm.runCachedQueries(
      [
        {
          include_fields: includeFields,
          resolution: "---",
          order: "cf_fx_points DESC, priority, changeddate DESC",
          rules: [
            {
              key: "assigned_to",
              operator: "anyexact",
              value: teams.omc.join(","),
            },
            {
              operator: "OR",
              rules: [
                {
                  key: "blocked",
                  operator: "anywordssubstr",
                  value: this.context.metas.map(m => m.id).join(","),
                },
                {
                  key: "component",
                  operator: "anyexact",
                  value: BUGZILLA_TRIAGE_COMPONENTS.join(","),
                },
              ],
            },
            {
              key: "cf_fx_iteration",
              operator: "notequals",
              value: "---",
            },
          ],
        },
      ],
      () => this._isMounted,
      ({ rsp: [{ bugs }], awaitingNetwork }) => {
        let bugsByEngineer = [];
        // put engineers in the alphabetic order they appear in the config, but
        // put the viewer first if they've set their bugzilla email in
        // SettingsView or MyBugs to an OMC engineer email.
        const email = prefs.get("bugzilla_email");
        if (email && teams.omc.includes(email)) {
          bugsByEngineer.push({
            engineer: email,
            bugs: [],
            user: this.context.teams.omc.find(e =>
              [e.name, e.email].includes(email)
            ),
          });
        }
        for (const engineer of teams.omc) {
          if (engineer === email) {
            continue;
          }
          let item = {
            engineer,
            bugs: [],
            user: this.context.teams.omc.find(e =>
              [e.name, e.email].includes(engineer)
            ),
          };
          bugsByEngineer.push(item);
        }

        for (const bug of bugs) {
          let item = bugsByEngineer.find(e => e.engineer === bug.assigned_to);
          if (!item) {
            continue;
          }

          // only add the bug if it matches the current or last release.
          const bugRelease = bug.cf_fx_iteration.split(".")[0];
          if (
            parseInt(bugRelease, 10) > this.props.release ||
            parseInt(bugRelease, 10) < this.props.release - 1
          ) {
            continue;
          }

          // find the ticket from the See Also field, if it exists.
          let ticket = "";
          if (bug.see_also) {
            for (const url of bug.see_also) {
              let match = url.match(
                /mozilla-hub.atlassian.net\/browse\/((?:OMC|FXE)-\d+)/
              );
              if (match) {
                ticket = match[1];
                break;
              }
            }
          }
          bug.ticket = ticket;
          item.bugs.push(bug);
        }

        bugsByEngineer.forEach((item, index) => {
          // if there are no bugs for this engineer, remove them from the list
          if (!item.bugs.length) {
            bugsByEngineer.splice(index, 1);
            return;
          }
          // sort bugs by see also field, then points, then by priority
          item.bugs.sort(
            (a, b) =>
              compareTicket(a.ticket, b.ticket) ||
              comparePoints(a.cf_fx_points, b.cf_fx_points) ||
              comparePriority(a.priority, b.priority)
          );
        });

        this.setState({
          loaded: true,
          awaitingNetwork,
          bugsByEngineer,
        });
      }
    );
  }