validateNewVertexType()

in hugegraph-hubble/hubble-fe/src/stores/GraphManagementStore/metadataConfigsStore/vertexTypeStore.ts [385:504]


  validateNewVertexType(category: VertexTypeValidateFields, initial = false) {
    let isReady = true;

    // if initial is true, error message won't be assigned
    // which intends to not pop up error layer
    if (category === 'name') {
      if (!/^[\w\u4e00-\u9fa5]{1,128}$/.test(this.newVertexType.name)) {
        if (this.newVertexType.name.length === 0) {
          !initial &&
            (this.validateNewVertexTypeErrorMessage.name = i18next.t(
              'addition.store.item-is-required'
            ));
          isReady = false;
        } else {
          !initial &&
            (this.validateNewVertexTypeErrorMessage.name = i18next.t(
              'addition.store.rule4'
            ));
          isReady = false;
        }
      } else {
        this.validateNewVertexTypeErrorMessage.name = '';
      }
    }

    if (category === 'properties') {
      if (
        this.newVertexType.properties.length === 0 &&
        this.newVertexType.id_strategy === 'PRIMARY_KEY'
      ) {
        !initial &&
          (this.validateNewVertexTypeErrorMessage.properties = i18next.t(
            'addition.store.item-is-required'
          ));
        isReady = false;
      }
    }

    if (category === 'primaryKeys') {
      if (
        this.newVertexType.id_strategy === 'PRIMARY_KEY' &&
        this.newVertexType.primary_keys.length === 0
      ) {
        !initial &&
          (this.validateNewVertexTypeErrorMessage.primaryKeys = i18next.t(
            'addition.store.item-is-required'
          ));
        isReady = false;
      }
    }

    if (category === 'displayFeilds') {
      if (this.newVertexType.style.display_fields.length === 0) {
        !initial &&
          (this.validateNewVertexTypeErrorMessage.displayFeilds = i18next.t(
            'addition.store.item-is-required'
          ));
        isReady = false;
      }
    }

    if (category === 'propertyIndexes') {
      this.isAddNewPropertyIndexReady = true;

      this.validateNewVertexTypeErrorMessage.propertyIndexes = this.newVertexType.property_indexes.map(
        ({ name, type, fields }) => {
          const validatedPropertyIndex = {
            name: '',
            type: '',
            properties: ''
          };

          if (!/^[\w\u4e00-\u9fa5]{1,128}$/.test(name)) {
            if (!initial) {
              if (name.length !== 0) {
                validatedPropertyIndex.name = i18next.t('addition.store.rule4');
              } else {
                validatedPropertyIndex.name = i18next.t(
                  'addition.store.item-is-required'
                );
              }
            }

            isReady = false;
            this.isAddNewPropertyIndexReady = false;
          } else {
            validatedPropertyIndex.name = '';
          }

          if (type.length === 0) {
            !initial &&
              (validatedPropertyIndex.type = i18next.t(
                'addition.store.item-is-required'
              ));
            isReady = false;
            this.isAddNewPropertyIndexReady = false;
          } else {
            validatedPropertyIndex.type = '';
          }

          if (Array.isArray(fields)) {
            if (fields.length === 0) {
              !initial &&
                (validatedPropertyIndex.properties = i18next.t(
                  'addition.store.item-is-required'
                ));
              isReady = false;
              this.isAddNewPropertyIndexReady = false;
            }
          } else {
            validatedPropertyIndex.properties = '';
          }

          return validatedPropertyIndex;
        }
      );
    }

    return isReady;
  }