@itwin/map-layers 3.5.0-dev.12 → 3.5.0-dev.13

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 (149) 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 +63 -63
  8. package/lib/cjs/mapLayers.js.map +1 -1
  9. package/lib/cjs/ui/FeatureInfoUiItemsProvider.d.ts +10 -10
  10. package/lib/cjs/ui/FeatureInfoUiItemsProvider.js +50 -50
  11. package/lib/cjs/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  12. package/lib/cjs/ui/Interfaces.d.ts +47 -47
  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 +338 -338
  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 +25 -25
  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 +139 -139
  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 +71 -71
  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 +86 -86
  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 +375 -375
  41. package/lib/cjs/ui/widget/MapLayerManager.js.map +1 -1
  42. package/lib/cjs/ui/widget/MapLayerManager.scss +389 -389
  43. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts +12 -12
  44. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js +83 -83
  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 +26 -26
  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 +22 -22
  58. package/lib/cjs/ui/widget/MapUrlDialog.js +530 -530
  59. package/lib/cjs/ui/widget/MapUrlDialog.js.map +1 -1
  60. package/lib/cjs/ui/widget/MapUrlDialog.scss +87 -87
  61. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts +20 -20
  62. package/lib/cjs/ui/widget/SubLayersDataProvider.js +76 -76
  63. package/lib/cjs/ui/widget/SubLayersDataProvider.js.map +1 -1
  64. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts +10 -10
  65. package/lib/cjs/ui/widget/SubLayersPopupButton.js +40 -40
  66. package/lib/cjs/ui/widget/SubLayersPopupButton.js.map +1 -1
  67. package/lib/cjs/ui/widget/SubLayersTree.d.ts +15 -15
  68. package/lib/cjs/ui/widget/SubLayersTree.js +414 -414
  69. package/lib/cjs/ui/widget/SubLayersTree.js.map +1 -1
  70. package/lib/cjs/ui/widget/SubLayersTree.scss +69 -69
  71. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts +14 -14
  72. package/lib/cjs/ui/widget/TransparencyPopupButton.js +47 -47
  73. package/lib/cjs/ui/widget/TransparencyPopupButton.js.map +1 -1
  74. package/lib/cjs/ui/widget/TransparencyPopupButton.scss +36 -36
  75. package/lib/esm/MapLayerPreferences.d.ts +88 -88
  76. package/lib/esm/MapLayerPreferences.js +307 -307
  77. package/lib/esm/MapLayerPreferences.js.map +1 -1
  78. package/lib/esm/map-layers.d.ts +6 -6
  79. package/lib/esm/map-layers.js +10 -10
  80. package/lib/esm/mapLayers.d.ts +44 -44
  81. package/lib/esm/mapLayers.js +59 -59
  82. package/lib/esm/mapLayers.js.map +1 -1
  83. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts +10 -10
  84. package/lib/esm/ui/FeatureInfoUiItemsProvider.js +46 -46
  85. package/lib/esm/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  86. package/lib/esm/ui/Interfaces.d.ts +47 -47
  87. package/lib/esm/ui/Interfaces.js +1 -1
  88. package/lib/esm/ui/Interfaces.js.map +1 -1
  89. package/lib/esm/ui/MapFeatureInfoTool.d.ts +13 -13
  90. package/lib/esm/ui/MapFeatureInfoTool.js +45 -45
  91. package/lib/esm/ui/MapFeatureInfoTool.js.map +1 -1
  92. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts +8 -8
  93. package/lib/esm/ui/MapLayersUiItemsProvider.js +34 -34
  94. package/lib/esm/ui/MapLayersUiItemsProvider.js.map +1 -1
  95. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts +14 -14
  96. package/lib/esm/ui/widget/AttachLayerPopupButton.js +334 -334
  97. package/lib/esm/ui/widget/BasemapPanel.d.ts +8 -8
  98. package/lib/esm/ui/widget/BasemapPanel.js +152 -152
  99. package/lib/esm/ui/widget/BasemapPanel.js.map +1 -1
  100. package/lib/esm/ui/widget/BasemapPanel.scss +87 -87
  101. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts +21 -21
  102. package/lib/esm/ui/widget/ConfirmMessageDialog.js +21 -21
  103. package/lib/esm/ui/widget/ConfirmMessageDialog.js.map +1 -1
  104. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts +40 -40
  105. package/lib/esm/ui/widget/FeatureInfoDataProvider.js +135 -135
  106. package/lib/esm/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  107. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts +7 -7
  108. package/lib/esm/ui/widget/FeatureInfoWidget.js +67 -67
  109. package/lib/esm/ui/widget/FeatureInfoWidget.js.map +1 -1
  110. package/lib/esm/ui/widget/MapLayerDroppable.d.ts +19 -19
  111. package/lib/esm/ui/widget/MapLayerDroppable.js +82 -82
  112. package/lib/esm/ui/widget/MapLayerDroppable.js.map +1 -1
  113. package/lib/esm/ui/widget/MapLayerManager.d.ts +26 -26
  114. package/lib/esm/ui/widget/MapLayerManager.js +370 -370
  115. package/lib/esm/ui/widget/MapLayerManager.js.map +1 -1
  116. package/lib/esm/ui/widget/MapLayerManager.scss +389 -389
  117. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts +12 -12
  118. package/lib/esm/ui/widget/MapLayerSettingsMenu.js +79 -79
  119. package/lib/esm/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  120. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts +7 -7
  121. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js +61 -61
  122. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  123. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  124. package/lib/esm/ui/widget/MapLayersWidget.d.ts +11 -11
  125. package/lib/esm/ui/widget/MapLayersWidget.js +22 -22
  126. package/lib/esm/ui/widget/MapLayersWidget.js.map +1 -1
  127. package/lib/esm/ui/widget/MapManagerSettings.d.ts +3 -3
  128. package/lib/esm/ui/widget/MapManagerSettings.js +196 -196
  129. package/lib/esm/ui/widget/MapManagerSettings.js.map +1 -1
  130. package/lib/esm/ui/widget/MapManagerSettings.scss +29 -29
  131. package/lib/esm/ui/widget/MapUrlDialog.d.ts +22 -22
  132. package/lib/esm/ui/widget/MapUrlDialog.js +526 -526
  133. package/lib/esm/ui/widget/MapUrlDialog.js.map +1 -1
  134. package/lib/esm/ui/widget/MapUrlDialog.scss +87 -87
  135. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts +20 -20
  136. package/lib/esm/ui/widget/SubLayersDataProvider.js +72 -72
  137. package/lib/esm/ui/widget/SubLayersDataProvider.js.map +1 -1
  138. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts +10 -10
  139. package/lib/esm/ui/widget/SubLayersPopupButton.js +36 -36
  140. package/lib/esm/ui/widget/SubLayersPopupButton.js.map +1 -1
  141. package/lib/esm/ui/widget/SubLayersTree.d.ts +15 -15
  142. package/lib/esm/ui/widget/SubLayersTree.js +409 -409
  143. package/lib/esm/ui/widget/SubLayersTree.js.map +1 -1
  144. package/lib/esm/ui/widget/SubLayersTree.scss +69 -69
  145. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts +14 -14
  146. package/lib/esm/ui/widget/TransparencyPopupButton.js +43 -43
  147. package/lib/esm/ui/widget/TransparencyPopupButton.js.map +1 -1
  148. package/lib/esm/ui/widget/TransparencyPopupButton.scss +36 -36
  149. package/package.json +26 -26
@@ -1,531 +1,531 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- // cSpell:ignore Modeless WMTS
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.MapUrlDialog = exports.MAP_TYPES = void 0;
9
- const appui_abstract_1 = require("@itwin/appui-abstract");
10
- const appui_react_1 = require("@itwin/appui-react");
11
- const itwinui_react_1 = require("@itwin/itwinui-react");
12
- const core_frontend_1 = require("@itwin/core-frontend");
13
- const core_react_1 = require("@itwin/core-react");
14
- const React = require("react");
15
- const MapLayerPreferences_1 = require("../../MapLayerPreferences");
16
- const mapLayers_1 = require("../../mapLayers");
17
- require("./MapUrlDialog.scss");
18
- const core_bentley_1 = require("@itwin/core-bentley");
19
- exports.MAP_TYPES = {
20
- wms: "WMS",
21
- arcGis: "ArcGIS",
22
- wmts: "WMTS",
23
- tileUrl: "TileURL",
24
- };
25
- // eslint-disable-next-line @typescript-eslint/naming-convention
26
- function MapUrlDialog(props) {
27
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
28
- const { isOverlay, onOkResult, mapTypesOptions } = props;
29
- const getMapUrlFromProps = React.useCallback(() => {
30
- var _a;
31
- if (props.mapLayerSourceToEdit) {
32
- return props.mapLayerSourceToEdit.url;
33
- }
34
- else if ((_a = props.layerRequiringCredentials) === null || _a === void 0 ? void 0 : _a.url) {
35
- return props.layerRequiringCredentials.url;
36
- }
37
- return "";
38
- }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
39
- const getMapNameFromProps = React.useCallback(() => {
40
- var _a;
41
- if (props.mapLayerSourceToEdit) {
42
- return props.mapLayerSourceToEdit.name;
43
- }
44
- else if ((_a = props.layerRequiringCredentials) === null || _a === void 0 ? void 0 : _a.name) {
45
- return props.layerRequiringCredentials.name;
46
- }
47
- return "";
48
- }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
49
- const getFormatFromProps = React.useCallback(() => {
50
- var _a;
51
- if (props.mapLayerSourceToEdit) {
52
- return props.mapLayerSourceToEdit.formatId;
53
- }
54
- else if ((_a = props.layerRequiringCredentials) === null || _a === void 0 ? void 0 : _a.formatId) {
55
- return props.layerRequiringCredentials.formatId;
56
- }
57
- return undefined;
58
- }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
59
- const [dialogTitle] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString(props.layerRequiringCredentials || props.mapLayerSourceToEdit ? "mapLayers:CustomAttach.EditCustomLayer" : "mapLayers:CustomAttach.AttachCustomLayer"));
60
- const [typeLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Type"));
61
- const [nameLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Name"));
62
- const [nameInputPlaceHolder] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NameInputPlaceHolder"));
63
- const [urlLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.URL"));
64
- const [urlInputPlaceHolder] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.UrlInputPlaceHolder"));
65
- const [iTwinSettingsLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnITwinSettings"));
66
- const [modelSettingsLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnModelSettings"));
67
- const [missingCredentialsLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MissingCredentials"));
68
- const [invalidCredentialsLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCredentials"));
69
- const [externalLoginTitle] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLogin"));
70
- const [externalLoginFailedMsg] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginFailed"));
71
- const [externalLoginSucceededMsg] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginSucceeded"));
72
- const [externalLoginWaitingMsg] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginWaiting"));
73
- const [externalLoginTryAgainLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginTryAgain"));
74
- const [serverRequireCredentials, setServerRequireCredentials] = React.useState(false);
75
- const [invalidCredentialsProvided, setInvalidCredentialsProvided] = React.useState(false);
76
- const [layerAttachPending, setLayerAttachPending] = React.useState(false);
77
- const [layerAuthPending, setLayerAuthPending] = React.useState(false);
78
- const [mapUrl, setMapUrl] = React.useState(getMapUrlFromProps());
79
- const [mapName, setMapName] = React.useState(getMapNameFromProps());
80
- const [userName, setUserName] = React.useState("");
81
- const [password, setPassword] = React.useState("");
82
- const [noSaveSettingsWarning] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NoSaveSettingsWarning"));
83
- const [passwordLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Password"));
84
- const [passwordRequiredLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.PasswordRequired"));
85
- const [userNameLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Username"));
86
- const [userNameRequiredLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.UsernameRequired"));
87
- const [settingsStorage, setSettingsStorageRadio] = React.useState("iTwin");
88
- const [oauthProcessSucceeded, setOAuthProcessSucceeded] = React.useState(undefined);
89
- const [showOauthPopup, setShowOauthPopup] = React.useState(false);
90
- const [externalLoginUrl, setExternalLoginUrl] = React.useState();
91
- const [onOauthProcessEnd] = React.useState(new core_bentley_1.BeEvent());
92
- const [accessClient, setAccessClient] = React.useState();
93
- const [isAccessClientInitialized, setAccessClientInitialized] = React.useState(false);
94
- const [mapType, setMapType] = React.useState((_a = getFormatFromProps()) !== null && _a !== void 0 ? _a : exports.MAP_TYPES.arcGis);
95
- // 'isMounted' is used to prevent any async operation once the hook has been
96
- // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
97
- const isMounted = React.useRef(false);
98
- React.useEffect(() => {
99
- isMounted.current = true;
100
- return () => {
101
- isMounted.current = false;
102
- };
103
- }, []);
104
- const [mapTypes] = React.useState(() => {
105
- const types = [
106
- { value: exports.MAP_TYPES.arcGis, label: exports.MAP_TYPES.arcGis },
107
- { value: exports.MAP_TYPES.wms, label: exports.MAP_TYPES.wms },
108
- { value: exports.MAP_TYPES.wmts, label: exports.MAP_TYPES.wmts },
109
- ];
110
- if (mapTypesOptions === null || mapTypesOptions === void 0 ? void 0 : mapTypesOptions.supportTileUrl)
111
- types.push({ value: exports.MAP_TYPES.tileUrl, label: exports.MAP_TYPES.tileUrl });
112
- return types;
113
- });
114
- const [isSettingsStorageAvailable] = React.useState(mapLayers_1.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));
115
- 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
116
- && props.activeViewport.iModel.iTwinId !== core_bentley_1.Guid.empty
117
- && ((_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
118
- && (props === null || props === void 0 ? void 0 : props.activeViewport.iModel.iModelId) !== core_bentley_1.Guid.empty);
119
- // Even though the settings storage is available,
120
- // we don't always want to enable it in the UI.
121
- const [settingsStorageDisabled] = React.useState(!isSettingsStorageAvailable || props.mapLayerSourceToEdit !== undefined || props.layerRequiringCredentials !== undefined);
122
- const [layerRequiringCredentialsIdx] = React.useState(() => {
123
- var _a;
124
- if (props.layerRequiringCredentials === undefined || !props.layerRequiringCredentials.name || !props.layerRequiringCredentials.url) {
125
- return undefined;
126
- }
127
- const indexInDisplayStyle = (_a = props.activeViewport) === null || _a === void 0 ? void 0 : _a.displayStyle.findMapLayerIndexByNameAndSource(props.layerRequiringCredentials.name, props.layerRequiringCredentials.url, isOverlay);
128
- if (indexInDisplayStyle === undefined || indexInDisplayStyle < 0) {
129
- return undefined;
130
- }
131
- else {
132
- return indexInDisplayStyle;
133
- }
134
- });
135
- const handleCancel = React.useCallback(() => {
136
- if (props.onCancelResult) {
137
- props.onCancelResult();
138
- return;
139
- }
140
- appui_react_1.ModalDialogManager.closeDialog();
141
- }, [props]);
142
- const onUsernameChange = React.useCallback((event) => {
143
- setUserName(event.target.value);
144
- if (invalidCredentialsProvided)
145
- setInvalidCredentialsProvided(false);
146
- }, [setUserName, invalidCredentialsProvided, setInvalidCredentialsProvided]);
147
- const onPasswordChange = React.useCallback((event) => {
148
- setPassword(event.target.value);
149
- if (invalidCredentialsProvided)
150
- setInvalidCredentialsProvided(false);
151
- }, [setPassword, invalidCredentialsProvided, setInvalidCredentialsProvided]);
152
- const handleArcGisLogin = React.useCallback(() => {
153
- setLayerAuthPending(true);
154
- setShowOauthPopup(true);
155
- if (oauthProcessSucceeded === false) {
156
- setOAuthProcessSucceeded(undefined);
157
- }
158
- }, [oauthProcessSucceeded]);
159
- // return true if authorization is needed
160
- const updateAuthState = React.useCallback(async (source, sourceValidation) => {
161
- const sourceRequireAuth = (sourceValidation.status === core_frontend_1.MapLayerSourceStatus.RequireAuth);
162
- const invalidCredentials = (sourceValidation.status === core_frontend_1.MapLayerSourceStatus.InvalidCredentials);
163
- if (sourceRequireAuth) {
164
- const settings = source.toLayerSettings();
165
- if (accessClient !== undefined && accessClient.getTokenServiceEndPoint !== undefined && settings !== undefined) {
166
- try {
167
- const tokenEndpoint = await accessClient.getTokenServiceEndPoint(settings.url);
168
- if (tokenEndpoint !== undefined) {
169
- const loginUrl = tokenEndpoint.getLoginUrl();
170
- setExternalLoginUrl(loginUrl);
171
- }
172
- }
173
- catch (_error) {
174
- }
175
- }
176
- }
177
- setServerRequireCredentials(sourceRequireAuth || invalidCredentials);
178
- if (invalidCredentials) {
179
- setInvalidCredentialsProvided(true);
180
- }
181
- else if (invalidCredentialsProvided) {
182
- setInvalidCredentialsProvided(false); // flag reset
183
- }
184
- return sourceRequireAuth || invalidCredentials;
185
- }, [accessClient, invalidCredentialsProvided]);
186
- const updateAttachedLayer = React.useCallback(async (source, validation) => {
187
- const vp = props === null || props === void 0 ? void 0 : props.activeViewport;
188
- if (vp === undefined || source === undefined || layerRequiringCredentialsIdx === undefined) {
189
- const error = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
190
- const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
191
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, msg));
192
- return true;
193
- }
194
- // Layer is already attached,
195
- vp.displayStyle.changeMapLayerProps({
196
- subLayers: validation.subLayers,
197
- }, layerRequiringCredentialsIdx, isOverlay);
198
- vp.displayStyle.changeMapLayerCredentials(layerRequiringCredentialsIdx, isOverlay, source.userName, source.password);
199
- // Reset the provider's status
200
- const provider = vp.getMapLayerImageryProvider(layerRequiringCredentialsIdx, isOverlay);
201
- if (provider && provider.status !== core_frontend_1.MapLayerImageryProviderStatus.Valid) {
202
- provider.status = core_frontend_1.MapLayerImageryProviderStatus.Valid;
203
- }
204
- vp.invalidateRenderPlan();
205
- // This handler will close the layer source handler, and therefore the MapUrl dialog.
206
- // don't call it if the dialog needs to remains open.
207
- onOkResult();
208
- return true;
209
- }, [isOverlay, layerRequiringCredentialsIdx, onOkResult, props.activeViewport]);
210
- // Returns true if no further input is needed from end-user.
211
- const doAttach = React.useCallback(async (source, validation) => {
212
- const vp = props === null || props === void 0 ? void 0 : props.activeViewport;
213
- if (vp === undefined || source === undefined) {
214
- const error = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
215
- const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
216
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, msg));
217
- return true;
218
- }
219
- // Update service settings if storage is available and we are not prompting user for credentials
220
- if (!settingsStorageDisabled && !props.layerRequiringCredentials) {
221
- const storeOnIModel = (hasImodelContext ? "Model" === settingsStorage : undefined);
222
- if (vp.iModel.iTwinId && !(await MapLayerPreferences_1.MapLayerPreferences.storeSource(source, vp.iModel.iTwinId, vp.iModel.iModelId, storeOnIModel))) {
223
- const msgError = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerPreferencesStoreFailed");
224
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, msgError));
225
- }
226
- }
227
- const settings = source.toLayerSettings(validation.subLayers);
228
- if (settings) {
229
- vp.displayStyle.attachMapLayer({ settings, isOverlay });
230
- const msg = core_frontend_1.IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttached", { sourceName: source.name, sourceUrl: source.url });
231
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, msg));
232
- }
233
- else {
234
- const msgError = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSettingsConversionError");
235
- const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MapLayerAttachError", { error: msgError, sourceUrl: source.url });
236
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, msg));
237
- }
238
- vp.invalidateRenderPlan();
239
- // This handler will close the layer source handler, and therefore the MapUrl dialog.
240
- // don't call it if the dialog needs to remains open.
241
- onOkResult();
242
- return true;
243
- }, [hasImodelContext, isOverlay, onOkResult, props === null || props === void 0 ? void 0 : props.activeViewport, props.layerRequiringCredentials, settingsStorage, settingsStorageDisabled]);
244
- // Validate the layer source and attempt to attach (or update) the layer.
245
- // Returns true if no further input is needed from end-user (i.e. close the dialog)
246
- const attemptAttachSource = React.useCallback(async (source) => {
247
- try {
248
- const validation = await source.validateSource(true);
249
- if (validation.status === core_frontend_1.MapLayerSourceStatus.Valid) {
250
- if (layerRequiringCredentialsIdx === undefined) {
251
- return await doAttach(source, validation);
252
- }
253
- else {
254
- return await updateAttachedLayer(source, validation);
255
- }
256
- }
257
- else {
258
- const authNeeded = await updateAuthState(source, validation);
259
- if (authNeeded) {
260
- return false;
261
- }
262
- else {
263
- const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ValidationError");
264
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, `${msg} ${source.url}`));
265
- return true;
266
- }
267
- }
268
- return false;
269
- }
270
- catch (error) {
271
- const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
272
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.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 = core_frontend_1.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
- appui_react_1.ModalDialogManager.closeDialog();
305
- onOkResult();
306
- if (source === undefined) {
307
- // Close the dialog and inform end user something went wrong.
308
- const msgError = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSourceCreationFailed");
309
- const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error: msgError, sourceUrl: mapUrl });
310
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.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_1.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 = core_frontend_1.IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerEditError", { layerName: (_b = props.mapLayerSourceToEdit) === null || _b === void 0 ? void 0 : _b.name });
324
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.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
- appui_react_1.ModalDialogManager.closeDialog();
344
- onOkResult();
345
- }
346
- }
347
- catch (_error) {
348
- onOkResult();
349
- appui_react_1.ModalDialogManager.closeDialog();
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 = core_frontend_1.IModelApp.mapLayerFormatRegistry.getAccessClient(exports.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 = core_frontend_1.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: 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(itwinui_react_1.Select, { className: "map-layer-source-select", options: mapTypes, value: mapType, disabled: props.layerRequiringCredentials !== undefined || props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, onChange: setMapType, size: "small" }),
508
- React.createElement("span", { className: "map-layer-source-label" }, nameLabel),
509
- React.createElement(itwinui_react_1.Input, { className: "map-layer-source-input", placeholder: nameInputPlaceHolder, onChange: onNameChange, value: mapName, disabled: props.layerRequiringCredentials !== undefined || layerAttachPending || layerAuthPending }),
510
- React.createElement("span", { className: "map-layer-source-label" }, urlLabel),
511
- React.createElement(itwinui_react_1.Input, { className: "map-layer-source-input", placeholder: urlInputPlaceHolder, onKeyPress: handleOnKeyDown, onChange: onUrlChange, disabled: props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, value: mapUrl }),
512
- serverRequireCredentials
513
- && externalLoginUrl === undefined // external login is handled in popup
514
- && props.mapLayerSourceToEdit === undefined &&
515
- React.createElement(React.Fragment, null,
516
- React.createElement("span", { className: "map-layer-source-label" }, userNameLabel),
517
- React.createElement(itwinui_react_1.LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", placeholder: serverRequireCredentials ? userNameRequiredLabel : userNameLabel, status: (!userName && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onUsernameChange, value: userName, size: "small" }),
518
- React.createElement("span", { className: "map-layer-source-label" }, passwordLabel),
519
- React.createElement(itwinui_react_1.LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", type: "password", placeholder: serverRequireCredentials ? passwordRequiredLabel : passwordLabel, status: (!password && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onPasswordChange, onKeyPress: handleOnKeyDown, value: password, size: "small" })),
520
- isSettingsStorageAvailable &&
521
- React.createElement("div", { title: settingsStorageDisabled ? noSaveSettingsWarning : "" }, hasImodelContext &&
522
- React.createElement("div", null,
523
- React.createElement(itwinui_react_1.Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "iTwin", label: iTwinSettingsLabel, checked: settingsStorage === "iTwin", onChange: onRadioChange }),
524
- React.createElement(itwinui_react_1.Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "Model", label: modelSettingsLabel, checked: settingsStorage === "Model", onChange: onRadioChange }))))),
525
- renderWarningMessage(),
526
- (layerAttachPending || layerAuthPending) &&
527
- React.createElement("div", { className: "map-layer-source-progressBar" },
528
- React.createElement(itwinui_react_1.ProgressLinear, { indeterminate: true })))));
529
- }
530
- exports.MapUrlDialog = MapUrlDialog;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ // cSpell:ignore Modeless WMTS
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.MapUrlDialog = exports.MAP_TYPES = void 0;
9
+ const appui_abstract_1 = require("@itwin/appui-abstract");
10
+ const appui_react_1 = require("@itwin/appui-react");
11
+ const itwinui_react_1 = require("@itwin/itwinui-react");
12
+ const core_frontend_1 = require("@itwin/core-frontend");
13
+ const core_react_1 = require("@itwin/core-react");
14
+ const React = require("react");
15
+ const MapLayerPreferences_1 = require("../../MapLayerPreferences");
16
+ const mapLayers_1 = require("../../mapLayers");
17
+ require("./MapUrlDialog.scss");
18
+ const core_bentley_1 = require("@itwin/core-bentley");
19
+ exports.MAP_TYPES = {
20
+ wms: "WMS",
21
+ arcGis: "ArcGIS",
22
+ wmts: "WMTS",
23
+ tileUrl: "TileURL",
24
+ };
25
+ // eslint-disable-next-line @typescript-eslint/naming-convention
26
+ function MapUrlDialog(props) {
27
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
28
+ const { isOverlay, onOkResult, mapTypesOptions } = props;
29
+ const getMapUrlFromProps = React.useCallback(() => {
30
+ var _a;
31
+ if (props.mapLayerSourceToEdit) {
32
+ return props.mapLayerSourceToEdit.url;
33
+ }
34
+ else if ((_a = props.layerRequiringCredentials) === null || _a === void 0 ? void 0 : _a.url) {
35
+ return props.layerRequiringCredentials.url;
36
+ }
37
+ return "";
38
+ }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
39
+ const getMapNameFromProps = React.useCallback(() => {
40
+ var _a;
41
+ if (props.mapLayerSourceToEdit) {
42
+ return props.mapLayerSourceToEdit.name;
43
+ }
44
+ else if ((_a = props.layerRequiringCredentials) === null || _a === void 0 ? void 0 : _a.name) {
45
+ return props.layerRequiringCredentials.name;
46
+ }
47
+ return "";
48
+ }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
49
+ const getFormatFromProps = React.useCallback(() => {
50
+ var _a;
51
+ if (props.mapLayerSourceToEdit) {
52
+ return props.mapLayerSourceToEdit.formatId;
53
+ }
54
+ else if ((_a = props.layerRequiringCredentials) === null || _a === void 0 ? void 0 : _a.formatId) {
55
+ return props.layerRequiringCredentials.formatId;
56
+ }
57
+ return undefined;
58
+ }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
59
+ const [dialogTitle] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString(props.layerRequiringCredentials || props.mapLayerSourceToEdit ? "mapLayers:CustomAttach.EditCustomLayer" : "mapLayers:CustomAttach.AttachCustomLayer"));
60
+ const [typeLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Type"));
61
+ const [nameLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Name"));
62
+ const [nameInputPlaceHolder] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NameInputPlaceHolder"));
63
+ const [urlLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.URL"));
64
+ const [urlInputPlaceHolder] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.UrlInputPlaceHolder"));
65
+ const [iTwinSettingsLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnITwinSettings"));
66
+ const [modelSettingsLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnModelSettings"));
67
+ const [missingCredentialsLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MissingCredentials"));
68
+ const [invalidCredentialsLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCredentials"));
69
+ const [externalLoginTitle] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLogin"));
70
+ const [externalLoginFailedMsg] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginFailed"));
71
+ const [externalLoginSucceededMsg] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginSucceeded"));
72
+ const [externalLoginWaitingMsg] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginWaiting"));
73
+ const [externalLoginTryAgainLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginTryAgain"));
74
+ const [serverRequireCredentials, setServerRequireCredentials] = React.useState(false);
75
+ const [invalidCredentialsProvided, setInvalidCredentialsProvided] = React.useState(false);
76
+ const [layerAttachPending, setLayerAttachPending] = React.useState(false);
77
+ const [layerAuthPending, setLayerAuthPending] = React.useState(false);
78
+ const [mapUrl, setMapUrl] = React.useState(getMapUrlFromProps());
79
+ const [mapName, setMapName] = React.useState(getMapNameFromProps());
80
+ const [userName, setUserName] = React.useState("");
81
+ const [password, setPassword] = React.useState("");
82
+ const [noSaveSettingsWarning] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NoSaveSettingsWarning"));
83
+ const [passwordLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Password"));
84
+ const [passwordRequiredLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.PasswordRequired"));
85
+ const [userNameLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Username"));
86
+ const [userNameRequiredLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.UsernameRequired"));
87
+ const [settingsStorage, setSettingsStorageRadio] = React.useState("iTwin");
88
+ const [oauthProcessSucceeded, setOAuthProcessSucceeded] = React.useState(undefined);
89
+ const [showOauthPopup, setShowOauthPopup] = React.useState(false);
90
+ const [externalLoginUrl, setExternalLoginUrl] = React.useState();
91
+ const [onOauthProcessEnd] = React.useState(new core_bentley_1.BeEvent());
92
+ const [accessClient, setAccessClient] = React.useState();
93
+ const [isAccessClientInitialized, setAccessClientInitialized] = React.useState(false);
94
+ const [mapType, setMapType] = React.useState((_a = getFormatFromProps()) !== null && _a !== void 0 ? _a : exports.MAP_TYPES.arcGis);
95
+ // 'isMounted' is used to prevent any async operation once the hook has been
96
+ // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
97
+ const isMounted = React.useRef(false);
98
+ React.useEffect(() => {
99
+ isMounted.current = true;
100
+ return () => {
101
+ isMounted.current = false;
102
+ };
103
+ }, []);
104
+ const [mapTypes] = React.useState(() => {
105
+ const types = [
106
+ { value: exports.MAP_TYPES.arcGis, label: exports.MAP_TYPES.arcGis },
107
+ { value: exports.MAP_TYPES.wms, label: exports.MAP_TYPES.wms },
108
+ { value: exports.MAP_TYPES.wmts, label: exports.MAP_TYPES.wmts },
109
+ ];
110
+ if (mapTypesOptions === null || mapTypesOptions === void 0 ? void 0 : mapTypesOptions.supportTileUrl)
111
+ types.push({ value: exports.MAP_TYPES.tileUrl, label: exports.MAP_TYPES.tileUrl });
112
+ return types;
113
+ });
114
+ const [isSettingsStorageAvailable] = React.useState(mapLayers_1.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));
115
+ 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
116
+ && props.activeViewport.iModel.iTwinId !== core_bentley_1.Guid.empty
117
+ && ((_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
118
+ && (props === null || props === void 0 ? void 0 : props.activeViewport.iModel.iModelId) !== core_bentley_1.Guid.empty);
119
+ // Even though the settings storage is available,
120
+ // we don't always want to enable it in the UI.
121
+ const [settingsStorageDisabled] = React.useState(!isSettingsStorageAvailable || props.mapLayerSourceToEdit !== undefined || props.layerRequiringCredentials !== undefined);
122
+ const [layerRequiringCredentialsIdx] = React.useState(() => {
123
+ var _a;
124
+ if (props.layerRequiringCredentials === undefined || !props.layerRequiringCredentials.name || !props.layerRequiringCredentials.url) {
125
+ return undefined;
126
+ }
127
+ const indexInDisplayStyle = (_a = props.activeViewport) === null || _a === void 0 ? void 0 : _a.displayStyle.findMapLayerIndexByNameAndSource(props.layerRequiringCredentials.name, props.layerRequiringCredentials.url, isOverlay);
128
+ if (indexInDisplayStyle === undefined || indexInDisplayStyle < 0) {
129
+ return undefined;
130
+ }
131
+ else {
132
+ return indexInDisplayStyle;
133
+ }
134
+ });
135
+ const handleCancel = React.useCallback(() => {
136
+ if (props.onCancelResult) {
137
+ props.onCancelResult();
138
+ return;
139
+ }
140
+ appui_react_1.ModalDialogManager.closeDialog();
141
+ }, [props]);
142
+ const onUsernameChange = React.useCallback((event) => {
143
+ setUserName(event.target.value);
144
+ if (invalidCredentialsProvided)
145
+ setInvalidCredentialsProvided(false);
146
+ }, [setUserName, invalidCredentialsProvided, setInvalidCredentialsProvided]);
147
+ const onPasswordChange = React.useCallback((event) => {
148
+ setPassword(event.target.value);
149
+ if (invalidCredentialsProvided)
150
+ setInvalidCredentialsProvided(false);
151
+ }, [setPassword, invalidCredentialsProvided, setInvalidCredentialsProvided]);
152
+ const handleArcGisLogin = React.useCallback(() => {
153
+ setLayerAuthPending(true);
154
+ setShowOauthPopup(true);
155
+ if (oauthProcessSucceeded === false) {
156
+ setOAuthProcessSucceeded(undefined);
157
+ }
158
+ }, [oauthProcessSucceeded]);
159
+ // return true if authorization is needed
160
+ const updateAuthState = React.useCallback(async (source, sourceValidation) => {
161
+ const sourceRequireAuth = (sourceValidation.status === core_frontend_1.MapLayerSourceStatus.RequireAuth);
162
+ const invalidCredentials = (sourceValidation.status === core_frontend_1.MapLayerSourceStatus.InvalidCredentials);
163
+ if (sourceRequireAuth) {
164
+ const settings = source.toLayerSettings();
165
+ if (accessClient !== undefined && accessClient.getTokenServiceEndPoint !== undefined && settings !== undefined) {
166
+ try {
167
+ const tokenEndpoint = await accessClient.getTokenServiceEndPoint(settings.url);
168
+ if (tokenEndpoint !== undefined) {
169
+ const loginUrl = tokenEndpoint.getLoginUrl();
170
+ setExternalLoginUrl(loginUrl);
171
+ }
172
+ }
173
+ catch (_error) {
174
+ }
175
+ }
176
+ }
177
+ setServerRequireCredentials(sourceRequireAuth || invalidCredentials);
178
+ if (invalidCredentials) {
179
+ setInvalidCredentialsProvided(true);
180
+ }
181
+ else if (invalidCredentialsProvided) {
182
+ setInvalidCredentialsProvided(false); // flag reset
183
+ }
184
+ return sourceRequireAuth || invalidCredentials;
185
+ }, [accessClient, invalidCredentialsProvided]);
186
+ const updateAttachedLayer = React.useCallback(async (source, validation) => {
187
+ const vp = props === null || props === void 0 ? void 0 : props.activeViewport;
188
+ if (vp === undefined || source === undefined || layerRequiringCredentialsIdx === undefined) {
189
+ const error = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
190
+ const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
191
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, msg));
192
+ return true;
193
+ }
194
+ // Layer is already attached,
195
+ vp.displayStyle.changeMapLayerProps({
196
+ subLayers: validation.subLayers,
197
+ }, layerRequiringCredentialsIdx, isOverlay);
198
+ vp.displayStyle.changeMapLayerCredentials(layerRequiringCredentialsIdx, isOverlay, source.userName, source.password);
199
+ // Reset the provider's status
200
+ const provider = vp.getMapLayerImageryProvider(layerRequiringCredentialsIdx, isOverlay);
201
+ if (provider && provider.status !== core_frontend_1.MapLayerImageryProviderStatus.Valid) {
202
+ provider.status = core_frontend_1.MapLayerImageryProviderStatus.Valid;
203
+ }
204
+ vp.invalidateRenderPlan();
205
+ // This handler will close the layer source handler, and therefore the MapUrl dialog.
206
+ // don't call it if the dialog needs to remains open.
207
+ onOkResult();
208
+ return true;
209
+ }, [isOverlay, layerRequiringCredentialsIdx, onOkResult, props.activeViewport]);
210
+ // Returns true if no further input is needed from end-user.
211
+ const doAttach = React.useCallback(async (source, validation) => {
212
+ const vp = props === null || props === void 0 ? void 0 : props.activeViewport;
213
+ if (vp === undefined || source === undefined) {
214
+ const error = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
215
+ const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
216
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, msg));
217
+ return true;
218
+ }
219
+ // Update service settings if storage is available and we are not prompting user for credentials
220
+ if (!settingsStorageDisabled && !props.layerRequiringCredentials) {
221
+ const storeOnIModel = (hasImodelContext ? "Model" === settingsStorage : undefined);
222
+ if (vp.iModel.iTwinId && !(await MapLayerPreferences_1.MapLayerPreferences.storeSource(source, vp.iModel.iTwinId, vp.iModel.iModelId, storeOnIModel))) {
223
+ const msgError = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerPreferencesStoreFailed");
224
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, msgError));
225
+ }
226
+ }
227
+ const settings = source.toLayerSettings(validation.subLayers);
228
+ if (settings) {
229
+ vp.displayStyle.attachMapLayer({ settings, isOverlay });
230
+ const msg = core_frontend_1.IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttached", { sourceName: source.name, sourceUrl: source.url });
231
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Info, msg));
232
+ }
233
+ else {
234
+ const msgError = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSettingsConversionError");
235
+ const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MapLayerAttachError", { error: msgError, sourceUrl: source.url });
236
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, msg));
237
+ }
238
+ vp.invalidateRenderPlan();
239
+ // This handler will close the layer source handler, and therefore the MapUrl dialog.
240
+ // don't call it if the dialog needs to remains open.
241
+ onOkResult();
242
+ return true;
243
+ }, [hasImodelContext, isOverlay, onOkResult, props === null || props === void 0 ? void 0 : props.activeViewport, props.layerRequiringCredentials, settingsStorage, settingsStorageDisabled]);
244
+ // Validate the layer source and attempt to attach (or update) the layer.
245
+ // Returns true if no further input is needed from end-user (i.e. close the dialog)
246
+ const attemptAttachSource = React.useCallback(async (source) => {
247
+ try {
248
+ const validation = await source.validateSource(true);
249
+ if (validation.status === core_frontend_1.MapLayerSourceStatus.Valid) {
250
+ if (layerRequiringCredentialsIdx === undefined) {
251
+ return await doAttach(source, validation);
252
+ }
253
+ else {
254
+ return await updateAttachedLayer(source, validation);
255
+ }
256
+ }
257
+ else {
258
+ const authNeeded = await updateAuthState(source, validation);
259
+ if (authNeeded) {
260
+ return false;
261
+ }
262
+ else {
263
+ const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ValidationError");
264
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, `${msg} ${source.url}`));
265
+ return true;
266
+ }
267
+ }
268
+ return false;
269
+ }
270
+ catch (error) {
271
+ const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
272
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.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 = core_frontend_1.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
+ appui_react_1.ModalDialogManager.closeDialog();
305
+ onOkResult();
306
+ if (source === undefined) {
307
+ // Close the dialog and inform end user something went wrong.
308
+ const msgError = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSourceCreationFailed");
309
+ const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error: msgError, sourceUrl: mapUrl });
310
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.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_1.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 = core_frontend_1.IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerEditError", { layerName: (_b = props.mapLayerSourceToEdit) === null || _b === void 0 ? void 0 : _b.name });
324
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.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
+ appui_react_1.ModalDialogManager.closeDialog();
344
+ onOkResult();
345
+ }
346
+ }
347
+ catch (_error) {
348
+ onOkResult();
349
+ appui_react_1.ModalDialogManager.closeDialog();
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 = core_frontend_1.IModelApp.mapLayerFormatRegistry.getAccessClient(exports.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 = core_frontend_1.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: 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(itwinui_react_1.Select, { className: "map-layer-source-select", options: mapTypes, value: mapType, disabled: props.layerRequiringCredentials !== undefined || props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, onChange: setMapType, size: "small" }),
508
+ React.createElement("span", { className: "map-layer-source-label" }, nameLabel),
509
+ React.createElement(itwinui_react_1.Input, { className: "map-layer-source-input", placeholder: nameInputPlaceHolder, onChange: onNameChange, value: mapName, disabled: props.layerRequiringCredentials !== undefined || layerAttachPending || layerAuthPending }),
510
+ React.createElement("span", { className: "map-layer-source-label" }, urlLabel),
511
+ React.createElement(itwinui_react_1.Input, { className: "map-layer-source-input", placeholder: urlInputPlaceHolder, onKeyPress: handleOnKeyDown, onChange: onUrlChange, disabled: props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, value: mapUrl }),
512
+ serverRequireCredentials
513
+ && externalLoginUrl === undefined // external login is handled in popup
514
+ && props.mapLayerSourceToEdit === undefined &&
515
+ React.createElement(React.Fragment, null,
516
+ React.createElement("span", { className: "map-layer-source-label" }, userNameLabel),
517
+ React.createElement(itwinui_react_1.LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", placeholder: serverRequireCredentials ? userNameRequiredLabel : userNameLabel, status: (!userName && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onUsernameChange, value: userName, size: "small" }),
518
+ React.createElement("span", { className: "map-layer-source-label" }, passwordLabel),
519
+ React.createElement(itwinui_react_1.LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", type: "password", placeholder: serverRequireCredentials ? passwordRequiredLabel : passwordLabel, status: (!password && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onPasswordChange, onKeyPress: handleOnKeyDown, value: password, size: "small" })),
520
+ isSettingsStorageAvailable &&
521
+ React.createElement("div", { title: settingsStorageDisabled ? noSaveSettingsWarning : "" }, hasImodelContext &&
522
+ React.createElement("div", null,
523
+ React.createElement(itwinui_react_1.Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "iTwin", label: iTwinSettingsLabel, checked: settingsStorage === "iTwin", onChange: onRadioChange }),
524
+ React.createElement(itwinui_react_1.Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "Model", label: modelSettingsLabel, checked: settingsStorage === "Model", onChange: onRadioChange }))))),
525
+ renderWarningMessage(),
526
+ (layerAttachPending || layerAuthPending) &&
527
+ React.createElement("div", { className: "map-layer-source-progressBar" },
528
+ React.createElement(itwinui_react_1.ProgressLinear, { indeterminate: true })))));
529
+ }
530
+ exports.MapUrlDialog = MapUrlDialog;
531
531
  //# sourceMappingURL=MapUrlDialog.js.map