<commit_before>import {Component, OnDestroy, OnInit} from '@angular/core';

import {
  Cluster,
  ClusterService,
  ClusterStatus,
} from 'generated';

@Component({
  styleUrls: ['../../styles/buttons.css',
              '../../styles/cards.css',
              '../../styles/headers.css',
              '../../styles/inputs.css',
              '../../styles/errors.css',
              './component.css'],
  templateUrl: './component.html',
})
export class SettingsComponent implements OnInit, OnDestroy {
  private pollClusterTimer: NodeJS.Timer;
  cluster: Cluster;
  clusterDeletionFailure = true;
  resetClusterModal = false;
  resetClusterPending = false;

  constructor(private clusterService: ClusterService) {}

  ngOnInit(): void {
    this.pollCluster();
  }

  ngOnDestroy(): void {
    if (this.pollClusterTimer) {
      clearTimeout(this.pollClusterTimer);
    }
  }

  private pollCluster(): void {
    const repoll = () => {
      this.pollClusterTimer = setTimeout(() => this.pollCluster(), 15000);
    };
    this.clusterService.listClusters()
      .subscribe((resp) => {
        const cluster = resp.defaultCluster;
        if (cluster.status === ClusterStatus.Running ||
            cluster.status === ClusterStatus.Error) {
          this.cluster = cluster;
          return;
        }
        repoll();
      }, () => {
        // Also retry on errors.
        repoll();
      });
  }

  openResetClusterModal(): void {
    this.resetClusterPending = false;
    this.resetClusterModal = true;
    this.clusterDeletionFailure = false;
  }

  closeResetClusterModal(): void {
    this.resetClusterModal = false;
  }

  resetCluster(): void {
    this.clusterService.deleteCluster(
      this.cluster.clusterNamespace, this.cluster.clusterName).subscribe(
        () => {
          this.cluster = null;
          this.resetClusterPending = false;
          this.closeResetClusterModal();
          this.pollCluster();
        },
        /* onError */ () => {
        this.resetClusterPending = false;
        this.clusterDeletionFailure = true;
        },
        /* onCompleted */ () => {
          this.resetClusterPending = false;
        });
  }
}
<commit_msg>[RW-1535][risk=no] Relax cluster state requirements for clicking "reset" (#1446)<commit_after>import {Component, OnDestroy, OnInit} from '@angular/core';

import {
  Cluster,
  ClusterService,
  ClusterStatus,
} from 'generated';

@Component({
  styleUrls: ['../../styles/buttons.css',
              '../../styles/cards.css',
              '../../styles/headers.css',
              '../../styles/inputs.css',
              '../../styles/errors.css',
              './component.css'],
  templateUrl: './component.html',
})
export class SettingsComponent implements OnInit, OnDestroy {
  private static readonly TRANSITIONAL_STATUSES = new Set<ClusterStatus>([
    ClusterStatus.Deleting, ClusterStatus.Creating,
    ClusterStatus.Starting, ClusterStatus.Stopping
  ]);

  private pollClusterTimer: NodeJS.Timer;
  cluster: Cluster;
  clusterDeletionFailure = true;
  resetClusterModal = false;
  resetClusterPending = false;

  constructor(private clusterService: ClusterService) {}

  ngOnInit(): void {
    this.pollCluster();
  }

  ngOnDestroy(): void {
    if (this.pollClusterTimer) {
      clearTimeout(this.pollClusterTimer);
    }
  }

  private pollCluster(): void {
    const repoll = () => {
      this.pollClusterTimer = setTimeout(() => this.pollCluster(), 15000);
    };
    this.clusterService.listClusters()
      .subscribe((resp) => {
        const cluster = resp.defaultCluster;
        if (SettingsComponent.TRANSITIONAL_STATUSES.has(cluster.status)) {
          repoll();
          return;
        }
        this.cluster = cluster;
      }, () => {
        // Also retry on errors.
        repoll();
      });
  }

  openResetClusterModal(): void {
    this.resetClusterPending = false;
    this.resetClusterModal = true;
    this.clusterDeletionFailure = false;
  }

  closeResetClusterModal(): void {
    this.resetClusterModal = false;
  }

  resetCluster(): void {
    this.clusterService.deleteCluster(
      this.cluster.clusterNamespace, this.cluster.clusterName).subscribe(
        () => {
          this.cluster = null;
          this.resetClusterPending = false;
          this.closeResetClusterModal();
          this.pollCluster();
        },
        /* onError */ () => {
        this.resetClusterPending = false;
        this.clusterDeletionFailure = true;
        },
        /* onCompleted */ () => {
          this.resetClusterPending = false;
        });
  }
}

{'fraction_non_alphanumeric': 0.1386160227024667, 'fraction_numerical': 0.003929273084479371, 'mean_word_length': 2.3940740740740742, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2478263', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1259, 'n_words': 233}