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

import {AddDataUrlType, servicesSupportedByUrl} from './types/url.type';
import {AddDataUrlValues} from './add-data-url-values';
import {HsAddDataCommonService} from '../common/common.service';
import {HsAddDataOwsService} from './add-data-ows.service';
import {HsAddDataService} from '../add-data.service';
import {HsConfig} from '../../../config.service';
import {HsLanguageService} from '../../language/language.service';
import {HsLayoutService} from '../../layout/layout.service';
import {HsShareUrlService} from '../../permalink/share-url.service';

@Component({
  selector: 'hs-add-data-url',
  templateUrl: './add-data-url.component.html',
})
export class HsAddDataUrlComponent {
  typeSelected: AddDataUrlType;
  types: {id: AddDataUrlType; text: string}[];

  constructor(
    public hsConfig: HsConfig,
    public hsLanguageService: HsLanguageService,
    public hsShareUrlService: HsShareUrlService,
    public hsAddDataService: HsAddDataService,
    public hsLayoutService: HsLayoutService,
    public hsAddDataCommonService: HsAddDataCommonService,
    public hsAddDataOwsService: HsAddDataOwsService
  ) {
    if (Array.isArray(this.hsConfig.connectTypes)) {
      this.types = this.hsConfig.connectTypes
        .filter((type) => servicesSupportedByUrl.includes(type))
        .map((type) => AddDataUrlValues.find((v) => v.id == type));
    } else {
      this.types = AddDataUrlValues;
    }
    //This component initializes after add-data.component which already set the urlType so *should* be fine to connect now
    if (this.hsAddDataService.urlType) {
      this.selectType(this.hsAddDataService.urlType);
      this.connectServiceFromUrlParam(this.hsAddDataService.urlType);
    }
  }

  selectType(type: AddDataUrlType): void {
    this.typeSelected = type;
    this.hsAddDataOwsService.baseDataType = type;
    this.hsAddDataCommonService.clearParams();
  }

  connectServiceFromUrlParam(type: AddDataUrlType): void {
    const layers = this.hsShareUrlService.getParamValue(`hs-${type}-layers`);
    const url = this.hsShareUrlService.getParamValue(`hs-${type}-to-connect`);

    // const serviceName = `hsAddLayersWmsService`;
    if (layers) {
      for (const layer of layers.split(';')) {
        this.hsAddDataOwsService.connectToOWS({
          type,
          uri: url,
          layer,
          style: undefined,
        });
      }
    } else {
      this.hsAddDataOwsService.connectToOWS({type, uri: url});
    }
  }
}<commit_msg>fix: Clear initial urlType after it is loaded<commit_after>import {Component} from '@angular/core';

import {AddDataUrlType, servicesSupportedByUrl} from './types/url.type';
import {AddDataUrlValues} from './add-data-url-values';
import {HsAddDataCommonService} from '../common/common.service';
import {HsAddDataOwsService} from './add-data-ows.service';
import {HsAddDataService} from '../add-data.service';
import {HsConfig} from '../../../config.service';
import {HsLanguageService} from '../../language/language.service';
import {HsLayoutService} from '../../layout/layout.service';
import {HsShareUrlService} from '../../permalink/share-url.service';

@Component({
  selector: 'hs-add-data-url',
  templateUrl: './add-data-url.component.html',
})
export class HsAddDataUrlComponent {
  typeSelected: AddDataUrlType;
  types: {id: AddDataUrlType; text: string}[];

  constructor(
    public hsConfig: HsConfig,
    public hsLanguageService: HsLanguageService,
    public hsShareUrlService: HsShareUrlService,
    public hsAddDataService: HsAddDataService,
    public hsLayoutService: HsLayoutService,
    public hsAddDataCommonService: HsAddDataCommonService,
    public hsAddDataOwsService: HsAddDataOwsService
  ) {
    if (Array.isArray(this.hsConfig.connectTypes)) {
      this.types = this.hsConfig.connectTypes
        .filter((type) => servicesSupportedByUrl.includes(type))
        .map((type) => AddDataUrlValues.find((v) => v.id == type));
    } else {
      this.types = AddDataUrlValues;
    }
    //This component initializes after add-data.component which already set the urlType so *should* be fine to connect now
    if (this.hsAddDataService.urlType) {
      this.selectType(this.hsAddDataService.urlType);
      this.connectServiceFromUrlParam(this.hsAddDataService.urlType);
    }
  }

  selectType(type: AddDataUrlType): void {
    this.typeSelected = type;
    this.hsAddDataOwsService.baseDataType = type;
    this.hsAddDataCommonService.clearParams();
  }

  connectServiceFromUrlParam(type: AddDataUrlType): void {
    const layers = this.hsShareUrlService.getParamValue(`hs-${type}-layers`);
    const url = this.hsShareUrlService.getParamValue(`hs-${type}-to-connect`);

    // const serviceName = `hsAddLayersWmsService`;
    if (layers) {
      for (const layer of layers.split(';')) {
        this.hsAddDataOwsService.connectToOWS({
          type,
          uri: url,
          layer,
          style: undefined,
        });
      }
    } else {
      this.hsAddDataOwsService.connectToOWS({type, uri: url});
    }
    this.hsAddDataService.urlType = null;
  }
}
{'fraction_non_alphanumeric': 0.13071512309495897, 'fraction_numerical': 0.0, 'mean_word_length': 3.7707362534948743, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '376934', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1556, 'n_words': 309}