Пример #1
0
 /**
  * Find index pattern by its title, of if not given, gets default
  * @param {string} [index]
  * @returns {Promise<string>} index id
  */
 async findIndex(index) {
   let idxObj;
   if (index) {
     idxObj = await findObjectByTitle(savedObjectsClient, 'index-pattern', index);
     if (!idxObj) throw new Error(`Index "${index}" not found`);
   } else {
     idxObj = await this._vis.API.indexPatterns.getDefault();
     if (!idxObj) throw new Error('Unable to find default index');
   }
   return idxObj.id;
 }
Пример #2
0
    /**
     * Returns a promise that resolves to true if either the title is unique, or if the user confirmed they
     * wished to save the duplicate title.  Promise is rejected if the user rejects the confirmation.
     */
    warnIfDuplicateTitle() {
      return findObjectByTitle(savedObjectsClient, type, this.title)
        .then(duplicate => {
          if (!duplicate) return false;
          if (duplicate.id === this.id) return false;

          const confirmMessage =
            `An index pattern with the title '${this.title}' already exists.`;

          return confirmModalPromise(confirmMessage, { confirmButtonText: 'Edit existing pattern' })
            .then(() => {
              kbnUrl.change('/management/kibana/indices/{{id}}', { id: duplicate.id });
              return true;
            })
            .catch(() => {
              throw new IndexPatternAlreadyExists(this.title);
            });
        });
    }
Пример #3
0
    const warnIfDuplicateTitle = () => {
      // Don't warn if the user isn't updating the title, otherwise that would become very annoying to have
      // to confirm the save every time, except when copyOnSave is true, then we do want to check.
      if (this.title === this.lastSavedTitle && !this.copyOnSave) {
        return Promise.resolve();
      }

      return findObjectByTitle(savedObjectsClient, this.getEsType(), this.title)
        .then(duplicate => {
          if (!duplicate) return true;
          if (duplicate.id === this.id) return true;

          const confirmMessage =
            `A ${this.getDisplayName()} with the title '${this.title}' already exists. Would you like to save anyway?`;

          return confirmModalPromise(confirmMessage, { confirmButtonText: `Save ${this.getDisplayName()}` })
            .catch(() => Promise.reject(new Error(SAVE_DUPLICATE_REJECTED)));
        });
    };