@itwin/map-layers 4.0.0-dev.8 → 5.0.0-dev.2

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 (203) hide show
  1. package/CHANGELOG.md +746 -848
  2. package/README.md +32 -32
  3. package/lib/cjs/MapLayerPreferences.d.ts +88 -88
  4. package/lib/cjs/MapLayerPreferences.js +311 -312
  5. package/lib/cjs/MapLayerPreferences.js.map +1 -1
  6. package/lib/cjs/map-layers.d.ts +6 -6
  7. package/lib/cjs/map-layers.js +22 -22
  8. package/lib/cjs/mapLayers.d.ts +26 -44
  9. package/lib/cjs/mapLayers.d.ts.map +1 -1
  10. package/lib/cjs/mapLayers.js +33 -63
  11. package/lib/cjs/mapLayers.js.map +1 -1
  12. package/lib/cjs/ui/FeatureInfoUiItemsProvider.d.ts +16 -11
  13. package/lib/cjs/ui/FeatureInfoUiItemsProvider.d.ts.map +1 -1
  14. package/lib/cjs/ui/FeatureInfoUiItemsProvider.js +46 -52
  15. package/lib/cjs/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  16. package/lib/cjs/ui/Interfaces.d.ts +50 -50
  17. package/lib/cjs/ui/Interfaces.d.ts.map +1 -1
  18. package/lib/cjs/ui/Interfaces.js +2 -2
  19. package/lib/cjs/ui/Interfaces.js.map +1 -1
  20. package/lib/cjs/ui/MapFeatureInfoTool.d.ts +13 -13
  21. package/lib/cjs/ui/MapFeatureInfoTool.d.ts.map +1 -1
  22. package/lib/cjs/ui/MapFeatureInfoTool.js +50 -50
  23. package/lib/cjs/ui/MapFeatureInfoTool.js.map +1 -1
  24. package/lib/cjs/ui/MapLayersUiItemsProvider.d.ts +8 -8
  25. package/lib/cjs/ui/MapLayersUiItemsProvider.d.ts.map +1 -1
  26. package/lib/cjs/ui/MapLayersUiItemsProvider.js +35 -38
  27. package/lib/cjs/ui/MapLayersUiItemsProvider.js.map +1 -1
  28. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts +13 -14
  29. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  30. package/lib/cjs/ui/widget/AttachLayerPopupButton.js +334 -338
  31. package/lib/cjs/ui/widget/AttachLayerPopupButton.js.map +1 -1
  32. package/lib/cjs/ui/widget/BasemapPanel.d.ts +7 -8
  33. package/lib/cjs/ui/widget/BasemapPanel.d.ts.map +1 -1
  34. package/lib/cjs/ui/widget/BasemapPanel.js +151 -156
  35. package/lib/cjs/ui/widget/BasemapPanel.js.map +1 -1
  36. package/lib/cjs/ui/widget/BasemapPanel.scss +87 -87
  37. package/lib/cjs/ui/widget/ConfirmMessageDialog.d.ts +20 -21
  38. package/lib/cjs/ui/widget/ConfirmMessageDialog.d.ts.map +1 -1
  39. package/lib/cjs/ui/widget/ConfirmMessageDialog.js +22 -25
  40. package/lib/cjs/ui/widget/ConfirmMessageDialog.js.map +1 -1
  41. package/lib/cjs/ui/widget/FeatureInfoDataProvider.d.ts +35 -40
  42. package/lib/cjs/ui/widget/FeatureInfoDataProvider.d.ts.map +1 -1
  43. package/lib/cjs/ui/widget/FeatureInfoDataProvider.js +139 -139
  44. package/lib/cjs/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  45. package/lib/cjs/ui/widget/FeatureInfoWidget.d.ts +6 -7
  46. package/lib/cjs/ui/widget/FeatureInfoWidget.d.ts.map +1 -1
  47. package/lib/cjs/ui/widget/FeatureInfoWidget.js +70 -71
  48. package/lib/cjs/ui/widget/FeatureInfoWidget.js.map +1 -1
  49. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts +18 -19
  50. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  51. package/lib/cjs/ui/widget/MapLayerDroppable.js +85 -88
  52. package/lib/cjs/ui/widget/MapLayerDroppable.js.map +1 -1
  53. package/lib/cjs/ui/widget/MapLayerManager.d.ts +26 -26
  54. package/lib/cjs/ui/widget/MapLayerManager.d.ts.map +1 -1
  55. package/lib/cjs/ui/widget/MapLayerManager.js +399 -403
  56. package/lib/cjs/ui/widget/MapLayerManager.js.map +1 -1
  57. package/lib/cjs/ui/widget/MapLayerManager.scss +409 -409
  58. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts +11 -12
  59. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts.map +1 -1
  60. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js +79 -83
  61. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  62. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.d.ts +6 -7
  63. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.d.ts.map +1 -1
  64. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js +65 -65
  65. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  66. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  67. package/lib/cjs/ui/widget/MapLayersWidget.d.ts +10 -11
  68. package/lib/cjs/ui/widget/MapLayersWidget.d.ts.map +1 -1
  69. package/lib/cjs/ui/widget/MapLayersWidget.js +31 -31
  70. package/lib/cjs/ui/widget/MapLayersWidget.js.map +1 -1
  71. package/lib/cjs/ui/widget/MapManagerSettings.d.ts +2 -3
  72. package/lib/cjs/ui/widget/MapManagerSettings.d.ts.map +1 -1
  73. package/lib/cjs/ui/widget/MapManagerSettings.js +195 -200
  74. package/lib/cjs/ui/widget/MapManagerSettings.js.map +1 -1
  75. package/lib/cjs/ui/widget/MapManagerSettings.scss +29 -29
  76. package/lib/cjs/ui/widget/MapUrlDialog.d.ts +22 -23
  77. package/lib/cjs/ui/widget/MapUrlDialog.d.ts.map +1 -1
  78. package/lib/cjs/ui/widget/MapUrlDialog.js +528 -527
  79. package/lib/cjs/ui/widget/MapUrlDialog.js.map +1 -1
  80. package/lib/cjs/ui/widget/MapUrlDialog.scss +99 -100
  81. package/lib/cjs/ui/widget/SelectMapFormat.d.ts +17 -18
  82. package/lib/cjs/ui/widget/SelectMapFormat.d.ts.map +1 -1
  83. package/lib/cjs/ui/widget/SelectMapFormat.js +54 -59
  84. package/lib/cjs/ui/widget/SelectMapFormat.js.map +1 -1
  85. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts +18 -20
  86. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts.map +1 -1
  87. package/lib/cjs/ui/widget/SubLayersDataProvider.js +74 -76
  88. package/lib/cjs/ui/widget/SubLayersDataProvider.js.map +1 -1
  89. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts +9 -10
  90. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts.map +1 -1
  91. package/lib/cjs/ui/widget/SubLayersPopupButton.js +40 -40
  92. package/lib/cjs/ui/widget/SubLayersPopupButton.js.map +1 -1
  93. package/lib/cjs/ui/widget/SubLayersTree.d.ts +14 -15
  94. package/lib/cjs/ui/widget/SubLayersTree.d.ts.map +1 -1
  95. package/lib/cjs/ui/widget/SubLayersTree.js +408 -419
  96. package/lib/cjs/ui/widget/SubLayersTree.js.map +1 -1
  97. package/lib/cjs/ui/widget/SubLayersTree.scss +70 -69
  98. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts +13 -14
  99. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts.map +1 -1
  100. package/lib/cjs/ui/widget/TransparencyPopupButton.js +47 -47
  101. package/lib/cjs/ui/widget/TransparencyPopupButton.js.map +1 -1
  102. package/lib/cjs/ui/widget/TransparencyPopupButton.scss +35 -36
  103. package/lib/esm/MapLayerPreferences.d.ts +88 -88
  104. package/lib/esm/MapLayerPreferences.js +307 -308
  105. package/lib/esm/MapLayerPreferences.js.map +1 -1
  106. package/lib/esm/map-layers.d.ts +6 -6
  107. package/lib/esm/map-layers.js +10 -10
  108. package/lib/esm/mapLayers.d.ts +26 -44
  109. package/lib/esm/mapLayers.d.ts.map +1 -1
  110. package/lib/esm/mapLayers.js +29 -59
  111. package/lib/esm/mapLayers.js.map +1 -1
  112. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts +16 -11
  113. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts.map +1 -1
  114. package/lib/esm/ui/FeatureInfoUiItemsProvider.js +42 -48
  115. package/lib/esm/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  116. package/lib/esm/ui/Interfaces.d.ts +50 -50
  117. package/lib/esm/ui/Interfaces.d.ts.map +1 -1
  118. package/lib/esm/ui/Interfaces.js +1 -1
  119. package/lib/esm/ui/Interfaces.js.map +1 -1
  120. package/lib/esm/ui/MapFeatureInfoTool.d.ts +13 -13
  121. package/lib/esm/ui/MapFeatureInfoTool.d.ts.map +1 -1
  122. package/lib/esm/ui/MapFeatureInfoTool.js +45 -45
  123. package/lib/esm/ui/MapFeatureInfoTool.js.map +1 -1
  124. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts +8 -8
  125. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts.map +1 -1
  126. package/lib/esm/ui/MapLayersUiItemsProvider.js +31 -34
  127. package/lib/esm/ui/MapLayersUiItemsProvider.js.map +1 -1
  128. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts +13 -14
  129. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  130. package/lib/esm/ui/widget/AttachLayerPopupButton.js +330 -334
  131. package/lib/esm/ui/widget/AttachLayerPopupButton.js.map +1 -1
  132. package/lib/esm/ui/widget/BasemapPanel.d.ts +7 -8
  133. package/lib/esm/ui/widget/BasemapPanel.d.ts.map +1 -1
  134. package/lib/esm/ui/widget/BasemapPanel.js +147 -152
  135. package/lib/esm/ui/widget/BasemapPanel.js.map +1 -1
  136. package/lib/esm/ui/widget/BasemapPanel.scss +87 -87
  137. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts +20 -21
  138. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts.map +1 -1
  139. package/lib/esm/ui/widget/ConfirmMessageDialog.js +18 -21
  140. package/lib/esm/ui/widget/ConfirmMessageDialog.js.map +1 -1
  141. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts +35 -40
  142. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts.map +1 -1
  143. package/lib/esm/ui/widget/FeatureInfoDataProvider.js +135 -135
  144. package/lib/esm/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  145. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts +6 -7
  146. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts.map +1 -1
  147. package/lib/esm/ui/widget/FeatureInfoWidget.js +66 -67
  148. package/lib/esm/ui/widget/FeatureInfoWidget.js.map +1 -1
  149. package/lib/esm/ui/widget/MapLayerDroppable.d.ts +18 -19
  150. package/lib/esm/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  151. package/lib/esm/ui/widget/MapLayerDroppable.js +81 -84
  152. package/lib/esm/ui/widget/MapLayerDroppable.js.map +1 -1
  153. package/lib/esm/ui/widget/MapLayerManager.d.ts +26 -26
  154. package/lib/esm/ui/widget/MapLayerManager.d.ts.map +1 -1
  155. package/lib/esm/ui/widget/MapLayerManager.js +394 -398
  156. package/lib/esm/ui/widget/MapLayerManager.js.map +1 -1
  157. package/lib/esm/ui/widget/MapLayerManager.scss +409 -409
  158. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts +11 -12
  159. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts.map +1 -1
  160. package/lib/esm/ui/widget/MapLayerSettingsMenu.js +75 -79
  161. package/lib/esm/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  162. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts +6 -7
  163. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts.map +1 -1
  164. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js +61 -61
  165. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  166. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  167. package/lib/esm/ui/widget/MapLayersWidget.d.ts +10 -11
  168. package/lib/esm/ui/widget/MapLayersWidget.d.ts.map +1 -1
  169. package/lib/esm/ui/widget/MapLayersWidget.js +27 -27
  170. package/lib/esm/ui/widget/MapLayersWidget.js.map +1 -1
  171. package/lib/esm/ui/widget/MapManagerSettings.d.ts +2 -3
  172. package/lib/esm/ui/widget/MapManagerSettings.d.ts.map +1 -1
  173. package/lib/esm/ui/widget/MapManagerSettings.js +191 -196
  174. package/lib/esm/ui/widget/MapManagerSettings.js.map +1 -1
  175. package/lib/esm/ui/widget/MapManagerSettings.scss +29 -29
  176. package/lib/esm/ui/widget/MapUrlDialog.d.ts +22 -23
  177. package/lib/esm/ui/widget/MapUrlDialog.d.ts.map +1 -1
  178. package/lib/esm/ui/widget/MapUrlDialog.js +524 -523
  179. package/lib/esm/ui/widget/MapUrlDialog.js.map +1 -1
  180. package/lib/esm/ui/widget/MapUrlDialog.scss +99 -100
  181. package/lib/esm/ui/widget/SelectMapFormat.d.ts +17 -18
  182. package/lib/esm/ui/widget/SelectMapFormat.d.ts.map +1 -1
  183. package/lib/esm/ui/widget/SelectMapFormat.js +50 -55
  184. package/lib/esm/ui/widget/SelectMapFormat.js.map +1 -1
  185. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts +18 -20
  186. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts.map +1 -1
  187. package/lib/esm/ui/widget/SubLayersDataProvider.js +70 -72
  188. package/lib/esm/ui/widget/SubLayersDataProvider.js.map +1 -1
  189. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts +9 -10
  190. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts.map +1 -1
  191. package/lib/esm/ui/widget/SubLayersPopupButton.js +36 -36
  192. package/lib/esm/ui/widget/SubLayersPopupButton.js.map +1 -1
  193. package/lib/esm/ui/widget/SubLayersTree.d.ts +14 -15
  194. package/lib/esm/ui/widget/SubLayersTree.d.ts.map +1 -1
  195. package/lib/esm/ui/widget/SubLayersTree.js +403 -414
  196. package/lib/esm/ui/widget/SubLayersTree.js.map +1 -1
  197. package/lib/esm/ui/widget/SubLayersTree.scss +70 -69
  198. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts +13 -14
  199. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts.map +1 -1
  200. package/lib/esm/ui/widget/TransparencyPopupButton.js +43 -43
  201. package/lib/esm/ui/widget/TransparencyPopupButton.js.map +1 -1
  202. package/lib/esm/ui/widget/TransparencyPopupButton.scss +35 -36
  203. package/package.json +39 -38
@@ -1,524 +1,525 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- // cSpell:ignore Modeless WMTS
6
- import { DialogButtonType, SpecialKey } from "@itwin/appui-abstract";
7
- import { ModalDialogManager } from "@itwin/appui-react";
8
- import { Button, Input, LabeledInput, ProgressLinear, Radio } from "@itwin/itwinui-react";
9
- import { IModelApp, MapLayerSource, MapLayerSourceStatus, NotifyMessageDetails, OutputMessagePriority, } from "@itwin/core-frontend";
10
- import { Dialog, Icon, useCrossOriginPopup } from "@itwin/core-react";
11
- import * as React from "react";
12
- import { MapLayerPreferences } from "../../MapLayerPreferences";
13
- import { MapLayersUI } from "../../mapLayers";
14
- import "./MapUrlDialog.scss";
15
- import { BeEvent, Guid } from "@itwin/core-bentley";
16
- import { SelectMapFormat } from "./SelectMapFormat";
17
- export const MAP_TYPES = {
18
- wms: "WMS",
19
- arcGis: "ArcGIS",
20
- wmts: "WMTS",
21
- tileUrl: "TileURL",
22
- arcGisFeature: "ArcGISFeature",
23
- };
24
- // eslint-disable-next-line @typescript-eslint/naming-convention
25
- export function MapUrlDialog(props) {
26
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
27
- const { isOverlay, onOkResult, mapTypesOptions } = props;
28
- const getMapUrlFromProps = React.useCallback(() => {
29
- var _a;
30
- if (props.mapLayerSourceToEdit) {
31
- return props.mapLayerSourceToEdit.url;
32
- }
33
- else if ((_a = props.layerRequiringCredentials) === null || _a === void 0 ? void 0 : _a.url) {
34
- return props.layerRequiringCredentials.url;
35
- }
36
- return "";
37
- }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
38
- const getMapNameFromProps = React.useCallback(() => {
39
- var _a;
40
- if (props.mapLayerSourceToEdit) {
41
- return props.mapLayerSourceToEdit.name;
42
- }
43
- else if ((_a = props.layerRequiringCredentials) === null || _a === void 0 ? void 0 : _a.name) {
44
- return props.layerRequiringCredentials.name;
45
- }
46
- return "";
47
- }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
48
- const getFormatFromProps = React.useCallback(() => {
49
- var _a;
50
- if (props.mapLayerSourceToEdit) {
51
- return props.mapLayerSourceToEdit.formatId;
52
- }
53
- else if ((_a = props.layerRequiringCredentials) === null || _a === void 0 ? void 0 : _a.formatId) {
54
- return props.layerRequiringCredentials.formatId;
55
- }
56
- return undefined;
57
- }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
58
- const [dialogTitle] = React.useState(MapLayersUI.localization.getLocalizedString(props.layerRequiringCredentials || props.mapLayerSourceToEdit ? "mapLayers:CustomAttach.EditCustomLayer" : "mapLayers:CustomAttach.AttachCustomLayer"));
59
- const [typeLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Type"));
60
- const [nameLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Name"));
61
- const [nameInputPlaceHolder] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NameInputPlaceHolder"));
62
- const [urlLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.URL"));
63
- const [urlInputPlaceHolder] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.UrlInputPlaceHolder"));
64
- const [iTwinSettingsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnITwinSettings"));
65
- const [modelSettingsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnModelSettings"));
66
- const [missingCredentialsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MissingCredentials"));
67
- const [invalidCredentialsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCredentials"));
68
- const [externalLoginTitle] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLogin"));
69
- const [externalLoginFailedMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginFailed"));
70
- const [externalLoginSucceededMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginSucceeded"));
71
- const [externalLoginWaitingMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginWaiting"));
72
- const [externalLoginTryAgainLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginTryAgain"));
73
- const [serverRequireCredentials, setServerRequireCredentials] = React.useState(false);
74
- const [invalidCredentialsProvided, setInvalidCredentialsProvided] = React.useState(false);
75
- const [layerAttachPending, setLayerAttachPending] = React.useState(false);
76
- const [layerAuthPending, setLayerAuthPending] = React.useState(false);
77
- const [mapUrl, setMapUrl] = React.useState(getMapUrlFromProps());
78
- const [mapName, setMapName] = React.useState(getMapNameFromProps());
79
- const [userName, setUserName] = React.useState("");
80
- const [password, setPassword] = React.useState("");
81
- const [noSaveSettingsWarning] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NoSaveSettingsWarning"));
82
- const [passwordLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Password"));
83
- const [passwordRequiredLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.PasswordRequired"));
84
- const [userNameLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Username"));
85
- const [userNameRequiredLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.UsernameRequired"));
86
- const [settingsStorage, setSettingsStorageRadio] = React.useState("iTwin");
87
- const [oauthProcessSucceeded, setOAuthProcessSucceeded] = React.useState(undefined);
88
- const [showOauthPopup, setShowOauthPopup] = React.useState(false);
89
- const [externalLoginUrl, setExternalLoginUrl] = React.useState();
90
- const [onOauthProcessEnd] = React.useState(new BeEvent());
91
- const [accessClient, setAccessClient] = React.useState();
92
- const [isAccessClientInitialized, setAccessClientInitialized] = React.useState(false);
93
- const [mapType, setMapType] = React.useState((_a = getFormatFromProps()) !== null && _a !== void 0 ? _a : "ArcGIS");
94
- // 'isMounted' is used to prevent any async operation once the hook has been
95
- // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
96
- const isMounted = React.useRef(false);
97
- React.useEffect(() => {
98
- isMounted.current = true;
99
- return () => {
100
- isMounted.current = false;
101
- };
102
- }, []);
103
- const [isSettingsStorageAvailable] = React.useState(MapLayersUI.iTwinConfig && ((_c = (_b = props === null || props === void 0 ? void 0 : props.activeViewport) === null || _b === void 0 ? void 0 : _b.iModel) === null || _c === void 0 ? void 0 : _c.iTwinId));
104
- const [hasImodelContext] = React.useState(((_e = (_d = props === null || props === void 0 ? void 0 : props.activeViewport) === null || _d === void 0 ? void 0 : _d.iModel) === null || _e === void 0 ? void 0 : _e.iTwinId) !== undefined
105
- && props.activeViewport.iModel.iTwinId !== Guid.empty
106
- && ((_g = (_f = props === null || props === void 0 ? void 0 : props.activeViewport) === null || _f === void 0 ? void 0 : _f.iModel) === null || _g === void 0 ? void 0 : _g.iModelId) !== undefined
107
- && (props === null || props === void 0 ? void 0 : props.activeViewport.iModel.iModelId) !== Guid.empty);
108
- // Even though the settings storage is available,
109
- // we don't always want to enable it in the UI.
110
- const [settingsStorageDisabled] = React.useState(!isSettingsStorageAvailable || props.mapLayerSourceToEdit !== undefined || props.layerRequiringCredentials !== undefined);
111
- const [layerRequiringCredentialsIdx] = React.useState(() => {
112
- var _a;
113
- if (props.layerRequiringCredentials === undefined || !props.layerRequiringCredentials.name || !props.layerRequiringCredentials.url) {
114
- return undefined;
115
- }
116
- const indexInDisplayStyle = (_a = props.activeViewport) === null || _a === void 0 ? void 0 : _a.displayStyle.findMapLayerIndexByNameAndSource(props.layerRequiringCredentials.name, props.layerRequiringCredentials.url, isOverlay);
117
- if (indexInDisplayStyle === undefined || indexInDisplayStyle < 0) {
118
- return undefined;
119
- }
120
- else {
121
- return indexInDisplayStyle;
122
- }
123
- });
124
- const handleCancel = React.useCallback(() => {
125
- if (props.onCancelResult) {
126
- props.onCancelResult();
127
- return;
128
- }
129
- ModalDialogManager.closeDialog();
130
- }, [props]);
131
- const onUsernameChange = React.useCallback((event) => {
132
- setUserName(event.target.value);
133
- if (invalidCredentialsProvided)
134
- setInvalidCredentialsProvided(false);
135
- }, [setUserName, invalidCredentialsProvided, setInvalidCredentialsProvided]);
136
- const onPasswordChange = React.useCallback((event) => {
137
- setPassword(event.target.value);
138
- if (invalidCredentialsProvided)
139
- setInvalidCredentialsProvided(false);
140
- }, [setPassword, invalidCredentialsProvided, setInvalidCredentialsProvided]);
141
- const handleArcGisLogin = React.useCallback(() => {
142
- setLayerAuthPending(true);
143
- setShowOauthPopup(true);
144
- if (oauthProcessSucceeded === false) {
145
- setOAuthProcessSucceeded(undefined);
146
- }
147
- }, [oauthProcessSucceeded]);
148
- // return true if authorization is needed
149
- const updateAuthState = React.useCallback(async (source, sourceValidation) => {
150
- const sourceRequireAuth = (sourceValidation.status === MapLayerSourceStatus.RequireAuth);
151
- const invalidCredentials = (sourceValidation.status === MapLayerSourceStatus.InvalidCredentials);
152
- if (sourceRequireAuth) {
153
- const settings = source.toLayerSettings();
154
- if (accessClient !== undefined && accessClient.getTokenServiceEndPoint !== undefined && settings !== undefined) {
155
- try {
156
- const tokenEndpoint = await accessClient.getTokenServiceEndPoint(settings.url);
157
- if (tokenEndpoint !== undefined) {
158
- const loginUrl = tokenEndpoint.getLoginUrl();
159
- setExternalLoginUrl(loginUrl);
160
- }
161
- }
162
- catch (_error) {
163
- }
164
- }
165
- }
166
- setServerRequireCredentials(sourceRequireAuth || invalidCredentials);
167
- if (invalidCredentials) {
168
- setInvalidCredentialsProvided(true);
169
- }
170
- else if (invalidCredentialsProvided) {
171
- setInvalidCredentialsProvided(false); // flag reset
172
- }
173
- return sourceRequireAuth || invalidCredentials;
174
- }, [accessClient, invalidCredentialsProvided]);
175
- const updateAttachedLayer = React.useCallback(async (source, validation) => {
176
- const vp = props === null || props === void 0 ? void 0 : props.activeViewport;
177
- if (vp === undefined || source === undefined || layerRequiringCredentialsIdx === undefined) {
178
- const error = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
179
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
180
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
181
- return true;
182
- }
183
- // Layer is already attached,
184
- vp.displayStyle.changeMapLayerProps({
185
- subLayers: validation.subLayers,
186
- }, layerRequiringCredentialsIdx, isOverlay);
187
- vp.displayStyle.changeMapLayerCredentials(layerRequiringCredentialsIdx, isOverlay, source.userName, source.password);
188
- // Either initial attach/initialize failed or the layer failed to load at least one tile
189
- // because of an invalid token; in both cases tile tree needs to be fully reset
190
- const provider = vp.getMapLayerImageryProvider(layerRequiringCredentialsIdx, isOverlay);
191
- provider === null || provider === void 0 ? void 0 : provider.resetStatus();
192
- vp.resetMapLayer(layerRequiringCredentialsIdx, isOverlay);
193
- vp.invalidateRenderPlan();
194
- // This handler will close the layer source handler, and therefore the MapUrl dialog.
195
- // don't call it if the dialog needs to remains open.
196
- onOkResult();
197
- return true;
198
- }, [isOverlay, layerRequiringCredentialsIdx, onOkResult, props.activeViewport]);
199
- // Returns true if no further input is needed from end-user.
200
- const doAttach = React.useCallback(async (source, validation) => {
201
- const vp = props === null || props === void 0 ? void 0 : props.activeViewport;
202
- if (vp === undefined || source === undefined) {
203
- const error = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
204
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
205
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
206
- return true;
207
- }
208
- // Update service settings if storage is available and we are not prompting user for credentials
209
- if (!settingsStorageDisabled && !props.layerRequiringCredentials) {
210
- const storeOnIModel = (hasImodelContext ? "Model" === settingsStorage : undefined);
211
- if (vp.iModel.iTwinId && !(await MapLayerPreferences.storeSource(source, vp.iModel.iTwinId, vp.iModel.iModelId, storeOnIModel))) {
212
- const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerPreferencesStoreFailed");
213
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msgError));
214
- }
215
- }
216
- const settings = source.toLayerSettings(validation.subLayers);
217
- if (settings) {
218
- vp.displayStyle.attachMapLayer({ settings, isOverlay });
219
- const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttached", { sourceName: source.name, sourceUrl: source.url });
220
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));
221
- }
222
- else {
223
- const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSettingsConversionError");
224
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MapLayerAttachError", { error: msgError, sourceUrl: source.url });
225
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
226
- }
227
- vp.invalidateRenderPlan();
228
- // This handler will close the layer source handler, and therefore the MapUrl dialog.
229
- // don't call it if the dialog needs to remains open.
230
- onOkResult();
231
- return true;
232
- }, [hasImodelContext, isOverlay, onOkResult, props === null || props === void 0 ? void 0 : props.activeViewport, props.layerRequiringCredentials, settingsStorage, settingsStorageDisabled]);
233
- // Validate the layer source and attempt to attach (or update) the layer.
234
- // Returns true if no further input is needed from end-user (i.e. close the dialog)
235
- const attemptAttachSource = React.useCallback(async (source) => {
236
- try {
237
- const validation = await source.validateSource(true);
238
- if (validation.status === MapLayerSourceStatus.Valid) {
239
- if (layerRequiringCredentialsIdx === undefined) {
240
- return await doAttach(source, validation);
241
- }
242
- else {
243
- return await updateAttachedLayer(source, validation);
244
- }
245
- }
246
- else if (validation.status === MapLayerSourceStatus.InvalidCoordinateSystem) {
247
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCoordinateSystem");
248
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
249
- return true;
250
- }
251
- else {
252
- const authNeeded = await updateAuthState(source, validation);
253
- if (authNeeded) {
254
- return false;
255
- }
256
- else {
257
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ValidationError");
258
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, `${msg} ${source.url}`));
259
- return true;
260
- }
261
- }
262
- return false;
263
- }
264
- catch (error) {
265
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
266
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
267
- return true;
268
- }
269
- }, [updateAuthState, doAttach, layerRequiringCredentialsIdx, updateAttachedLayer]);
270
- const onNameChange = React.useCallback((event) => {
271
- setMapName(event.target.value);
272
- }, [setMapName]);
273
- const onRadioChange = React.useCallback((event) => {
274
- setSettingsStorageRadio(event.target.value);
275
- }, [setSettingsStorageRadio]);
276
- const onUrlChange = React.useCallback((event) => {
277
- setMapUrl(event.target.value);
278
- }, [setMapUrl]);
279
- const createSource = React.useCallback(() => {
280
- let source;
281
- if (mapUrl && mapName) {
282
- source = MapLayerSource.fromJSON({
283
- url: mapUrl,
284
- name: mapName,
285
- formatId: mapType
286
- });
287
- // Set credentials separately since they are not part of JSON
288
- if (source) {
289
- source.userName = userName || undefined; // When there is no value, empty string is always returned, in this case force it to undefined,
290
- source.password = password || undefined;
291
- }
292
- }
293
- return source;
294
- }, [mapName, mapType, mapUrl, password, userName]);
295
- const handleOk = React.useCallback(() => {
296
- const source = createSource();
297
- if (source === undefined || props.mapLayerSourceToEdit) {
298
- ModalDialogManager.closeDialog();
299
- onOkResult();
300
- if (source === undefined) {
301
- // Close the dialog and inform end user something went wrong.
302
- const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSourceCreationFailed");
303
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error: msgError, sourceUrl: mapUrl });
304
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
305
- return;
306
- }
307
- // Simply change the source definition in the setting service
308
- if (props.mapLayerSourceToEdit !== undefined) {
309
- const vp = props.activeViewport;
310
- void (async () => {
311
- var _a, _b;
312
- if (isSettingsStorageAvailable && ((_a = vp === null || vp === void 0 ? void 0 : vp.iModel) === null || _a === void 0 ? void 0 : _a.iTwinId)) {
313
- try {
314
- await MapLayerPreferences.replaceSource(props.mapLayerSourceToEdit, source, vp.iModel.iTwinId, vp === null || vp === void 0 ? void 0 : vp.iModel.iModelId);
315
- }
316
- catch (err) {
317
- const errorMessage = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerEditError", { layerName: (_b = props.mapLayerSourceToEdit) === null || _b === void 0 ? void 0 : _b.name });
318
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, errorMessage));
319
- return;
320
- }
321
- }
322
- })();
323
- return;
324
- }
325
- }
326
- setLayerAttachPending(true);
327
- // Attach source asynchronously.
328
- void (async () => {
329
- try {
330
- const closeDialog = await attemptAttachSource(source);
331
- if (isMounted.current) {
332
- setLayerAttachPending(false);
333
- }
334
- // In theory the modal dialog should always get closed by the parent
335
- // AttachLayerPanel's 'onOkResult' handler. We close it here just in case.
336
- if (closeDialog) {
337
- ModalDialogManager.closeDialog();
338
- onOkResult();
339
- }
340
- }
341
- catch (_error) {
342
- onOkResult();
343
- ModalDialogManager.closeDialog();
344
- }
345
- })();
346
- }, [createSource, props.mapLayerSourceToEdit, props.activeViewport, onOkResult, mapUrl, isSettingsStorageAvailable, attemptAttachSource]);
347
- React.useEffect(() => {
348
- const handleOAuthProcessEnd = (success, _state) => {
349
- onOauthProcessEnd.raiseEvent(success, _state);
350
- };
351
- // Currently only arcgis support AccessClient
352
- const ac = IModelApp.mapLayerFormatRegistry.getAccessClient(MAP_TYPES.arcGis);
353
- if (ac === null || ac === void 0 ? void 0 : ac.onOAuthProcessEnd) {
354
- setAccessClient(ac); // cache it, so we dont need to make another lookup;
355
- ac.onOAuthProcessEnd.addListener(handleOAuthProcessEnd);
356
- }
357
- setAccessClientInitialized(true);
358
- return () => {
359
- if (ac === null || ac === void 0 ? void 0 : ac.onOAuthProcessEnd) {
360
- ac.onOAuthProcessEnd.removeListener(handleOAuthProcessEnd);
361
- }
362
- setAccessClient(undefined);
363
- setAccessClientInitialized(false);
364
- };
365
- }, [mapType, onOauthProcessEnd, setAccessClient]);
366
- // After a map type change, make sure the different Oauth states are reset.
367
- React.useEffect(() => {
368
- // Reset few states
369
- setServerRequireCredentials(false);
370
- setInvalidCredentialsProvided(false);
371
- setShowOauthPopup(false);
372
- setOAuthProcessSucceeded(undefined);
373
- setExternalLoginUrl(undefined);
374
- }, [mapType]);
375
- // The first time the dialog is loaded and we already know the layer requires auth. (i.e ImageryProvider already made an attempt)
376
- // makes a request to discover the authentification types and adjust UI accordingly (i.e. username/password fields, Oauth popup)
377
- // Without this effect, user would have to manually click the 'OK' button in order to trigger the layer connection.
378
- React.useEffect(() => {
379
- // Attach source asynchronously.
380
- void (async () => {
381
- var _a, _b;
382
- if (isAccessClientInitialized && ((_a = props.layerRequiringCredentials) === null || _a === void 0 ? void 0 : _a.url) !== undefined && ((_b = props.layerRequiringCredentials) === null || _b === void 0 ? void 0 : _b.name) !== undefined) {
383
- try {
384
- const source = MapLayerSource.fromJSON({
385
- url: props.layerRequiringCredentials.url,
386
- name: props.layerRequiringCredentials.name,
387
- formatId: props.layerRequiringCredentials.formatId
388
- });
389
- if (source !== undefined) {
390
- setLayerAttachPending(true);
391
- const validation = await source.validateSource(true);
392
- if (isMounted.current) {
393
- setLayerAttachPending(false);
394
- }
395
- await updateAuthState(source, validation);
396
- }
397
- }
398
- catch (_error) { }
399
- }
400
- })();
401
- }, [isAccessClientInitialized, (_h = props.layerRequiringCredentials) === null || _h === void 0 ? void 0 : _h.formatId, (_j = props.layerRequiringCredentials) === null || _j === void 0 ? void 0 : _j.name, (_k = props.layerRequiringCredentials) === null || _k === void 0 ? void 0 : _k.url, updateAuthState]);
402
- const dialogContainer = React.useRef(null);
403
- const readyToSave = React.useCallback(() => {
404
- const credentialsSet = !!userName && !!password;
405
- return (!!mapUrl && !!mapName)
406
- && !layerAttachPending
407
- && (!serverRequireCredentials || credentialsSet)
408
- && !invalidCredentialsProvided
409
- && (externalLoginUrl === undefined || (externalLoginUrl !== undefined && oauthProcessSucceeded));
410
- }, [userName, password, mapUrl, mapName, serverRequireCredentials, layerAttachPending, invalidCredentialsProvided, externalLoginUrl, oauthProcessSucceeded]);
411
- const buttonCluster = React.useMemo(() => [
412
- { type: DialogButtonType.OK, onClick: handleOk, disabled: !readyToSave() },
413
- { type: DialogButtonType.Cancel, onClick: handleCancel },
414
- ], [readyToSave, handleCancel, handleOk]);
415
- const handleOnKeyDown = React.useCallback((event) => {
416
- if (event.key === SpecialKey.Enter) {
417
- if (readyToSave())
418
- handleOk();
419
- }
420
- }, [handleOk, readyToSave]);
421
- // onOauthProcessEnd events handler
422
- React.useEffect(() => {
423
- const handleOauthProcess = (success, _state) => {
424
- setLayerAuthPending(false);
425
- if (success) {
426
- setOAuthProcessSucceeded(true);
427
- setShowOauthPopup(false);
428
- setLayerAttachPending(false);
429
- handleOk(); // Add the layer the same way the user would do by clicking 'ok'
430
- }
431
- else {
432
- setShowOauthPopup(false);
433
- setLayerAttachPending(false);
434
- setOAuthProcessSucceeded(false);
435
- }
436
- };
437
- onOauthProcessEnd.addListener(handleOauthProcess);
438
- return () => {
439
- onOauthProcessEnd.removeListener(handleOauthProcess);
440
- };
441
- }, [handleOk, onOauthProcessEnd]);
442
- //
443
- // Monitors authentication method changes
444
- React.useEffect(() => {
445
- if (serverRequireCredentials && oauthProcessSucceeded === undefined && externalLoginUrl !== undefined) {
446
- handleArcGisLogin();
447
- }
448
- }, [oauthProcessSucceeded, externalLoginUrl, handleArcGisLogin, serverRequireCredentials]);
449
- // Monitors Oauth2 popup was closed
450
- const handleOAuthPopupClose = React.useCallback(() => {
451
- setShowOauthPopup(false);
452
- setLayerAuthPending(false);
453
- if (oauthProcessSucceeded === undefined)
454
- setOAuthProcessSucceeded(false); // indicates there was a failed attempt
455
- }, [oauthProcessSucceeded]);
456
- // Utility function to get warning message section
457
- function renderWarningMessage() {
458
- let node;
459
- let warningMessage;
460
- // Get the proper warning message
461
- if (showOauthPopup) {
462
- warningMessage = externalLoginWaitingMsg;
463
- }
464
- else if (oauthProcessSucceeded === false) {
465
- warningMessage = externalLoginFailedMsg;
466
- }
467
- else if (oauthProcessSucceeded === true) {
468
- warningMessage = externalLoginSucceededMsg;
469
- }
470
- else if (invalidCredentialsProvided) {
471
- warningMessage = invalidCredentialsLabel;
472
- }
473
- else if (serverRequireCredentials && (!userName || !password)) {
474
- warningMessage = missingCredentialsLabel;
475
- }
476
- // Sometimes we want to add an extra node, such as a button
477
- let extraNode;
478
- if (oauthProcessSucceeded === false) {
479
- extraNode = React.createElement("div", null,
480
- React.createElement(Button, { onClick: handleArcGisLogin }, externalLoginTryAgainLabel));
481
- }
482
- if (warningMessage !== undefined) {
483
- return (React.createElement("div", { className: "map-layer-source-warnMessage" },
484
- React.createElement(Icon, { className: "map-layer-source-warnMessage-icon", iconSpec: "icon-status-warning" }),
485
- React.createElement("span", { className: "map-layer-source-warnMessage-label" }, warningMessage),
486
- extraNode));
487
- }
488
- else {
489
- return (React.createElement("span", { className: "map-layer-source-placeholder" }, "\u00A0"));
490
- }
491
- return node;
492
- }
493
- // Use a hook to display the popup.
494
- // The display of the popup is controlled by the 'showOauthPopup' state variable.
495
- useCrossOriginPopup(showOauthPopup, externalLoginUrl, externalLoginTitle, 450, 450, handleOAuthPopupClose);
496
- return (React.createElement("div", { ref: dialogContainer },
497
- React.createElement(Dialog, { className: "map-layer-url-dialog", title: dialogTitle, opened: true, resizable: true, movable: true, modal: true, buttonCluster: buttonCluster, onClose: handleCancel, onEscape: handleCancel, minHeight: 120, maxWidth: 600, titleStyle: { paddingLeft: "10px" }, footerStyle: { paddingBottom: "10px", paddingRight: "10px" }, trapFocus: false },
498
- React.createElement("div", { className: "map-layer-url-dialog-content" },
499
- React.createElement("div", { className: "map-layer-source-url" },
500
- React.createElement("span", { className: "map-layer-source-label" }, typeLabel),
501
- React.createElement(SelectMapFormat, { value: mapType, disabled: props.layerRequiringCredentials !== undefined || props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, onChange: setMapType, mapTypesOptions: mapTypesOptions }),
502
- React.createElement("span", { className: "map-layer-source-label" }, nameLabel),
503
- React.createElement(Input, { className: "map-layer-source-input", placeholder: nameInputPlaceHolder, onChange: onNameChange, value: mapName, disabled: props.layerRequiringCredentials !== undefined || layerAttachPending || layerAuthPending }),
504
- React.createElement("span", { className: "map-layer-source-label" }, urlLabel),
505
- React.createElement(Input, { className: "map-layer-source-input", placeholder: urlInputPlaceHolder, onKeyPress: handleOnKeyDown, onChange: onUrlChange, disabled: props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, value: mapUrl }),
506
- serverRequireCredentials
507
- && externalLoginUrl === undefined // external login is handled in popup
508
- && props.mapLayerSourceToEdit === undefined &&
509
- React.createElement(React.Fragment, null,
510
- React.createElement("span", { className: "map-layer-source-label" }, userNameLabel),
511
- React.createElement(LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", placeholder: serverRequireCredentials ? userNameRequiredLabel : userNameLabel, status: (!userName && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onUsernameChange, value: userName, size: "small" }),
512
- React.createElement("span", { className: "map-layer-source-label" }, passwordLabel),
513
- React.createElement(LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", type: "password", placeholder: serverRequireCredentials ? passwordRequiredLabel : passwordLabel, status: (!password && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onPasswordChange, onKeyPress: handleOnKeyDown, value: password, size: "small" })),
514
- isSettingsStorageAvailable &&
515
- React.createElement("div", { title: settingsStorageDisabled ? noSaveSettingsWarning : "" }, hasImodelContext &&
516
- React.createElement("div", null,
517
- React.createElement(Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "iTwin", label: iTwinSettingsLabel, checked: settingsStorage === "iTwin", onChange: onRadioChange }),
518
- React.createElement(Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "Model", label: modelSettingsLabel, checked: settingsStorage === "Model", onChange: onRadioChange }))))),
519
- renderWarningMessage(),
520
- (layerAttachPending || layerAuthPending) &&
521
- React.createElement("div", { className: "map-layer-source-progressBar" },
522
- React.createElement(ProgressLinear, { indeterminate: true })))));
523
- }
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ // cSpell:ignore Modeless WMTS
6
+ import { DialogButtonType, SpecialKey } from "@itwin/appui-abstract";
7
+ import { UiFramework } from "@itwin/appui-react";
8
+ import { Button, Input, LabeledInput, ProgressLinear, Radio } from "@itwin/itwinui-react";
9
+ import { IModelApp, MapLayerSource, MapLayerSourceStatus, NotifyMessageDetails, OutputMessagePriority, } from "@itwin/core-frontend";
10
+ import { Dialog, Icon, useCrossOriginPopup } from "@itwin/core-react";
11
+ import * as React from "react";
12
+ import { MapLayerPreferences } from "../../MapLayerPreferences";
13
+ import { MapLayersUI } from "../../mapLayers";
14
+ import "./MapUrlDialog.scss";
15
+ import { BeEvent, Guid } from "@itwin/core-bentley";
16
+ import { SelectMapFormat } from "./SelectMapFormat";
17
+ export const MAP_TYPES = {
18
+ wms: "WMS",
19
+ arcGis: "ArcGIS",
20
+ wmts: "WMTS",
21
+ tileUrl: "TileURL",
22
+ arcGisFeature: "ArcGISFeature",
23
+ };
24
+ // eslint-disable-next-line @typescript-eslint/naming-convention
25
+ export function MapUrlDialog(props) {
26
+ const { isOverlay, onOkResult, mapTypesOptions } = props;
27
+ const getMapUrlFromProps = React.useCallback(() => {
28
+ if (props.mapLayerSourceToEdit) {
29
+ return props.mapLayerSourceToEdit.url;
30
+ }
31
+ else if (props.layerRequiringCredentials?.url) {
32
+ return props.layerRequiringCredentials.url;
33
+ }
34
+ return "";
35
+ }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
36
+ const getMapNameFromProps = React.useCallback(() => {
37
+ if (props.mapLayerSourceToEdit) {
38
+ return props.mapLayerSourceToEdit.name;
39
+ }
40
+ else if (props.layerRequiringCredentials?.name) {
41
+ return props.layerRequiringCredentials.name;
42
+ }
43
+ return "";
44
+ }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
45
+ const getFormatFromProps = React.useCallback(() => {
46
+ if (props.mapLayerSourceToEdit) {
47
+ return props.mapLayerSourceToEdit.formatId;
48
+ }
49
+ else if (props.layerRequiringCredentials?.formatId) {
50
+ return props.layerRequiringCredentials.formatId;
51
+ }
52
+ return undefined;
53
+ }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
54
+ const [dialogTitle] = React.useState(MapLayersUI.localization.getLocalizedString(props.layerRequiringCredentials || props.mapLayerSourceToEdit ? "mapLayers:CustomAttach.EditCustomLayer" : "mapLayers:CustomAttach.AttachCustomLayer"));
55
+ const [typeLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Type"));
56
+ const [nameLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Name"));
57
+ const [nameInputPlaceHolder] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NameInputPlaceHolder"));
58
+ const [urlLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.URL"));
59
+ const [urlInputPlaceHolder] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.UrlInputPlaceHolder"));
60
+ const [iTwinSettingsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnITwinSettings"));
61
+ const [modelSettingsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnModelSettings"));
62
+ const [missingCredentialsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MissingCredentials"));
63
+ const [invalidCredentialsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCredentials"));
64
+ const [externalLoginTitle] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLogin"));
65
+ const [externalLoginFailedMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginFailed"));
66
+ const [externalLoginSucceededMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginSucceeded"));
67
+ const [externalLoginWaitingMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginWaiting"));
68
+ const [externalLoginTryAgainLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginTryAgain"));
69
+ const [serverRequireCredentials, setServerRequireCredentials] = React.useState(false);
70
+ const [invalidCredentialsProvided, setInvalidCredentialsProvided] = React.useState(false);
71
+ const [layerAttachPending, setLayerAttachPending] = React.useState(false);
72
+ const [layerAuthPending, setLayerAuthPending] = React.useState(false);
73
+ const [mapUrl, setMapUrl] = React.useState(getMapUrlFromProps());
74
+ const [mapName, setMapName] = React.useState(getMapNameFromProps());
75
+ const [userName, setUserName] = React.useState("");
76
+ const [password, setPassword] = React.useState("");
77
+ const [noSaveSettingsWarning] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NoSaveSettingsWarning"));
78
+ const [passwordLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Password"));
79
+ const [passwordRequiredLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.PasswordRequired"));
80
+ const [userNameLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Username"));
81
+ const [userNameRequiredLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.UsernameRequired"));
82
+ const [settingsStorage, setSettingsStorageRadio] = React.useState("iTwin");
83
+ const [oauthProcessSucceeded, setOAuthProcessSucceeded] = React.useState(undefined);
84
+ const [showOauthPopup, setShowOauthPopup] = React.useState(false);
85
+ const [externalLoginUrl, setExternalLoginUrl] = React.useState();
86
+ const [onOauthProcessEnd] = React.useState(new BeEvent());
87
+ const [accessClient, setAccessClient] = React.useState();
88
+ const [isAccessClientInitialized, setAccessClientInitialized] = React.useState(false);
89
+ const [mapType, setMapType] = React.useState(getFormatFromProps() ?? "ArcGIS");
90
+ // 'isMounted' is used to prevent any async operation once the hook has been
91
+ // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
92
+ const isMounted = React.useRef(false);
93
+ React.useEffect(() => {
94
+ isMounted.current = true;
95
+ return () => {
96
+ isMounted.current = false;
97
+ };
98
+ }, []);
99
+ const [isSettingsStorageAvailable] = React.useState(MapLayersUI.iTwinConfig && props?.activeViewport?.iModel?.iTwinId);
100
+ const [hasImodelContext] = React.useState(props?.activeViewport?.iModel?.iTwinId !== undefined
101
+ && props.activeViewport.iModel.iTwinId !== Guid.empty
102
+ && props?.activeViewport?.iModel?.iModelId !== undefined
103
+ && props?.activeViewport.iModel.iModelId !== Guid.empty);
104
+ // Even though the settings storage is available,
105
+ // we don't always want to enable it in the UI.
106
+ const [settingsStorageDisabled] = React.useState(!isSettingsStorageAvailable || props.mapLayerSourceToEdit !== undefined || props.layerRequiringCredentials !== undefined);
107
+ const [layerRequiringCredentialsIdx] = React.useState(() => {
108
+ if (props.layerRequiringCredentials === undefined || !props.layerRequiringCredentials.name || !props.layerRequiringCredentials.url) {
109
+ return undefined;
110
+ }
111
+ const indexInDisplayStyle = props.activeViewport?.displayStyle.findMapLayerIndexByNameAndSource(props.layerRequiringCredentials.name, props.layerRequiringCredentials.url, isOverlay);
112
+ if (indexInDisplayStyle === undefined || indexInDisplayStyle < 0) {
113
+ return undefined;
114
+ }
115
+ else {
116
+ return indexInDisplayStyle;
117
+ }
118
+ });
119
+ const handleCancel = React.useCallback(() => {
120
+ if (props.onCancelResult) {
121
+ props.onCancelResult();
122
+ return;
123
+ }
124
+ UiFramework.dialogs.modal.close();
125
+ }, [props]);
126
+ const onUsernameChange = React.useCallback((event) => {
127
+ setUserName(event.target.value);
128
+ if (invalidCredentialsProvided)
129
+ setInvalidCredentialsProvided(false);
130
+ }, [setUserName, invalidCredentialsProvided, setInvalidCredentialsProvided]);
131
+ const onPasswordChange = React.useCallback((event) => {
132
+ setPassword(event.target.value);
133
+ if (invalidCredentialsProvided)
134
+ setInvalidCredentialsProvided(false);
135
+ }, [setPassword, invalidCredentialsProvided, setInvalidCredentialsProvided]);
136
+ const handleArcGisLogin = React.useCallback(() => {
137
+ setLayerAuthPending(true);
138
+ setShowOauthPopup(true);
139
+ if (oauthProcessSucceeded === false) {
140
+ setOAuthProcessSucceeded(undefined);
141
+ }
142
+ }, [oauthProcessSucceeded]);
143
+ // return true if authorization is needed
144
+ const updateAuthState = React.useCallback(async (source, sourceValidation) => {
145
+ const sourceRequireAuth = (sourceValidation.status === MapLayerSourceStatus.RequireAuth);
146
+ const invalidCredentials = (sourceValidation.status === MapLayerSourceStatus.InvalidCredentials);
147
+ if (sourceRequireAuth) {
148
+ const settings = source.toLayerSettings();
149
+ if (accessClient !== undefined && accessClient.getTokenServiceEndPoint !== undefined && settings !== undefined) {
150
+ try {
151
+ const tokenEndpoint = await accessClient.getTokenServiceEndPoint(settings.url);
152
+ if (tokenEndpoint !== undefined) {
153
+ const loginUrl = tokenEndpoint.getLoginUrl();
154
+ setExternalLoginUrl(loginUrl);
155
+ }
156
+ }
157
+ catch (_error) {
158
+ }
159
+ }
160
+ }
161
+ setServerRequireCredentials(sourceRequireAuth || invalidCredentials);
162
+ if (invalidCredentials) {
163
+ setInvalidCredentialsProvided(true);
164
+ }
165
+ else if (invalidCredentialsProvided) {
166
+ setInvalidCredentialsProvided(false); // flag reset
167
+ }
168
+ return sourceRequireAuth || invalidCredentials;
169
+ }, [accessClient, invalidCredentialsProvided]);
170
+ const updateAttachedLayer = React.useCallback(async (source, validation) => {
171
+ const vp = props?.activeViewport;
172
+ if (vp === undefined || source === undefined || layerRequiringCredentialsIdx === undefined) {
173
+ const error = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
174
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
175
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
176
+ return true;
177
+ }
178
+ // Layer is already attached,
179
+ // This calls invalidateRenderPlan()
180
+ vp.displayStyle.changeMapLayerProps({
181
+ subLayers: validation.subLayers,
182
+ }, { index: layerRequiringCredentialsIdx, isOverlay });
183
+ vp.displayStyle.changeMapLayerCredentials({ index: layerRequiringCredentialsIdx, isOverlay }, source.userName, source.password);
184
+ // Either initial attach/initialize failed or the layer failed to load at least one tile
185
+ // because of an invalid token; in both cases tile tree needs to be fully reset
186
+ const provider = vp.getMapLayerImageryProvider({ index: layerRequiringCredentialsIdx, isOverlay });
187
+ provider?.resetStatus();
188
+ vp.resetMapLayer({ index: layerRequiringCredentialsIdx, isOverlay });
189
+ // This handler will close the layer source handler, and therefore the MapUrl dialog.
190
+ // don't call it if the dialog needs to remains open.
191
+ onOkResult();
192
+ return true;
193
+ }, [isOverlay, layerRequiringCredentialsIdx, onOkResult, props.activeViewport]);
194
+ // Returns true if no further input is needed from end-user.
195
+ const doAttach = React.useCallback(async (source, validation) => {
196
+ const vp = props?.activeViewport;
197
+ if (vp === undefined || source === undefined) {
198
+ const error = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
199
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
200
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
201
+ return true;
202
+ }
203
+ // Update service settings if storage is available and we are not prompting user for credentials
204
+ if (!settingsStorageDisabled && !props.layerRequiringCredentials) {
205
+ const storeOnIModel = (hasImodelContext ? "Model" === settingsStorage : undefined);
206
+ if (vp.iModel.iTwinId && !(await MapLayerPreferences.storeSource(source, vp.iModel.iTwinId, vp.iModel.iModelId, storeOnIModel))) {
207
+ const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerPreferencesStoreFailed");
208
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msgError));
209
+ }
210
+ }
211
+ // Some sources have a single non-visible sub-layer (i.e. ArcGIS World Topo Map); to avoid having a layer with no content (and no way to change the sub-layer visibility)
212
+ // we force the sub-layer visibility to ON.
213
+ let subLayers = validation.subLayers;
214
+ if (validation.subLayers && validation.subLayers.length === 1 && validation.subLayers[0].visible === false) {
215
+ subLayers = [{ ...validation.subLayers[0], visible: true }];
216
+ }
217
+ const settings = source.toLayerSettings(subLayers);
218
+ if (settings) {
219
+ vp.displayStyle.attachMapLayer({ settings, mapLayerIndex: { index: -1, isOverlay } });
220
+ const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttached", { sourceName: source.name, sourceUrl: source.url });
221
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));
222
+ }
223
+ else {
224
+ const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSettingsConversionError");
225
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MapLayerAttachError", { error: msgError, sourceUrl: source.url });
226
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
227
+ }
228
+ // This handler will close the layer source handler, and therefore the MapUrl dialog.
229
+ // don't call it if the dialog needs to remains open.
230
+ onOkResult();
231
+ return true;
232
+ }, [hasImodelContext, isOverlay, onOkResult, props?.activeViewport, props.layerRequiringCredentials, settingsStorage, settingsStorageDisabled]);
233
+ // Validate the layer source and attempt to attach (or update) the layer.
234
+ // Returns true if no further input is needed from end-user (i.e. close the dialog)
235
+ const attemptAttachSource = React.useCallback(async (source) => {
236
+ try {
237
+ const validation = await source.validateSource(true);
238
+ if (validation.status === MapLayerSourceStatus.Valid) {
239
+ if (layerRequiringCredentialsIdx === undefined) {
240
+ return await doAttach(source, validation);
241
+ }
242
+ else {
243
+ return await updateAttachedLayer(source, validation);
244
+ }
245
+ }
246
+ else if (validation.status === MapLayerSourceStatus.InvalidCoordinateSystem) {
247
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCoordinateSystem");
248
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
249
+ return true;
250
+ }
251
+ else {
252
+ const authNeeded = await updateAuthState(source, validation);
253
+ if (authNeeded) {
254
+ return false;
255
+ }
256
+ else {
257
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ValidationError");
258
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, `${msg} ${source.url}`));
259
+ return true;
260
+ }
261
+ }
262
+ }
263
+ catch (error) {
264
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
265
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
266
+ return true;
267
+ }
268
+ }, [updateAuthState, doAttach, layerRequiringCredentialsIdx, updateAttachedLayer]);
269
+ const onNameChange = React.useCallback((event) => {
270
+ setMapName(event.target.value);
271
+ }, [setMapName]);
272
+ const onRadioChange = React.useCallback((event) => {
273
+ setSettingsStorageRadio(event.target.value);
274
+ }, [setSettingsStorageRadio]);
275
+ const onUrlChange = React.useCallback((event) => {
276
+ setMapUrl(event.target.value);
277
+ }, [setMapUrl]);
278
+ const createSource = React.useCallback(() => {
279
+ let source;
280
+ if (mapUrl && mapName) {
281
+ source = MapLayerSource.fromJSON({
282
+ url: mapUrl,
283
+ name: mapName,
284
+ formatId: mapType,
285
+ });
286
+ // Set credentials separately since they are not part of JSON
287
+ if (source) {
288
+ source.userName = userName || undefined; // When there is no value, empty string is always returned, in this case force it to undefined,
289
+ source.password = password || undefined;
290
+ }
291
+ }
292
+ return source;
293
+ }, [mapName, mapType, mapUrl, password, userName]);
294
+ const handleOk = React.useCallback(() => {
295
+ const source = createSource();
296
+ if (source === undefined || props.mapLayerSourceToEdit) {
297
+ UiFramework.dialogs.modal.close();
298
+ onOkResult();
299
+ if (source === undefined) {
300
+ // Close the dialog and inform end user something went wrong.
301
+ const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSourceCreationFailed");
302
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error: msgError, sourceUrl: mapUrl });
303
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
304
+ return;
305
+ }
306
+ // Simply change the source definition in the setting service
307
+ if (props.mapLayerSourceToEdit !== undefined) {
308
+ const vp = props.activeViewport;
309
+ void (async () => {
310
+ if (isSettingsStorageAvailable && vp?.iModel?.iTwinId) {
311
+ try {
312
+ await MapLayerPreferences.replaceSource(props.mapLayerSourceToEdit, source, vp.iModel.iTwinId, vp?.iModel.iModelId);
313
+ }
314
+ catch (err) {
315
+ const errorMessage = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerEditError", { layerName: props.mapLayerSourceToEdit?.name });
316
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, errorMessage));
317
+ return;
318
+ }
319
+ }
320
+ })();
321
+ return;
322
+ }
323
+ }
324
+ setLayerAttachPending(true);
325
+ // Attach source asynchronously.
326
+ void (async () => {
327
+ try {
328
+ const closeDialog = await attemptAttachSource(source);
329
+ if (isMounted.current) {
330
+ setLayerAttachPending(false);
331
+ }
332
+ // In theory the modal dialog should always get closed by the parent
333
+ // AttachLayerPanel's 'onOkResult' handler. We close it here just in case.
334
+ if (closeDialog) {
335
+ UiFramework.dialogs.modal.close();
336
+ onOkResult();
337
+ }
338
+ }
339
+ catch (_error) {
340
+ onOkResult();
341
+ UiFramework.dialogs.modal.close();
342
+ }
343
+ })();
344
+ }, [createSource, props.mapLayerSourceToEdit, props.activeViewport, onOkResult, mapUrl, isSettingsStorageAvailable, attemptAttachSource]);
345
+ React.useEffect(() => {
346
+ const handleOAuthProcessEnd = (success, _state) => {
347
+ onOauthProcessEnd.raiseEvent(success, _state);
348
+ };
349
+ // Currently only arcgis support AccessClient
350
+ const ac = IModelApp.mapLayerFormatRegistry.getAccessClient(MAP_TYPES.arcGis);
351
+ if (ac?.onOAuthProcessEnd) {
352
+ setAccessClient(ac); // cache it, so we dont need to make another lookup;
353
+ ac.onOAuthProcessEnd.addListener(handleOAuthProcessEnd);
354
+ }
355
+ setAccessClientInitialized(true);
356
+ return () => {
357
+ if (ac?.onOAuthProcessEnd) {
358
+ ac.onOAuthProcessEnd.removeListener(handleOAuthProcessEnd);
359
+ }
360
+ setAccessClient(undefined);
361
+ setAccessClientInitialized(false);
362
+ };
363
+ }, [mapType, onOauthProcessEnd, setAccessClient]);
364
+ // After a map type change, make sure the different Oauth states are reset.
365
+ React.useEffect(() => {
366
+ // Reset few states
367
+ setServerRequireCredentials(false);
368
+ setInvalidCredentialsProvided(false);
369
+ setShowOauthPopup(false);
370
+ setOAuthProcessSucceeded(undefined);
371
+ setExternalLoginUrl(undefined);
372
+ }, [mapType]);
373
+ // The first time the dialog is loaded and we already know the layer requires auth. (i.e ImageryProvider already made an attempt)
374
+ // makes a request to discover the authentification types and adjust UI accordingly (i.e. username/password fields, Oauth popup)
375
+ // Without this effect, user would have to manually click the 'OK' button in order to trigger the layer connection.
376
+ React.useEffect(() => {
377
+ // Attach source asynchronously.
378
+ void (async () => {
379
+ if (isAccessClientInitialized && props.layerRequiringCredentials?.url !== undefined && props.layerRequiringCredentials?.name !== undefined) {
380
+ try {
381
+ const source = MapLayerSource.fromJSON({
382
+ url: props.layerRequiringCredentials.url,
383
+ name: props.layerRequiringCredentials.name,
384
+ formatId: props.layerRequiringCredentials.formatId,
385
+ });
386
+ if (source !== undefined) {
387
+ setLayerAttachPending(true);
388
+ const validation = await source.validateSource(true);
389
+ if (isMounted.current) {
390
+ setLayerAttachPending(false);
391
+ }
392
+ await updateAuthState(source, validation);
393
+ }
394
+ }
395
+ catch (_error) { }
396
+ }
397
+ })();
398
+ }, [isAccessClientInitialized,
399
+ props.layerRequiringCredentials?.formatId,
400
+ props.layerRequiringCredentials?.name,
401
+ props.layerRequiringCredentials?.url,
402
+ updateAuthState]);
403
+ const dialogContainer = React.useRef(null);
404
+ const readyToSave = React.useCallback(() => {
405
+ const credentialsSet = !!userName && !!password;
406
+ return (!!mapUrl && !!mapName)
407
+ && !layerAttachPending
408
+ && (!serverRequireCredentials || credentialsSet)
409
+ && !invalidCredentialsProvided
410
+ && (externalLoginUrl === undefined || (externalLoginUrl !== undefined && oauthProcessSucceeded));
411
+ }, [userName, password, mapUrl, mapName, serverRequireCredentials, layerAttachPending, invalidCredentialsProvided, externalLoginUrl, oauthProcessSucceeded]);
412
+ const buttonCluster = React.useMemo(() => [
413
+ { type: DialogButtonType.OK, onClick: handleOk, disabled: !readyToSave() },
414
+ { type: DialogButtonType.Cancel, onClick: handleCancel },
415
+ ], [readyToSave, handleCancel, handleOk]);
416
+ const handleOnKeyDown = React.useCallback((event) => {
417
+ if (event.key === SpecialKey.Enter) {
418
+ if (readyToSave())
419
+ handleOk();
420
+ }
421
+ }, [handleOk, readyToSave]);
422
+ // onOauthProcessEnd events handler
423
+ React.useEffect(() => {
424
+ const handleOauthProcess = (success, _state) => {
425
+ setLayerAuthPending(false);
426
+ if (success) {
427
+ setOAuthProcessSucceeded(true);
428
+ setShowOauthPopup(false);
429
+ setLayerAttachPending(false);
430
+ handleOk(); // Add the layer the same way the user would do by clicking 'ok'
431
+ }
432
+ else {
433
+ setShowOauthPopup(false);
434
+ setLayerAttachPending(false);
435
+ setOAuthProcessSucceeded(false);
436
+ }
437
+ };
438
+ onOauthProcessEnd.addListener(handleOauthProcess);
439
+ return () => {
440
+ onOauthProcessEnd.removeListener(handleOauthProcess);
441
+ };
442
+ }, [handleOk, onOauthProcessEnd]);
443
+ //
444
+ // Monitors authentication method changes
445
+ React.useEffect(() => {
446
+ if (serverRequireCredentials && oauthProcessSucceeded === undefined && externalLoginUrl !== undefined) {
447
+ handleArcGisLogin();
448
+ }
449
+ }, [oauthProcessSucceeded, externalLoginUrl, handleArcGisLogin, serverRequireCredentials]);
450
+ // Monitors Oauth2 popup was closed
451
+ const handleOAuthPopupClose = React.useCallback(() => {
452
+ setShowOauthPopup(false);
453
+ setLayerAuthPending(false);
454
+ if (oauthProcessSucceeded === undefined)
455
+ setOAuthProcessSucceeded(false); // indicates there was a failed attempt
456
+ }, [oauthProcessSucceeded]);
457
+ // Utility function to get warning message section
458
+ function renderWarningMessage() {
459
+ let node;
460
+ let warningMessage;
461
+ // Get the proper warning message
462
+ if (showOauthPopup) {
463
+ warningMessage = externalLoginWaitingMsg;
464
+ }
465
+ else if (oauthProcessSucceeded === false) {
466
+ warningMessage = externalLoginFailedMsg;
467
+ }
468
+ else if (oauthProcessSucceeded === true) {
469
+ warningMessage = externalLoginSucceededMsg;
470
+ }
471
+ else if (invalidCredentialsProvided) {
472
+ warningMessage = invalidCredentialsLabel;
473
+ }
474
+ else if (serverRequireCredentials && (!userName || !password)) {
475
+ warningMessage = missingCredentialsLabel;
476
+ }
477
+ // Sometimes we want to add an extra node, such as a button
478
+ let extraNode;
479
+ if (oauthProcessSucceeded === false) {
480
+ extraNode = React.createElement("div", null,
481
+ React.createElement(Button, { onClick: handleArcGisLogin }, externalLoginTryAgainLabel));
482
+ }
483
+ if (warningMessage !== undefined) {
484
+ return (React.createElement("div", { className: "map-layer-source-warnMessage" },
485
+ React.createElement(Icon, { className: "map-layer-source-warnMessage-icon", iconSpec: "icon-status-warning" }),
486
+ React.createElement("span", { className: "map-layer-source-warnMessage-label" }, warningMessage),
487
+ extraNode));
488
+ }
489
+ else {
490
+ return (React.createElement("span", { className: "map-layer-source-placeholder" }, "\u00A0"));
491
+ }
492
+ return node;
493
+ }
494
+ // Use a hook to display the popup.
495
+ // The display of the popup is controlled by the 'showOauthPopup' state variable.
496
+ useCrossOriginPopup(showOauthPopup, externalLoginUrl, externalLoginTitle, 450, 450, handleOAuthPopupClose);
497
+ return (React.createElement("div", { ref: dialogContainer },
498
+ React.createElement(Dialog, { className: "map-layer-url-dialog", title: dialogTitle, opened: true, resizable: true, movable: true, modal: true, buttonCluster: buttonCluster, onClose: handleCancel, onEscape: handleCancel, minHeight: 120, maxWidth: 600, titleStyle: { paddingLeft: "10px" }, footerStyle: { paddingBottom: "10px", paddingRight: "10px" }, trapFocus: false },
499
+ React.createElement("div", { className: "map-layer-url-dialog-content" },
500
+ React.createElement("div", { className: "map-layer-source-url" },
501
+ React.createElement("span", { className: "map-layer-source-label" }, typeLabel),
502
+ React.createElement(SelectMapFormat, { value: mapType, disabled: props.layerRequiringCredentials !== undefined || props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, onChange: setMapType, mapTypesOptions: mapTypesOptions }),
503
+ React.createElement("span", { className: "map-layer-source-label" }, nameLabel),
504
+ React.createElement(Input, { className: "map-layer-source-input", placeholder: nameInputPlaceHolder, onChange: onNameChange, value: mapName, disabled: props.layerRequiringCredentials !== undefined || layerAttachPending || layerAuthPending }),
505
+ React.createElement("span", { className: "map-layer-source-label" }, urlLabel),
506
+ React.createElement(Input, { className: "map-layer-source-input", placeholder: urlInputPlaceHolder, onKeyPress: handleOnKeyDown, onChange: onUrlChange, disabled: props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, value: mapUrl }),
507
+ serverRequireCredentials
508
+ && externalLoginUrl === undefined // external login is handled in popup
509
+ && props.mapLayerSourceToEdit === undefined &&
510
+ React.createElement(React.Fragment, null,
511
+ React.createElement("span", { className: "map-layer-source-label" }, userNameLabel),
512
+ React.createElement(LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", placeholder: serverRequireCredentials ? userNameRequiredLabel : userNameLabel, status: (!userName && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onUsernameChange, value: userName, size: "small" }),
513
+ React.createElement("span", { className: "map-layer-source-label" }, passwordLabel),
514
+ React.createElement(LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", type: "password", placeholder: serverRequireCredentials ? passwordRequiredLabel : passwordLabel, status: (!password && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onPasswordChange, onKeyPress: handleOnKeyDown, value: password, size: "small" })),
515
+ isSettingsStorageAvailable &&
516
+ React.createElement("div", { title: settingsStorageDisabled ? noSaveSettingsWarning : "" }, hasImodelContext &&
517
+ React.createElement("div", null,
518
+ React.createElement(Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "iTwin", label: iTwinSettingsLabel, checked: settingsStorage === "iTwin", onChange: onRadioChange }),
519
+ React.createElement(Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "Model", label: modelSettingsLabel, checked: settingsStorage === "Model", onChange: onRadioChange }))))),
520
+ renderWarningMessage(),
521
+ (layerAttachPending || layerAuthPending) &&
522
+ React.createElement("div", { className: "map-layer-source-progressBar" },
523
+ React.createElement(ProgressLinear, { indeterminate: true })))));
524
+ }
524
525
  //# sourceMappingURL=MapUrlDialog.js.map