private prefetchAndRender()

in src/Explorer/Tables/DataTable/TableEntityListViewModel.ts [413:493]


  private prefetchAndRender(
    tableQuery: Entities.ITableQuery,
    tablePageStartIndex: number,
    tablePageSize: number,
    downloadSize: number,
    draw: number,
    renderCallBack: Function,
    oSettings: any,
    columnSortOrder: any,
  ): void {
    this.queryErrorMessage(null);
    if (this.cache.serverCallInProgress) {
      return;
    }
    this.prefetchData(tableQuery, downloadSize, /* currentRetry */ 0)
      .then((result: IListTableEntitiesSegmentedResult) => {
        if (!result) {
          return;
        }

        var entities = this.cache.data;
        if (userContext.apiType === "Cassandra" && DataTableUtilities.checkForDefaultHeader(this.headers)) {
          (<CassandraAPIDataClient>this.queryTablesTab.container.tableDataClient)
            .getTableSchema(this.queryTablesTab.collection)
            .then((headers: CassandraTableKey[]) => {
              this.updateHeaders(
                headers.map((header) => header.property),
                true,
              );
            });
        } else {
          var selectedHeadersUnion: string[] = DataTableUtilities.getPropertyIntersectionFromTableEntities(
            entities,
            userContext.apiType === "Cassandra",
          );
          var newHeaders: string[] = _.difference(selectedHeadersUnion, this.headers);
          if (newHeaders.length > 0) {
            // Any new columns found will be added into headers array, which will trigger a re-render of the DataTable.
            // So there is no need to call it here.
            this.updateHeaders(selectedHeadersUnion, /* notifyColumnChanges */ true);
          } else {
            if (columnSortOrder) {
              this.sortColumns(columnSortOrder, oSettings);
            }
            this.renderPage(renderCallBack, draw, tablePageStartIndex, tablePageSize, oSettings);
          }
        }

        if (result.ExceedMaximumRetries) {
          var message: string = "We are having trouble getting your data. Please try again."; // localize
        }
      })
      .catch((error: any) => {
        const parsedErrors = parseError(error);
        var errors = parsedErrors.map((error) => {
          return <ViewModels.QueryError>{
            message: error.message,
            start: error.location ? error.location.start : undefined,
            end: error.location ? error.location.end : undefined,
            code: error.code,
            severity: error.severity,
          };
        });
        this.queryErrorMessage(errors[0].message);
        if (this.queryTablesTab.onLoadStartKey != null && this.queryTablesTab.onLoadStartKey != undefined) {
          TelemetryProcessor.traceFailure(
            Action.Tab,
            {
              databaseName: this.queryTablesTab.collection.databaseId,
              collectionName: this.queryTablesTab.collection.id(),
              dataExplorerArea: Areas.Tab,
              tabTitle: this.queryTablesTab.tabTitle(),
              error: error,
            },
            this.queryTablesTab.onLoadStartKey,
          );
          this.queryTablesTab.onLoadStartKey = null;
        }
        DataTableUtilities.turnOffProgressIndicator();
      });
  }