<commit_before>import Component from '@ember/component';
import ArrayProxy from '@ember/array/proxy';
import { computed } from '@ember/object';
import { gt } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { Promise } from 'rsvp';
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';

export default Component.extend({
  currentUser: service(),
  store: service(),

  classNameBindings: [':unassigned-students-summary', ':small-component', 'alert'],
  tagName: 'div',

  schoolId: null,
  schools: null,

  alert: gt('unassignedStudentsProxy.length', 0),

  selectedSchool: computed('currentUser', 'schoolId', async function() {
    const schools = this.schools;
    const currentUser = this.currentUser;
    const schoolId = this.schoolId;

    if (schoolId) {
      return schools.findBy('id', schoolId);
    }
    const user = await currentUser.get('model');
    const school = await user.get('school');
    const defaultSchool = schools.findBy('id', school.get('id'));
    if (defaultSchool) {
      return defaultSchool;
    }

    return schools.get('firstObject');
  }),

  unassignedStudents: computed('selectedSchool', function() {
    return new Promise(resolve => {
      this.selectedSchool.then(school => {
        this.store.query('user', {
          filters: {
            roles: [4],
            school: school.get('id'),
            cohorts: null,
            enabled: true
          }
        }).then(students => {
          resolve(students);
        });
      });
    });
  }),

  //temporary solution until the classNameBindings can be promise aware
  unassignedStudentsProxy: computed('unassignedStudents', function() {
    let ap = ArrayProxy.extend(PromiseProxyMixin);
    return ap.create({
      promise: this.unassignedStudents
    });
  }),

  actions: {
    changeSelectedSchool(schoolId) {
      this.set('schoolId', schoolId);
    }
  }
});
<commit_msg>promise refactor unassigned-students-summary component<commit_after>import Component from '@ember/component';
import ArrayProxy from '@ember/array/proxy';
import { computed } from '@ember/object';
import { gt } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';

export default Component.extend({
  currentUser: service(),
  store: service(),

  classNameBindings: [':unassigned-students-summary', ':small-component', 'alert'],
  tagName: 'div',

  schoolId: null,
  schools: null,

  alert: gt('unassignedStudentsProxy.length', 0),

  selectedSchool: computed('currentUser', 'schoolId', async function() {
    const schools = this.schools;
    const currentUser = this.currentUser;
    const schoolId = this.schoolId;

    if (schoolId) {
      return schools.findBy('id', schoolId);
    }
    const user = await currentUser.get('model');
    const school = await user.get('school');
    const defaultSchool = schools.findBy('id', school.get('id'));
    if (defaultSchool) {
      return defaultSchool;
    }

    return schools.get('firstObject');
  }),

  unassignedStudents: computed('selectedSchool', async function() {
    const school = await this.selectedSchool;
    return await this.store.query('user', {
      filters: {
        cohorts: null,
        enabled: true,
        roles: [4],
        school: school.id
      }
    });
  }),

  //temporary solution until the classNameBindings can be promise aware
  unassignedStudentsProxy: computed('unassignedStudents', function() {
    let ap = ArrayProxy.extend(PromiseProxyMixin);
    return ap.create({
      promise: this.unassignedStudents
    });
  }),

  actions: {
    changeSelectedSchool(schoolId) {
      this.set('schoolId', schoolId);
    }
  }
});

{'fraction_non_alphanumeric': 0.13673849428039372, 'fraction_numerical': 0.0010641127959563714, 'mean_word_length': 3.4339622641509435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4033249', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1073, 'n_words': 258}