@itwin/map-layers 4.0.0-dev.7 → 4.0.0

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 (199) 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 +312 -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 +34 -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 +47 -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.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.d.ts.map +1 -1
  21. package/lib/cjs/ui/MapFeatureInfoTool.js +50 -50
  22. package/lib/cjs/ui/MapFeatureInfoTool.js.map +1 -1
  23. package/lib/cjs/ui/MapLayersUiItemsProvider.d.ts +8 -8
  24. package/lib/cjs/ui/MapLayersUiItemsProvider.d.ts.map +1 -1
  25. package/lib/cjs/ui/MapLayersUiItemsProvider.js +35 -38
  26. package/lib/cjs/ui/MapLayersUiItemsProvider.js.map +1 -1
  27. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts +13 -14
  28. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  29. package/lib/cjs/ui/widget/AttachLayerPopupButton.js +338 -338
  30. package/lib/cjs/ui/widget/AttachLayerPopupButton.js.map +1 -1
  31. package/lib/cjs/ui/widget/BasemapPanel.d.ts +7 -8
  32. package/lib/cjs/ui/widget/BasemapPanel.d.ts.map +1 -1
  33. package/lib/cjs/ui/widget/BasemapPanel.js +156 -156
  34. package/lib/cjs/ui/widget/BasemapPanel.js.map +1 -1
  35. package/lib/cjs/ui/widget/BasemapPanel.scss +87 -87
  36. package/lib/cjs/ui/widget/ConfirmMessageDialog.d.ts +20 -21
  37. package/lib/cjs/ui/widget/ConfirmMessageDialog.d.ts.map +1 -1
  38. package/lib/cjs/ui/widget/ConfirmMessageDialog.js +25 -25
  39. package/lib/cjs/ui/widget/ConfirmMessageDialog.js.map +1 -1
  40. package/lib/cjs/ui/widget/FeatureInfoDataProvider.d.ts +35 -40
  41. package/lib/cjs/ui/widget/FeatureInfoDataProvider.d.ts.map +1 -1
  42. package/lib/cjs/ui/widget/FeatureInfoDataProvider.js +140 -139
  43. package/lib/cjs/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  44. package/lib/cjs/ui/widget/FeatureInfoWidget.d.ts +6 -7
  45. package/lib/cjs/ui/widget/FeatureInfoWidget.d.ts.map +1 -1
  46. package/lib/cjs/ui/widget/FeatureInfoWidget.js +76 -71
  47. package/lib/cjs/ui/widget/FeatureInfoWidget.js.map +1 -1
  48. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts +18 -19
  49. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  50. package/lib/cjs/ui/widget/MapLayerDroppable.js +88 -88
  51. package/lib/cjs/ui/widget/MapLayerDroppable.js.map +1 -1
  52. package/lib/cjs/ui/widget/MapLayerManager.d.ts +26 -26
  53. package/lib/cjs/ui/widget/MapLayerManager.js +403 -403
  54. package/lib/cjs/ui/widget/MapLayerManager.js.map +1 -1
  55. package/lib/cjs/ui/widget/MapLayerManager.scss +409 -409
  56. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts +11 -12
  57. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts.map +1 -1
  58. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js +83 -83
  59. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  60. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.d.ts +6 -7
  61. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.d.ts.map +1 -1
  62. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js +65 -65
  63. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  64. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  65. package/lib/cjs/ui/widget/MapLayersWidget.d.ts +10 -11
  66. package/lib/cjs/ui/widget/MapLayersWidget.d.ts.map +1 -1
  67. package/lib/cjs/ui/widget/MapLayersWidget.js +31 -31
  68. package/lib/cjs/ui/widget/MapLayersWidget.js.map +1 -1
  69. package/lib/cjs/ui/widget/MapManagerSettings.d.ts +2 -3
  70. package/lib/cjs/ui/widget/MapManagerSettings.d.ts.map +1 -1
  71. package/lib/cjs/ui/widget/MapManagerSettings.js +200 -200
  72. package/lib/cjs/ui/widget/MapManagerSettings.js.map +1 -1
  73. package/lib/cjs/ui/widget/MapManagerSettings.scss +29 -29
  74. package/lib/cjs/ui/widget/MapUrlDialog.d.ts +22 -23
  75. package/lib/cjs/ui/widget/MapUrlDialog.d.ts.map +1 -1
  76. package/lib/cjs/ui/widget/MapUrlDialog.js +533 -527
  77. package/lib/cjs/ui/widget/MapUrlDialog.js.map +1 -1
  78. package/lib/cjs/ui/widget/MapUrlDialog.scss +99 -100
  79. package/lib/cjs/ui/widget/SelectMapFormat.d.ts +17 -18
  80. package/lib/cjs/ui/widget/SelectMapFormat.d.ts.map +1 -1
  81. package/lib/cjs/ui/widget/SelectMapFormat.js +59 -59
  82. package/lib/cjs/ui/widget/SelectMapFormat.js.map +1 -1
  83. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts +18 -20
  84. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts.map +1 -1
  85. package/lib/cjs/ui/widget/SubLayersDataProvider.js +75 -76
  86. package/lib/cjs/ui/widget/SubLayersDataProvider.js.map +1 -1
  87. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts +9 -10
  88. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts.map +1 -1
  89. package/lib/cjs/ui/widget/SubLayersPopupButton.js +40 -40
  90. package/lib/cjs/ui/widget/SubLayersPopupButton.js.map +1 -1
  91. package/lib/cjs/ui/widget/SubLayersTree.d.ts +14 -15
  92. package/lib/cjs/ui/widget/SubLayersTree.d.ts.map +1 -1
  93. package/lib/cjs/ui/widget/SubLayersTree.js +419 -419
  94. package/lib/cjs/ui/widget/SubLayersTree.js.map +1 -1
  95. package/lib/cjs/ui/widget/SubLayersTree.scss +70 -69
  96. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts +13 -14
  97. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts.map +1 -1
  98. package/lib/cjs/ui/widget/TransparencyPopupButton.js +47 -47
  99. package/lib/cjs/ui/widget/TransparencyPopupButton.js.map +1 -1
  100. package/lib/cjs/ui/widget/TransparencyPopupButton.scss +35 -36
  101. package/lib/esm/MapLayerPreferences.d.ts +88 -88
  102. package/lib/esm/MapLayerPreferences.js +308 -308
  103. package/lib/esm/MapLayerPreferences.js.map +1 -1
  104. package/lib/esm/map-layers.d.ts +6 -6
  105. package/lib/esm/map-layers.js +10 -10
  106. package/lib/esm/mapLayers.d.ts +26 -44
  107. package/lib/esm/mapLayers.d.ts.map +1 -1
  108. package/lib/esm/mapLayers.js +30 -59
  109. package/lib/esm/mapLayers.js.map +1 -1
  110. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts +16 -11
  111. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts.map +1 -1
  112. package/lib/esm/ui/FeatureInfoUiItemsProvider.js +43 -48
  113. package/lib/esm/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  114. package/lib/esm/ui/Interfaces.d.ts +50 -50
  115. package/lib/esm/ui/Interfaces.js +1 -1
  116. package/lib/esm/ui/Interfaces.js.map +1 -1
  117. package/lib/esm/ui/MapFeatureInfoTool.d.ts +13 -13
  118. package/lib/esm/ui/MapFeatureInfoTool.d.ts.map +1 -1
  119. package/lib/esm/ui/MapFeatureInfoTool.js +45 -45
  120. package/lib/esm/ui/MapFeatureInfoTool.js.map +1 -1
  121. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts +8 -8
  122. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts.map +1 -1
  123. package/lib/esm/ui/MapLayersUiItemsProvider.js +31 -34
  124. package/lib/esm/ui/MapLayersUiItemsProvider.js.map +1 -1
  125. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts +13 -14
  126. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  127. package/lib/esm/ui/widget/AttachLayerPopupButton.js +334 -334
  128. package/lib/esm/ui/widget/AttachLayerPopupButton.js.map +1 -1
  129. package/lib/esm/ui/widget/BasemapPanel.d.ts +7 -8
  130. package/lib/esm/ui/widget/BasemapPanel.d.ts.map +1 -1
  131. package/lib/esm/ui/widget/BasemapPanel.js +152 -152
  132. package/lib/esm/ui/widget/BasemapPanel.js.map +1 -1
  133. package/lib/esm/ui/widget/BasemapPanel.scss +87 -87
  134. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts +20 -21
  135. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts.map +1 -1
  136. package/lib/esm/ui/widget/ConfirmMessageDialog.js +21 -21
  137. package/lib/esm/ui/widget/ConfirmMessageDialog.js.map +1 -1
  138. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts +35 -40
  139. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts.map +1 -1
  140. package/lib/esm/ui/widget/FeatureInfoDataProvider.js +136 -135
  141. package/lib/esm/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  142. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts +6 -7
  143. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts.map +1 -1
  144. package/lib/esm/ui/widget/FeatureInfoWidget.js +72 -67
  145. package/lib/esm/ui/widget/FeatureInfoWidget.js.map +1 -1
  146. package/lib/esm/ui/widget/MapLayerDroppable.d.ts +18 -19
  147. package/lib/esm/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  148. package/lib/esm/ui/widget/MapLayerDroppable.js +84 -84
  149. package/lib/esm/ui/widget/MapLayerDroppable.js.map +1 -1
  150. package/lib/esm/ui/widget/MapLayerManager.d.ts +26 -26
  151. package/lib/esm/ui/widget/MapLayerManager.js +398 -398
  152. package/lib/esm/ui/widget/MapLayerManager.js.map +1 -1
  153. package/lib/esm/ui/widget/MapLayerManager.scss +409 -409
  154. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts +11 -12
  155. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts.map +1 -1
  156. package/lib/esm/ui/widget/MapLayerSettingsMenu.js +79 -79
  157. package/lib/esm/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  158. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts +6 -7
  159. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts.map +1 -1
  160. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js +61 -61
  161. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  162. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  163. package/lib/esm/ui/widget/MapLayersWidget.d.ts +10 -11
  164. package/lib/esm/ui/widget/MapLayersWidget.d.ts.map +1 -1
  165. package/lib/esm/ui/widget/MapLayersWidget.js +27 -27
  166. package/lib/esm/ui/widget/MapLayersWidget.js.map +1 -1
  167. package/lib/esm/ui/widget/MapManagerSettings.d.ts +2 -3
  168. package/lib/esm/ui/widget/MapManagerSettings.d.ts.map +1 -1
  169. package/lib/esm/ui/widget/MapManagerSettings.js +196 -196
  170. package/lib/esm/ui/widget/MapManagerSettings.js.map +1 -1
  171. package/lib/esm/ui/widget/MapManagerSettings.scss +29 -29
  172. package/lib/esm/ui/widget/MapUrlDialog.d.ts +22 -23
  173. package/lib/esm/ui/widget/MapUrlDialog.d.ts.map +1 -1
  174. package/lib/esm/ui/widget/MapUrlDialog.js +529 -523
  175. package/lib/esm/ui/widget/MapUrlDialog.js.map +1 -1
  176. package/lib/esm/ui/widget/MapUrlDialog.scss +99 -100
  177. package/lib/esm/ui/widget/SelectMapFormat.d.ts +17 -18
  178. package/lib/esm/ui/widget/SelectMapFormat.d.ts.map +1 -1
  179. package/lib/esm/ui/widget/SelectMapFormat.js +55 -55
  180. package/lib/esm/ui/widget/SelectMapFormat.js.map +1 -1
  181. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts +18 -20
  182. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts.map +1 -1
  183. package/lib/esm/ui/widget/SubLayersDataProvider.js +71 -72
  184. package/lib/esm/ui/widget/SubLayersDataProvider.js.map +1 -1
  185. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts +9 -10
  186. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts.map +1 -1
  187. package/lib/esm/ui/widget/SubLayersPopupButton.js +36 -36
  188. package/lib/esm/ui/widget/SubLayersPopupButton.js.map +1 -1
  189. package/lib/esm/ui/widget/SubLayersTree.d.ts +14 -15
  190. package/lib/esm/ui/widget/SubLayersTree.d.ts.map +1 -1
  191. package/lib/esm/ui/widget/SubLayersTree.js +414 -414
  192. package/lib/esm/ui/widget/SubLayersTree.js.map +1 -1
  193. package/lib/esm/ui/widget/SubLayersTree.scss +70 -69
  194. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts +13 -14
  195. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts.map +1 -1
  196. package/lib/esm/ui/widget/TransparencyPopupButton.js +43 -43
  197. package/lib/esm/ui/widget/TransparencyPopupButton.js.map +1 -1
  198. package/lib/esm/ui/widget/TransparencyPopupButton.scss +35 -36
  199. package/package.json +39 -38
@@ -1,524 +1,530 @@
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
+ 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
+ UiFramework.dialogs.modal.close();
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
+ // 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)
217
+ // we force the sub-layer visibility to ON.
218
+ let subLayers = validation.subLayers;
219
+ if (validation.subLayers && validation.subLayers.length === 1 && validation.subLayers[0].visible === false) {
220
+ subLayers = [{ ...validation.subLayers[0], visible: true }];
221
+ }
222
+ const settings = source.toLayerSettings(subLayers);
223
+ if (settings) {
224
+ vp.displayStyle.attachMapLayer({ settings, isOverlay });
225
+ const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttached", { sourceName: source.name, sourceUrl: source.url });
226
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));
227
+ }
228
+ else {
229
+ const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSettingsConversionError");
230
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MapLayerAttachError", { error: msgError, sourceUrl: source.url });
231
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
232
+ }
233
+ vp.invalidateRenderPlan();
234
+ // This handler will close the layer source handler, and therefore the MapUrl dialog.
235
+ // don't call it if the dialog needs to remains open.
236
+ onOkResult();
237
+ return true;
238
+ }, [hasImodelContext, isOverlay, onOkResult, props === null || props === void 0 ? void 0 : props.activeViewport, props.layerRequiringCredentials, settingsStorage, settingsStorageDisabled]);
239
+ // Validate the layer source and attempt to attach (or update) the layer.
240
+ // Returns true if no further input is needed from end-user (i.e. close the dialog)
241
+ const attemptAttachSource = React.useCallback(async (source) => {
242
+ try {
243
+ const validation = await source.validateSource(true);
244
+ if (validation.status === MapLayerSourceStatus.Valid) {
245
+ if (layerRequiringCredentialsIdx === undefined) {
246
+ return await doAttach(source, validation);
247
+ }
248
+ else {
249
+ return await updateAttachedLayer(source, validation);
250
+ }
251
+ }
252
+ else if (validation.status === MapLayerSourceStatus.InvalidCoordinateSystem) {
253
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCoordinateSystem");
254
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
255
+ return true;
256
+ }
257
+ else {
258
+ const authNeeded = await updateAuthState(source, validation);
259
+ if (authNeeded) {
260
+ return false;
261
+ }
262
+ else {
263
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ValidationError");
264
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, `${msg} ${source.url}`));
265
+ return true;
266
+ }
267
+ }
268
+ return false;
269
+ }
270
+ catch (error) {
271
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
272
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
273
+ return true;
274
+ }
275
+ }, [updateAuthState, doAttach, layerRequiringCredentialsIdx, updateAttachedLayer]);
276
+ const onNameChange = React.useCallback((event) => {
277
+ setMapName(event.target.value);
278
+ }, [setMapName]);
279
+ const onRadioChange = React.useCallback((event) => {
280
+ setSettingsStorageRadio(event.target.value);
281
+ }, [setSettingsStorageRadio]);
282
+ const onUrlChange = React.useCallback((event) => {
283
+ setMapUrl(event.target.value);
284
+ }, [setMapUrl]);
285
+ const createSource = React.useCallback(() => {
286
+ let source;
287
+ if (mapUrl && mapName) {
288
+ source = MapLayerSource.fromJSON({
289
+ url: mapUrl,
290
+ name: mapName,
291
+ formatId: mapType
292
+ });
293
+ // Set credentials separately since they are not part of JSON
294
+ if (source) {
295
+ source.userName = userName || undefined; // When there is no value, empty string is always returned, in this case force it to undefined,
296
+ source.password = password || undefined;
297
+ }
298
+ }
299
+ return source;
300
+ }, [mapName, mapType, mapUrl, password, userName]);
301
+ const handleOk = React.useCallback(() => {
302
+ const source = createSource();
303
+ if (source === undefined || props.mapLayerSourceToEdit) {
304
+ UiFramework.dialogs.modal.close();
305
+ onOkResult();
306
+ if (source === undefined) {
307
+ // Close the dialog and inform end user something went wrong.
308
+ const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSourceCreationFailed");
309
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error: msgError, sourceUrl: mapUrl });
310
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
311
+ return;
312
+ }
313
+ // Simply change the source definition in the setting service
314
+ if (props.mapLayerSourceToEdit !== undefined) {
315
+ const vp = props.activeViewport;
316
+ void (async () => {
317
+ var _a, _b;
318
+ if (isSettingsStorageAvailable && ((_a = vp === null || vp === void 0 ? void 0 : vp.iModel) === null || _a === void 0 ? void 0 : _a.iTwinId)) {
319
+ try {
320
+ await MapLayerPreferences.replaceSource(props.mapLayerSourceToEdit, source, vp.iModel.iTwinId, vp === null || vp === void 0 ? void 0 : vp.iModel.iModelId);
321
+ }
322
+ catch (err) {
323
+ const errorMessage = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerEditError", { layerName: (_b = props.mapLayerSourceToEdit) === null || _b === void 0 ? void 0 : _b.name });
324
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, errorMessage));
325
+ return;
326
+ }
327
+ }
328
+ })();
329
+ return;
330
+ }
331
+ }
332
+ setLayerAttachPending(true);
333
+ // Attach source asynchronously.
334
+ void (async () => {
335
+ try {
336
+ const closeDialog = await attemptAttachSource(source);
337
+ if (isMounted.current) {
338
+ setLayerAttachPending(false);
339
+ }
340
+ // In theory the modal dialog should always get closed by the parent
341
+ // AttachLayerPanel's 'onOkResult' handler. We close it here just in case.
342
+ if (closeDialog) {
343
+ UiFramework.dialogs.modal.close();
344
+ onOkResult();
345
+ }
346
+ }
347
+ catch (_error) {
348
+ onOkResult();
349
+ UiFramework.dialogs.modal.close();
350
+ }
351
+ })();
352
+ }, [createSource, props.mapLayerSourceToEdit, props.activeViewport, onOkResult, mapUrl, isSettingsStorageAvailable, attemptAttachSource]);
353
+ React.useEffect(() => {
354
+ const handleOAuthProcessEnd = (success, _state) => {
355
+ onOauthProcessEnd.raiseEvent(success, _state);
356
+ };
357
+ // Currently only arcgis support AccessClient
358
+ const ac = IModelApp.mapLayerFormatRegistry.getAccessClient(MAP_TYPES.arcGis);
359
+ if (ac === null || ac === void 0 ? void 0 : ac.onOAuthProcessEnd) {
360
+ setAccessClient(ac); // cache it, so we dont need to make another lookup;
361
+ ac.onOAuthProcessEnd.addListener(handleOAuthProcessEnd);
362
+ }
363
+ setAccessClientInitialized(true);
364
+ return () => {
365
+ if (ac === null || ac === void 0 ? void 0 : ac.onOAuthProcessEnd) {
366
+ ac.onOAuthProcessEnd.removeListener(handleOAuthProcessEnd);
367
+ }
368
+ setAccessClient(undefined);
369
+ setAccessClientInitialized(false);
370
+ };
371
+ }, [mapType, onOauthProcessEnd, setAccessClient]);
372
+ // After a map type change, make sure the different Oauth states are reset.
373
+ React.useEffect(() => {
374
+ // Reset few states
375
+ setServerRequireCredentials(false);
376
+ setInvalidCredentialsProvided(false);
377
+ setShowOauthPopup(false);
378
+ setOAuthProcessSucceeded(undefined);
379
+ setExternalLoginUrl(undefined);
380
+ }, [mapType]);
381
+ // The first time the dialog is loaded and we already know the layer requires auth. (i.e ImageryProvider already made an attempt)
382
+ // makes a request to discover the authentification types and adjust UI accordingly (i.e. username/password fields, Oauth popup)
383
+ // Without this effect, user would have to manually click the 'OK' button in order to trigger the layer connection.
384
+ React.useEffect(() => {
385
+ // Attach source asynchronously.
386
+ void (async () => {
387
+ var _a, _b;
388
+ 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) {
389
+ try {
390
+ const source = MapLayerSource.fromJSON({
391
+ url: props.layerRequiringCredentials.url,
392
+ name: props.layerRequiringCredentials.name,
393
+ formatId: props.layerRequiringCredentials.formatId
394
+ });
395
+ if (source !== undefined) {
396
+ setLayerAttachPending(true);
397
+ const validation = await source.validateSource(true);
398
+ if (isMounted.current) {
399
+ setLayerAttachPending(false);
400
+ }
401
+ await updateAuthState(source, validation);
402
+ }
403
+ }
404
+ catch (_error) { }
405
+ }
406
+ })();
407
+ }, [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]);
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: DialogButtonType.OK, onClick: handleOk, disabled: !readyToSave() },
419
+ { type: DialogButtonType.Cancel, onClick: handleCancel },
420
+ ], [readyToSave, handleCancel, handleOk]);
421
+ const handleOnKeyDown = React.useCallback((event) => {
422
+ if (event.key === 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(Button, { onClick: handleArcGisLogin }, externalLoginTryAgainLabel));
487
+ }
488
+ if (warningMessage !== undefined) {
489
+ return (React.createElement("div", { className: "map-layer-source-warnMessage" },
490
+ React.createElement(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
+ useCrossOriginPopup(showOauthPopup, externalLoginUrl, externalLoginTitle, 450, 450, handleOAuthPopupClose);
502
+ return (React.createElement("div", { ref: dialogContainer },
503
+ 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 },
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, { 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(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(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(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(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(Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "iTwin", label: iTwinSettingsLabel, checked: settingsStorage === "iTwin", onChange: onRadioChange }),
524
+ React.createElement(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(ProgressLinear, { indeterminate: true })))));
529
+ }
524
530
  //# sourceMappingURL=MapUrlDialog.js.map