@itwin/map-layers 4.0.0-dev.41 → 4.0.0-dev.47

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