packages/strapi-plugin-content-type-builder/services/schema-builder/component-builder.js
/**
     * create a component in the tmpComponent map
     */
create a component in the tmpComponent map
create a component in the tmpComponent map
editComponent(infos) {
      const { uid } = infos;
      if (!this.components.has(uid)) {
        throw new Error('component.notFound');
      }
      const component = this.components.get(uid);
      const [, nameUID] = uid.split('.');
      const newCategory = nameToSlug(infos.category);
      const newUID = `${newCategory}.${nameUID}`;
      if (newUID !== uid && this.components.has(newUID)) {
        throw new Error('component.edit.alreadyExists');
      }
      const newDir = path.join(strapi.dir, 'components', newCategory);
      const oldAttributes = component.schema.attributes;
      const newAttributes = _.omitBy(infos.attributes, (attr, key) => {
        return _.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);
      });
      component
        .setUID(newUID)
        .setDir(newDir)
        .set('connection', infos.connection)
        .set('collectionName', infos.collectionName)
        .set(['info', 'name'], infos.name)
        .set(['info', 'icon'], infos.icon)
        .set(['info', 'description'], infos.description)
        .setAttributes(this.convertAttributes(newAttributes));
      if (newUID !== uid) {
        this.components.forEach(compo => {
          compo.updateComponent(uid, newUID);
        });
        this.contentTypes.forEach(ct => {
          ct.updateComponent(uid, newUID);
        });
      }
      return component;
    }
editComponent ( infos ) { const { uid } = infos ; if ( ! this . components . has ( uid ) ) { throw new Error ( 'component.notFound' ) ; } const component = this . components . get ( uid ) ; const [ , nameUID ] = uid . split ( '.' ) ; const newCategory = nameToSlug ( infos . category ) ; const newUID = ` ${ newCategory } ${ nameUID } ` ; if ( newUID !== uid && this . components . has ( newUID ) ) { throw new Error ( 'component.edit.alreadyExists' ) ; } const newDir = path . join ( strapi . dir , 'components' , newCategory ) ; const oldAttributes = component . schema . attributes ; const newAttributes = _ . omitBy ( infos . attributes , ( attr , key ) => { return _ . has ( oldAttributes , key ) && ! isConfigurable ( oldAttributes [ key ] ) ; } ) ; component . setUID ( newUID ) . setDir ( newDir ) . set ( 'connection' , infos . connection ) . set ( 'collectionName' , infos . collectionName ) . set ( [ 'info' , 'name' ] , infos . name ) . set ( [ 'info' , 'icon' ] , infos . icon ) . set ( [ 'info' , 'description' ] , infos . description ) . setAttributes ( this . convertAttributes ( newAttributes ) ) ; if ( newUID !== uid ) { this . components . forEach ( compo => { compo . updateComponent ( uid , newUID ) ; } ) ; this . contentTypes . forEach ( ct => { ct . updateComponent ( uid , newUID ) ; } ) ; } return component ; }
create a component in the tmpComponent map
create a component in the tmpComponent map