<commit_before>import { Component, ChangeDetectorRef } from '@angular/core';
import { OAuthAppListItem } from './oauth-apps.component';
import { OAuthAppStore } from '../../store/oauthApp/oauth-app.store';
import { OAuthApp, OAuthApps } from '../../model';
import { ModalService } from '../../common/modal/modal.service';

@Component({
  selector: 'syndesis-oauth-app-modal',
  templateUrl: './oauth-app-modal.component.html',
})
export class OAuthAppModalComponent {

  // Holds the candidate for clearing credentials
  item: OAuthAppListItem;
  constructor(
    public store: OAuthAppStore,
    public detector: ChangeDetectorRef,
    private modalService: ModalService,
  ) {}

  show(item: OAuthAppListItem) {
    this.item = item;
    this.modalService.show()
      .then(result => result
        ? this.removeCredentials()
          // TODO toast notification
          .then(app => this.item.client = app)
          .catch(error => {})
          .then(_ => this.detector.markForCheck())
        : undefined);
  }

  // Clear the store credentials for the selected oauth app
  removeCredentials() {
    const app = this.item.client;
    app['clientId'] = '';
    app['clientSecret'] = '';
    return this.store.update(app).take(1).toPromise();
  }
}<commit_msg>fix(settings): Clone client settings before update to rollback on error<commit_after>import { Component, ChangeDetectorRef } from '@angular/core';
import { OAuthAppListItem } from './oauth-apps.component';
import { OAuthAppStore } from '../../store/oauthApp/oauth-app.store';
import { OAuthApp, OAuthApps } from '../../model';
import { ModalService } from '../../common/modal/modal.service';

@Component({
  selector: 'syndesis-oauth-app-modal',
  templateUrl: './oauth-app-modal.component.html',
})
export class OAuthAppModalComponent {

  // Holds the candidate for clearing credentials
  item: OAuthAppListItem;
  constructor(
    public store: OAuthAppStore,
    public detector: ChangeDetectorRef,
    private modalService: ModalService,
  ) {}

  show(item: OAuthAppListItem) {
    this.item = item;
    this.modalService.show()
      .then(result => result
        ? this.removeCredentials()
          // TODO toast notification
          .then(app => this.item.client = app)
          .catch(error => {})
          .then(_ => this.detector.markForCheck())
        : undefined);
  }

  // Clear the store credentials for the selected oauth app
  removeCredentials() {
    const app = { ...this.item.client, clientId: '', clientSecret: '' };
    return this.store.update(app).take(1).toPromise();
  }
}
{'fraction_non_alphanumeric': 0.1436893203883495, 'fraction_numerical': 0.0007766990291262136, 'mean_word_length': 3.1886178861788617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6740358', 'n_tokens_mistral': 760, 'n_tokens_neox': 764, 'n_words': 175}