@itwin/map-layers 4.0.0-dev.28 → 4.0.0-dev.32

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