SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
733 stars 379 forks source link

Refactoring / review feedback (see content of the task) #13286

Open Larisa-Staroverova opened 3 years ago

Larisa-Staroverova commented 3 years ago

this task could / should be done in the major release

Larisa-Staroverova commented 3 years ago

@WeizhengSap suggested to make the following refactoring:

/**
* Retrieves a unique key for config attribute to be sent to configurator.
*
* @return {string} - Generated attribute ID
*/
get attributeId(): string {
    return this.configAttributeTypeUtilsService.createAttributeIdForConfigurator(
      this.attribute
    );
}
/**
   * Retrieves unique key for configurator attribute on the UI.
   *
   * @return {string} - Generated attribute UI key
   */
  get attributeUiKey(): string {
    return this.configAttributeTypeUtilsService.createAttributeUiKey(
      'label',
      this.attribute.name
    );
  }
  /**
   * Retrieves a certain conflict link key depending on the current group type for translation.
   *
   * @param groupType {Configurator.GroupType}- group type
   * @return {string} - the conflict link key
   */
  getConflictMessageKey(groupType: Configurator.GroupType): string {
    return groupType === Configurator.GroupType.CONFLICT_GROUP
      ? 'configurator.conflict.viewConfigurationDetails'
      : 'configurator.conflict.viewConflictDetails';
  }
  /**
   * Get code from attribute.
   * The code is not a mandatory attribute (since not available for VC flavour),
   * still it is mandatory in the context of CPQ. Calling this method therefore only
   * makes sense when CPQ is active. In case the method is called in the wrong context, an exception will
   * be thrown.
   *
   * @param {Configurator.Attribute} attribute - Attribute
   * @returns {number} Attribute code
   */
  getAttributeCode(attribute: Configurator.Attribute): number {
    return this.configAttributeTypeUtilsService.getAttributeCode(attribute);
  }