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

import { cloneDeep } from 'lodash';
import {
  Filter,
  FilterEvent,
  SortEvent,
  SortField
} from 'patternfly-ng';
import { Observable, Subscription } from 'rxjs';

import { DeploymentsToolbarComponent } from '../deployments-toolbar/deployments-toolbar.component';
import { Environment } from '../models/environment';

@Component({
  selector: 'deployments-apps',
  templateUrl: 'deployments-apps.component.html'
})
export class DeploymentsAppsComponent implements OnInit, OnDestroy {

  @Input() public applications: Observable<string[]>;
  @Input() public environments: Observable<Environment[]>;
  @Input() public spaceId: Observable<string>;

  public filteredApplicationsList: string[];
  public resultsCount: number = 0;

  private applicationsList: string[];
  private currentFilters: Filter[];
  private currentSortField: SortField;
  private isAscendingSort: boolean = true;
  private subscriptions: Subscription[] = [];

  public constructor() { }

  ngOnInit(): void {
    this.subscriptions.push(this.applications.subscribe(applications => {
      this.applicationsList = applications;
      this.applyFilters();
    }));
  }

  ngOnDestroy(): void {
    this.subscriptions.forEach((sub: Subscription) => sub.unsubscribe());
  }

  filterChange($event: FilterEvent): void {
    this.currentFilters = $event.appliedFilters;
    this.applyFilters();
  }

  sortChange($event: SortEvent): void {
    this.currentSortField = $event.field;
    this.isAscendingSort = $event.isAscending;

    this.filteredApplicationsList.sort((a: string, b: string) => {
      let v: number = a.localeCompare(b);
      if (!this.isAscendingSort) {
        v = v * -1;
      }

      return v;
    });
  }

  applyFilters(): void {
    this.filteredApplicationsList = [];
    if (this.currentFilters && this.currentFilters.length > 0) {<commit_msg>fix(deployments): fix sorting and filtering toolbar<commit_after>import {
  Component,
  Input,
  OnDestroy,
  OnInit
} from '@angular/core';

import { cloneDeep } from 'lodash';
import {
  Filter,
  FilterEvent,
  SortEvent,
  SortField
} from 'patternfly-ng';
import { Observable, Subscription } from 'rxjs';

import { DeploymentsToolbarComponent } from '../deployments-toolbar/deployments-toolbar.component';
import { Environment } from '../models/environment';

@Component({
  selector: 'deployments-apps',
  templateUrl: 'deployments-apps.component.html'
})
export class DeploymentsAppsComponent implements OnInit, OnDestroy {

  @Input() public applications: Observable<string[]>;
  @Input() public environments: Observable<Environment[]>;
  @Input() public spaceId: Observable<string>;

  public filteredApplicationsList: string[];
  public resultsCount: number = 0;

  private applicationsList: string[];
  private currentFilters: Filter[];
  private currentSortField: SortField;
  private isAscendingSort: boolean = true;
  private subscriptions: Subscription[] = [];

  public constructor() { }

  ngOnInit(): void {
    this.subscriptions.push(this.applications.subscribe(applications => {
      this.applicationsList = applications;
      this.applyFilters();
    }));
  }

  ngOnDestroy(): void {
    this.subscriptions.forEach((sub: Subscription) => sub.unsubscribe());
  }

  filterChange($event: FilterEvent): void {
    this.currentFilters = $event.appliedFilters;
    this.applyFilters();

    this.sortApplications();
  }

  sortChange($event: SortEvent): void {
    this.currentSortField = $event.field;
    this.isAscendingSort = $event.isAscending;

    this.sortApplications();
  }

  sortApplications(): void {
    this.filteredApplicationsList.sort((a: string, b: string) => {
      let v: number = a.localeCompare(b);
      if (!this.isAscendingSort) {
        v = v * -1;
      }

      return v;
    });
  }

  applyFilters(): void {
    this.filteredApplicationsList = [];
    if (this.currentFilters && this.currentFilters.length > 0) {
{'fraction_non_alphanumeric': 0.13046738315421144, 'fraction_numerical': 0.0014996250937265683, 'mean_word_length': 4.104591836734694, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '6615140', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1157, 'n_words': 259}