private gridIsReady()

in web/frontend/src/app/pages/streams/components/stream-view-reverse/stream-view-reverse.component.ts [384:502]


  private gridIsReady(readyEvent: GridReadyEvent) {
    this.readyApi = {...readyEvent};
    
    this.gridService.setTooltipDelay(readyEvent);
    
    const tabToUnique = (tab) =>
      JSON.stringify({id: tab.id, filter: {...tab.filter, silent: null, manuallyChanged: null}});
    
    const getProps = (schema) => {
      return [
        columnsVisibleColumn(),
        {
          headerName: 'Symbol',
          field: 'symbol',
          tooltipField: 'symbol',
          pinned: 'left',
          filter: false,
          sortable: false,
          headerTooltip: 'Symbol',
        },
        {
          headerName: 'Timestamp',
          field: 'timestamp',
          pinned: 'left',
          filter: false,
          sortable: false,
          headerTooltip: 'Timestamp',
          width: 180,
          cellRenderer: (params: ICellRendererParams) => this.gridService.dateFormat(params, params.data?.nanoTime, true),
          tooltipValueGetter: (params: ICellRendererParams) => this.gridService.dateFormat(params, params.data?.nanoTime, true),
        },
        {
          headerName: 'Time',
          field: 'time',
          pinned: 'left',
          filter: false,
          sortable: false,
          headerTooltip: 'Time',
          hide: !this.periodicity,
          cellRenderer: (params: ICellRendererParams) => this.gridService.dateFormat(params, params.data?.nanoTime, false, this.periodicity),
          tooltipValueGetter: (params: ICellRendererParams) => this.gridService.dateFormat(params, params.data?.nanoTime, false, this.periodicity),
        },
        {
          headerName: 'Type',
          field: '$type',
          tooltipField: '$type',
          pinned: 'left',
          filter: false,
          sortable: false,
          headerTooltip: 'Type',
          hide: true,
        },
        ...this.gridService.columnFromSchema(
          this.streamModelsService.getSchemaForColumns(schema.types, schema.all),
          true,
        ),
      ];
    };
    
    this.appStore
      .pipe(
        select(getActiveTab),
        filter(Boolean),
        distinctUntilChanged((prev, current) => tabToUnique(prev) === tabToUnique(current)),
        filter(tab => !!tab['filter'].from),
      )
      .pipe(
        debounceTime(0),
        switchMap((activeTab: TabModel) => {
          this.hideGrid$.next(true);
          this.error$.next(null);
          return this.schemaService.getSchema(activeTab.stream, null, true).pipe(
            map((schema) => [activeTab, schema]),
            take(1),
            catchError(e => {
              this.error$.next(e);
              return of(null);
            }),
            filter(Boolean),
          );
        }),
        tap(
          ([activeTab, schema]: [
            TabModel,
            { types: SchemaTypeModel[]; all: SchemaAllTypeModel[] },
          ]) => {
            this.schema = schema;
            this.messageInfoService.tabChanged();
            this.tabFilter = {...activeTab.filter};
            this.columnsIdVisible = {};
            readyEvent.api.setDatasource(this.dataSource.withTab(activeTab, schema.all));
          },
        ),
        switchMap(([activeTab, schema]) => this.streamsService.getProps(activeTab.stream)),
        tap(streamInfo => {
          if (streamInfo.props.periodicity.type === 'REGULAR') {
            this.periodicity = streamInfo.props.periodicity.milliseconds;
          }
        }),
        switchMap(() =>
          this.dataSource.onLoadedData().pipe(
            take(1),
            map((data) => [getProps(this.schema), data]),
          ),
        ),
        takeUntil(this.destroy$),
      )
      .subscribe(([props, data]) => {
        this.rowData = data;
        readyEvent.api.setColumnDefs(null);
        readyEvent.api.setColumnDefs(props);
        this.columnsIdVisible = {};
        this.columnsVisibleData(readyEvent.columnApi, data);
        timer().subscribe(() => this.hideGrid$.next(false));
      });
    
    this.columnsIdVisible = {};
    this.messageInfoService.setGridApi(this.readyApi);
  }