<commit_before>import {Component, EventEmitter, Output} from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {ActivatedRoute} from '@angular/router';

import {ReviewStateService} from '../review-state.service';

import {
  AnnotationType,
  CohortAnnotationDefinition,
  CohortAnnotationDefinitionService,
  ModifyCohortAnnotationDefinitionRequest,
} from 'generated';

@Component({
  selector: 'app-set-annotation-create',
  templateUrl: './set-annotation-create.component.html',
  styleUrls: ['./set-annotation-create.component.css']
})
export class SetAnnotationCreateComponent {
  readonly datatypes = [{
    value: AnnotationType.STRING,
    displayName: 'Text'
  }, {
    value: AnnotationType.ENUM,
    displayName: 'Enumeration'
  }, {
    value: AnnotationType.DATE,
    displayName: 'Date'
  }, {
    value: AnnotationType.BOOLEAN,
    displayName: 'Boolean'
  }, {
    value: AnnotationType.INTEGER,
    displayName: 'Integer'
  }];

  @Output() onFinish = new EventEmitter<boolean>();
  posting = false;
  enumValues = <string[]>[];
 annotationOptions = '';

  form = new FormGroup({
    name: new FormControl('', Validators.required),
    kind: new FormControl('', Validators.required),
    addValue: new FormControl(),
  });

  get name() { return this.form.get('name'); }
  get kind() { return this.form.get('kind'); }
  get addValue() { return this.form.get('addValue'); }

  constructor(
    private annotationAPI: CohortAnnotationDefinitionService,
    private state: ReviewStateService,
    private route: ActivatedRoute,
  ) {}

  create(): void {
    this.posting = true;
    const {ns, wsid, cid} = this.route.snapshot.params;

    const request = <CohortAnnotationDefinition>{
      cohortId: cid,
      columnName: this.name.value,
      annotationType: this.kind.value,
    };

    if (this.isEnum) {
      const val = this.addValue.value;
      const hasVal = this.enumValues.includes(val);
      if (val && val !== '' && !hasVal) {
        request.enumValues = [...this.enumValues, val];
        this.addValue.reset();
      }
    }

    this.annotationAPI
      .createCohortAnnotationDefinition(ns, wsid, cid, request)
      .switchMap(_ => this.annotationAPI
        .getCohortAnnotationDefinitions(ns, wsid, cid)
        .pluck('items'))
      .do((defns: CohortAnnotationDefinition[]) =>
        this.state.annotationDefinitions.next(defns))
      .subscribe(_ => {
          this.open = false;
        this.posting = false;
          this.annotationOptions = '';
          // this.isEnum = false;
          this.kind.patchValue('');
          this.enumValues.length = 0;
         this.name.patchValue('');
        this.onFinish.emit(true);
      });
  }
   get open() {
    return this.state.annotationManagerOpen.getValue();
  }

  set open(value: boolean) {
      this.state.annotationManagerOpen.next(value);
  }

  cancel() {
    this.onFinish.emit(true);
  }

  addEnumValue() {
    const val = this.addValue.value;
    const hasVal = this.enumValues.includes(val);
    if (val && val !== '' && !hasVal) {<commit_msg>[RW-1556][risk = no]P2] When creating a list of enum values -> list is empty (#1429)<commit_after>import {Component, EventEmitter, Output} from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {ActivatedRoute} from '@angular/router';

import {ReviewStateService} from '../review-state.service';

import {
  AnnotationType,
  CohortAnnotationDefinition,
  CohortAnnotationDefinitionService,
  ModifyCohortAnnotationDefinitionRequest,
} from 'generated';

@Component({
  selector: 'app-set-annotation-create',
  templateUrl: './set-annotation-create.component.html',
  styleUrls: ['./set-annotation-create.component.css']
})
export class SetAnnotationCreateComponent {
  readonly datatypes = [{
    value: AnnotationType.STRING,
    displayName: 'Text'
  }, {
    value: AnnotationType.ENUM,
    displayName: 'Enumeration'
  }, {
    value: AnnotationType.DATE,
    displayName: 'Date'
  }, {
    value: AnnotationType.BOOLEAN,
    displayName: 'Boolean'
  }, {
    value: AnnotationType.INTEGER,
    displayName: 'Integer'
  }];

  @Output() onFinish = new EventEmitter<boolean>();
  posting = false;
  enumValues = <string[]>[];
 annotationOptions = '';

  form = new FormGroup({
    name: new FormControl('', Validators.required),
    kind: new FormControl('', Validators.required),
    addValue: new FormControl(),
  });

  get name() { return this.form.get('name'); }
  get kind() { return this.form.get('kind'); }
  get addValue() { return this.form.get('addValue'); }

  constructor(
    private annotationAPI: CohortAnnotationDefinitionService,
    private state: ReviewStateService,
    private route: ActivatedRoute,
  ) {}

  create(): void {
    this.posting = true;
    const {ns, wsid, cid} = this.route.snapshot.params;

    const request = <CohortAnnotationDefinition>{
      cohortId: cid,
      columnName: this.name.value,
      annotationType: this.kind.value,
    };

    if (this.isEnum) {
      const val = this.addValue.value;
      const hasVal = this.enumValues.includes(val);
      if (val && val !== '' && !hasVal) {
        request.enumValues = [...this.enumValues, val];
      } else {
        request.enumValues = [...this.enumValues];
      }
    }

    this.annotationAPI
      .createCohortAnnotationDefinition(ns, wsid, cid, request)
      .switchMap(_ => this.annotationAPI
        .getCohortAnnotationDefinitions(ns, wsid, cid)
        .pluck('items'))
      .do((defns: CohortAnnotationDefinition[]) =>
        this.state.annotationDefinitions.next(defns))
      .subscribe(_ => {
          this.open = false;
        this.posting = false;
          this.annotationOptions = '';
          // this.isEnum = false;
          this.kind.patchValue('');
          this.enumValues.length = 0;
         this.name.patchValue('');
        this.onFinish.emit(true);
        this.addValue.reset();
      });
  }
   get open() {
    return this.state.annotationManagerOpen.getValue();
  }

  set open(value: boolean) {
      this.state.annotationManagerOpen.next(value);
  }

  cancel() {
    this.onFinish.emit(true);
  }

  addEnumValue() {
    const val = this.addValue.value;
    const hasVal = this.enumValues.includes(val);
    if (val && val !== '' && !hasVal) {
{'fraction_non_alphanumeric': 0.14227064582346438, 'fraction_numerical': 0.0017369335228169904, 'mean_word_length': 3.1836195508586527, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 16, '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': '4673545', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1918, 'n_words': 387}