All files / addon/components freestyle-prop-types.js

34.78% Statements 8/23
0% Branches 0/12
50% Functions 1/2
38.1% Lines 8/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44    1x           2x 2x 2x 2x 2x                                             2x         2x      
import Component from '@ember/component';
import layout from '../templates/components/freestyle-prop-types';
const definedTypes = ['arrayOf', 'bool', 'instanceOf', 'number', 'oneOf', 'string', 'date'];
 
export default Component.extend({
  layout,
  options: null,
  didReceiveAttrs() {
    let propDefinitions = this.get('propDefinitions');
    let properties = [];
    let componentName = '';
    let type = null;
    for (var key in propDefinitions) {
      if (propDefinitions.hasOwnProperty(key)) {
        componentName = 'freestyle-prop-types/-default';
        if(typeof(propDefinitions[key].type) === 'object') {
          type = propDefinitions[key].type;
        } else if (typeof(propDefinitions[key].type) === 'function') {
          type = propDefinitions[key].type();
        } else {
          window.alert("Unknown type: " + type + " at key " + key + ". Double check your PropTypes");
        }
        if (definedTypes.includes(type.type)) {
          componentName = `freestyle-prop-types/-${type.type.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()}`;
        }
        properties.push({
          componentName: componentName,
          description: propDefinitions[key].description,
          default: propDefinitions[key].default,
          name: key,
          required: type.required,
          type: type
        });
      }
    }
    properties.sort((a, b) => {
      if (a.name < b.name) return -1;
      if (a.name > b.name) return 1;
      return 0;
    });
    this.set('options', properties);
  },
});