doCreate() {
    const { values, sendResource, isEditing, name } = this.props;
    const postObject = getStateDataOnly(this.state);

    if (!postObject.lenses.length) {
      this.showError('Please enter a valid lens.');
    } else if (!postObject.subjects.length) {
      this.showError('Please enter a valid subject.');
    } else if (!postObject.name.length) {
      this.showError('Please enter a name for this perspective.');
    } else {

      // check if lens field is uid. if not, need to get uid for lens name
      const regexpUUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
      if (!regexpUUID.test(postObject.lenses)) {
        let lens = values.lenses.filter((_lens) => {
          return _lens.name === postObject.lenses;
        });

        if (!lens.length) {
          this.showError('Please enter a valid lens name. No lens with name '
            + postObject.lenses + ' found');
        }

        postObject.lenses = lens[ZERO].id;
      }

      // for create perspectives, rename key lenses --> lensId,
      // and perspectives --> name. Start with deep copy values obj
      postObject.lensId = postObject.lenses;
      postObject.rootSubject = postObject.subjects;
      delete postObject.lenses;
      delete postObject.subjects;

      // go to created perspective page
      let method = 'POST'; // default
      postObject.url = '/v1/perspectives';

      if (isEditing) {
        method = 'PUT';

        // use the original perspective name
        postObject.url = postObject.url + '/' + name;
      }

      sendResource(method, postObject, this.showError);
    }
  }
// POST or PUT, depending on state
POST or PUT, depending on state
POST or PUT depending on state
doCreate() {
    const { values, sendResource, isEditing, name } = this.props;
    const postObject = getStateDataOnly(this.state);
    if (!postObject.lenses.length) {
      this.showError('Please enter a valid lens.');
    } else if (!postObject.subjects.length) {
      this.showError('Please enter a valid subject.');
    } else if (!postObject.name.length) {
      this.showError('Please enter a name for this perspective.');
    } else {
      const regexpUUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
      if (!regexpUUID.test(postObject.lenses)) {
        let lens = values.lenses.filter((_lens) => {
          return _lens.name === postObject.lenses;
        });
        if (!lens.length) {
          this.showError('Please enter a valid lens name. No lens with name '
            + postObject.lenses + ' found');
        }
        postObject.lenses = lens[ZERO].id;
      }
      postObject.lensId = postObject.lenses;
      postObject.rootSubject = postObject.subjects;
      delete postObject.lenses;
      delete postObject.subjects;
      let method = 'POST'; 
      postObject.url = '/v1/perspectives';
      if (isEditing) {
        method = 'PUT';
        postObject.url = postObject.url + '/' + name;
      }
      sendResource(method, postObject, this.showError);
    }
  }
doCreate ( ) { const { values , sendResource , isEditing , name } = this . props ; const postObject = getStateDataOnly ( this . state ) ; if ( ! postObject . lenses . length ) { this . showError ( 'Please enter a valid lens.' ) ; } else if ( ! postObject . subjects . length ) { this . showError ( 'Please enter a valid subject.' ) ; } else if ( ! postObject . name . length ) { this . showError ( 'Please enter a name for this perspective.' ) ; } else { const regexpUUID = / ^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ / i ; if ( ! regexpUUID . test ( postObject . lenses ) ) { let lens = values . lenses . filter ( ( _lens ) => { return _lens . name === postObject . lenses ; } ) ; if ( ! lens . length ) { this . showError ( 'Please enter a valid lens name. No lens with name ' + postObject . lenses + ' found' ) ; } postObject . lenses = lens [ ZERO ] . id ; } postObject . lensId = postObject . lenses ; postObject . rootSubject = postObject . subjects ; delete postObject . lenses ; delete postObject . subjects ; let method = 'POST' ; postObject . url = '/v1/perspectives' ; if ( isEditing ) { method = 'PUT' ; postObject . url = postObject . url + '/' + name ; } sendResource ( method , postObject , this . showError ) ; } }
POST or PUT, depending on state
POST or PUT depending on state
// check if lens field is uid. if not, need to get uid for lens name // for create perspectives, rename key lenses --> lensId, // and perspectives --> name. Start with deep copy values obj // go to created perspective page // default // use the original perspective name