<commit_before>import { createSelector } from 'reselect';

import { createUrlWithToken } from '../../../shared/services/api/api';
import MAP_CONFIG from '../../services/map-config';

export const FETCH_MAP_LAYERS_REQUEST = 'FETCH_MAP_LAYERS_REQUEST';
export const FETCH_MAP_LAYERS_SUCCESS = 'FETCH_MAP_LAYERS_SUCCESS';
export const FETCH_MAP_LAYERS_FAILURE = 'FETCH_MAP_LAYERS_FAILURE';

const initialState = {
  items: [],
  isLoading: false,
  error: null
};

const findLayer = (layers, id) => layers.find((mapLayer) => mapLayer.id === id);
const generateLayer = (layers, overlay, url) => ({
  ...overlay,
  url,
  overlayOptions: {
    ...MAP_CONFIG.OVERLAY_OPTIONS,
    layers: findLayer(layers, overlay.id).layers
  }
});

const getMapLayers = (state) => state.mapLayers.layers.items;
const getOverlays = (state) => state.map.overlays;
const getAccessToken = (state) => state.user.accessToken;

export const getLayers = createSelector(
  [getOverlays, getAccessToken, getMapLayers],
  (overlays, token, layers) => (
    overlays.map((overlay) => {
      const layer = findLayer(layers, overlay.id);
      if (!layer) {
        return false;
      }
      const layerUrl = `${MAP_CONFIG.OVERLAY_ROOT}/${layer.url}`;
      if (!layer.authScope) {
        return generateLayer(layers, overlay, layerUrl);
      }
      if (token) {
        return generateLayer(
          layers,
          overlay,
          createUrlWithToken(layerUrl, token)
        );
      }
      return false;
    })
    .filter((layer) => layer))<commit_msg>Add support to external url's<commit_after>import { createSelector } from 'reselect';

import { createUrlWithToken } from '../../../shared/services/api/api';
import MAP_CONFIG from '../../services/map-config';

export const FETCH_MAP_LAYERS_REQUEST = 'FETCH_MAP_LAYERS_REQUEST';
export const FETCH_MAP_LAYERS_SUCCESS = 'FETCH_MAP_LAYERS_SUCCESS';
export const FETCH_MAP_LAYERS_FAILURE = 'FETCH_MAP_LAYERS_FAILURE';

const initialState = {
  items: [],
  isLoading: false,
  error: null
};

const findLayer = (layers, id) => layers.find((mapLayer) => mapLayer.id === id);
const generateLayer = (layers, overlay, url) => ({
  ...overlay,
  url,
  overlayOptions: {
    ...MAP_CONFIG.OVERLAY_OPTIONS,
    layers: findLayer(layers, overlay.id).layers
  }
});

const getMapLayers = (state) => state.mapLayers.layers.items;
const getOverlays = (state) => state.map.overlays;
const getAccessToken = (state) => state.user.accessToken;

export const getLayers = createSelector(
  [getOverlays, getAccessToken, getMapLayers],
  (overlays, token, layers) => (
    overlays.map((overlay) => {
      const layer = findLayer(layers, overlay.id);
      if (!layer) {
        return false;
      }
      const layerUrl = !layer.external ? `${MAP_CONFIG.OVERLAY_ROOT}/${layer.url}` : layer.url;
      if (!layer.authScope) {
        return generateLayer(layers, overlay, layerUrl);
      }
      if (token) {
        return generateLayer(
          layers,
          overlay,
          createUrlWithToken(layerUrl, token)
        );
      }
      return false;
    })
    .filter((layer) => layer))
{'fraction_non_alphanumeric': 0.1386392811296534, 'fraction_numerical': 0.0, 'mean_word_length': 3.396332863187588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '7538582', 'n_tokens_mistral': 1018, 'n_tokens_neox': 998, 'n_words': 209}