@opengeoweb/layer-select 19.0.0 → 19.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/README.md +11 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.esm.js +3477 -0
  4. package/dist/src/index.d.ts +4 -0
  5. package/dist/src/lib/components/DataExplorerButtonConnect/DataExplorerButtonConnect.d.ts +8 -0
  6. package/dist/src/lib/components/DataExplorerButtonConnect/index.d.ts +1 -0
  7. package/dist/src/lib/components/KeywordFilterButton/KeywordFilterButtonConnect.d.ts +9 -0
  8. package/dist/src/lib/components/KeywordFilterButton/index.d.ts +1 -0
  9. package/dist/src/lib/components/KeywordFilterResults/KeywordFilterResults.d.ts +13 -0
  10. package/dist/src/lib/components/KeywordFilterResults/KeywordFilterResultsConnect.d.ts +8 -0
  11. package/dist/src/lib/components/KeywordFilterResults/KeywordFilterResultsListItemConnect.d.ts +6 -0
  12. package/dist/src/lib/components/KeywordFilterResults/KeywordFilterSelectAllSwitchConnect.d.ts +2 -0
  13. package/dist/src/lib/components/KeywordFilterResults/index.d.ts +4 -0
  14. package/dist/src/lib/components/LayerList/LayerAddRemoveButton.d.ts +26 -0
  15. package/dist/src/lib/components/LayerList/LayerList.d.ts +32 -0
  16. package/dist/src/lib/components/LayerList/LayerListConnect.d.ts +9 -0
  17. package/dist/src/lib/components/LayerList/LayerListDimensions.d.ts +7 -0
  18. package/dist/src/lib/components/LayerList/LayerListRow.d.ts +27 -0
  19. package/dist/src/lib/components/LayerList/index.d.ts +5 -0
  20. package/dist/src/lib/components/LayerSelect/LayerSelect.d.ts +21 -0
  21. package/dist/src/lib/components/LayerSelect/LayerSelectButtonConnect.d.ts +11 -0
  22. package/dist/src/lib/components/LayerSelect/LayerSelectConnect.d.ts +16 -0
  23. package/dist/src/lib/components/LayerSelect/LayerSelectUtils.d.ts +77 -0
  24. package/dist/src/lib/components/LayerSelect/index.d.ts +2 -0
  25. package/dist/src/lib/components/Providers/Providers.d.ts +22 -0
  26. package/dist/src/lib/components/Providers/index.d.ts +1 -0
  27. package/dist/src/lib/components/SearchField/SearchFieldConnect.d.ts +2 -0
  28. package/dist/src/lib/components/SearchField/index.d.ts +1 -0
  29. package/dist/src/lib/components/ServiceList/ServiceChip.d.ts +12 -0
  30. package/dist/src/lib/components/ServiceList/ServiceChipConnect.d.ts +10 -0
  31. package/dist/src/lib/components/ServiceList/ServiceList.d.ts +8 -0
  32. package/dist/src/lib/components/ServiceList/ServiceListConnect.d.ts +6 -0
  33. package/dist/src/lib/components/ServiceList/index.d.ts +4 -0
  34. package/dist/src/lib/components/ServiceOptionsButton/ServiceOptionsButton.d.ts +6 -0
  35. package/dist/src/lib/components/ServiceOptionsButton/index.d.ts +1 -0
  36. package/dist/src/lib/components/ServiceOptionsDialog/ServiceOptionsDialog.d.ts +20 -0
  37. package/dist/src/lib/components/ServiceOptionsDialog/ServiceOptionsDialogConnect.d.ts +8 -0
  38. package/dist/src/lib/components/ServiceOptionsDialog/index.d.ts +2 -0
  39. package/dist/src/lib/components/ServicePopup/ServicePopup.d.ts +21 -0
  40. package/dist/src/lib/components/ServicePopup/ServicePopupConnect.d.ts +2 -0
  41. package/dist/src/lib/components/ServicePopup/ServicePopupDialogConnect.d.ts +11 -0
  42. package/dist/src/lib/components/ServicePopup/index.d.ts +3 -0
  43. package/dist/src/lib/components/ServicePopup/utils.d.ts +14 -0
  44. package/dist/src/lib/components/index.d.ts +10 -0
  45. package/dist/src/lib/index.d.ts +2 -0
  46. package/dist/src/lib/store/index.d.ts +7 -0
  47. package/dist/src/lib/store/listeners.d.ts +2 -0
  48. package/dist/src/lib/store/reducer.d.ts +26 -0
  49. package/dist/src/lib/store/selectors.d.ts +200 -0
  50. package/dist/src/lib/store/store.d.ts +6 -0
  51. package/dist/src/lib/store/testData.d.ts +17 -0
  52. package/dist/src/lib/store/types.d.ts +72 -0
  53. package/dist/src/lib/store/utils.d.ts +9 -0
  54. package/dist/src/lib/utils/i18n.d.ts +7 -0
  55. package/package.json +2 -1
@@ -0,0 +1,3477 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import React from 'react';
3
+ import { useSelector, useDispatch } from 'react-redux';
4
+ import { CustomIconButton, FilterOption, ToolContainerDraggable, CustomAccordion, CustomTooltip, SearchHighlight, SearchField, CustomToggleButton, AlertBanner, ToggleMenu, CustomDialog, sessionStorageProvider } from '@opengeoweb/shared';
5
+ import { uiTypes, serviceActions, selectorMemoizationOptions, serviceSelectors, uiActions, getUserAddedServices, setUserAddedServices, layerActions, uiSelectors, layerSelectors, mapListener, serviceListener, layersListener, openlayersListener, uiReducer, layerReducer, serviceReducer, mapReducer, useSetupDialog, mapSelectors, layerTypes, mapEnums } from '@opengeoweb/store';
6
+ import { Filter, ArrowDropDownDown, StacIcon, LayersAdd, MeteoGate, Add, Cached, Edit, Visibility, Delete, Copy } from '@opengeoweb/theme';
7
+ import { createEntityAdapter, createSlice, createSelector, createListenerMiddleware, isAnyOf, combineReducers, configureStore } from '@reduxjs/toolkit';
8
+ import { compact, countBy, partition } from 'lodash';
9
+ import { snackbarListener, snackbarReducer, snackbarActions, snackbarTypes } from '@opengeoweb/snackbar';
10
+ import { Switch, Grid, List, ToggleButtonGroup, ToggleButton, Box, Popper, Grow, Paper, ClickAwayListener, MenuList, MenuItem, Typography, useTheme, Backdrop, CircularProgress, Button, ListItem, ListItemText, LinearProgress, InputAdornment } from '@mui/material';
11
+ import 'i18next';
12
+ import { useTranslation } from 'react-i18next';
13
+ import { List as List$1 } from 'react-window';
14
+ import { getDimensionsList, LayerInfoButton, stacCatalogCollectionToLayerProps, fetchStacCatalogRoot, fetchStacCatalogCollections, clearImageCacheForAllMaps } from '@opengeoweb/webmap-react';
15
+ import { LayerType, webmapUtils, getWMSServiceId, queryWMSServiceInfo, queryWMSLayers, invalidateWMSGetCapabilities } from '@opengeoweb/webmap';
16
+ import { useFormContext } from 'react-hook-form';
17
+ import { ReactHookFormProvider, defaultFormOptions, ReactHookFormTextField } from '@opengeoweb/form-fields';
18
+
19
+ var en = {
20
+ "layer-select": "Layer Select",
21
+ "select-all": "Select all",
22
+ "groups-and-keywords-dialog-title": "Groups & Keywords",
23
+ add: "add",
24
+ remove: "remove",
25
+ "layer-list-results": "results",
26
+ groups: "Groups",
27
+ keywords: "Keywords",
28
+ "layer-select-button-tooltip": "Open the layer selector",
29
+ all: "All",
30
+ services: "Services",
31
+ "add-a-new-service": "Add a new service",
32
+ "update-service-title": "Update layers from WMS service",
33
+ "edit-service-title": "Edit Service",
34
+ "save-service-title": "Save service",
35
+ "show-service-title": "Show Service",
36
+ "service-has-active-layers-error": "Service has active layers. Cannot remove this service",
37
+ "delete-service": "Delete Service",
38
+ "copy-url-message": "Service URL copied to clipboard",
39
+ "get-success-message": "Service \"{{serviceName}}\" has been saved successfully",
40
+ "service-popup-helper-text": "Short description of what this service does",
41
+ close: "close",
42
+ cancel: "cancel",
43
+ save: "save",
44
+ "validations-name-existing": "This name already exists. Choose another name.",
45
+ "validations-service-existing": "URL already exists.",
46
+ "validations-service-valid-url": "Not a valid URL.",
47
+ "validations-request-failed": "Download failed. Check the URL.",
48
+ "validations-field-required": "This field is required",
49
+ "service-url-label": "This service refers to this URL",
50
+ "service-name-label": "Service name",
51
+ "service-abstracts-label": "Abstracts",
52
+ "service-successfully-updated": "Service \"{{serviceName}}\" has been succesfully updated",
53
+ "unable-to-update-service": "Unable to update service, reason: \"{{message}}\"",
54
+ "service-has-been-deleted": "Service \"{{serviceName}}\" has been deleted",
55
+ "add-to-all-maps": "Add to all maps",
56
+ "remove-from-all-maps": "Remove from all maps"
57
+ };
58
+ var fi = {
59
+ "layer-select": "Layer Select",
60
+ "select-all": "Valitse kaikki",
61
+ "groups-and-keywords-dialog-title": "Ryhmät ja Avainsanat",
62
+ add: "lisää",
63
+ remove: "poista",
64
+ "layer-list-results": "tulosta",
65
+ groups: "Ryhmät",
66
+ keywords: "Avainsanat",
67
+ "layer-select-button-tooltip": "Avaa Layer Select",
68
+ all: "Kaikki",
69
+ services: "Palvelut",
70
+ "add-a-new-service": "Lisää uusi pavelu",
71
+ "update-service-title": "Päivitä karttatasot WMS palvelusta",
72
+ "edit-service-title": "Muokkaa palvelua",
73
+ "save-service-title": "Tallenna palvelu",
74
+ "show-service-title": "Näytä palvelu",
75
+ "service-has-active-layers-error": "Palvelu sisältää aktiivisia karttatasoja. Palvelua ei voi poistaa",
76
+ "delete-service": "Poista palvelu",
77
+ "copy-url-message": "Palvelun osoite kopioitu leikepöydälle",
78
+ "get-success-message": "Palvelu \"{{serviceName}}\" tallennettu onnistuneesti",
79
+ "service-popup-helper-text": "Lyhyt kuvaus siitä mitä palvelu tekee",
80
+ close: "sulje",
81
+ cancel: "peruuta",
82
+ save: "tallenna",
83
+ "validations-name-existing": "Nimi on jo käytössä. Valitse toinen nimi.",
84
+ "validations-service-existing": "Osoite on jo käytössä.",
85
+ "validations-service-valid-url": "Epäkelpo URL-osoite",
86
+ "validations-request-failed": "Lataus epäonnistui. Tarkista URL-osoite",
87
+ "validations-field-required": "Kenttä tulee täyttää",
88
+ "service-url-label": "Tämä palvelu viittaa tähän URL-osoitteeseen",
89
+ "service-name-label": "Palvelun nimi",
90
+ "service-abstracts-label": "Tiivistelmä",
91
+ "service-successfully-updated": "Palvelu \"{{serviceName}}\" päivitetty onnistuneesti",
92
+ "unable-to-update-service": "Palvelun päivitys epäonnistui. Syy: \"{{message}}\"",
93
+ "service-has-been-deleted": "Palvelu \"{{serviceName}}\" poistettu",
94
+ "add-to-all-maps": "Lisää kaikkiin karttoihin",
95
+ "remove-from-all-maps": "Poista kaikista kartoista"
96
+ };
97
+ var no = {
98
+ "layer-select": "Datavelger",
99
+ "select-all": "Velg alle",
100
+ "groups-and-keywords-dialog-title": "Grupper & Nøkkelord",
101
+ add: "legg til",
102
+ remove: "fjern",
103
+ "layer-list-results": "resultat",
104
+ groups: "Grupper",
105
+ keywords: "Nøkkelord",
106
+ "layer-select-button-tooltip": "Åpne datavelger",
107
+ all: "ALLE",
108
+ services: "Tjenester",
109
+ "add-a-new-service": "Legg til en ny tjeneste",
110
+ "update-service-title": "Oppdater lag fra WMS-tjeneste",
111
+ "edit-service-title": "Rediger tjeneste",
112
+ "save-service-title": "Lagre tjeneste",
113
+ "show-service-title": "Vis tjeneste",
114
+ "service-has-active-layers-error": "Tjenesten har aktive lag. Kan ikke fjerne denne tjenesten",
115
+ "delete-service": "Slett tjeneste",
116
+ "copy-url-message": "Kopier tjeneste-URL til utklippstavle",
117
+ "get-success-message": "Tjeneste \"{{serviceName}}\" har blitt lagret",
118
+ "service-popup-helper-text": "Kort beskrivelse av hva denne tjenesten gjør",
119
+ close: "lukk",
120
+ cancel: "avbryt",
121
+ save: "lagre",
122
+ "validations-name-existing": "Dette navnet eksisterer fra før. Velg et annet navn.",
123
+ "validations-service-existing": "URL eksisterer fra før.",
124
+ "validations-service-valid-url": "Ikke en gyldig URL",
125
+ "validations-request-failed": "Nedlasting feilet. Sjekk URLen",
126
+ "validations-field-required": "Dette feltet er påkrevd",
127
+ "service-url-label": "Denne tjenesten referer til denne URLen",
128
+ "service-name-label": "Tjenestenavn",
129
+ "service-abstracts-label": "Sammendrag",
130
+ "service-successfully-updated": "Tjeneste \"{{serviceName}}\" har blitt oppdatert",
131
+ "unable-to-update-service": "Kan ikke oppdatere tjeneste, grunn: \"{{message}}\"",
132
+ "service-has-been-deleted": "Tjeneste \"{{serviceName}}\" har blitt slettet",
133
+ "add-to-all-maps": "Legg til i alle kart",
134
+ "remove-from-all-maps": "Fjern fra alle kart"
135
+ };
136
+ var nl = {
137
+ "layer-select": "Layer Select",
138
+ "select-all": "Selecteer alles",
139
+ "groups-and-keywords-dialog-title": "Groepen & Trefwoorden",
140
+ add: "toevoegen",
141
+ remove: "verwijderen",
142
+ "layer-list-results": "resultaten",
143
+ groups: "Groepen",
144
+ keywords: "Trefwoorden",
145
+ "layer-select-button-tooltip": "Open de Layer Select",
146
+ all: "Alle",
147
+ services: "Services",
148
+ "add-a-new-service": "Voeg een nieuwe service toe",
149
+ "update-service-title": "Lagen bijwerken vanaf WMS service",
150
+ "edit-service-title": "Service bewerken",
151
+ "save-service-title": "Service opslaan",
152
+ "show-service-title": "Service tonen",
153
+ "service-has-active-layers-error": "Service heeft actieve lagen. Kan niet verwijderd worden",
154
+ "delete-service": "Service verwijderen",
155
+ "copy-url-message": "Service URL is naar het klembord gekopieerd",
156
+ "get-success-message": "Service \"{{serviceName}}\" is succesvol opgeslagen",
157
+ "service-popup-helper-text": "Korte beschrijving van wat de service doet",
158
+ close: "sluiten",
159
+ cancel: "annuleren",
160
+ save: "opslaan",
161
+ "validations-name-existing": "Deze naam is al in gebruik. Kies een andere naam.",
162
+ "validations-service-existing": "URL is al in gebruik.",
163
+ "validations-service-valid-url": "Geen geldige URL.",
164
+ "validations-request-failed": "Download mislukt. Controleer de URL.",
165
+ "validations-field-required": "Dit veld is verplicht",
166
+ "service-url-label": "Deze service verwijst naar deze URL",
167
+ "service-name-label": "Service naam",
168
+ "service-abstracts-label": "Beschrijving",
169
+ "service-successfully-updated": "Service \"{{serviceName}}\" is succesvol bijgewerkt",
170
+ "unable-to-update-service": "Bijwerken service niet mogelijk, reden: \"{{message}}\"",
171
+ "service-has-been-deleted": "Service \"{{serviceName}}\" is verwijderd",
172
+ "add-to-all-maps": "Toevoegen aan alle kaarten",
173
+ "remove-from-all-maps": "Verwijderen van alle kaarten"
174
+ };
175
+ var layerSelectTranslations = {
176
+ en: en,
177
+ fi: fi,
178
+ no: no,
179
+ nl: nl
180
+ };
181
+
182
+ /* *
183
+ * Licensed under the Apache License, Version 2.0 (the "License");
184
+ * you may not use this file except in compliance with the License.
185
+ * You may obtain a copy of the License at
186
+ *
187
+ * http://www.apache.org/licenses/LICENSE-2.0
188
+ *
189
+ * Unless required by applicable law or agreed to in writing, software
190
+ * distributed under the License is distributed on an "AS IS" BASIS,
191
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
192
+ * See the License for the specific language governing permissions and
193
+ * limitations under the License.
194
+ *
195
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
196
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
197
+ * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
198
+ * */
199
+ var getFilterId = function getFilterId(filterType, filterName) {
200
+ return filterType + "-" + filterName;
201
+ };
202
+ var produceFilters = function produceFilters(filterNames, filterType, draft, layerSelectFilterAdapter) {
203
+ filterNames.forEach(function (filterName) {
204
+ layerSelectFilterAdapter.addOne(draft.filters.filters, {
205
+ id: getFilterId(filterType, filterName),
206
+ name: filterName,
207
+ checked: true,
208
+ type: filterType
209
+ });
210
+ });
211
+ };
212
+ var filterLayersFromService = function filterLayersFromService(serviceId, services, filterIds, allFiltersActive, searchString) {
213
+ var mapStoreService = services[serviceId];
214
+ if (!mapStoreService) {
215
+ return [];
216
+ }
217
+ if (searchString === '' && allFiltersActive) {
218
+ return mapStoreService.layers.filter(function (layer) {
219
+ return layer.leaf;
220
+ });
221
+ }
222
+ var searchStringArray = searchString.split(' ');
223
+ return mapStoreService.layers.filter(function (layer) {
224
+ return searchStringArray.every(function (search) {
225
+ var _layer$keywords, _layer$name, _layer$title, _layer$abstract;
226
+ var searchLowercase = search.toLowerCase();
227
+ var layerFilterIds = layer.path.map(function (group) {
228
+ return getFilterId('groups', group);
229
+ }).concat(((_layer$keywords = layer.keywords) != null ? _layer$keywords : []).map(function (keyword) {
230
+ return getFilterId('keywords', keyword);
231
+ }));
232
+ var isFilterInLayer = (layerFilterIds == null ? void 0 : layerFilterIds.some(function (id) {
233
+ return filterIds.includes(id);
234
+ })) || allFiltersActive;
235
+ var isSearchTextInLayerFilter = layerFilterIds == null ? void 0 : layerFilterIds.some(function (filterId) {
236
+ return filterId.toLowerCase().includes(searchLowercase);
237
+ });
238
+ var isSearchTextInLayerName = (_layer$name = layer.name) == null ? void 0 : _layer$name.toLowerCase().includes(searchLowercase);
239
+ var isSearchTextInLayerText = (_layer$title = layer.title) == null ? void 0 : _layer$title.toLowerCase().includes(searchLowercase);
240
+ var isSearchTextInLayerAbstract = (_layer$abstract = layer["abstract"]) == null ? void 0 : _layer$abstract.toLowerCase().includes(searchLowercase);
241
+ var isSearchTextInServiceName = mapStoreService.name.toLowerCase().includes(searchLowercase);
242
+ var isSearchTextInLayer = isSearchTextInLayerName || isSearchTextInLayerText || isSearchTextInLayerAbstract || isSearchTextInLayerFilter || isSearchTextInServiceName;
243
+ return isFilterInLayer && isSearchTextInLayer;
244
+ });
245
+ }).filter(function (layer) {
246
+ return layer.leaf;
247
+ });
248
+ };
249
+ var isUserAddedService = function isUserAddedService(scope) {
250
+ return scope === 'user';
251
+ };
252
+
253
+ var layerSelectFilterAdapter = createEntityAdapter();
254
+ var layerSelectActiveServicesAdapter = createEntityAdapter({
255
+ selectId: function selectId(service) {
256
+ return service.serviceId;
257
+ }
258
+ });
259
+ var initialServicePopupState = {
260
+ isOpen: false,
261
+ url: '',
262
+ serviceId: '',
263
+ variant: 'add'
264
+ };
265
+ var initialState = {
266
+ filters: {
267
+ searchFilter: '',
268
+ activeServices: layerSelectActiveServicesAdapter.getInitialState(),
269
+ filters: layerSelectFilterAdapter.getInitialState()
270
+ },
271
+ allServicesEnabled: true,
272
+ servicePopup: initialServicePopupState
273
+ };
274
+ var slice = createSlice({
275
+ initialState: initialState,
276
+ name: uiTypes.DialogTypes.LayerSelect,
277
+ reducers: {
278
+ setSearchFilter: function setSearchFilter(draft, action) {
279
+ var filterText = action.payload.filterText;
280
+ draft.filters.searchFilter = filterText;
281
+ },
282
+ closeServicePopupOpen: function closeServicePopupOpen(draft) {
283
+ draft.servicePopup.isOpen = false;
284
+ },
285
+ toggleServicePopup: function toggleServicePopup(draft, action) {
286
+ var _action$payload = action.payload,
287
+ variant = _action$payload.variant,
288
+ isOpen = _action$payload.isOpen;
289
+ draft.servicePopup.isOpen = isOpen;
290
+ draft.servicePopup.url = action.payload.url ? action.payload.url : '';
291
+ draft.servicePopup.variant = variant;
292
+ draft.servicePopup.serviceId = action.payload.serviceId ? action.payload.serviceId : '';
293
+ },
294
+ layerSelectRemoveService: function layerSelectRemoveService(draft, action) {
295
+ var serviceId = action.payload.serviceId;
296
+ layerSelectActiveServicesAdapter.removeOne(draft.filters.activeServices, serviceId);
297
+ },
298
+ enableActiveService: function enableActiveService(draft, action) {
299
+ var activeServicesById = draft.filters.activeServices.entities;
300
+ var activeServices = compact(Object.values(activeServicesById));
301
+ var countPressedServices = activeServices.filter(function (service) {
302
+ return service.enabled;
303
+ }).length;
304
+ var isAllServicesGoingToBeEnabled = countPressedServices === activeServices.length - 1;
305
+ if (isAllServicesGoingToBeEnabled) {
306
+ slice.caseReducers.enableAllActiveServices(draft);
307
+ return;
308
+ }
309
+ var service = activeServicesById[action.payload.serviceId];
310
+ service.enabled = true;
311
+ },
312
+ enableAllActiveServices: function enableAllActiveServices(draft) {
313
+ var activeServices = draft.filters.activeServices.entities;
314
+ var servicesToTurnOn = compact(Object.values(activeServices)).filter(function (service) {
315
+ return !service.enabled;
316
+ });
317
+ var updates = servicesToTurnOn.map(function (service) {
318
+ return {
319
+ id: service.serviceId,
320
+ changes: {
321
+ enabled: true
322
+ }
323
+ };
324
+ });
325
+ layerSelectActiveServicesAdapter.updateMany(draft.filters.activeServices, updates);
326
+ draft.allServicesEnabled = true;
327
+ },
328
+ onlyThisServiceEnabled: function onlyThisServiceEnabled(draft, action) {
329
+ var activeServicesById = draft.filters.activeServices.entities;
330
+ var services = compact(Object.values(activeServicesById));
331
+ var servicesToTurnOff = services.filter(function (service) {
332
+ return service.serviceId !== action.payload.serviceId;
333
+ });
334
+ var updates = servicesToTurnOff.map(function (service) {
335
+ return {
336
+ id: service.serviceId,
337
+ changes: {
338
+ enabled: false
339
+ }
340
+ };
341
+ });
342
+ layerSelectActiveServicesAdapter.updateMany(draft.filters.activeServices, updates);
343
+ draft.allServicesEnabled = false;
344
+ },
345
+ disableActiveService: function disableActiveService(draft, action) {
346
+ var activeServicesById = draft.filters.activeServices.entities;
347
+ var countPressedServices = Object.values(activeServicesById).filter(function (service) {
348
+ return service == null ? void 0 : service.enabled;
349
+ }).length;
350
+ var isAllServicesGoingToBeDisabled = countPressedServices === 1;
351
+ if (isAllServicesGoingToBeDisabled) {
352
+ slice.caseReducers.enableAllActiveServices(draft);
353
+ return;
354
+ }
355
+ var service = activeServicesById[action.payload.serviceId];
356
+ service.enabled = false;
357
+ },
358
+ toggleFilter: function toggleFilter(draft, action) {
359
+ var _action$payload2 = action.payload,
360
+ filterId = _action$payload2.filterId,
361
+ only = _action$payload2.only;
362
+ if (only) {
363
+ Object.keys(draft.filters.filters.entities).forEach(function (filterId) {
364
+ draft.filters.filters.entities[filterId].checked = false;
365
+ });
366
+ draft.filters.filters.entities[filterId].checked = true;
367
+ } else {
368
+ draft.filters.filters.entities[filterId].checked = !draft.filters.filters.entities[filterId].checked;
369
+ }
370
+ },
371
+ toggleAllFilters: function toggleAllFilters(draft) {
372
+ var allFiltersChecked = Object.values(draft.filters.filters.entities).every(function (filter) {
373
+ return filter == null ? void 0 : filter.checked;
374
+ });
375
+ draft.filters.filters.ids.forEach(function (filterId) {
376
+ draft.filters.filters.entities[filterId].checked = !allFiltersChecked;
377
+ });
378
+ }
379
+ },
380
+ extraReducers: function extraReducers(builder) {
381
+ builder.addCase(serviceActions.serviceSetLayers, function (draft, action) {
382
+ var _draft$filters$active;
383
+ var _action$payload3 = action.payload,
384
+ serviceId = _action$payload3.id,
385
+ serviceUrl = _action$payload3.serviceUrl,
386
+ serviceName = _action$payload3.name,
387
+ scope = _action$payload3.scope,
388
+ _abstract = _action$payload3["abstract"],
389
+ layers = _action$payload3.layers,
390
+ isUpdating = _action$payload3.isUpdating,
391
+ type = _action$payload3.type;
392
+ if (isUpdating) {
393
+ return;
394
+ }
395
+ if (type === 'EDR') {
396
+ // EDR services do not work yet in the layer-select, so skip them for now
397
+ return;
398
+ }
399
+ var keywords = layers.reduce(function (keywords, layer) {
400
+ if (layer.leaf) {
401
+ var _layer$keywords;
402
+ return keywords.concat((_layer$keywords = layer.keywords) != null ? _layer$keywords : []);
403
+ }
404
+ return keywords;
405
+ }, []);
406
+ var groups = layers.reduce(function (groups, layer) {
407
+ if (layer.leaf) {
408
+ var _layer$path;
409
+ return groups.concat((_layer$path = layer.path) != null ? _layer$path : []);
410
+ }
411
+ return groups;
412
+ }, []);
413
+ if (!((_draft$filters$active = draft.filters.activeServices.entities[serviceId]) != null && (_draft$filters$active = _draft$filters$active.filterIds) != null && _draft$filters$active.length)) {
414
+ // If the service has no filters yet, add them
415
+ produceFilters(groups, 'groups', draft, layerSelectFilterAdapter);
416
+ produceFilters(keywords, 'keywords', draft, layerSelectFilterAdapter);
417
+ }
418
+ var filterIds = groups.map(function (group) {
419
+ return getFilterId('groups', group);
420
+ }).concat(keywords.map(function (keyword) {
421
+ return getFilterId('keywords', keyword);
422
+ }));
423
+ layerSelectActiveServicesAdapter.setOne(draft.filters.activeServices, {
424
+ serviceId: serviceId,
425
+ enabled: draft.allServicesEnabled,
426
+ keywords: keywords,
427
+ groups: groups,
428
+ filterIds: filterIds,
429
+ scope: scope,
430
+ serviceName: serviceName,
431
+ serviceUrl: serviceUrl,
432
+ "abstract": _abstract,
433
+ isLoading: false,
434
+ type: type
435
+ });
436
+ }).addCase(serviceActions.fetchInitialServices, function (draft, action) {
437
+ var services = action.payload.services;
438
+ services.forEach(function (service) {
439
+ var serviceId = service.id,
440
+ serviceName = service.name,
441
+ serviceUrl = service.url,
442
+ _abstract2 = service["abstract"],
443
+ scope = service.scope;
444
+ layerSelectActiveServicesAdapter.setOne(draft.filters.activeServices, {
445
+ serviceId: serviceId,
446
+ enabled: draft.allServicesEnabled,
447
+ filterIds: [],
448
+ scope: scope,
449
+ serviceName: serviceName,
450
+ serviceUrl: serviceUrl,
451
+ "abstract": _abstract2,
452
+ isLoading: true
453
+ });
454
+ });
455
+ });
456
+ }
457
+ });
458
+ var layerSelectReducer = slice.reducer,
459
+ layerSelectActions = slice.actions;
460
+
461
+ /* *
462
+ * Licensed under the Apache License, Version 2.0 (the "License");
463
+ * you may not use this file except in compliance with the License.
464
+ * You may obtain a copy of the License at
465
+ *
466
+ * http://www.apache.org/licenses/LICENSE-2.0
467
+ *
468
+ * Unless required by applicable law or agreed to in writing, software
469
+ * distributed under the License is distributed on an "AS IS" BASIS,
470
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
471
+ * See the License for the specific language governing permissions and
472
+ * limitations under the License.
473
+ *
474
+ * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
475
+ * Copyright 2021 - Finnish Meteorological Institute (FMI)
476
+ * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
477
+ * */
478
+ var useAppSelector = useSelector;
479
+ var layerSelectStore = function layerSelectStore(store) {
480
+ return store != null && store.layerSelect ? store.layerSelect : null;
481
+ };
482
+ /**
483
+ * Returns search filter string
484
+ *
485
+ * Example getSearchFilter(store);
486
+ * @param {object} store store: object - store object
487
+ * @returns {array} returnType: string
488
+ */
489
+ var getSearchFilter = createSelector(layerSelectStore, function (store) {
490
+ var _store$filters;
491
+ return (store == null || (_store$filters = store.filters) == null ? void 0 : _store$filters.searchFilter) || '';
492
+ });
493
+ /**
494
+ * Returns active services array
495
+ *
496
+ * Example getActiveServices(store);
497
+ * @param {object} store store: object - store object
498
+ * @returns {ActiveServiceObjectEntities} returnType: ActiveServiceObjectEntitiesobject of active services
499
+ */
500
+ // cast to usable type - selectEntities returns Dictionary<ActiveServiceObject> which is not usable inside of the code
501
+ var getActiveServices = function getActiveServices(store) {
502
+ return getActiveServicesDictionary(store);
503
+ };
504
+ var EMPTY_ACTIVE_SERVICES = {
505
+ entities: {},
506
+ ids: []
507
+ };
508
+ var _layerSelectActiveSer = layerSelectActiveServicesAdapter.getSelectors(function (store) {
509
+ var _store$layerSelect;
510
+ return (store == null || (_store$layerSelect = store.layerSelect) == null || (_store$layerSelect = _store$layerSelect.filters) == null ? void 0 : _store$layerSelect.activeServices) || EMPTY_ACTIVE_SERVICES;
511
+ }),
512
+ getActiveServicesDictionary = _layerSelectActiveSer.selectEntities,
513
+ getActiveServiceById = _layerSelectActiveSer.selectById,
514
+ getAllActiveServices = _layerSelectActiveSer.selectAll;
515
+ var getEnabledServiceIds = createSelector(getAllActiveServices, function (services) {
516
+ return services.filter(function (service) {
517
+ return service.enabled;
518
+ }).map(function (service) {
519
+ return service.serviceId;
520
+ });
521
+ }, selectorMemoizationOptions);
522
+ /**
523
+ * Returns ids of all keywords
524
+ *
525
+ * Example getAllKeywordIds(store);
526
+ * @param {object} store store: object - store object
527
+ * @returns {array} returnType: array of all keyword ids
528
+ */
529
+ // cast to usable type - selectIds returns EntityId[] which is not usable inside of the code
530
+ var getAllFilterIds = function getAllFilterIds(store) {
531
+ return getAllFilterIdsEntity(store);
532
+ };
533
+ var EMPTY_FILTERS = {
534
+ entities: {},
535
+ ids: []
536
+ };
537
+ var _layerSelectFilterAda = layerSelectFilterAdapter.getSelectors(function (store) {
538
+ var _store$layerSelect2;
539
+ return (store == null || (_store$layerSelect2 = store.layerSelect) == null || (_store$layerSelect2 = _store$layerSelect2.filters) == null ? void 0 : _store$layerSelect2.filters) || EMPTY_FILTERS;
540
+ }),
541
+ getAllFilters = _layerSelectFilterAda.selectAll,
542
+ getAllFilterIdsEntity = _layerSelectFilterAda.selectIds,
543
+ getFilterById = _layerSelectFilterAda.selectById;
544
+ var getCheckedFilterIds = createSelector(getAllFilters, function (filters) {
545
+ return filters.filter(function (filter) {
546
+ return filter == null ? void 0 : filter.checked;
547
+ }).map(function (filter) {
548
+ return filter.id;
549
+ });
550
+ }, selectorMemoizationOptions);
551
+ var getFilters = createSelector(getAllActiveServices, getAllFilters, function (services, filters) {
552
+ var enabledServices = services.filter(function (service) {
553
+ return service.enabled;
554
+ });
555
+ var keywords = enabledServices.flatMap(function (service) {
556
+ return service.keywords;
557
+ });
558
+ var groups = enabledServices.flatMap(function (service) {
559
+ return service.groups;
560
+ });
561
+ var countEachKeyword = countBy(keywords);
562
+ var countEachGroup = countBy(groups);
563
+ var filtersWithCount = filters.map(function (filter) {
564
+ var _countEachKeyword$fil;
565
+ if (filter.type === 'groups') {
566
+ var _countEachGroup$filte;
567
+ return Object.assign({}, filter, {
568
+ amountVisible: (_countEachGroup$filte = countEachGroup[filter.name]) != null ? _countEachGroup$filte : 0
569
+ });
570
+ }
571
+ return Object.assign({}, filter, {
572
+ amountVisible: (_countEachKeyword$fil = countEachKeyword[filter.name]) != null ? _countEachKeyword$fil : 0
573
+ });
574
+ });
575
+ var _partition = partition(filtersWithCount, function (filter) {
576
+ return filter.type === 'groups';
577
+ }),
578
+ groupsWithCount = _partition[0],
579
+ keywordsWithCount = _partition[1];
580
+ var groupsSorted = [].concat(groupsWithCount).sort(function (groupA, groupB) {
581
+ return groupA.name.localeCompare(groupB.name);
582
+ });
583
+ var keywordsSorted = [].concat(keywordsWithCount).sort(function (groupA, groupB) {
584
+ return groupA.name.localeCompare(groupB.name);
585
+ });
586
+ return {
587
+ groups: groupsSorted,
588
+ keywords: keywordsSorted
589
+ };
590
+ });
591
+ /**
592
+ * Returns if all keywords are checked
593
+ *
594
+ * Example isAllKeywordsChecked(store);
595
+ * @param {object} store store: object - store object
596
+ * @returns {array} returnType: boolean if all keywords are checked
597
+ */
598
+ var isAllFiltersChecked = createSelector(layerSelectStore, function (store) {
599
+ var _store$filters2;
600
+ return store == null || (_store$filters2 = store.filters) == null || (_store$filters2 = _store$filters2.filters) == null ? void 0 : _store$filters2.ids.every(function (filterId) {
601
+ var _store$filters3;
602
+ return store == null || (_store$filters3 = store.filters) == null || (_store$filters3 = _store$filters3.filters) == null || (_store$filters3 = _store$filters3.entities[filterId]) == null ? void 0 : _store$filters3.checked;
603
+ });
604
+ });
605
+ /**
606
+ * Returns a filtered active layer object based on the given filter settings
607
+ * Example: layerSelectSelectors.getFilteredLayers(store, filteredSettings);
608
+ * @param {object} store store: object - object from which the service state will be extracted
609
+ * @returns {array} returnType: LayerWithServiceName - an array of all filtered activelayers
610
+ */
611
+ var getFilteredLayers = createSelector([getEnabledServiceIds, serviceSelectors.getServices, getCheckedFilterIds, isAllFiltersChecked, getSearchFilter], function (enabledServiceIds, servicesStore, checkedFilterIds, allFiltersActive, searchFilter) {
612
+ return enabledServiceIds.reduce(function (layerList, serviceId) {
613
+ return layerList.concat(filterLayersFromService(serviceId, servicesStore, checkedFilterIds, allFiltersActive, searchFilter).map(function (layer) {
614
+ return Object.assign({}, layer, {
615
+ serviceName: serviceId
616
+ });
617
+ }));
618
+ }, []);
619
+ }, selectorMemoizationOptions);
620
+ /**
621
+ * Returns service popup details
622
+ *
623
+ * Example getServicePopupDetails(store, 'server-id');
624
+ * @param {object} store store: object - store object
625
+ * @returns {object} returnType: object of active service
626
+ */
627
+ var getServicePopupDetails = function getServicePopupDetails(store) {
628
+ var _store$layerSelect3;
629
+ return (store == null || (_store$layerSelect3 = store.layerSelect) == null ? void 0 : _store$layerSelect3.servicePopup) || initialServicePopupState;
630
+ };
631
+ /**
632
+ * Returns service with active filtered layers from seaerch
633
+ *
634
+ * Example getFilteredActiveServices(store);
635
+ * @param {object} store store: object - store object
636
+ * @returns {object} returnType: object of active service
637
+ */
638
+ var getFilteredActiveServices = createSelector([getFilteredLayers, getActiveServices, getSearchFilter], function (layers, activeServices, searchResult) {
639
+ var servicesResult = searchResult.length ? layers.reduce(function (layers, _ref) {
640
+ var serviceName = _ref.serviceName;
641
+ return layers.includes(serviceName) ? layers : layers.concat(serviceName);
642
+ }, []) : [];
643
+ var updatedServices = Object.fromEntries(Object.entries(activeServices).map(function (_ref2) {
644
+ var key = _ref2[0],
645
+ service = _ref2[1];
646
+ return [key, Object.assign({}, service, {
647
+ isInSearch: servicesResult.includes(service.serviceId)
648
+ })];
649
+ }));
650
+ return updatedServices;
651
+ }, selectorMemoizationOptions);
652
+
653
+ var selectors = /*#__PURE__*/Object.freeze({
654
+ __proto__: null,
655
+ getActiveServiceById: getActiveServiceById,
656
+ getActiveServices: getActiveServices,
657
+ getActiveServicesDictionary: getActiveServicesDictionary,
658
+ getAllActiveServices: getAllActiveServices,
659
+ getAllFilterIds: getAllFilterIds,
660
+ getAllFilterIdsEntity: getAllFilterIdsEntity,
661
+ getAllFilters: getAllFilters,
662
+ getCheckedFilterIds: getCheckedFilterIds,
663
+ getEnabledServiceIds: getEnabledServiceIds,
664
+ getFilterById: getFilterById,
665
+ getFilteredActiveServices: getFilteredActiveServices,
666
+ getFilteredLayers: getFilteredLayers,
667
+ getFilters: getFilters,
668
+ getSearchFilter: getSearchFilter,
669
+ getServicePopupDetails: getServicePopupDetails,
670
+ isAllFiltersChecked: isAllFiltersChecked,
671
+ useAppSelector: useAppSelector
672
+ });
673
+
674
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
675
+ try {
676
+ var i = n[a](c),
677
+ u = i.value;
678
+ } catch (n) {
679
+ return void e(n);
680
+ }
681
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
682
+ }
683
+ function _asyncToGenerator(n) {
684
+ return function () {
685
+ var t = this,
686
+ e = arguments;
687
+ return new Promise(function (r, o) {
688
+ var a = n.apply(t, e);
689
+ function _next(n) {
690
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
691
+ }
692
+ function _throw(n) {
693
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
694
+ }
695
+ _next(void 0);
696
+ });
697
+ };
698
+ }
699
+ function _objectDestructuringEmpty(t) {
700
+ if (null == t) throw new TypeError("Cannot destructure " + t);
701
+ }
702
+ function _regenerator() {
703
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
704
+ var e,
705
+ t,
706
+ r = "function" == typeof Symbol ? Symbol : {},
707
+ n = r.iterator || "@@iterator",
708
+ o = r.toStringTag || "@@toStringTag";
709
+ function i(r, n, o, i) {
710
+ var c = n && n.prototype instanceof Generator ? n : Generator,
711
+ u = Object.create(c.prototype);
712
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
713
+ var i,
714
+ c,
715
+ u,
716
+ f = 0,
717
+ p = o || [],
718
+ y = false,
719
+ G = {
720
+ p: 0,
721
+ n: 0,
722
+ v: e,
723
+ a: d,
724
+ f: d.bind(e, 4),
725
+ d: function (t, r) {
726
+ return i = t, c = 0, u = e, G.n = r, a;
727
+ }
728
+ };
729
+ function d(r, n) {
730
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
731
+ var o,
732
+ i = p[t],
733
+ d = G.p,
734
+ l = i[2];
735
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
736
+ }
737
+ if (o || r > 1) return a;
738
+ throw y = true, n;
739
+ }
740
+ return function (o, p, l) {
741
+ if (f > 1) throw TypeError("Generator is already running");
742
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
743
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
744
+ try {
745
+ if (f = 2, i) {
746
+ if (c || (o = "next"), t = i[o]) {
747
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
748
+ if (!t.done) return t;
749
+ u = t.value, c < 2 && (c = 0);
750
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
751
+ i = e;
752
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
753
+ } catch (t) {
754
+ i = e, c = 1, u = t;
755
+ } finally {
756
+ f = 1;
757
+ }
758
+ }
759
+ return {
760
+ value: t,
761
+ done: y
762
+ };
763
+ };
764
+ }(r, o, i), true), u;
765
+ }
766
+ var a = {};
767
+ function Generator() {}
768
+ function GeneratorFunction() {}
769
+ function GeneratorFunctionPrototype() {}
770
+ t = Object.getPrototypeOf;
771
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
772
+ return this;
773
+ }), t),
774
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
775
+ function f(e) {
776
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
777
+ }
778
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
779
+ return this;
780
+ }), _regeneratorDefine(u, "toString", function () {
781
+ return "[object Generator]";
782
+ }), (_regenerator = function () {
783
+ return {
784
+ w: i,
785
+ m: f
786
+ };
787
+ })();
788
+ }
789
+ function _regeneratorDefine(e, r, n, t) {
790
+ var i = Object.defineProperty;
791
+ try {
792
+ i({}, "", {});
793
+ } catch (e) {
794
+ i = 0;
795
+ }
796
+ _regeneratorDefine = function (e, r, n, t) {
797
+ function o(r, n) {
798
+ _regeneratorDefine(e, r, function (e) {
799
+ return this._invoke(r, n, e);
800
+ });
801
+ }
802
+ r ? i ? i(e, r, {
803
+ value: n,
804
+ enumerable: !t,
805
+ configurable: !t,
806
+ writable: !t
807
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
808
+ }, _regeneratorDefine(e, r, n, t);
809
+ }
810
+
811
+ var layerSelectListener = createListenerMiddleware();
812
+ layerSelectListener.startListening({
813
+ actionCreator: serviceActions.mapStoreRemoveService,
814
+ effect: function () {
815
+ var _effect = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(action) {
816
+ var serviceUrl, localStorageServices;
817
+ return _regenerator().w(function (_context) {
818
+ while (1) switch (_context.n) {
819
+ case 0:
820
+ serviceUrl = action.payload.serviceUrl;
821
+ localStorageServices = getUserAddedServices();
822
+ delete localStorageServices[serviceUrl];
823
+ setUserAddedServices(localStorageServices);
824
+ case 1:
825
+ return _context.a(2);
826
+ }
827
+ }, _callee);
828
+ }));
829
+ function effect(_x) {
830
+ return _effect.apply(this, arguments);
831
+ }
832
+ return effect;
833
+ }()
834
+ });
835
+ layerSelectListener.startListening({
836
+ actionCreator: layerSelectActions.layerSelectRemoveService,
837
+ effect: function () {
838
+ var _effect2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(action, listenerApi) {
839
+ var removedService, serviceId, serviceUrl, services, servicesEnabled;
840
+ return _regenerator().w(function (_context2) {
841
+ while (1) switch (_context2.n) {
842
+ case 0:
843
+ removedService = action.payload;
844
+ serviceId = removedService.serviceId, serviceUrl = removedService.serviceUrl;
845
+ services = getActiveServices(listenerApi.getState());
846
+ servicesEnabled = Object.values(services).find(function (service) {
847
+ return service == null ? void 0 : service.enabled;
848
+ });
849
+ if (servicesEnabled === undefined) {
850
+ Object.entries(services).map(function (_ref) {
851
+ var entryServiceId = _ref[0];
852
+ return listenerApi.dispatch(layerSelectActions.enableActiveService({
853
+ serviceId: entryServiceId
854
+ }));
855
+ });
856
+ }
857
+ listenerApi.dispatch(serviceActions.mapStoreRemoveService({
858
+ id: serviceId,
859
+ serviceUrl: serviceUrl
860
+ }));
861
+ case 1:
862
+ return _context2.a(2);
863
+ }
864
+ }, _callee2);
865
+ }));
866
+ function effect(_x2, _x3) {
867
+ return _effect2.apply(this, arguments);
868
+ }
869
+ return effect;
870
+ }()
871
+ });
872
+ layerSelectListener.startListening({
873
+ actionCreator: serviceActions.serviceSetLayers,
874
+ effect: function () {
875
+ var _effect3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(action) {
876
+ var _action$payload, scope, name, serviceUrl, _abstract, type, _Object$assign, localStorageServices, storedService;
877
+ return _regenerator().w(function (_context3) {
878
+ while (1) switch (_context3.n) {
879
+ case 0:
880
+ _action$payload = action.payload, scope = _action$payload.scope, name = _action$payload.name, serviceUrl = _action$payload.serviceUrl, _abstract = _action$payload["abstract"], type = _action$payload.type;
881
+ if (isUserAddedService(scope)) {
882
+ localStorageServices = getUserAddedServices();
883
+ storedService = {
884
+ name: name,
885
+ url: serviceUrl,
886
+ "abstract": _abstract,
887
+ type: type
888
+ };
889
+ setUserAddedServices(Object.assign({}, localStorageServices, (_Object$assign = {}, _Object$assign[serviceUrl] = storedService, _Object$assign)));
890
+ }
891
+ case 1:
892
+ return _context3.a(2);
893
+ }
894
+ }, _callee3);
895
+ }));
896
+ function effect(_x4) {
897
+ return _effect3.apply(this, arguments);
898
+ }
899
+ return effect;
900
+ }()
901
+ });
902
+ layerSelectListener.startListening({
903
+ matcher: isAnyOf(uiActions.setToggleOpenDialog, uiActions.setActiveMapIdForDialog),
904
+ effect: function () {
905
+ var _effect4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(action, listenerApi) {
906
+ var payload;
907
+ return _regenerator().w(function (_context4) {
908
+ while (1) switch (_context4.n) {
909
+ case 0:
910
+ payload = action.payload;
911
+ if (!payload.setOpen && payload.type === uiTypes.DialogTypes.LayerSelect) {
912
+ listenerApi.dispatch(layerActions.hideLayerInfo());
913
+ }
914
+ case 1:
915
+ return _context4.a(2);
916
+ }
917
+ }, _callee4);
918
+ }));
919
+ function effect(_x5, _x6) {
920
+ return _effect4.apply(this, arguments);
921
+ }
922
+ return effect;
923
+ }()
924
+ });
925
+ layerSelectListener.startListening({
926
+ matcher: isAnyOf(layerSelectActions.disableActiveService, layerSelectActions.onlyThisServiceEnabled, layerSelectActions.toggleFilter, layerSelectActions.setSearchFilter),
927
+ effect: function () {
928
+ var _effect5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(action, listenerApi) {
929
+ var filteredLayers, dialogInfo, layerWithData;
930
+ return _regenerator().w(function (_context5) {
931
+ while (1) switch (_context5.n) {
932
+ case 0:
933
+ if (uiSelectors.getisDialogOpen(listenerApi.getState(), uiTypes.DialogTypes.LayerInfo)) {
934
+ filteredLayers = getFilteredLayers(listenerApi.getState());
935
+ dialogInfo = layerSelectors.getActiveLayerInfo(listenerApi.getState());
936
+ layerWithData = dialogInfo && serviceSelectors.getLayerFromService(listenerApi.getState(), dialogInfo.serviceUrl, dialogInfo.layerName);
937
+ if (!filteredLayers.map(function (layer) {
938
+ return layer.title;
939
+ }).includes((layerWithData == null ? void 0 : layerWithData.title) || '')) {
940
+ listenerApi.dispatch(layerActions.hideLayerInfo());
941
+ }
942
+ }
943
+ case 1:
944
+ return _context5.a(2);
945
+ }
946
+ }, _callee5);
947
+ }));
948
+ function effect(_x7, _x8) {
949
+ return _effect5.apply(this, arguments);
950
+ }
951
+ return effect;
952
+ }()
953
+ });
954
+
955
+ /* *
956
+ * Licensed under the Apache License, Version 2.0 (the "License");
957
+ * you may not use this file except in compliance with the License.
958
+ * You may obtain a copy of the License at
959
+ *
960
+ * http://www.apache.org/licenses/LICENSE-2.0
961
+ *
962
+ * Unless required by applicable law or agreed to in writing, software
963
+ * distributed under the License is distributed on an "AS IS" BASIS,
964
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
965
+ * See the License for the specific language governing permissions and
966
+ * limitations under the License.
967
+ *
968
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
969
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
970
+ * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
971
+ * */
972
+ var layerSelectReducersMap = {
973
+ webmap: mapReducer,
974
+ services: serviceReducer,
975
+ layers: layerReducer,
976
+ layerSelect: layerSelectReducer,
977
+ ui: uiReducer,
978
+ snackbar: snackbarReducer
979
+ };
980
+ var layerSelectMiddlewares = [mapListener.middleware, serviceListener.middleware, layersListener.middleware, layerSelectListener.middleware, snackbarListener.middleware, openlayersListener.middleware];
981
+ var layerSelectRootReducer = combineReducers(layerSelectReducersMap);
982
+ var createMockStore = function createMockStore(mockState) {
983
+ return configureStore({
984
+ reducer: layerSelectRootReducer,
985
+ preloadedState: mockState,
986
+ middleware: function middleware(getDefaultMiddleware) {
987
+ return getDefaultMiddleware().concat(layerSelectMiddlewares);
988
+ }
989
+ });
990
+ };
991
+
992
+ var KeywordFilterButtonConnect = function KeywordFilterButtonConnect(_ref) {
993
+ var mapId = _ref.mapId,
994
+ _ref$source = _ref.source,
995
+ source = _ref$source === void 0 ? 'app' : _ref$source,
996
+ isMultiMap = _ref.isMultiMap;
997
+ var dispatch = useDispatch();
998
+ var dialogType = isMultiMap ? uiTypes.DialogTypes.KeywordFilter + "-" + mapId : uiTypes.DialogTypes.KeywordFilter;
999
+ var currentActiveMapId = useAppSelector(function (store) {
1000
+ return uiSelectors.getDialogMapId(store, dialogType);
1001
+ });
1002
+ var isOpenInStore = useAppSelector(function (store) {
1003
+ return uiSelectors.getisDialogOpen(store, dialogType);
1004
+ });
1005
+ var openFilterResultsDialog = React.useCallback(function () {
1006
+ dispatch(uiActions.setActiveMapIdForDialog({
1007
+ type: dialogType,
1008
+ mapId: mapId,
1009
+ setOpen: currentActiveMapId !== mapId ? true : !isOpenInStore,
1010
+ source: source
1011
+ }));
1012
+ }, [currentActiveMapId, dispatch, isOpenInStore, mapId, source, dialogType]);
1013
+ return jsx(CustomIconButton, {
1014
+ "data-testid": "keywordFilterButton",
1015
+ id: "keywordFilterButton",
1016
+ isSelected: isOpenInStore,
1017
+ onClick: openFilterResultsDialog,
1018
+ variant: "tool",
1019
+ children: jsx(Filter, {})
1020
+ });
1021
+ };
1022
+
1023
+ var KeywordFilterResultsListItemConnect = function KeywordFilterResultsListItemConnect(_ref) {
1024
+ var filter = _ref.filter;
1025
+ var dispatch = useDispatch();
1026
+ var toggleFilter = React.useCallback(function (filterId, only) {
1027
+ dispatch(layerSelectActions.toggleFilter({
1028
+ filterId: filterId,
1029
+ only: only
1030
+ }));
1031
+ }, [dispatch]);
1032
+ return jsx(FilterOption, {
1033
+ checked: !!filter.checked,
1034
+ label: filter.amountVisible ? filter.name + " (" + filter.amountVisible + ")" : filter.name,
1035
+ onClick: function onClick(checked, only) {
1036
+ toggleFilter(filter.id, only);
1037
+ },
1038
+ optionId: filter.id
1039
+ });
1040
+ };
1041
+
1042
+ var KeywordFilterSelectAllSwitchConnect = function KeywordFilterSelectAllSwitchConnect() {
1043
+ var dispatch = useDispatch();
1044
+ var allFiltersActive = useAppSelector(function (store) {
1045
+ return isAllFiltersChecked(store);
1046
+ });
1047
+ var toggleFilters = React.useCallback(function () {
1048
+ dispatch(layerSelectActions.toggleAllFilters());
1049
+ }, [dispatch]);
1050
+ return jsx(Switch, {
1051
+ checked: allFiltersActive,
1052
+ "data-testid": "customSwitch",
1053
+ onChange: toggleFilters,
1054
+ slotProps: {
1055
+ input: {
1056
+ 'aria-label': 'All'
1057
+ }
1058
+ }
1059
+ });
1060
+ };
1061
+
1062
+ /* *
1063
+ * Licensed under the Apache License, Version 2.0 (the "License");
1064
+ * you may not use this file except in compliance with the License.
1065
+ * You may obtain a copy of the License at
1066
+ *
1067
+ * http://www.apache.org/licenses/LICENSE-2.0
1068
+ *
1069
+ * Unless required by applicable law or agreed to in writing, software
1070
+ * distributed under the License is distributed on an "AS IS" BASIS,
1071
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1072
+ * See the License for the specific language governing permissions and
1073
+ * limitations under the License.
1074
+ *
1075
+ * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1076
+ * Copyright 2024 - Finnish Meteorological Institute (FMI)
1077
+ * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1078
+ * */
1079
+ var LAYER_SELECT_NAMESPACE = 'layerselect';
1080
+ var useLayerSelectTranslation = function useLayerSelectTranslation() {
1081
+ return useTranslation(LAYER_SELECT_NAMESPACE);
1082
+ };
1083
+
1084
+ var listStyle = {
1085
+ padding: '0px'
1086
+ };
1087
+ var accordionDetailsStyle = {
1088
+ margin: '0px',
1089
+ padding: '0 12px'
1090
+ };
1091
+ var KeywordFilterResults = function KeywordFilterResults(_ref) {
1092
+ var filters = _ref.filters,
1093
+ bounds = _ref.bounds,
1094
+ _ref$onClose = _ref.onClose,
1095
+ onClose = _ref$onClose === void 0 ? function () {} : _ref$onClose,
1096
+ isOpen = _ref.isOpen,
1097
+ _ref$onMouseDown = _ref.onMouseDown,
1098
+ onMouseDown = _ref$onMouseDown === void 0 ? function () {} : _ref$onMouseDown,
1099
+ _ref$order = _ref.order,
1100
+ order = _ref$order === void 0 ? 0 : _ref$order,
1101
+ _ref$source = _ref.source,
1102
+ source = _ref$source === void 0 ? 'module' : _ref$source;
1103
+ var _useLayerSelectTransl = useLayerSelectTranslation(),
1104
+ t = _useLayerSelectTransl.t;
1105
+ return jsxs(ToolContainerDraggable, {
1106
+ bounds: bounds,
1107
+ "data-testid": "keywordFilterResults",
1108
+ isOpen: isOpen,
1109
+ minHeight: 192,
1110
+ minWidth: 312,
1111
+ onClose: onClose,
1112
+ onMouseDown: onMouseDown,
1113
+ order: order,
1114
+ source: source,
1115
+ startSize: {
1116
+ width: 349,
1117
+ height: 600
1118
+ },
1119
+ title: t('groups-and-keywords-dialog-title'),
1120
+ children: [jsxs(Grid, {
1121
+ container: true,
1122
+ size: {
1123
+ xs: 12
1124
+ },
1125
+ sx: {
1126
+ alignItems: 'center',
1127
+ justifyContent: 'space-between',
1128
+ backgroundColor: 'background.paper',
1129
+ position: 'sticky',
1130
+ top: 0,
1131
+ zIndex: 100
1132
+ },
1133
+ children: [jsx(Grid, {
1134
+ container: true,
1135
+ size: {
1136
+ xs: 6
1137
+ },
1138
+ sx: {
1139
+ alignItems: 'center',
1140
+ justifyContent: 'flex-start',
1141
+ padding: '15px 15px 0 24px'
1142
+ },
1143
+ children: t('select-all')
1144
+ }), jsx(Grid, {
1145
+ container: true,
1146
+ size: {
1147
+ xs: 6
1148
+ },
1149
+ sx: {
1150
+ alignContent: 'center',
1151
+ justifyContent: 'flex-end',
1152
+ padding: '15px 15px 0 15px'
1153
+ },
1154
+ children: jsx(KeywordFilterSelectAllSwitchConnect, {})
1155
+ })]
1156
+ }), jsx(CustomAccordion, {
1157
+ detailsSx: accordionDetailsStyle,
1158
+ title: t('groups'),
1159
+ children: jsx(List, {
1160
+ dense: true,
1161
+ style: listStyle,
1162
+ children: filters.groups.map(function (group) {
1163
+ return jsx(KeywordFilterResultsListItemConnect, {
1164
+ filter: group
1165
+ }, group.id);
1166
+ })
1167
+ })
1168
+ }), jsx(CustomAccordion, {
1169
+ detailsSx: accordionDetailsStyle,
1170
+ title: t('keywords'),
1171
+ children: jsx(List, {
1172
+ dense: true,
1173
+ style: listStyle,
1174
+ children: filters.keywords.map(function (keyword) {
1175
+ return jsx(KeywordFilterResultsListItemConnect, {
1176
+ filter: keyword
1177
+ }, keyword.id);
1178
+ })
1179
+ })
1180
+ })]
1181
+ });
1182
+ };
1183
+
1184
+ var KeywordFilterResultsConnect = function KeywordFilterResultsConnect(_ref) {
1185
+ var bounds = _ref.bounds,
1186
+ mapId = _ref.mapId,
1187
+ isMultiMap = _ref.isMultiMap;
1188
+ var dialogType = isMultiMap ? uiTypes.DialogTypes.KeywordFilter + "-" + mapId : uiTypes.DialogTypes.KeywordFilter;
1189
+ var _useSetupDialog = useSetupDialog(dialogType),
1190
+ dialogOrder = _useSetupDialog.dialogOrder,
1191
+ onCloseDialog = _useSetupDialog.onCloseDialog,
1192
+ setDialogOrder = _useSetupDialog.setDialogOrder,
1193
+ isDialogOpen = _useSetupDialog.isDialogOpen,
1194
+ uiSource = _useSetupDialog.uiSource;
1195
+ var filters = useAppSelector(getFilters);
1196
+ return jsx(KeywordFilterResults, {
1197
+ bounds: bounds,
1198
+ filters: filters,
1199
+ isOpen: isDialogOpen,
1200
+ onClose: onCloseDialog,
1201
+ onMouseDown: setDialogOrder,
1202
+ order: dialogOrder,
1203
+ source: uiSource
1204
+ });
1205
+ };
1206
+
1207
+ var LayerAddRemoveButton = function LayerAddRemoveButton(_ref) {
1208
+ var layer = _ref.layer,
1209
+ serviceUrl = _ref.serviceUrl,
1210
+ serviceType = _ref.serviceType,
1211
+ allLayers = _ref.allLayers,
1212
+ allMapIds = _ref.allMapIds,
1213
+ addLayer = _ref.addLayer,
1214
+ addLayerToAllMaps = _ref.addLayerToAllMaps,
1215
+ deleteLayer = _ref.deleteLayer,
1216
+ removeLayerFromAllMaps = _ref.removeLayerFromAllMaps,
1217
+ mapLayers = _ref.mapLayers;
1218
+ var _useLayerSelectTransl = useLayerSelectTranslation(),
1219
+ t = _useLayerSelectTransl.t;
1220
+ var _React$useState = React.useState(false),
1221
+ open = _React$useState[0],
1222
+ setOpen = _React$useState[1];
1223
+ var anchorRef = React.useRef(null);
1224
+ var foundLayerIndex = React.useMemo(function () {
1225
+ return mapLayers.findIndex(function (lr) {
1226
+ return lr.name === layer.name && lr.service === serviceUrl;
1227
+ });
1228
+ }, [mapLayers, layer.name, serviceUrl]);
1229
+ var foundLayer = foundLayerIndex !== -1 && mapLayers[foundLayerIndex];
1230
+ var layerExistsInWorkspace = React.useMemo(function () {
1231
+ return allLayers.find(function (current) {
1232
+ return current.name === layer.name && current.service === serviceUrl;
1233
+ });
1234
+ }, [allLayers, layer.name, serviceUrl]);
1235
+ var existsInAllMaps = React.useMemo(function () {
1236
+ return allMapIds.every(function (mapId) {
1237
+ return allLayers.some(function (current) {
1238
+ return current.mapId === mapId && current.name === layer.name && current.service === serviceUrl;
1239
+ });
1240
+ });
1241
+ }, [allMapIds, allLayers, layer.name, serviceUrl]);
1242
+ var handleToggle = function handleToggle() {
1243
+ setOpen(function (prevOpen) {
1244
+ return !prevOpen;
1245
+ });
1246
+ };
1247
+ var handleClose = function handleClose(event) {
1248
+ var _anchorRef$current;
1249
+ if ((_anchorRef$current = anchorRef.current) != null && _anchorRef$current.contains(event.target)) {
1250
+ return;
1251
+ }
1252
+ setOpen(false);
1253
+ };
1254
+ var handleAddAll = function handleAddAll() {
1255
+ addLayerToAllMaps({
1256
+ serviceUrl: serviceUrl,
1257
+ layerName: layer.name,
1258
+ serviceType: serviceType
1259
+ });
1260
+ setOpen(false);
1261
+ };
1262
+ var handleRemoveAll = function handleRemoveAll(id) {
1263
+ removeLayerFromAllMaps(id);
1264
+ setOpen(false);
1265
+ };
1266
+ return jsxs(Fragment, {
1267
+ children: [jsxs(ToggleButtonGroup, {
1268
+ fullWidth: true,
1269
+ ref: anchorRef,
1270
+ style: {
1271
+ height: '32px'
1272
+ },
1273
+ children: [jsx(ToggleButton, {
1274
+ className: "tool",
1275
+ "data-testid": "layerAddRemoveButton-" + layer.name,
1276
+ fullWidth: true,
1277
+ onClick: function onClick() {
1278
+ !foundLayer ? addLayer({
1279
+ serviceUrl: serviceUrl,
1280
+ layerName: layer.name,
1281
+ serviceType: serviceType
1282
+ }) : deleteLayer({
1283
+ layerId: foundLayer.id,
1284
+ layerIndex: foundLayerIndex
1285
+ });
1286
+ },
1287
+ onMouseDown: function onMouseDown(e) {
1288
+ e.stopPropagation();
1289
+ },
1290
+ selected: !!foundLayer,
1291
+ style: {
1292
+ borderRadius: '3px 0 0 3px',
1293
+ height: 'inherit',
1294
+ minWidth: '62px',
1295
+ fontSize: '12px'
1296
+ },
1297
+ value: "selected",
1298
+ children: !foundLayer ? t('add') : t('remove')
1299
+ }), jsx(Box, {
1300
+ sx: {
1301
+ minWidth: '1px',
1302
+ backgroundColor: foundLayer || layerExistsInWorkspace ? 'geowebColors.buttons.primary.default.borderColor' : 'geowebColors.buttons.secondary.default.fill'
1303
+ }
1304
+ }), jsx(ToggleButton, {
1305
+ className: "tool",
1306
+ "data-testid": "layerAddRemoveButton-dropdown-" + layer.name,
1307
+ onClick: handleToggle,
1308
+ onMouseDown: function onMouseDown(e) {
1309
+ e.stopPropagation();
1310
+ },
1311
+ selected: !!layerExistsInWorkspace,
1312
+ style: {
1313
+ marginLeft: '0',
1314
+ minWidth: '32px',
1315
+ borderRadius: '0 3px 3px 0',
1316
+ height: 'inherit'
1317
+ },
1318
+ value: "dropdown",
1319
+ children: jsx(ArrowDropDownDown, {
1320
+ style: {
1321
+ marginRight: '1px'
1322
+ }
1323
+ })
1324
+ })]
1325
+ }), jsx(Popper, {
1326
+ anchorEl: anchorRef.current,
1327
+ open: open,
1328
+ placement: "bottom-end",
1329
+ role: undefined,
1330
+ style: {
1331
+ zIndex: 1300
1332
+ },
1333
+ transition: true,
1334
+ children: function children(_ref2) {
1335
+ var TransitionProps = _ref2.TransitionProps,
1336
+ placement = _ref2.placement;
1337
+ return jsx(Grow, Object.assign({}, TransitionProps, {
1338
+ style: {
1339
+ transformOrigin: placement === 'bottom' ? 'center top' : 'center bottom'
1340
+ },
1341
+ children: jsx(Paper, {
1342
+ children: jsx(ClickAwayListener, {
1343
+ onClickAway: handleClose,
1344
+ children: jsxs(MenuList, {
1345
+ autoFocusItem: true,
1346
+ children: [jsx(MenuItem, {
1347
+ disabled: existsInAllMaps,
1348
+ onClick: handleAddAll,
1349
+ children: t('add-to-all-maps')
1350
+ }), jsx(MenuItem, {
1351
+ disabled: !layerExistsInWorkspace,
1352
+ onClick: function onClick() {
1353
+ layerExistsInWorkspace && handleRemoveAll(layerExistsInWorkspace.id);
1354
+ },
1355
+ children: t('remove-from-all-maps')
1356
+ })]
1357
+ })
1358
+ })
1359
+ })
1360
+ }));
1361
+ }
1362
+ })]
1363
+ });
1364
+ };
1365
+
1366
+ var LayerListDimensions = function LayerListDimensions(_ref) {
1367
+ var dimensions = _ref.dimensions;
1368
+ if (!(dimensions != null && dimensions.length)) {
1369
+ return null;
1370
+ }
1371
+ return jsx(Fragment, {
1372
+ children: dimensions.map(function (dimension) {
1373
+ return jsx(CustomTooltip, {
1374
+ title: dimension.label + ": " + dimension.value,
1375
+ children: jsx("span", {
1376
+ style: {
1377
+ marginRight: 4
1378
+ },
1379
+ children: dimension.icon
1380
+ })
1381
+ }, dimension.label);
1382
+ })
1383
+ });
1384
+ };
1385
+
1386
+ /* *
1387
+ * Licensed under the Apache License, Version 2.0 (the "License");
1388
+ * you may not use this file except in compliance with the License.
1389
+ * You may obtain a copy of the License at
1390
+ *
1391
+ * http://www.apache.org/licenses/LICENSE-2.0
1392
+ *
1393
+ * Unless required by applicable law or agreed to in writing, software
1394
+ * distributed under the License is distributed on an "AS IS" BASIS,
1395
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1396
+ * See the License for the specific language governing permissions and
1397
+ * limitations under the License.
1398
+ *
1399
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1400
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
1401
+ * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1402
+ * */
1403
+ var buttonLarge = 80;
1404
+ var buttonSmall = 60;
1405
+ var layerSelectColumnsLarge = {
1406
+ column1: {
1407
+ width: 112
1408
+ },
1409
+ column2: {
1410
+ marginTop: '6px',
1411
+ width: "calc(100% - 112px)",
1412
+ height: '36px',
1413
+ paddingLeft: '20px'
1414
+ },
1415
+ column3: {
1416
+ height: '12px'
1417
+ },
1418
+ column4: {
1419
+ height: '24px'
1420
+ },
1421
+ column5: {
1422
+ height: '24px',
1423
+ width: 140
1424
+ },
1425
+ column6: {
1426
+ height: '24px',
1427
+ width: "calc(100% - 140px)"
1428
+ },
1429
+ column7: {
1430
+ height: '48px',
1431
+ width: buttonLarge,
1432
+ marginRight: 1,
1433
+ marginLeft: 2
1434
+ },
1435
+ column8: {
1436
+ width: "calc(100% - " + buttonLarge + "px - 32px)"
1437
+ },
1438
+ column9: {
1439
+ width: "calc(" + buttonLarge + "px + 32px)"
1440
+ }
1441
+ };
1442
+ var layerSelectColumnsSmall = {
1443
+ column1: {
1444
+ width: '100%'
1445
+ },
1446
+ column2: {
1447
+ marginTop: '4px',
1448
+ width: "calc(100% - 20px)"
1449
+ },
1450
+ column3: {
1451
+ height: '12px'
1452
+ },
1453
+ column4: {
1454
+ height: '48px'
1455
+ },
1456
+ column5: {
1457
+ height: '24px',
1458
+ width: '100%'
1459
+ },
1460
+ column6: {
1461
+ height: '24px',
1462
+ width: '100%'
1463
+ },
1464
+ column7: {
1465
+ height: '48px',
1466
+ width: buttonSmall,
1467
+ marginRight: 0,
1468
+ marginLeft: 1
1469
+ },
1470
+ column8: {
1471
+ width: "calc(100% - " + buttonSmall + "px - 50px)"
1472
+ },
1473
+ column9: {
1474
+ width: "calc(" + buttonSmall + "px + 50px)"
1475
+ }
1476
+ };
1477
+ var breakpoint = 500;
1478
+ var widthToColumns = function widthToColumns(width) {
1479
+ if (width <= breakpoint) {
1480
+ return layerSelectColumnsSmall;
1481
+ }
1482
+ return layerSelectColumnsLarge;
1483
+ };
1484
+ var rowHeightLarge = 68;
1485
+ var rowHeightSmall = 136;
1486
+ var widthToRowHeight = function widthToRowHeight(width) {
1487
+ if (width <= breakpoint) {
1488
+ return rowHeightSmall;
1489
+ }
1490
+ return rowHeightLarge;
1491
+ };
1492
+ var sortByService = function sortByService(serviceObj) {
1493
+ return Object.entries(serviceObj).sort(function (_ref, _ref2) {
1494
+ var serviceA = _ref[1];
1495
+ var serviceB = _ref2[1];
1496
+ return serviceA.serviceName.localeCompare(serviceB == null ? void 0 : serviceB.serviceName);
1497
+ }).reduce(function (result, _ref3) {
1498
+ var _Object$assign;
1499
+ var key = _ref3[0],
1500
+ value = _ref3[1];
1501
+ return Object.assign({}, result, (_Object$assign = {}, _Object$assign[key] = value, _Object$assign));
1502
+ }, {});
1503
+ };
1504
+
1505
+ var layerInfoStyle = {
1506
+ fontSize: '10px',
1507
+ textOverflow: 'ellipsis',
1508
+ overflow: 'hidden',
1509
+ whiteSpace: 'nowrap',
1510
+ lineHeight: 1
1511
+ };
1512
+ var LayerListRow = function LayerListRow(_ref) {
1513
+ var _layer$keywords, _layer$keywords2;
1514
+ var layer = _ref.layer,
1515
+ service = _ref.service,
1516
+ allLayers = _ref.allLayers,
1517
+ allMapIds = _ref.allMapIds,
1518
+ addLayer = _ref.addLayer,
1519
+ addLayerToAllMaps = _ref.addLayerToAllMaps,
1520
+ deleteLayer = _ref.deleteLayer,
1521
+ removeLayerFromAllMaps = _ref.removeLayerFromAllMaps,
1522
+ mapLayers = _ref.mapLayers,
1523
+ layerSelectWidth = _ref.layerSelectWidth,
1524
+ searchFilter = _ref.searchFilter,
1525
+ _ref$hasActiveLayer = _ref.hasActiveLayer,
1526
+ hasActiveLayer = _ref$hasActiveLayer === void 0 ? false : _ref$hasActiveLayer,
1527
+ onToggleActiveLayer = _ref.onToggleActiveLayer;
1528
+ var _useLayerSelectTransl = useLayerSelectTranslation(),
1529
+ t = _useLayerSelectTransl.t;
1530
+ var rowHeight = widthToRowHeight(layerSelectWidth);
1531
+ var columns = widthToColumns(layerSelectWidth);
1532
+ var dimensions = getDimensionsList(layer.dimensions);
1533
+ var layerServiceUrl = React.useMemo(function () {
1534
+ if (service.type !== 'STAC') {
1535
+ return service.serviceUrl;
1536
+ }
1537
+ var baseUrl = service.serviceUrl.replace(/\/$/, '');
1538
+ return baseUrl + "/collections/" + encodeURIComponent(layer.name);
1539
+ }, [layer.name, service.serviceUrl, service.type]);
1540
+ return jsxs(Grid, {
1541
+ container: true,
1542
+ "data-testid": "layerListLayerRow",
1543
+ sx: {
1544
+ alignItems: 'center',
1545
+ justifyContent: 'center',
1546
+ backgroundColor: 'geowebColors.cards.cardContainer',
1547
+ padding: '8px',
1548
+ marginBottom: '4px',
1549
+ height: rowHeight,
1550
+ border: 'solid 1px',
1551
+ borderColor: 'geowebColors.cards.cardContainerBorder'
1552
+ },
1553
+ children: [jsxs(Grid, {
1554
+ container: true,
1555
+ sx: columns.column8,
1556
+ children: [jsx(Grid, {
1557
+ size: {
1558
+ xs: 12
1559
+ },
1560
+ children: jsx(Box, {
1561
+ sx: {
1562
+ fontSize: '12px',
1563
+ height: '14px',
1564
+ lineHeight: '14px',
1565
+ fontWeight: 500,
1566
+ textOverflow: 'ellipsis',
1567
+ overflow: 'hidden'
1568
+ },
1569
+ children: jsx(SearchHighlight, {
1570
+ search: searchFilter,
1571
+ text: layer.title
1572
+ })
1573
+ })
1574
+ }), jsxs(Grid, {
1575
+ container: true,
1576
+ sx: Object.assign({}, columns.column1, {
1577
+ flexDirection: 'column'
1578
+ }),
1579
+ children: [jsx(Box, {
1580
+ sx: {
1581
+ fontSize: '12px',
1582
+ height: '18px',
1583
+ lineHeight: '18px',
1584
+ textOverflow: 'ellipsis',
1585
+ overflow: 'hidden'
1586
+ },
1587
+ children: jsx(SearchHighlight, {
1588
+ search: searchFilter,
1589
+ text: service.name
1590
+ })
1591
+ }), jsxs(Box, {
1592
+ sx: {
1593
+ display: 'flex',
1594
+ alignItems: 'center',
1595
+ gap: '4px'
1596
+ },
1597
+ children: [jsx(LayerInfoButton, {
1598
+ isActive: hasActiveLayer,
1599
+ onClick: onToggleActiveLayer
1600
+ }), service.type === 'STAC' && jsx(CustomTooltip, {
1601
+ title: "STAC Collection",
1602
+ children: jsx("span", {
1603
+ style: {
1604
+ display: 'flex'
1605
+ },
1606
+ children: jsx(StacIcon, {
1607
+ fontSize: "small"
1608
+ })
1609
+ })
1610
+ })]
1611
+ })]
1612
+ }), jsxs(Grid, {
1613
+ sx: columns.column2,
1614
+ children: [jsx(Grid, {
1615
+ sx: columns.column3,
1616
+ children: !!layer["abstract"] && jsx(Typography, {
1617
+ "data-testid": "layerAbstract",
1618
+ sx: layerInfoStyle,
1619
+ children: jsx(SearchHighlight, {
1620
+ search: searchFilter,
1621
+ text: layer["abstract"]
1622
+ })
1623
+ })
1624
+ }), jsxs(Grid, {
1625
+ container: true,
1626
+ sx: columns.column4,
1627
+ children: [jsx(Grid, {
1628
+ sx: columns.column5,
1629
+ children: jsx(LayerListDimensions, {
1630
+ dimensions: dimensions
1631
+ })
1632
+ }), jsxs(Grid, {
1633
+ sx: columns.column6,
1634
+ children: [layer.path.length > 0 && jsxs(Typography, {
1635
+ sx: layerInfoStyle,
1636
+ children: [t('groups'), ":", ' ', jsx(SearchHighlight, {
1637
+ search: searchFilter,
1638
+ text: layer.path.join(' / ')
1639
+ })]
1640
+ }), ((_layer$keywords = layer.keywords) == null ? void 0 : _layer$keywords.length) > 0 && jsxs(Typography, {
1641
+ sx: layerInfoStyle,
1642
+ children: [t('keywords'), ":", ' ', jsx(SearchHighlight, {
1643
+ search: searchFilter,
1644
+ text: ((_layer$keywords2 = layer.keywords) != null ? _layer$keywords2 : []).slice().sort(function (textA, textB) {
1645
+ return textA.localeCompare(textB);
1646
+ }).join(', ')
1647
+ })]
1648
+ })]
1649
+ })]
1650
+ })]
1651
+ })]
1652
+ }), jsx(Grid, {
1653
+ container: true,
1654
+ sx: [{
1655
+ alignItems: 'center',
1656
+ justifyContent: 'flex-end'
1657
+ }, columns.column9],
1658
+ children: jsx(Box, {
1659
+ sx: [{
1660
+ alignItems: 'flex-start'
1661
+ }, (columns.column7, {
1662
+ width: '100%',
1663
+ paddingLeft: '16px'
1664
+ })],
1665
+ children: jsx(LayerAddRemoveButton, {
1666
+ addLayer: addLayer,
1667
+ addLayerToAllMaps: addLayerToAllMaps,
1668
+ allLayers: allLayers,
1669
+ allMapIds: allMapIds,
1670
+ deleteLayer: deleteLayer,
1671
+ layer: layer,
1672
+ mapLayers: mapLayers,
1673
+ removeLayerFromAllMaps: removeLayerFromAllMaps,
1674
+ serviceType: service.type,
1675
+ serviceUrl: layerServiceUrl
1676
+ })
1677
+ })
1678
+ })]
1679
+ });
1680
+ };
1681
+
1682
+ var LayerRow = function LayerRow(_ref) {
1683
+ var index = _ref.index,
1684
+ style = _ref.style,
1685
+ services = _ref.services,
1686
+ filteredLayers = _ref.filteredLayers,
1687
+ allLayers = _ref.allLayers,
1688
+ allMapIds = _ref.allMapIds,
1689
+ addLayer = _ref.addLayer,
1690
+ addLayerToAllMaps = _ref.addLayerToAllMaps,
1691
+ deleteLayer = _ref.deleteLayer,
1692
+ removeLayerFromAllMaps = _ref.removeLayerFromAllMaps,
1693
+ mapLayers = _ref.mapLayers,
1694
+ searchFilter = _ref.searchFilter,
1695
+ isLayerInfoVisibleInStore = _ref.isLayerInfoVisibleInStore,
1696
+ _onToggleActiveLayer = _ref.onToggleActiveLayer,
1697
+ currentLayerInfo = _ref.currentLayerInfo,
1698
+ layerSelectWidth = _ref.layerSelectWidth,
1699
+ rowMargin = _ref.rowMargin;
1700
+ var layer = filteredLayers[index];
1701
+ var service = services[layer.serviceName];
1702
+ if (!service) {
1703
+ return jsx("div", {
1704
+ style: style
1705
+ });
1706
+ }
1707
+ var isActiveLayer = isLayerInfoVisibleInStore && (currentLayerInfo == null ? void 0 : currentLayerInfo.serviceUrl) === service.serviceUrl && (currentLayerInfo == null ? void 0 : currentLayerInfo.layerName) === layer.name;
1708
+ var rowStyle = Object.assign({}, style, {
1709
+ boxSizing: 'border-box',
1710
+ paddingBottom: rowMargin
1711
+ });
1712
+ return jsx("div", {
1713
+ style: rowStyle,
1714
+ children: jsx(LayerListRow, {
1715
+ addLayer: addLayer,
1716
+ addLayerToAllMaps: addLayerToAllMaps,
1717
+ allLayers: allLayers,
1718
+ allMapIds: allMapIds,
1719
+ deleteLayer: deleteLayer,
1720
+ hasActiveLayer: isActiveLayer,
1721
+ layer: layer,
1722
+ layerSelectWidth: layerSelectWidth,
1723
+ mapLayers: mapLayers,
1724
+ onToggleActiveLayer: function onToggleActiveLayer() {
1725
+ return _onToggleActiveLayer({
1726
+ serviceUrl: service.serviceUrl,
1727
+ layerName: layer.name,
1728
+ isActiveLayer: isActiveLayer
1729
+ });
1730
+ },
1731
+ removeLayerFromAllMaps: removeLayerFromAllMaps,
1732
+ searchFilter: searchFilter,
1733
+ service: service
1734
+ })
1735
+ }, layer.name);
1736
+ };
1737
+ var LayerList = function LayerList(_ref2) {
1738
+ var services = _ref2.services,
1739
+ filteredLayers = _ref2.filteredLayers,
1740
+ layerSelectHeight = _ref2.layerSelectHeight,
1741
+ serviceListHeight = _ref2.serviceListHeight,
1742
+ layerSelectWidth = _ref2.layerSelectWidth,
1743
+ allLayers = _ref2.allLayers,
1744
+ allMapIds = _ref2.allMapIds,
1745
+ addLayer = _ref2.addLayer,
1746
+ addLayerToAllMaps = _ref2.addLayerToAllMaps,
1747
+ deleteLayer = _ref2.deleteLayer,
1748
+ removeLayerFromAllMaps = _ref2.removeLayerFromAllMaps,
1749
+ mapLayers = _ref2.mapLayers,
1750
+ searchFilter = _ref2.searchFilter,
1751
+ isLayerInfoVisibleInStore = _ref2.isLayerInfoVisibleInStore,
1752
+ onToggleActiveLayer = _ref2.onToggleActiveLayer,
1753
+ currentLayerInfo = _ref2.currentLayerInfo;
1754
+ var _useLayerSelectTransl = useLayerSelectTranslation(),
1755
+ t = _useLayerSelectTransl.t;
1756
+ var rowMargin = 4;
1757
+ var rowHeight = widthToRowHeight(layerSelectWidth);
1758
+ var layerSelectFilterHeight = 155 + serviceListHeight;
1759
+ var minHeight = 320;
1760
+ var listHeight = layerSelectHeight - layerSelectFilterHeight < minHeight ? minHeight : layerSelectHeight - layerSelectFilterHeight;
1761
+ return jsxs(Box, {
1762
+ "data-testid": "layerList",
1763
+ children: [jsxs(Box, {
1764
+ sx: {
1765
+ marginBottom: '4px',
1766
+ fontSize: '12px'
1767
+ },
1768
+ children: [filteredLayers.length, " ", t('layer-list-results')]
1769
+ }), jsx(List$1, {
1770
+ defaultHeight: minHeight,
1771
+ rowComponent: LayerRow,
1772
+ rowCount: filteredLayers.length,
1773
+ rowHeight: rowHeight + rowMargin,
1774
+ rowProps: {
1775
+ services: services,
1776
+ filteredLayers: filteredLayers,
1777
+ allLayers: allLayers,
1778
+ allMapIds: allMapIds,
1779
+ addLayer: addLayer,
1780
+ addLayerToAllMaps: addLayerToAllMaps,
1781
+ deleteLayer: deleteLayer,
1782
+ removeLayerFromAllMaps: removeLayerFromAllMaps,
1783
+ mapLayers: mapLayers,
1784
+ searchFilter: searchFilter,
1785
+ isLayerInfoVisibleInStore: isLayerInfoVisibleInStore,
1786
+ onToggleActiveLayer: onToggleActiveLayer,
1787
+ currentLayerInfo: currentLayerInfo,
1788
+ layerSelectWidth: layerSelectWidth,
1789
+ rowMargin: rowMargin
1790
+ },
1791
+ style: {
1792
+ height: listHeight,
1793
+ width: '100%'
1794
+ }
1795
+ })]
1796
+ });
1797
+ };
1798
+
1799
+ var LayerListConnect = function LayerListConnect(_ref) {
1800
+ var mapId = _ref.mapId,
1801
+ layerSelectHeight = _ref.layerSelectHeight,
1802
+ serviceListHeight = _ref.serviceListHeight,
1803
+ layerSelectWidth = _ref.layerSelectWidth;
1804
+ var dispatch = useDispatch();
1805
+ var services = useAppSelector(function (store) {
1806
+ return serviceSelectors.getServices(store);
1807
+ });
1808
+ var mapLayers = useAppSelector(function (store) {
1809
+ return mapSelectors.getMapLayersWithoutDimensionCurrentValue(store, mapId);
1810
+ });
1811
+ var allLayers = useAppSelector(function (store) {
1812
+ return layerSelectors.getAllLayers(store);
1813
+ });
1814
+ var allMapIds = useAppSelector(function (store) {
1815
+ return mapSelectors.getAllMapIds(store);
1816
+ });
1817
+ var _addLayer = function addLayer(_ref2, mapId) {
1818
+ var serviceUrl = _ref2.serviceUrl,
1819
+ layerName = _ref2.layerName,
1820
+ serviceType = _ref2.serviceType;
1821
+ var layer = {
1822
+ service: serviceUrl,
1823
+ name: layerName,
1824
+ id: webmapUtils.generateLayerId(),
1825
+ layerType: serviceType === 'STAC' ? LayerType.stacGeoTIFFLayer : LayerType.mapLayer
1826
+ };
1827
+ addMapLayer({
1828
+ mapId: mapId,
1829
+ layerId: layer.id,
1830
+ layer: layer,
1831
+ origin: layerTypes.LayerActionOrigin.layerManager
1832
+ });
1833
+ };
1834
+ var addMapLayer = React.useCallback(function (_ref3) {
1835
+ var mapId = _ref3.mapId,
1836
+ layerId = _ref3.layerId,
1837
+ layer = _ref3.layer,
1838
+ origin = _ref3.origin;
1839
+ return dispatch(layerActions.addLayer({
1840
+ mapId: mapId,
1841
+ layerId: layerId,
1842
+ layer: layer,
1843
+ origin: origin
1844
+ }));
1845
+ }, [dispatch]);
1846
+ var addLayerToAllMaps = function addLayerToAllMaps(_ref4) {
1847
+ var serviceUrl = _ref4.serviceUrl,
1848
+ layerName = _ref4.layerName,
1849
+ serviceType = _ref4.serviceType;
1850
+ allMapIds.forEach(function (mapId) {
1851
+ if (allLayers.find(function (layer) {
1852
+ return layer.name === layerName && layer.service === serviceUrl && layer.mapId === mapId;
1853
+ })) {
1854
+ return;
1855
+ }
1856
+ _addLayer({
1857
+ serviceUrl: serviceUrl,
1858
+ layerName: layerName,
1859
+ serviceType: serviceType
1860
+ }, mapId);
1861
+ });
1862
+ };
1863
+ var deleteLayer = React.useCallback(function (_ref5) {
1864
+ var layerId = _ref5.layerId,
1865
+ layerIndex = _ref5.layerIndex;
1866
+ return dispatch(layerActions.layerDelete({
1867
+ mapId: mapId,
1868
+ layerId: layerId,
1869
+ layerIndex: layerIndex,
1870
+ origin: layerTypes.LayerActionOrigin.layerManager
1871
+ }));
1872
+ }, [dispatch, mapId]);
1873
+ var removeLayerFromAllMaps = React.useCallback(function (layerId) {
1874
+ if (!layerId) {
1875
+ return;
1876
+ }
1877
+ var layerToRemove = allLayers.find(function (layer) {
1878
+ return layer.id === layerId;
1879
+ });
1880
+ (layerToRemove == null ? void 0 : layerToRemove.name) && (layerToRemove == null ? void 0 : layerToRemove.service) && allLayers.filter(function (layer) {
1881
+ return layer.name === layerToRemove.name && layer.service === layerToRemove.service;
1882
+ }).forEach(function (layer) {
1883
+ layer.mapId && layer.id && dispatch(layerActions.layerDelete({
1884
+ mapId: layer.mapId,
1885
+ layerId: layer.id
1886
+ }));
1887
+ });
1888
+ }, [dispatch, allLayers]);
1889
+ var filteredLayers = useAppSelector(function (store) {
1890
+ return getFilteredLayers(store);
1891
+ });
1892
+ var searchFilter = useAppSelector(function (store) {
1893
+ return getSearchFilter(store);
1894
+ });
1895
+ var isLayerInfoVisibleInStore = useAppSelector(function (store) {
1896
+ return uiSelectors.getisDialogOpen(store, uiTypes.DialogTypes.LayerInfo);
1897
+ });
1898
+ var currentLayerInfo = useAppSelector(function (store) {
1899
+ return layerSelectors.getActiveLayerInfo(store);
1900
+ });
1901
+ var onToggleActiveLayer = React.useCallback(function (_ref6) {
1902
+ var serviceUrl = _ref6.serviceUrl,
1903
+ layerName = _ref6.layerName,
1904
+ isActiveLayer = _ref6.isActiveLayer;
1905
+ if (!isActiveLayer) {
1906
+ dispatch(layerActions.showLayerInfo({
1907
+ layerName: layerName,
1908
+ serviceUrl: serviceUrl,
1909
+ mapId: mapId
1910
+ }));
1911
+ } else {
1912
+ dispatch(layerActions.hideLayerInfo());
1913
+ }
1914
+ }, [mapId, dispatch]);
1915
+ return jsx(LayerList, {
1916
+ addLayer: function addLayer(params) {
1917
+ return _addLayer(params, mapId);
1918
+ },
1919
+ addLayerToAllMaps: addLayerToAllMaps,
1920
+ allLayers: allLayers,
1921
+ allMapIds: allMapIds,
1922
+ currentLayerInfo: currentLayerInfo,
1923
+ deleteLayer: deleteLayer,
1924
+ filteredLayers: filteredLayers,
1925
+ isLayerInfoVisibleInStore: isLayerInfoVisibleInStore,
1926
+ layerSelectHeight: layerSelectHeight,
1927
+ layerSelectWidth: layerSelectWidth,
1928
+ mapLayers: mapLayers,
1929
+ onToggleActiveLayer: onToggleActiveLayer,
1930
+ removeLayerFromAllMaps: removeLayerFromAllMaps,
1931
+ searchFilter: searchFilter,
1932
+ serviceListHeight: serviceListHeight,
1933
+ services: services
1934
+ });
1935
+ };
1936
+
1937
+ var style$2 = {
1938
+ width: 'auto !important',
1939
+ height: 'auto !important',
1940
+ padding: 0
1941
+ };
1942
+ var LayerSelectButtonConnect = function LayerSelectButtonConnect(_ref) {
1943
+ var mapId = _ref.mapId,
1944
+ _ref$source = _ref.source,
1945
+ source = _ref$source === void 0 ? 'app' : _ref$source,
1946
+ tooltipTitle = _ref.tooltipTitle,
1947
+ _ref$icon = _ref.icon,
1948
+ icon = _ref$icon === void 0 ? jsx(LayersAdd, {
1949
+ "data-testid": "layerSelectButtonConnectIcon"
1950
+ }) : _ref$icon,
1951
+ _ref$isMultiMap = _ref.isMultiMap,
1952
+ isMultiMap = _ref$isMultiMap === void 0 ? false : _ref$isMultiMap;
1953
+ var _useLayerSelectTransl = useLayerSelectTranslation(),
1954
+ t = _useLayerSelectTransl.t;
1955
+ var dispatch = useDispatch();
1956
+ var dialogType = isMultiMap ? uiTypes.DialogTypes.LayerSelect + "-" + mapId : uiTypes.DialogTypes.LayerSelect;
1957
+ var currentActiveMapId = useAppSelector(function (store) {
1958
+ return uiSelectors.getDialogMapId(store, dialogType);
1959
+ });
1960
+ var isOpenInStore = useAppSelector(function (store) {
1961
+ return uiSelectors.getisDialogOpen(store, dialogType);
1962
+ });
1963
+ var openLayerSelectDialog = React.useCallback(function () {
1964
+ dispatch(uiActions.setActiveMapIdForDialog({
1965
+ type: dialogType,
1966
+ mapId: mapId,
1967
+ setOpen: currentActiveMapId !== mapId ? true : !isOpenInStore,
1968
+ source: source
1969
+ }));
1970
+ }, [currentActiveMapId, dispatch, isOpenInStore, mapId, source, dialogType]);
1971
+ return jsx(CustomIconButton, {
1972
+ "data-testid": "layerSelectButton",
1973
+ id: "layerSelectButton",
1974
+ onClick: openLayerSelectDialog,
1975
+ sx: style$2,
1976
+ tooltipTitle: tooltipTitle || t('layer-select-button-tooltip'),
1977
+ children: icon
1978
+ });
1979
+ };
1980
+
1981
+ var DataExplorerButtonConnect = function DataExplorerButtonConnect(_ref) {
1982
+ var mapId = _ref.mapId,
1983
+ _ref$source = _ref.source,
1984
+ source = _ref$source === void 0 ? 'app' : _ref$source;
1985
+ var dispatch = useDispatch();
1986
+ var dialogType = uiTypes.DialogTypes.DataExplorer;
1987
+ var currentActiveMapId = useSelector(function (store) {
1988
+ return uiSelectors.getDialogMapId(store, dialogType);
1989
+ });
1990
+ var isOpenInStore = useSelector(function (store) {
1991
+ return uiSelectors.getisDialogOpen(store, dialogType);
1992
+ });
1993
+ var openDataExplorerDialog = React.useCallback(function () {
1994
+ dispatch(uiActions.setActiveMapIdForDialog({
1995
+ type: dialogType,
1996
+ setOpen: currentActiveMapId !== mapId ? true : !isOpenInStore,
1997
+ source: source,
1998
+ mapId: mapId,
1999
+ origin: mapEnums.MapActionOrigin.map
2000
+ }));
2001
+ }, [dispatch, dialogType, currentActiveMapId, mapId, isOpenInStore, source]);
2002
+ return jsx(CustomTooltip, {
2003
+ title: "MeteoGate Data Explorer",
2004
+ children: jsx(CustomIconButton, {
2005
+ "data-testid": "dataExplorerButton",
2006
+ isSelected: currentActiveMapId !== mapId ? false : isOpenInStore,
2007
+ onClick: openDataExplorerDialog,
2008
+ variant: "tool",
2009
+ children: jsx(MeteoGate, {
2010
+ sx: {}
2011
+ })
2012
+ })
2013
+ });
2014
+ };
2015
+
2016
+ var SearchFieldConnect = function SearchFieldConnect() {
2017
+ var dispatch = useDispatch();
2018
+ var searchFilter = useAppSelector(function (store) {
2019
+ return getSearchFilter(store);
2020
+ });
2021
+ var toggleServicePopup = function toggleServicePopup(url) {
2022
+ dispatch(layerSelectActions.toggleServicePopup({
2023
+ isOpen: true,
2024
+ url: url,
2025
+ variant: 'save'
2026
+ }));
2027
+ };
2028
+ var setSearchFilter = function setSearchFilter(filterText) {
2029
+ dispatch(layerSelectActions.setSearchFilter({
2030
+ filterText: filterText
2031
+ }));
2032
+ };
2033
+ return jsx(SearchField, {
2034
+ onOpenServicePopup: toggleServicePopup,
2035
+ searchFilter: searchFilter,
2036
+ setSearchFilter: setSearchFilter
2037
+ });
2038
+ };
2039
+
2040
+ var style$1 = {
2041
+ borderRadius: '20px!important',
2042
+ marginRight: '4px',
2043
+ whiteSpace: 'nowrap',
2044
+ height: '24px!important',
2045
+ padding: '5px 12px!important',
2046
+ textTransform: 'none!important',
2047
+ fontWeight: 'normal',
2048
+ marginBottom: '4px'
2049
+ };
2050
+ var ServiceChip = function ServiceChip(_ref) {
2051
+ var _ref$all = _ref.all,
2052
+ all = _ref$all === void 0 ? false : _ref$all,
2053
+ service = _ref.service,
2054
+ isSelected = _ref.isSelected,
2055
+ isDisabled = _ref.isDisabled,
2056
+ toggleChip = _ref.toggleChip,
2057
+ isInSearch = _ref.isInSearch;
2058
+ var _useLayerSelectTransl = useLayerSelectTranslation(),
2059
+ t = _useLayerSelectTransl.t;
2060
+ var _useTheme = useTheme(),
2061
+ geowebColors = _useTheme.palette.geowebColors;
2062
+ var _React$useState = React.useState(false),
2063
+ isIconHovered = _React$useState[0],
2064
+ setIsIconHovered = _React$useState[1];
2065
+ var chip = all ? 'all' : service == null ? void 0 : service.serviceUrl;
2066
+ var tooltipTitle = '';
2067
+ if (!isIconHovered && service != null && service["abstract"]) {
2068
+ tooltipTitle = "Abstract: " + service["abstract"];
2069
+ }
2070
+ return jsx(CustomTooltip, {
2071
+ title: tooltipTitle,
2072
+ children: jsx("span", {
2073
+ children: jsxs(CustomToggleButton, {
2074
+ "data-testid": all ? 'serviceChipAll' : 'serviceChip',
2075
+ disabled: isDisabled,
2076
+ onClick: function onClick() {
2077
+ return toggleChip(chip);
2078
+ },
2079
+ onKeyDown: function onKeyDown() {
2080
+ return toggleChip(chip);
2081
+ },
2082
+ selected: Boolean(isSelected),
2083
+ sx: Object.assign({}, style$1, isInSearch && Object.assign({
2084
+ backgroundColor: geowebColors.chip.highlightDefault.rgba + "!important",
2085
+ '&:hover': {
2086
+ backgroundColor: geowebColors.chip.highlightDefaultMouseOver.rgba + "!important"
2087
+ }
2088
+ }, isSelected && {
2089
+ backgroundColor: geowebColors.chip.highlightActiveDefault.rgba + "!important",
2090
+ '&:hover': {
2091
+ backgroundColor: geowebColors.chip.highlightActiveMouseOver.rgba + "!important"
2092
+ }
2093
+ })),
2094
+ tabIndex: 0,
2095
+ variant: "boxed",
2096
+ children: [(service == null ? void 0 : service.type) === 'STAC' && jsx(CustomTooltip, {
2097
+ title: "STAC Service",
2098
+ children: jsx("span", {
2099
+ onMouseEnter: function onMouseEnter() {
2100
+ return setIsIconHovered(true);
2101
+ },
2102
+ onMouseLeave: function onMouseLeave() {
2103
+ return setIsIconHovered(false);
2104
+ },
2105
+ style: {
2106
+ display: 'flex',
2107
+ alignItems: 'center'
2108
+ },
2109
+ children: jsx(StacIcon, {
2110
+ fontSize: "inherit",
2111
+ sx: {
2112
+ mr: '4px',
2113
+ verticalAlign: 'middle'
2114
+ }
2115
+ })
2116
+ })
2117
+ }), service ? service.serviceName : t('all')]
2118
+ })
2119
+ })
2120
+ });
2121
+ };
2122
+
2123
+ var ServiceChipConnect = function ServiceChipConnect(_ref) {
2124
+ var service = _ref.service,
2125
+ isAllSelected = _ref.isAllSelected;
2126
+ var dispatch = useDispatch();
2127
+ var serviceId = service.serviceId;
2128
+ var isInSearch = service.isInSearch || false;
2129
+ var toggleChip = function toggleChip() {
2130
+ if (service.enabled) {
2131
+ if (isAllSelected) {
2132
+ dispatch(layerSelectActions.onlyThisServiceEnabled({
2133
+ serviceId: serviceId
2134
+ }));
2135
+ return;
2136
+ }
2137
+ dispatch(layerSelectActions.disableActiveService({
2138
+ serviceId: serviceId
2139
+ }));
2140
+ return;
2141
+ }
2142
+ dispatch(layerSelectActions.enableActiveService({
2143
+ serviceId: serviceId
2144
+ }));
2145
+ };
2146
+ return jsx(ServiceChip, {
2147
+ isDisabled: service.isLoading,
2148
+ isInSearch: isInSearch,
2149
+ isSelected: isAllSelected ? false : service.enabled,
2150
+ service: service,
2151
+ toggleChip: toggleChip
2152
+ });
2153
+ };
2154
+ var AllChipConnect = function AllChipConnect(_ref2) {
2155
+ var isAllSelected = _ref2.isAllSelected;
2156
+ var dispatch = useDispatch();
2157
+ return jsx(ServiceChip, {
2158
+ isSelected: isAllSelected,
2159
+ toggleChip: function toggleChip() {
2160
+ if (!isAllSelected) {
2161
+ dispatch(layerSelectActions.enableAllActiveServices());
2162
+ }
2163
+ }
2164
+ });
2165
+ };
2166
+
2167
+ var ServiceList = function ServiceList(_ref) {
2168
+ var _ref$current;
2169
+ var activeServicesById = _ref.activeServicesById,
2170
+ setHeight = _ref.setHeight;
2171
+ var ref = React.useRef(null);
2172
+ var _React$useState = React.useState(0),
2173
+ serviceListHeight = _React$useState[0],
2174
+ setServiceListHeight = _React$useState[1];
2175
+ var clientHeight = (ref == null || (_ref$current = ref.current) == null ? void 0 : _ref$current.clientHeight) && ref.current.clientHeight;
2176
+ React.useEffect(function () {
2177
+ var _ref$current2;
2178
+ if (ref != null && (_ref$current2 = ref.current) != null && _ref$current2.clientHeight) {
2179
+ setServiceListHeight(ref.current.clientHeight);
2180
+ }
2181
+ }, [activeServicesById, clientHeight]);
2182
+ React.useEffect(function () {
2183
+ setHeight(serviceListHeight);
2184
+ }, [serviceListHeight, setHeight]);
2185
+ var activeServicesIds = Object.keys(activeServicesById);
2186
+ var activeServices = Object.values(activeServicesById);
2187
+ var isAllSelected = activeServices.every(function (activeService) {
2188
+ return activeService.enabled;
2189
+ });
2190
+ return jsx(Box, {
2191
+ "data-testid": "serviceList",
2192
+ sx: {
2193
+ marginTop: '8px',
2194
+ width: '100%',
2195
+ overflow: 'hidden'
2196
+ },
2197
+ children: jsxs(Box, {
2198
+ ref: ref,
2199
+ sx: {
2200
+ width: '100%',
2201
+ display: 'block',
2202
+ alignItems: 'center',
2203
+ "float": 'left',
2204
+ paddingLeft: '48px',
2205
+ paddingRight: '40px',
2206
+ marginBottom: '8px',
2207
+ fontSize: '0.875rem'
2208
+ },
2209
+ children: [!!(activeServicesIds != null && activeServicesIds.length) && jsx(AllChipConnect, {
2210
+ isAllSelected: isAllSelected
2211
+ }), activeServices.map(function (service) {
2212
+ return jsx(ServiceChipConnect, {
2213
+ isAllSelected: isAllSelected,
2214
+ service: service
2215
+ }, service.serviceUrl);
2216
+ })]
2217
+ })
2218
+ });
2219
+ };
2220
+
2221
+ var ServiceListConnect = function ServiceListConnect(_ref) {
2222
+ var setHeight = _ref.setHeight;
2223
+ var filteredActiveServices = useAppSelector(function (store) {
2224
+ return getFilteredActiveServices(store);
2225
+ });
2226
+ return jsx(ServiceList, {
2227
+ activeServicesById: sortByService(filteredActiveServices),
2228
+ setHeight: setHeight
2229
+ });
2230
+ };
2231
+
2232
+ var styles = {
2233
+ servicesContainer: {
2234
+ width: '360px',
2235
+ maxHeight: '412px',
2236
+ top: '140px',
2237
+ backgroundColor: 'geowebColors.background.surface',
2238
+ boxShadow: 6,
2239
+ overflow: 'auto'
2240
+ },
2241
+ header: {
2242
+ position: 'sticky',
2243
+ top: 0,
2244
+ padding: '12px',
2245
+ backgroundColor: 'geowebColors.background.surface',
2246
+ zIndex: 100
2247
+ },
2248
+ text: {
2249
+ fontSize: 'default',
2250
+ opacity: 0.67
2251
+ },
2252
+ loading: {
2253
+ position: 'absolute',
2254
+ zIndex: 101
2255
+ },
2256
+ footer: {
2257
+ display: 'flex',
2258
+ justifyContent: 'center',
2259
+ alignItems: 'center',
2260
+ position: 'sticky',
2261
+ bottom: 0,
2262
+ backgroundColor: 'geowebColors.background.surface',
2263
+ zIndex: 100
2264
+ },
2265
+ button: {
2266
+ margin: '16px',
2267
+ width: '80%',
2268
+ fontSize: '12px',
2269
+ textTransform: 'none'
2270
+ }
2271
+ };
2272
+ var stopTabPropagation = function stopTabPropagation(event) {
2273
+ if (event.key === 'Tab') {
2274
+ event.stopPropagation();
2275
+ }
2276
+ };
2277
+ var ServiceOptionsDialog = function ServiceOptionsDialog(_ref) {
2278
+ var services = _ref.services,
2279
+ layerSelectRemoveService = _ref.layerSelectRemoveService,
2280
+ layerSelectReloadService = _ref.layerSelectReloadService,
2281
+ selectedLayers = _ref.selectedLayers,
2282
+ setServicePopupInfo = _ref.setServicePopupInfo,
2283
+ _ref$isLoading = _ref.isLoading,
2284
+ isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
2285
+ error = _ref.error;
2286
+ var _useLayerSelectTransl = useLayerSelectTranslation(),
2287
+ t = _useLayerSelectTransl.t;
2288
+ var openAddService = function openAddService() {
2289
+ setServicePopupInfo({
2290
+ isOpen: true,
2291
+ variant: 'add'
2292
+ });
2293
+ };
2294
+ var dialogRef = React.useRef(null);
2295
+ React.useEffect(function () {
2296
+ var _dialogRef$current;
2297
+ (_dialogRef$current = dialogRef.current) == null || _dialogRef$current.focus();
2298
+ }, []);
2299
+ return jsxs(Box, {
2300
+ "data-testid": "ServiceDialog",
2301
+ onKeyDown: function onKeyDown(event) {
2302
+ if (event.key !== 'Escape') {
2303
+ event.stopPropagation();
2304
+ }
2305
+ },
2306
+ ref: dialogRef,
2307
+ sx: styles.servicesContainer,
2308
+ tabIndex: -1,
2309
+ children: [jsxs(Box, {
2310
+ sx: styles.header,
2311
+ children: [jsx(Box, {
2312
+ sx: styles.text,
2313
+ children: t('services')
2314
+ }), error ? jsx(AlertBanner, {
2315
+ shouldClose: true,
2316
+ title: error
2317
+ }) : null]
2318
+ }), jsx(Backdrop, {
2319
+ open: isLoading,
2320
+ sx: Object.assign({}, styles.loading, {
2321
+ backgroundSize: 'cover'
2322
+ }),
2323
+ children: jsx(CircularProgress, {})
2324
+ }), jsx(Rows, {
2325
+ layerSelectReloadService: layerSelectReloadService,
2326
+ layerSelectRemoveService: layerSelectRemoveService,
2327
+ selectedLayers: selectedLayers,
2328
+ services: services,
2329
+ setServicePopupInfo: setServicePopupInfo
2330
+ }), jsx(Box, {
2331
+ sx: styles.footer,
2332
+ children: jsx(Button, {
2333
+ "data-testid": "openAddServiceButton",
2334
+ onClick: openAddService,
2335
+ onKeyDown: stopTabPropagation,
2336
+ startIcon: jsx(Add, {}),
2337
+ sx: styles.button,
2338
+ variant: "tertiary",
2339
+ children: t('add-a-new-service')
2340
+ })
2341
+ })]
2342
+ });
2343
+ };
2344
+ var deleteServiceTitle = function deleteServiceTitle(t, hasActiveLayers) {
2345
+ return hasActiveLayers ? t('service-has-active-layers-error') : t('delete-service');
2346
+ };
2347
+ var tooltipPlacement = function tooltipPlacement() {
2348
+ return 'left';
2349
+ };
2350
+ var tooltipPopperProps = {
2351
+ disablePortal: true,
2352
+ sx: {
2353
+ '& .MuiTooltip-tooltip': {
2354
+ width: '200px',
2355
+ display: 'flex',
2356
+ justifyContent: 'center',
2357
+ alignItems: 'center'
2358
+ }
2359
+ }
2360
+ };
2361
+ var Rows = function Rows(_ref2) {
2362
+ var services = _ref2.services,
2363
+ layerSelectReloadService = _ref2.layerSelectReloadService,
2364
+ layerSelectRemoveService = _ref2.layerSelectRemoveService,
2365
+ setServicePopupInfo = _ref2.setServicePopupInfo,
2366
+ selectedLayers = _ref2.selectedLayers;
2367
+ var _useLayerSelectTransl2 = useLayerSelectTranslation(),
2368
+ t = _useLayerSelectTransl2.t;
2369
+ var checkIfServiceHasActiveLayers = function checkIfServiceHasActiveLayers(serviceUrl) {
2370
+ var foundService = selectedLayers.find(function (object) {
2371
+ return object.service === serviceUrl;
2372
+ });
2373
+ if (foundService) {
2374
+ return true;
2375
+ }
2376
+ return false;
2377
+ };
2378
+ var sortedServices = sortByService(services);
2379
+ return jsx(List, {
2380
+ disablePadding: true,
2381
+ children: Object.keys(sortedServices).map(function (serviceId) {
2382
+ var _services$serviceId = services[serviceId],
2383
+ serviceUrl = _services$serviceId.serviceUrl,
2384
+ serviceName = _services$serviceId.serviceName,
2385
+ scope = _services$serviceId.scope;
2386
+ var serviceHasActiveLayers = checkIfServiceHasActiveLayers(serviceUrl);
2387
+ var userAddedService = isUserAddedService(scope);
2388
+ return jsx(ListItem, {
2389
+ secondaryAction: jsx(Box, {
2390
+ sx: {
2391
+ marginRight: '0px',
2392
+ width: 96,
2393
+ button: {
2394
+ marginLeft: 1
2395
+ }
2396
+ },
2397
+ children: jsxs(Grid, {
2398
+ container: true,
2399
+ sx: {
2400
+ justifyContent: 'left',
2401
+ marginRight: '0px',
2402
+ width: 96,
2403
+ button: {
2404
+ marginLeft: 1
2405
+ }
2406
+ },
2407
+ children: [jsx(CustomTooltip, {
2408
+ "data-testid": "updateServiceTooltip",
2409
+ placement: tooltipPlacement(),
2410
+ slotProps: {
2411
+ popper: tooltipPopperProps
2412
+ },
2413
+ title: t('update-service-title'),
2414
+ children: jsx(CustomIconButton, {
2415
+ "aria-label": "Update layers from WMS service",
2416
+ "data-testid": "updateServiceButton",
2417
+ onClick: function onClick() {
2418
+ layerSelectReloadService(serviceUrl);
2419
+ },
2420
+ onKeyDown: stopTabPropagation,
2421
+ children: jsx(Cached, {})
2422
+ })
2423
+ }), userAddedService ? jsx(CustomTooltip, {
2424
+ placement: tooltipPlacement(),
2425
+ slotProps: {
2426
+ popper: tooltipPopperProps
2427
+ },
2428
+ title: t('edit-service-title'),
2429
+ children: jsx("span", {
2430
+ children: jsx(CustomIconButton, {
2431
+ "aria-label": "edit service",
2432
+ "data-testid": "openEditServiceButton",
2433
+ onClick: function onClick() {
2434
+ setServicePopupInfo({
2435
+ isOpen: true,
2436
+ serviceId: serviceId,
2437
+ serviceUrl: serviceUrl,
2438
+ variant: 'edit'
2439
+ });
2440
+ },
2441
+ onKeyDown: stopTabPropagation,
2442
+ children: jsx(Edit, {})
2443
+ })
2444
+ })
2445
+ }) : jsx(CustomTooltip, {
2446
+ placement: tooltipPlacement(),
2447
+ slotProps: {
2448
+ popper: tooltipPopperProps
2449
+ },
2450
+ title: t('show-service-title'),
2451
+ children: jsx("span", {
2452
+ children: jsx(CustomIconButton, {
2453
+ "aria-label": "show service",
2454
+ "data-testid": "openShowServiceButton",
2455
+ onClick: function onClick() {
2456
+ setServicePopupInfo({
2457
+ isOpen: true,
2458
+ serviceId: serviceId,
2459
+ serviceUrl: serviceUrl,
2460
+ variant: 'show'
2461
+ });
2462
+ },
2463
+ onKeyDown: stopTabPropagation,
2464
+ children: jsx(Visibility, {})
2465
+ })
2466
+ })
2467
+ }), !!userAddedService && jsx(Box, {
2468
+ children: jsx(CustomTooltip, {
2469
+ "data-testid": "removeServiceTooltip",
2470
+ placement: tooltipPlacement(),
2471
+ slotProps: {
2472
+ popper: tooltipPopperProps
2473
+ },
2474
+ title: deleteServiceTitle(t, serviceHasActiveLayers),
2475
+ children: jsx("span", {
2476
+ children: jsx(CustomIconButton, {
2477
+ "aria-label": "delete service",
2478
+ "data-testid": "removeServiceButton",
2479
+ disabled: serviceHasActiveLayers,
2480
+ onClick: function onClick() {
2481
+ return layerSelectRemoveService(serviceId, serviceUrl, serviceName);
2482
+ },
2483
+ onKeyDown: stopTabPropagation,
2484
+ children: jsx(Delete, {})
2485
+ })
2486
+ })
2487
+ })
2488
+ })]
2489
+ })
2490
+ }),
2491
+ children: jsx(ListItemText, {
2492
+ style: {
2493
+ fontSize: '16px'
2494
+ },
2495
+ children: jsx(Typography, {
2496
+ noWrap: true,
2497
+ style: {
2498
+ textOverflow: 'ellipsis',
2499
+ paddingRight: '70px'
2500
+ },
2501
+ children: serviceName
2502
+ })
2503
+ })
2504
+ }, serviceUrl);
2505
+ })
2506
+ });
2507
+ };
2508
+
2509
+ var DetectableServiceType;
2510
+ (function (DetectableServiceType) {
2511
+ DetectableServiceType["STAC"] = "STAC";
2512
+ DetectableServiceType["WMS"] = "WMS";
2513
+ })(DetectableServiceType || (DetectableServiceType = {}));
2514
+ var normalizeStacServiceUrl = function normalizeStacServiceUrl(serviceUrl) {
2515
+ return (serviceUrl != null ? serviceUrl : '').replace(/\/collections.*$/i, '');
2516
+ };
2517
+ var validateServiceName = function validateServiceName(t, value, services, ownServiceName) {
2518
+ if (ownServiceName === void 0) {
2519
+ ownServiceName = '';
2520
+ }
2521
+ var serviceName = value == null ? void 0 : value.toLowerCase();
2522
+ var foundName = Object.keys(services).find(function (serviceId) {
2523
+ var _services$serviceId;
2524
+ return ((_services$serviceId = services[serviceId]) == null ? void 0 : _services$serviceId.serviceName.toLowerCase()) === serviceName && serviceName !== ownServiceName.toLocaleLowerCase();
2525
+ });
2526
+ return foundName === undefined ? true : t('validations-name-existing');
2527
+ };
2528
+ var isValidUrl = function isValidUrl(url) {
2529
+ if (url === '' || url === null || typeof url === 'undefined') {
2530
+ return false;
2531
+ }
2532
+ var matcher = /^(?:\w+:)?\/\/([^\s.]+\.\S{2}|[0-9a-zA-Z]+[:?\d]*)\S*$/;
2533
+ if (!matcher.test(url)) {
2534
+ return false;
2535
+ }
2536
+ return true;
2537
+ };
2538
+ var validateServiceUrl = function validateServiceUrl(t, value, services) {
2539
+ var serviceUrl = value;
2540
+ // validate valid url
2541
+ var isServiceUrlValid = isValidUrl(serviceUrl);
2542
+ if (!isServiceUrlValid) {
2543
+ return t('validations-service-valid-url');
2544
+ }
2545
+ // check url existing
2546
+ var foundUrl = Object.keys(services).find(function (serviceId) {
2547
+ var _services$serviceId2;
2548
+ return ((_services$serviceId2 = services[serviceId]) == null ? void 0 : _services$serviceId2.serviceUrl) === serviceUrl;
2549
+ });
2550
+ if (foundUrl) {
2551
+ return t('validations-service-existing');
2552
+ }
2553
+ return true;
2554
+ };
2555
+ var loadWMSService = /*#__PURE__*/function () {
2556
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(serviceUrl, forceReload) {
2557
+ var layers, service;
2558
+ return _regenerator().w(function (_context) {
2559
+ while (1) switch (_context.n) {
2560
+ case 0:
2561
+ if (forceReload === void 0) {
2562
+ forceReload = false;
2563
+ }
2564
+ if (!forceReload) {
2565
+ _context.n = 1;
2566
+ break;
2567
+ }
2568
+ _context.n = 1;
2569
+ return invalidateWMSGetCapabilities(serviceUrl);
2570
+ case 1:
2571
+ _context.n = 2;
2572
+ return queryWMSLayers(serviceUrl);
2573
+ case 2:
2574
+ layers = _context.v;
2575
+ _context.n = 3;
2576
+ return queryWMSServiceInfo(serviceUrl);
2577
+ case 3:
2578
+ service = _context.v;
2579
+ return _context.a(2, {
2580
+ id: service.id || getWMSServiceId(serviceUrl),
2581
+ name: service.title,
2582
+ serviceUrl: serviceUrl,
2583
+ "abstract": service["abstract"],
2584
+ layers: layers,
2585
+ scope: 'user'
2586
+ });
2587
+ }
2588
+ }, _callee);
2589
+ }));
2590
+ return function loadWMSService(_x, _x2) {
2591
+ return _ref.apply(this, arguments);
2592
+ };
2593
+ }();
2594
+ var detectServiceType = /*#__PURE__*/function () {
2595
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(url) {
2596
+ var root, hasStacRootShape;
2597
+ return _regenerator().w(function (_context2) {
2598
+ while (1) switch (_context2.p = _context2.n) {
2599
+ case 0:
2600
+ _context2.p = 0;
2601
+ _context2.n = 1;
2602
+ return fetchStacCatalogRoot(url);
2603
+ case 1:
2604
+ root = _context2.v;
2605
+ hasStacRootShape = root.stac_version || root.type === 'Catalog' || Array.isArray(root.conformsTo);
2606
+ if (!hasStacRootShape) {
2607
+ _context2.n = 2;
2608
+ break;
2609
+ }
2610
+ return _context2.a(2, DetectableServiceType.STAC);
2611
+ case 2:
2612
+ if (!(root.type === 'Collection' && root.stac_version && Array.isArray(root.links))) {
2613
+ _context2.n = 3;
2614
+ break;
2615
+ }
2616
+ return _context2.a(2, DetectableServiceType.STAC);
2617
+ case 3:
2618
+ _context2.n = 5;
2619
+ break;
2620
+ case 4:
2621
+ _context2.p = 4;
2622
+ _context2.v;
2623
+ case 5:
2624
+ return _context2.a(2, DetectableServiceType.WMS);
2625
+ }
2626
+ }, _callee2, null, [[0, 4]]);
2627
+ }));
2628
+ return function detectServiceType(_x3) {
2629
+ return _ref2.apply(this, arguments);
2630
+ };
2631
+ }();
2632
+ var loadSTACService = /*#__PURE__*/function () {
2633
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(serviceUrl) {
2634
+ var _ref4, _root$title, _root$description;
2635
+ var _yield$Promise$all, root, collections, serviceId, layers;
2636
+ return _regenerator().w(function (_context3) {
2637
+ while (1) switch (_context3.n) {
2638
+ case 0:
2639
+ _context3.n = 1;
2640
+ return Promise.all([fetchStacCatalogRoot(serviceUrl), fetchStacCatalogCollections(serviceUrl)]);
2641
+ case 1:
2642
+ _yield$Promise$all = _context3.v;
2643
+ root = _yield$Promise$all[0];
2644
+ collections = _yield$Promise$all[1];
2645
+ serviceId = serviceUrl.replace(/\/+$/, '').replace(/[^a-zA-Z0-9]/g, '_');
2646
+ layers = collections.map(stacCatalogCollectionToLayerProps);
2647
+ return _context3.a(2, {
2648
+ // Use URL-based ids so different STAC endpoints with identical root.id
2649
+ // values (e.g. "stac-fastapi") can coexist in the service store.
2650
+ id: serviceId,
2651
+ name: (_ref4 = (_root$title = root.title) != null ? _root$title : root.id) != null ? _ref4 : serviceId,
2652
+ serviceUrl: serviceUrl,
2653
+ "abstract": (_root$description = root.description) != null ? _root$description : '',
2654
+ layers: layers,
2655
+ scope: 'user',
2656
+ type: DetectableServiceType.STAC
2657
+ });
2658
+ }
2659
+ }, _callee3);
2660
+ }));
2661
+ return function loadSTACService(_x4) {
2662
+ return _ref3.apply(this, arguments);
2663
+ };
2664
+ }();
2665
+
2666
+ var getService = function getService(services, serviceUrl) {
2667
+ var serviceIds = Object.keys(services);
2668
+ var serviceIndex = serviceIds.findIndex(function (serviceId) {
2669
+ var _services$serviceId;
2670
+ return ((_services$serviceId = services[serviceId]) == null ? void 0 : _services$serviceId.serviceUrl) === serviceUrl;
2671
+ });
2672
+ if (serviceIndex < 0) {
2673
+ return null;
2674
+ }
2675
+ return services[serviceIds[serviceIndex]];
2676
+ };
2677
+ var getServiceSuccesUpdateMessage = function getServiceSuccesUpdateMessage(serviceName) {
2678
+ return {
2679
+ type: snackbarTypes.SnackbarMessageType.TRANSLATABLE_MESSAGE,
2680
+ key: 'service-successfully-updated',
2681
+ params: {
2682
+ serviceName: serviceName
2683
+ }
2684
+ };
2685
+ };
2686
+ var ServiceOptionsDialogConnect = function ServiceOptionsDialogConnect(_ref) {
2687
+ var mapId = _ref.mapId;
2688
+ var _React$useState = React.useState(false),
2689
+ isLoading = _React$useState[0],
2690
+ setIsLoading = _React$useState[1];
2691
+ var _React$useState2 = React.useState(undefined),
2692
+ error = _React$useState2[0],
2693
+ setError = _React$useState2[1];
2694
+ var dispatch = useDispatch();
2695
+ var _useLayerSelectTransl = useLayerSelectTranslation(),
2696
+ t = _useLayerSelectTransl.t;
2697
+ var serviceSetLayers = React.useCallback(function (payload) {
2698
+ dispatch(serviceActions.serviceSetLayers(Object.assign({}, payload, {
2699
+ isUpdating: true
2700
+ })));
2701
+ }, [dispatch]);
2702
+ var setServicePopupInfo = React.useCallback(function (popupInfo) {
2703
+ var payload = Object.assign({}, popupInfo, {
2704
+ variant: popupInfo.variant || 'default'
2705
+ });
2706
+ dispatch(layerSelectActions.toggleServicePopup(payload));
2707
+ }, [dispatch]);
2708
+ var showSnackbar = React.useCallback(function (message) {
2709
+ dispatch(snackbarActions.openSnackbar(message));
2710
+ }, [dispatch]);
2711
+ var services = useAppSelector(function (store) {
2712
+ return getActiveServices(store);
2713
+ });
2714
+ var selectedLayers = useAppSelector(function (store) {
2715
+ return mapSelectors.getMapLayersWithoutDimensionCurrentValue(store, mapId);
2716
+ });
2717
+ var layerSelectRemoveService = React.useCallback(function (serviceId, serviceUrl, serviceName) {
2718
+ var message = {
2719
+ type: snackbarTypes.SnackbarMessageType.TRANSLATABLE_MESSAGE,
2720
+ key: 'service-has-been-deleted',
2721
+ params: {
2722
+ serviceName: serviceName
2723
+ }
2724
+ };
2725
+ showSnackbar(message);
2726
+ dispatch(layerSelectActions.layerSelectRemoveService({
2727
+ serviceId: serviceId,
2728
+ serviceUrl: serviceUrl
2729
+ }));
2730
+ }, [dispatch, showSnackbar]);
2731
+ var layerSelectReloadService = React.useCallback(/*#__PURE__*/function () {
2732
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(serviceUrl) {
2733
+ var layersForService, service, serviceTitle, _t;
2734
+ return _regenerator().w(function (_context) {
2735
+ while (1) switch (_context.p = _context.n) {
2736
+ case 0:
2737
+ setIsLoading(true);
2738
+ setError(undefined);
2739
+ _context.p = 1;
2740
+ _context.n = 2;
2741
+ return loadWMSService(serviceUrl, true);
2742
+ case 2:
2743
+ layersForService = _context.v;
2744
+ service = getService(services, serviceUrl);
2745
+ serviceSetLayers({
2746
+ id: layersForService.id,
2747
+ name: (service == null ? void 0 : service.serviceName) || layersForService.name,
2748
+ serviceUrl: serviceUrl,
2749
+ "abstract": (service == null ? void 0 : service["abstract"]) || layersForService["abstract"],
2750
+ layers: layersForService.layers,
2751
+ scope: (service == null ? void 0 : service.scope) || 'user',
2752
+ isUpdating: true
2753
+ });
2754
+ clearImageCacheForAllMaps();
2755
+ serviceTitle = (service == null ? void 0 : service.serviceName) || layersForService.name;
2756
+ showSnackbar(getServiceSuccesUpdateMessage(serviceTitle));
2757
+ _context.n = 4;
2758
+ break;
2759
+ case 3:
2760
+ _context.p = 3;
2761
+ _t = _context.v;
2762
+ setError(t('unable-to-update-service', {
2763
+ message: _t.message
2764
+ }));
2765
+ case 4:
2766
+ _context.p = 4;
2767
+ setIsLoading(false);
2768
+ return _context.f(4);
2769
+ case 5:
2770
+ return _context.a(2);
2771
+ }
2772
+ }, _callee, null, [[1, 3, 4, 5]]);
2773
+ }));
2774
+ return function (_x) {
2775
+ return _ref2.apply(this, arguments);
2776
+ };
2777
+ }(), [serviceSetLayers, services, showSnackbar, t]);
2778
+ return jsx(ServiceOptionsDialog, {
2779
+ error: error,
2780
+ isLoading: isLoading,
2781
+ layerSelectReloadService: layerSelectReloadService,
2782
+ layerSelectRemoveService: layerSelectRemoveService,
2783
+ selectedLayers: selectedLayers,
2784
+ services: services,
2785
+ setServicePopupInfo: setServicePopupInfo
2786
+ });
2787
+ };
2788
+
2789
+ var ServiceOptionsButton = function ServiceOptionsButton(_ref) {
2790
+ var mapId = _ref.mapId;
2791
+ return jsx(ToggleMenu, {
2792
+ buttonTestId: "serviceOptionsButton",
2793
+ menuPosition: "bottom",
2794
+ children: jsx(ServiceOptionsDialogConnect, {
2795
+ mapId: mapId
2796
+ })
2797
+ });
2798
+ };
2799
+
2800
+ var LayerSelect = function LayerSelect(_ref) {
2801
+ var mapId = _ref.mapId,
2802
+ bounds = _ref.bounds,
2803
+ _ref$onClose = _ref.onClose,
2804
+ onClose = _ref$onClose === void 0 ? function () {} : _ref$onClose,
2805
+ showTitle = _ref.showTitle,
2806
+ isOpen = _ref.isOpen,
2807
+ _ref$onMouseDown = _ref.onMouseDown,
2808
+ _onMouseDown = _ref$onMouseDown === void 0 ? function () {} : _ref$onMouseDown,
2809
+ _ref$order = _ref.order,
2810
+ order = _ref$order === void 0 ? 0 : _ref$order,
2811
+ _ref$source = _ref.source,
2812
+ source = _ref$source === void 0 ? 'module' : _ref$source,
2813
+ _ref$startSize = _ref.startSize,
2814
+ startSize = _ref$startSize === void 0 ? {
2815
+ width: 750,
2816
+ height: 500
2817
+ } : _ref$startSize,
2818
+ _ref$isMultiMap = _ref.isMultiMap,
2819
+ isMultiMap = _ref$isMultiMap === void 0 ? false : _ref$isMultiMap,
2820
+ _ref$hasDataExplorer = _ref.hasDataExplorer,
2821
+ hasDataExplorer = _ref$hasDataExplorer === void 0 ? false : _ref$hasDataExplorer;
2822
+ var initialServiceListHeight = hasDataExplorer ? 52 : 37;
2823
+ var _React$useState = React.useState(startSize.height),
2824
+ height = _React$useState[0],
2825
+ setHeight = _React$useState[1];
2826
+ var _React$useState2 = React.useState(startSize.width),
2827
+ width = _React$useState2[0],
2828
+ setWidth = _React$useState2[1];
2829
+ var _React$useState3 = React.useState(initialServiceListHeight),
2830
+ serviceListHeight = _React$useState3[0],
2831
+ setServiceListHeight = _React$useState3[1];
2832
+ var onChangeSize = function onChangeSize(_ref2) {
2833
+ var height = _ref2.height,
2834
+ width = _ref2.width;
2835
+ setHeight(height);
2836
+ setWidth(width);
2837
+ };
2838
+ var handleHeightChange = function handleHeightChange(height) {
2839
+ if (height > initialServiceListHeight) {
2840
+ setServiceListHeight(height);
2841
+ }
2842
+ };
2843
+ return jsxs(ToolContainerDraggable, {
2844
+ bounds: bounds,
2845
+ "data-testid": "layerSelectWindow",
2846
+ isOpen: isOpen,
2847
+ minHeight: 126,
2848
+ minWidth: 320,
2849
+ onClose: onClose,
2850
+ onMouseDown: function onMouseDown(event) {
2851
+ var target = event.target;
2852
+ var isButtonInScrollableList = target.closest('.layerInfoButton') || target.closest('.layerAddRemoveButton');
2853
+ // don't propagate when clicking on layerInfoButton or addRemoveButton
2854
+ if (isButtonInScrollableList) {
2855
+ event.stopPropagation();
2856
+ return;
2857
+ }
2858
+ _onMouseDown(event);
2859
+ },
2860
+ onResizeStop: function onResizeStop(_event, _direction, node) {
2861
+ var width = node.offsetWidth,
2862
+ height = node.offsetHeight;
2863
+ onChangeSize({
2864
+ width: width,
2865
+ height: height
2866
+ });
2867
+ },
2868
+ order: order,
2869
+ source: source,
2870
+ startPosition: {
2871
+ top: 150,
2872
+ left: 100
2873
+ },
2874
+ startSize: {
2875
+ width: width,
2876
+ height: height
2877
+ },
2878
+ title: showTitle ? "Layer Select " + mapId : 'Layer Select',
2879
+ children: [jsx(Box, {
2880
+ sx: {
2881
+ padding: '4px 16px 0 16px'
2882
+ },
2883
+ children: jsx(SearchFieldConnect, {})
2884
+ }), jsx(Box, {
2885
+ sx: {
2886
+ "float": 'left',
2887
+ position: 'absolute',
2888
+ margin: '8px 8px 0 16px',
2889
+ zIndex: 2
2890
+ },
2891
+ children: jsxs(Grid, {
2892
+ container: true,
2893
+ children: [jsx(Grid, {
2894
+ size: 12,
2895
+ children: jsx(KeywordFilterButtonConnect, {
2896
+ isMultiMap: isMultiMap,
2897
+ mapId: mapId,
2898
+ source: source
2899
+ })
2900
+ }), !!hasDataExplorer && jsx(Grid, {
2901
+ size: 12,
2902
+ children: jsx(DataExplorerButtonConnect, {
2903
+ mapId: mapId
2904
+ })
2905
+ })]
2906
+ })
2907
+ }), jsx(Box, {
2908
+ sx: {
2909
+ position: 'absolute',
2910
+ margin: '8px 0 0 calc(100% - 40px)',
2911
+ zIndex: 2
2912
+ },
2913
+ children: jsx(ServiceOptionsButton, {
2914
+ mapId: mapId
2915
+ })
2916
+ }), jsx(Box, {
2917
+ sx: hasDataExplorer ? {
2918
+ minHeight: '52px'
2919
+ } : {},
2920
+ children: jsx(ServiceListConnect, {
2921
+ setHeight: handleHeightChange
2922
+ })
2923
+ }), jsx(Box, {
2924
+ sx: {
2925
+ padding: '0 16px'
2926
+ },
2927
+ children: jsx(LayerListConnect, {
2928
+ layerSelectHeight: height,
2929
+ layerSelectWidth: width,
2930
+ mapId: mapId,
2931
+ serviceListHeight: serviceListHeight
2932
+ })
2933
+ })]
2934
+ });
2935
+ };
2936
+
2937
+ var style = {
2938
+ textField: {
2939
+ width: '100%',
2940
+ marginBottom: 2
2941
+ }
2942
+ };
2943
+ var getSuccesMessage = function getSuccesMessage(serviceName, t) {
2944
+ return t('get-success-message', {
2945
+ serviceName: serviceName
2946
+ });
2947
+ };
2948
+ var getTitleForVariant = function getTitleForVariant(t, variant) {
2949
+ switch (variant) {
2950
+ case 'add':
2951
+ return t('add-a-new-service');
2952
+ case 'edit':
2953
+ return t('edit-service-title');
2954
+ case 'save':
2955
+ return t('save-service-title');
2956
+ default:
2957
+ return 'Service';
2958
+ }
2959
+ };
2960
+ var FormFields;
2961
+ (function (FormFields) {
2962
+ FormFields["serviceUrl"] = "serviceUrl";
2963
+ FormFields["serviceName"] = "serviceName";
2964
+ FormFields["serviceAbstracts"] = "serviceAbstracts";
2965
+ })(FormFields || (FormFields = {}));
2966
+ var InitialValidationsTrigger = function InitialValidationsTrigger(_ref) {
2967
+ var trigger = _ref.trigger,
2968
+ getValues = _ref.getValues,
2969
+ onValidField = _ref.onValidField;
2970
+ React.useEffect(function () {
2971
+ var value = getValues(FormFields.serviceUrl);
2972
+ if (value) {
2973
+ void trigger(FormFields.serviceUrl).then(function (isValid) {
2974
+ return isValid && onValidField(value);
2975
+ });
2976
+ }
2977
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2978
+ }, []);
2979
+ return null;
2980
+ };
2981
+ var ServicePopupUnwrapped = function ServicePopupUnwrapped(_ref2) {
2982
+ var servicePopupVariant = _ref2.servicePopupVariant,
2983
+ _ref2$hideBackdrop = _ref2.hideBackdrop,
2984
+ hideBackdrop = _ref2$hideBackdrop === void 0 ? false : _ref2$hideBackdrop,
2985
+ isOpen = _ref2.isOpen,
2986
+ closePopup = _ref2.closePopup,
2987
+ shouldDisableAutoFocus = _ref2.shouldDisableAutoFocus,
2988
+ services = _ref2.services,
2989
+ serviceSetLayers = _ref2.serviceSetLayers,
2990
+ serviceUrl = _ref2.serviceUrl,
2991
+ serviceName = _ref2.serviceName,
2992
+ _ref2$showSnackbar = _ref2.showSnackbar,
2993
+ showSnackbar = _ref2$showSnackbar === void 0 ? function () {} : _ref2$showSnackbar,
2994
+ _ref2$disableAutoFocu = _ref2.disableAutoFocus,
2995
+ disableAutoFocus = _ref2$disableAutoFocu === void 0 ? false : _ref2$disableAutoFocu;
2996
+ var _useLayerSelectTransl = useLayerSelectTranslation(),
2997
+ t = _useLayerSelectTransl.t;
2998
+ var _useFormContext = useFormContext(),
2999
+ errors = _useFormContext.formState.errors,
3000
+ handleSubmit = _useFormContext.handleSubmit,
3001
+ setError = _useFormContext.setError,
3002
+ clearErrors = _useFormContext.clearErrors,
3003
+ watch = _useFormContext.watch,
3004
+ trigger = _useFormContext.trigger,
3005
+ getValues = _useFormContext.getValues,
3006
+ setValue = _useFormContext.setValue;
3007
+ var _React$useState = React.useState(false),
3008
+ isLoading = _React$useState[0],
3009
+ setIsLoading = _React$useState[1];
3010
+ var _React$useState2 = React.useState(false),
3011
+ shouldForceReload = _React$useState2[0],
3012
+ setShouldForceReload = _React$useState2[1];
3013
+ var _React$useState3 = React.useState(null),
3014
+ detectedServiceType = _React$useState3[0],
3015
+ setDetectedServiceType = _React$useState3[1];
3016
+ var fetchServiceData = /*#__PURE__*/function () {
3017
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(newServiceUrl) {
3018
+ var type, serviceUrlForLoading, service, _t;
3019
+ return _regenerator().w(function (_context) {
3020
+ while (1) switch (_context.p = _context.n) {
3021
+ case 0:
3022
+ _context.p = 0;
3023
+ setIsLoading(true);
3024
+ _context.n = 1;
3025
+ return detectServiceType(newServiceUrl);
3026
+ case 1:
3027
+ type = _context.v;
3028
+ setDetectedServiceType(type);
3029
+ serviceUrlForLoading = type === DetectableServiceType.STAC ? normalizeStacServiceUrl(newServiceUrl) : newServiceUrl;
3030
+ if (serviceUrlForLoading !== newServiceUrl) {
3031
+ setValue(FormFields.serviceUrl, serviceUrlForLoading);
3032
+ }
3033
+ if (!(type === DetectableServiceType.STAC)) {
3034
+ _context.n = 3;
3035
+ break;
3036
+ }
3037
+ _context.n = 2;
3038
+ return loadSTACService(serviceUrlForLoading);
3039
+ case 2:
3040
+ _t = _context.v;
3041
+ _context.n = 5;
3042
+ break;
3043
+ case 3:
3044
+ _context.n = 4;
3045
+ return loadWMSService(serviceUrlForLoading, true);
3046
+ case 4:
3047
+ _t = _context.v;
3048
+ case 5:
3049
+ service = _t;
3050
+ setValue(FormFields.serviceName, service.name);
3051
+ setValue(FormFields.serviceAbstracts, service["abstract"] || '');
3052
+ setIsLoading(false);
3053
+ setShouldForceReload(false);
3054
+ _context.n = 7;
3055
+ break;
3056
+ case 6:
3057
+ _context.p = 6;
3058
+ _context.v;
3059
+ setIsLoading(false);
3060
+ setShouldForceReload(true);
3061
+ setError(FormFields.serviceUrl, {
3062
+ message: t('validations-request-failed'),
3063
+ type: 'SYSTEM'
3064
+ });
3065
+ case 7:
3066
+ return _context.a(2);
3067
+ }
3068
+ }, _callee, null, [[0, 6]]);
3069
+ }));
3070
+ return function fetchServiceData(_x) {
3071
+ return _ref3.apply(this, arguments);
3072
+ };
3073
+ }();
3074
+ var addNewService = /*#__PURE__*/function () {
3075
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(formValues) {
3076
+ var type, serviceUrlForSaving, service, _t3, _t4;
3077
+ return _regenerator().w(function (_context2) {
3078
+ while (1) switch (_context2.p = _context2.n) {
3079
+ case 0:
3080
+ clearErrors(FormFields.serviceUrl);
3081
+ setIsLoading(true);
3082
+ _context2.p = 1;
3083
+ if (!(detectedServiceType != null)) {
3084
+ _context2.n = 2;
3085
+ break;
3086
+ }
3087
+ _t3 = detectedServiceType;
3088
+ _context2.n = 4;
3089
+ break;
3090
+ case 2:
3091
+ _context2.n = 3;
3092
+ return detectServiceType(formValues.serviceUrl);
3093
+ case 3:
3094
+ _t3 = _context2.v;
3095
+ case 4:
3096
+ type = _t3;
3097
+ serviceUrlForSaving = type === DetectableServiceType.STAC ? normalizeStacServiceUrl(formValues.serviceUrl) : formValues.serviceUrl;
3098
+ if (!(type === DetectableServiceType.STAC)) {
3099
+ _context2.n = 6;
3100
+ break;
3101
+ }
3102
+ _context2.n = 5;
3103
+ return loadSTACService(serviceUrlForSaving);
3104
+ case 5:
3105
+ _t4 = _context2.v;
3106
+ _context2.n = 8;
3107
+ break;
3108
+ case 6:
3109
+ _context2.n = 7;
3110
+ return loadWMSService(serviceUrlForSaving, shouldForceReload);
3111
+ case 7:
3112
+ _t4 = _context2.v;
3113
+ case 8:
3114
+ service = _t4;
3115
+ if (serviceUrlForSaving !== formValues.serviceUrl) {
3116
+ setValue(FormFields.serviceUrl, serviceUrlForSaving);
3117
+ }
3118
+ serviceSetLayers({
3119
+ id: service.id,
3120
+ name: formValues.serviceName,
3121
+ serviceUrl: serviceUrlForSaving,
3122
+ "abstract": formValues.serviceAbstracts,
3123
+ layers: service.layers,
3124
+ scope: 'user',
3125
+ type: service.type
3126
+ });
3127
+ setIsLoading(false);
3128
+ showSnackbar(getSuccesMessage(formValues.serviceName, t));
3129
+ closePopup();
3130
+ _context2.n = 10;
3131
+ break;
3132
+ case 9:
3133
+ _context2.p = 9;
3134
+ _context2.v;
3135
+ setIsLoading(false);
3136
+ setError(FormFields.serviceUrl, {
3137
+ message: t('validations-request-failed'),
3138
+ type: 'SYSTEM'
3139
+ });
3140
+ case 10:
3141
+ return _context2.a(2);
3142
+ }
3143
+ }, _callee2, null, [[1, 9]]);
3144
+ }));
3145
+ return function addNewService(_x2) {
3146
+ return _ref4.apply(this, arguments);
3147
+ };
3148
+ }();
3149
+ var onValidateServiceUrl = function onValidateServiceUrl(value) {
3150
+ return validateServiceUrl(t, value, services);
3151
+ };
3152
+ var onFocusServiceUrl = function onFocusServiceUrl() {
3153
+ var hasValue = getValues(FormFields.serviceUrl);
3154
+ if (!errors[FormFields.serviceUrl] && hasValue) {
3155
+ void trigger(FormFields.serviceUrl);
3156
+ }
3157
+ };
3158
+ var onBlurServiceUrl = function onBlurServiceUrl() {
3159
+ void trigger(FormFields.serviceUrl).then(function () {
3160
+ var hasValue = getValues(FormFields.serviceUrl);
3161
+ if (!errors[FormFields.serviceUrl] && hasValue) {
3162
+ void fetchServiceData(getValues(FormFields.serviceUrl));
3163
+ }
3164
+ });
3165
+ };
3166
+ var onKeyDownServiceUrl = function onKeyDownServiceUrl(event) {
3167
+ if (event.key === 'Enter') {
3168
+ onBlurServiceUrl();
3169
+ }
3170
+ };
3171
+ var onValidateServiceName = function onValidateServiceName(value) {
3172
+ return validateServiceName(t, value, services, serviceName);
3173
+ };
3174
+ var getFormAreRequiredFieldsEmpty = function getFormAreRequiredFieldsEmpty() {
3175
+ var serviceNameField = watch(FormFields.serviceName);
3176
+ var serviceUrlField = watch(FormFields.serviceUrl);
3177
+ return serviceNameField === '' || serviceNameField === undefined || serviceUrlField === '' || serviceUrlField === undefined;
3178
+ };
3179
+ var getFormHasformErrors = function getFormHasformErrors() {
3180
+ var totalErrors = Object.keys(errors).length;
3181
+ if (totalErrors > 0) {
3182
+ // prevent SYSTEM error types from blocking the save button
3183
+ if (totalErrors === 1 && errors.serviceUrl) {
3184
+ return errors.serviceUrl.type !== undefined && errors.serviceUrl.type !== 'SYSTEM';
3185
+ }
3186
+ return true;
3187
+ }
3188
+ return false;
3189
+ };
3190
+ var isSubmitDisabled = getFormHasformErrors() || getFormAreRequiredFieldsEmpty();
3191
+ var isShowPopup = servicePopupVariant === 'show';
3192
+ var isServiceUrlDisabled = isShowPopup || servicePopupVariant === 'edit';
3193
+ return jsx(CustomDialog, {
3194
+ actions: isShowPopup ? jsx(Button, {
3195
+ onClick: function onClick() {
3196
+ return closePopup();
3197
+ },
3198
+ sx: {
3199
+ width: {
3200
+ xs: '100%',
3201
+ sm: '117px'
3202
+ }
3203
+ },
3204
+ variant: "tertiary",
3205
+ children: t('close')
3206
+ }) : jsxs(Fragment, {
3207
+ children: [jsx(Button, {
3208
+ "data-testid": "closePopupButtonCancel",
3209
+ onClick: closePopup,
3210
+ sx: {
3211
+ width: {
3212
+ xs: '100%',
3213
+ sm: '117px'
3214
+ }
3215
+ },
3216
+ variant: "tertiary",
3217
+ children: t('cancel')
3218
+ }), jsx(Button, {
3219
+ "data-testid": "saveServiceButton",
3220
+ disabled: isSubmitDisabled || isLoading,
3221
+ form: "servicePopupForm",
3222
+ sx: {
3223
+ marginLeft: {
3224
+ xs: '0px!important',
3225
+ sm: '8px!important'
3226
+ },
3227
+ width: {
3228
+ xs: '100%',
3229
+ sm: '117px'
3230
+ }
3231
+ },
3232
+ type: "submit",
3233
+ variant: "primary",
3234
+ children: t('save')
3235
+ })]
3236
+ }),
3237
+ "data-testid": "servicePopup",
3238
+ disableAutoFocus: disableAutoFocus,
3239
+ fullWidth: true,
3240
+ hideBackdrop: hideBackdrop,
3241
+ maxWidth: "xs",
3242
+ onClose: function onClose() {
3243
+ return closePopup == null ? void 0 : closePopup();
3244
+ },
3245
+ open: isOpen,
3246
+ sx: {
3247
+ '& .MuiDialog-paper': {
3248
+ backgroundColor: "geowebColors.cards.cardContainer",
3249
+ maxWidth: 458
3250
+ }
3251
+ },
3252
+ title: getTitleForVariant(t, servicePopupVariant),
3253
+ children: jsxs("form", {
3254
+ id: "servicePopupForm",
3255
+ onSubmit: handleSubmit(/*#__PURE__*/function () {
3256
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(formValues) {
3257
+ return _regenerator().w(function (_context3) {
3258
+ while (1) switch (_context3.n) {
3259
+ case 0:
3260
+ return _context3.a(2, addNewService(formValues));
3261
+ }
3262
+ }, _callee3);
3263
+ }));
3264
+ return function (_x3) {
3265
+ return _ref5.apply(this, arguments);
3266
+ };
3267
+ }()),
3268
+ children: [!!isLoading && jsx(Box, {
3269
+ sx: {
3270
+ position: 'relative'
3271
+ },
3272
+ children: jsx(LinearProgress, {
3273
+ color: "secondary",
3274
+ "data-testid": "loadingIndicator",
3275
+ sx: {
3276
+ position: 'absolute',
3277
+ width: '100%',
3278
+ top: 8
3279
+ }
3280
+ })
3281
+ }), jsx(ReactHookFormTextField, {
3282
+ autoFocus: !shouldDisableAutoFocus,
3283
+ defaultValue: serviceUrl,
3284
+ disabled: isServiceUrlDisabled || isLoading,
3285
+ inputSlotProps: {
3286
+ disableUnderline: isShowPopup,
3287
+ endAdornment: isShowPopup && jsx(InputAdornment, {
3288
+ position: "end",
3289
+ children: jsx(CustomIconButton, {
3290
+ "aria-label": "copy url",
3291
+ onClick: function onClick() {
3292
+ void navigator.clipboard.writeText(serviceUrl);
3293
+ showSnackbar(t('copy-url-message'));
3294
+ },
3295
+ sx: {
3296
+ marginTop: 0.5
3297
+ },
3298
+ children: jsx(Copy, {})
3299
+ })
3300
+ })
3301
+ },
3302
+ isReadOnly: isShowPopup,
3303
+ label: t('service-url-label'),
3304
+ name: FormFields.serviceUrl,
3305
+ onBlur: onBlurServiceUrl,
3306
+ onFocus: onFocusServiceUrl,
3307
+ onKeyDown: onKeyDownServiceUrl,
3308
+ rules: {
3309
+ required: true,
3310
+ validate: Object.assign({}, !isServiceUrlDisabled && {
3311
+ onValidateServiceUrl: onValidateServiceUrl
3312
+ })
3313
+ },
3314
+ sx: style.textField
3315
+ }), jsx(ReactHookFormTextField, {
3316
+ defaultValue: serviceName,
3317
+ disabled: isShowPopup || isLoading,
3318
+ inputSlotProps: {
3319
+ disableUnderline: isShowPopup
3320
+ },
3321
+ isReadOnly: isShowPopup,
3322
+ label: t('service-name-label'),
3323
+ name: FormFields.serviceName,
3324
+ rules: {
3325
+ required: true,
3326
+ validate: {
3327
+ onValidateServiceName: onValidateServiceName
3328
+ }
3329
+ },
3330
+ sx: style.textField
3331
+ }), jsx(ReactHookFormTextField, {
3332
+ defaultValue: "",
3333
+ disabled: isShowPopup || isLoading,
3334
+ helperText: !isShowPopup ? t('service-popup-helper-text') : '',
3335
+ inputSlotProps: {
3336
+ disableUnderline: isShowPopup
3337
+ },
3338
+ isReadOnly: isShowPopup,
3339
+ label: t('service-abstracts-label'),
3340
+ multiline: true,
3341
+ name: FormFields.serviceAbstracts,
3342
+ rows: 4,
3343
+ sx: style.textField
3344
+ }), !isServiceUrlDisabled && jsx(InitialValidationsTrigger, {
3345
+ getValues: getValues,
3346
+ onValidField: fetchServiceData,
3347
+ trigger: trigger
3348
+ })]
3349
+ })
3350
+ });
3351
+ };
3352
+ var ServicePopup = function ServicePopup(_ref6) {
3353
+ var props = Object.assign({}, (_objectDestructuringEmpty(_ref6), _ref6));
3354
+ return jsx(ReactHookFormProvider, {
3355
+ options: Object.assign({}, defaultFormOptions, {
3356
+ defaultValues: {
3357
+ serviceUrl: props.serviceUrl,
3358
+ serviceName: props.serviceName,
3359
+ serviceAbstracts: props.serviceAbstracts
3360
+ }
3361
+ }),
3362
+ children: jsx(ServicePopupUnwrapped, Object.assign({}, props))
3363
+ });
3364
+ };
3365
+
3366
+ // Extracted from ServicePopupDialog as the getActiveServices and getActiveServiceById selectors
3367
+ // Result in many rerenders. By extracting we're able to only render this component and these selectors
3368
+ // when the dialog is open
3369
+ var ServicePopupDialogConnect = function ServicePopupDialogConnect(_ref) {
3370
+ var isOpen = _ref.isOpen,
3371
+ _ref$serviceId = _ref.serviceId,
3372
+ serviceId = _ref$serviceId === void 0 ? '' : _ref$serviceId,
3373
+ variant = _ref.variant,
3374
+ _ref$url = _ref.url,
3375
+ url = _ref$url === void 0 ? '' : _ref$url,
3376
+ setServicePopupClosed = _ref.setServicePopupClosed;
3377
+ var dispatch = useDispatch();
3378
+ var services = useAppSelector(function (store) {
3379
+ return getActiveServices(store);
3380
+ });
3381
+ var activeService = useAppSelector(function (store) {
3382
+ return getActiveServiceById(store, serviceId);
3383
+ });
3384
+ var serviceSetLayers = React.useCallback(function (payload) {
3385
+ dispatch(serviceActions.serviceSetLayers(payload));
3386
+ }, [dispatch]);
3387
+ var showSnackbar = React.useCallback(function (message) {
3388
+ dispatch(snackbarActions.openSnackbar({
3389
+ type: snackbarTypes.SnackbarMessageType.VERBATIM_MESSAGE,
3390
+ message: message
3391
+ }));
3392
+ }, [dispatch]);
3393
+ return jsx(ServicePopup, {
3394
+ closePopup: setServicePopupClosed,
3395
+ isOpen: isOpen,
3396
+ serviceAbstracts: activeService == null ? void 0 : activeService["abstract"],
3397
+ serviceId: serviceId,
3398
+ serviceName: activeService == null ? void 0 : activeService.serviceName,
3399
+ servicePopupVariant: variant,
3400
+ serviceSetLayers: serviceSetLayers,
3401
+ serviceUrl: url || (activeService == null ? void 0 : activeService.serviceUrl),
3402
+ services: services,
3403
+ showSnackbar: showSnackbar
3404
+ });
3405
+ };
3406
+
3407
+ var ServicePopupConnect = function ServicePopupConnect() {
3408
+ var dispatch = useDispatch();
3409
+ var _useAppSelector = useAppSelector(function (store) {
3410
+ return getServicePopupDetails(store);
3411
+ }),
3412
+ isOpen = _useAppSelector.isOpen,
3413
+ url = _useAppSelector.url,
3414
+ serviceId = _useAppSelector.serviceId,
3415
+ variant = _useAppSelector.variant;
3416
+ var setServicePopupClosed = React.useCallback(function () {
3417
+ dispatch(layerSelectActions.closeServicePopupOpen());
3418
+ }, [dispatch]);
3419
+ if (!isOpen) {
3420
+ return null;
3421
+ }
3422
+ return jsx(ServicePopupDialogConnect, {
3423
+ isOpen: isOpen,
3424
+ serviceId: serviceId,
3425
+ setServicePopupClosed: setServicePopupClosed,
3426
+ url: url,
3427
+ variant: variant
3428
+ });
3429
+ };
3430
+
3431
+ /**
3432
+ * LayerSelectConnect is a component that is opened from LayerManager
3433
+ * It's used to add Services and Layers to the application
3434
+ * It doesn't expect any props, its subcomponents only read and write to redux store
3435
+ *
3436
+ * ``` <LayerSelectConnect />```
3437
+ */
3438
+ var LayerSelectConnect = function LayerSelectConnect(_ref) {
3439
+ var _ref$mapId = _ref.mapId,
3440
+ initialMapId = _ref$mapId === void 0 ? null : _ref$mapId,
3441
+ bounds = _ref.bounds,
3442
+ _ref$showTitle = _ref.showTitle,
3443
+ showTitle = _ref$showTitle === void 0 ? false : _ref$showTitle,
3444
+ _ref$isMultiMap = _ref.isMultiMap,
3445
+ isMultiMap = _ref$isMultiMap === void 0 ? false : _ref$isMultiMap;
3446
+ var dialogType = isMultiMap ? uiTypes.DialogTypes.LayerSelect + "-" + initialMapId : uiTypes.DialogTypes.LayerSelect;
3447
+ var mapId = useAppSelector(function (store) {
3448
+ return uiSelectors.getDialogMapId(store, dialogType);
3449
+ });
3450
+ var _useSetupDialog = useSetupDialog(dialogType),
3451
+ dialogOrder = _useSetupDialog.dialogOrder,
3452
+ isDialogOpen = _useSetupDialog.isDialogOpen,
3453
+ onCloseDialog = _useSetupDialog.onCloseDialog,
3454
+ setDialogOrder = _useSetupDialog.setDialogOrder,
3455
+ uiSource = _useSetupDialog.uiSource;
3456
+ var config = sessionStorageProvider.getConfig();
3457
+ var hasDataExplorer = !!config.GW_DATA_EXPLORER_CONFIGURATION_FILENAME;
3458
+ return jsxs(Fragment, {
3459
+ children: [jsx(LayerSelect, {
3460
+ bounds: bounds,
3461
+ hasDataExplorer: hasDataExplorer,
3462
+ isMultiMap: isMultiMap,
3463
+ isOpen: isDialogOpen,
3464
+ mapId: mapId || initialMapId,
3465
+ onClose: onCloseDialog,
3466
+ onMouseDown: setDialogOrder,
3467
+ order: dialogOrder,
3468
+ showTitle: showTitle,
3469
+ source: uiSource
3470
+ }), jsx(KeywordFilterResultsConnect, {
3471
+ isMultiMap: isMultiMap,
3472
+ mapId: mapId || initialMapId
3473
+ }), jsx(ServicePopupConnect, {})]
3474
+ });
3475
+ };
3476
+
3477
+ export { AllChipConnect, DataExplorerButtonConnect, KeywordFilterButtonConnect, KeywordFilterResults, KeywordFilterResultsConnect, KeywordFilterResultsListItemConnect, KeywordFilterSelectAllSwitchConnect, LAYER_SELECT_NAMESPACE, LayerAddRemoveButton, LayerList, LayerListConnect, LayerListDimensions, LayerListRow, LayerSelectButtonConnect, LayerSelectConnect, SearchFieldConnect, ServiceChip, ServiceChipConnect, ServiceList, ServiceListConnect, ServiceOptionsButton, ServiceOptionsDialog, ServiceOptionsDialogConnect, ServicePopup, ServicePopupConnect, ServicePopupDialogConnect, createMockStore, getServiceSuccesUpdateMessage, getSuccesMessage, isUserAddedService, layerSelectActions, initialState as layerSelectInitialState, layerSelectListener, layerSelectMiddlewares, layerSelectReducer, layerSelectReducersMap, selectors as layerSelectSelectors, layerSelectTranslations, useAppSelector };