@itwin/grouping-mapping-widget 0.21.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/lib/cjs/WidgetShell/GroupingMapping.js +5 -1
  2. package/lib/cjs/WidgetShell/GroupingMapping.js.map +1 -1
  3. package/lib/cjs/WidgetShell/GroupingMappingContent.js +5 -1
  4. package/lib/cjs/WidgetShell/GroupingMappingContent.js.map +1 -1
  5. package/lib/cjs/common/hooks/useIsMounted.d.ts +2 -0
  6. package/lib/cjs/common/hooks/useIsMounted.js +20 -0
  7. package/lib/cjs/common/hooks/useIsMounted.js.map +1 -0
  8. package/lib/cjs/common/hooks/useMemoizedCollectionPick.d.ts +2 -0
  9. package/lib/cjs/common/hooks/useMemoizedCollectionPick.js +31 -0
  10. package/lib/cjs/common/hooks/useMemoizedCollectionPick.js.map +1 -0
  11. package/lib/cjs/common/utils.d.ts +1 -0
  12. package/lib/cjs/common/utils.js +13 -1
  13. package/lib/cjs/common/utils.js.map +1 -1
  14. package/lib/cjs/components/Constants.d.ts +4 -0
  15. package/lib/cjs/components/Constants.js +13 -0
  16. package/lib/cjs/components/Constants.js.map +1 -0
  17. package/lib/cjs/components/GroupingMappingContext.d.ts +5 -0
  18. package/lib/cjs/components/GroupingMappingContext.js +56 -26
  19. package/lib/cjs/components/GroupingMappingContext.js.map +1 -1
  20. package/lib/cjs/components/Groups/Editing/GroupAction.js +57 -57
  21. package/lib/cjs/components/Groups/Editing/GroupAction.js.map +1 -1
  22. package/lib/cjs/components/Groups/Editing/GroupDetailsActionPanel.d.ts +1 -1
  23. package/lib/cjs/components/Groups/Editing/GroupDetailsActionPanel.js.map +1 -1
  24. package/lib/cjs/components/Groups/GroupItem.js +1 -1
  25. package/lib/cjs/components/Groups/GroupItem.js.map +1 -1
  26. package/lib/cjs/components/Groups/GroupMenuActions.js +5 -1
  27. package/lib/cjs/components/Groups/GroupMenuActions.js.map +1 -1
  28. package/lib/cjs/components/Groups/Groups.d.ts +3 -2
  29. package/lib/cjs/components/Groups/Groups.js +8 -4
  30. package/lib/cjs/components/Groups/Groups.js.map +1 -1
  31. package/lib/cjs/components/Groups/GroupsShowHideButtons.d.ts +2 -2
  32. package/lib/cjs/components/Groups/GroupsShowHideButtons.js +8 -4
  33. package/lib/cjs/components/Groups/GroupsShowHideButtons.js.map +1 -1
  34. package/lib/cjs/components/Groups/GroupsView.js +1 -1
  35. package/lib/cjs/components/Groups/GroupsView.js.map +1 -1
  36. package/lib/cjs/components/Groups/GroupsVisualization.d.ts +1 -1
  37. package/lib/cjs/components/Groups/GroupsVisualization.js +103 -67
  38. package/lib/cjs/components/Groups/GroupsVisualization.js.map +1 -1
  39. package/lib/cjs/components/Groups/GroupsVisualizationActions.d.ts +6 -4
  40. package/lib/cjs/components/Groups/GroupsVisualizationActions.js +8 -6
  41. package/lib/cjs/components/Groups/GroupsVisualizationActions.js.map +1 -1
  42. package/lib/cjs/components/Groups/GroupsVisualizationActions.scss +1 -0
  43. package/lib/cjs/components/Groups/groupsHelpers.d.ts +19 -7
  44. package/lib/cjs/components/Groups/groupsHelpers.js +11 -70
  45. package/lib/cjs/components/Groups/groupsHelpers.js.map +1 -1
  46. package/lib/cjs/components/Groups/hooks/useFetchGroups.d.ts +5 -0
  47. package/lib/cjs/components/Groups/hooks/useFetchGroups.js +18 -0
  48. package/lib/cjs/components/Groups/hooks/useFetchGroups.js.map +1 -0
  49. package/lib/cjs/components/Groups/hooks/useGroupsOperations.d.ts +1 -5
  50. package/lib/cjs/components/Groups/hooks/useGroupsOperations.js +17 -31
  51. package/lib/cjs/components/Groups/hooks/useGroupsOperations.js.map +1 -1
  52. package/lib/cjs/components/Groups/hooks/useKeySetHiliteQueries.d.ts +32 -0
  53. package/lib/cjs/components/Groups/hooks/useKeySetHiliteQueries.js +31 -0
  54. package/lib/cjs/components/Groups/hooks/useKeySetHiliteQueries.js.map +1 -0
  55. package/lib/cjs/components/Groups/hooks/useVisualization.js +4 -4
  56. package/lib/cjs/components/Groups/hooks/useVisualization.js.map +1 -1
  57. package/lib/cjs/components/Mappings/Editing/MappingAction.js +26 -31
  58. package/lib/cjs/components/Mappings/Editing/MappingAction.js.map +1 -1
  59. package/lib/cjs/components/Mappings/Extraction/ExtractionLogCustomFilter.js +5 -1
  60. package/lib/cjs/components/Mappings/Extraction/ExtractionLogCustomFilter.js.map +1 -1
  61. package/lib/cjs/components/Mappings/Extraction/ExtractionMessageModal.d.ts +6 -1
  62. package/lib/cjs/components/Mappings/Extraction/ExtractionMessageModal.js +51 -40
  63. package/lib/cjs/components/Mappings/Extraction/ExtractionMessageModal.js.map +1 -1
  64. package/lib/cjs/components/Mappings/Extraction/ExtractionStatusIcon.d.ts +7 -1
  65. package/lib/cjs/components/Mappings/Extraction/ExtractionStatusIcon.js.map +1 -1
  66. package/lib/cjs/components/Mappings/{ConfirmMappingsImport.d.ts → Import/ConfirmMappingsImport.d.ts} +1 -1
  67. package/lib/cjs/components/Mappings/{ConfirmMappingsImport.js → Import/ConfirmMappingsImport.js} +32 -21
  68. package/lib/cjs/components/Mappings/Import/ConfirmMappingsImport.js.map +1 -0
  69. package/lib/cjs/components/Mappings/Import/MappingImportWizardModal.js +9 -8
  70. package/lib/cjs/components/Mappings/Import/MappingImportWizardModal.js.map +1 -1
  71. package/lib/cjs/components/Mappings/Import/SelectIModel.js +35 -50
  72. package/lib/cjs/components/Mappings/Import/SelectIModel.js.map +1 -1
  73. package/lib/cjs/components/Mappings/Import/SelectITwin.d.ts +6 -1
  74. package/lib/cjs/components/Mappings/Import/SelectITwin.js +44 -53
  75. package/lib/cjs/components/Mappings/Import/SelectITwin.js.map +1 -1
  76. package/lib/cjs/components/Mappings/Import/SelectMappings.js +18 -37
  77. package/lib/cjs/components/Mappings/Import/SelectMappings.js.map +1 -1
  78. package/lib/cjs/components/Mappings/Mappings.js +5 -27
  79. package/lib/cjs/components/Mappings/Mappings.js.map +1 -1
  80. package/lib/cjs/components/Mappings/MappingsView.d.ts +5 -4
  81. package/lib/cjs/components/Mappings/MappingsView.js +33 -7
  82. package/lib/cjs/components/Mappings/MappingsView.js.map +1 -1
  83. package/lib/cjs/components/Mappings/hooks/useFetchExtractionStatus.d.ts +13 -0
  84. package/lib/cjs/components/Mappings/hooks/useFetchExtractionStatus.js +50 -0
  85. package/lib/cjs/components/Mappings/hooks/useFetchExtractionStatus.js.map +1 -0
  86. package/lib/cjs/components/Mappings/hooks/useFetchMappings.d.ts +4 -0
  87. package/lib/cjs/components/Mappings/hooks/useFetchMappings.js +14 -0
  88. package/lib/cjs/components/Mappings/hooks/useFetchMappings.js.map +1 -0
  89. package/lib/cjs/components/Mappings/hooks/useMappingsOperations.d.ts +9 -10
  90. package/lib/cjs/components/Mappings/hooks/useMappingsOperations.js +35 -108
  91. package/lib/cjs/components/Mappings/hooks/useMappingsOperations.js.map +1 -1
  92. package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyAction.js +5 -1
  93. package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyAction.js.map +1 -1
  94. package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyActionWithVisuals.js +16 -21
  95. package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyActionWithVisuals.js.map +1 -1
  96. package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyTable.js +5 -1
  97. package/lib/cjs/components/Properties/CalculatedProperties/CalculatedPropertyTable.js.map +1 -1
  98. package/lib/cjs/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.js +5 -1
  99. package/lib/cjs/components/Properties/CalculatedProperties/SharedCalculatedPropertyForms.js.map +1 -1
  100. package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationAction.js +5 -1
  101. package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationAction.js.map +1 -1
  102. package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationTable.js +5 -1
  103. package/lib/cjs/components/Properties/CustomCalculations/CustomCalculationTable.js.map +1 -1
  104. package/lib/cjs/components/Properties/GroupColorToggle.js +13 -10
  105. package/lib/cjs/components/Properties/GroupColorToggle.js.map +1 -1
  106. package/lib/cjs/components/Properties/GroupProperties/GroupPropertyAction.js +7 -3
  107. package/lib/cjs/components/Properties/GroupProperties/GroupPropertyAction.js.map +1 -1
  108. package/lib/cjs/components/Properties/GroupProperties/GroupPropertyTable.js +5 -1
  109. package/lib/cjs/components/Properties/GroupProperties/GroupPropertyTable.js.map +1 -1
  110. package/lib/cjs/components/Properties/GroupProperties/SortableHorizontalTile.js +5 -1
  111. package/lib/cjs/components/Properties/GroupProperties/SortableHorizontalTile.js.map +1 -1
  112. package/lib/cjs/components/Properties/PropertyAction.js +5 -1
  113. package/lib/cjs/components/Properties/PropertyAction.js.map +1 -1
  114. package/lib/cjs/components/Properties/PropertyMenu.js +5 -1
  115. package/lib/cjs/components/Properties/PropertyMenu.js.map +1 -1
  116. package/lib/cjs/components/Properties/PropertyMenuWithVisualization.js +5 -1
  117. package/lib/cjs/components/Properties/PropertyMenuWithVisualization.js.map +1 -1
  118. package/lib/cjs/components/Properties/PropertyTable.js +7 -2
  119. package/lib/cjs/components/Properties/PropertyTable.js.map +1 -1
  120. package/lib/cjs/components/SharedComponents/ActionPanel.js +5 -1
  121. package/lib/cjs/components/SharedComponents/ActionPanel.js.map +1 -1
  122. package/lib/cjs/components/SharedComponents/DeleteModal.d.ts +2 -2
  123. package/lib/cjs/components/SharedComponents/DeleteModal.js +20 -20
  124. package/lib/cjs/components/SharedComponents/DeleteModal.js.map +1 -1
  125. package/lib/cjs/components/context/GroupHilitedElementsContext.d.ts +9 -16
  126. package/lib/cjs/components/context/GroupHilitedElementsContext.js +13 -10
  127. package/lib/cjs/components/context/GroupHilitedElementsContext.js.map +1 -1
  128. package/lib/cjs/components/context/GroupingApiConfigContext.js +5 -1
  129. package/lib/cjs/components/context/GroupingApiConfigContext.js.map +1 -1
  130. package/lib/cjs/components/context/PropertiesContext.js +5 -1
  131. package/lib/cjs/components/context/PropertiesContext.js.map +1 -1
  132. package/lib/cjs/components/context/PropertyGridWrapperContext.js +5 -1
  133. package/lib/cjs/components/context/PropertyGridWrapperContext.js.map +1 -1
  134. package/lib/cjs/components/customUI/GroupQueryBuilderCustomUI.js +5 -1
  135. package/lib/cjs/components/customUI/GroupQueryBuilderCustomUI.js.map +1 -1
  136. package/lib/cjs/formula/FormulaFunctionProvider.js +10 -1
  137. package/lib/cjs/formula/FormulaFunctionProvider.js.map +1 -1
  138. package/lib/cjs/grouping-mapping-widget.js +5 -1
  139. package/lib/cjs/grouping-mapping-widget.js.map +1 -1
  140. package/lib/cjs/test/GroupingMappingCustomUI.test.js +5 -1
  141. package/lib/cjs/test/GroupingMappingCustomUI.test.js.map +1 -1
  142. package/lib/cjs/test/MockFactory.js +5 -1
  143. package/lib/cjs/test/MockFactory.js.map +1 -1
  144. package/lib/cjs/test/PropertyFieldsHelpers.d.ts +4 -20
  145. package/lib/cjs/test/test-utils.js +13 -1
  146. package/lib/cjs/test/test-utils.js.map +1 -1
  147. package/lib/esm/common/hooks/useIsMounted.d.ts +2 -0
  148. package/lib/esm/common/hooks/useIsMounted.js +16 -0
  149. package/lib/esm/common/hooks/useIsMounted.js.map +1 -0
  150. package/lib/esm/common/hooks/useMemoizedCollectionPick.d.ts +2 -0
  151. package/lib/esm/common/hooks/useMemoizedCollectionPick.js +27 -0
  152. package/lib/esm/common/hooks/useMemoizedCollectionPick.js.map +1 -0
  153. package/lib/esm/common/utils.d.ts +1 -0
  154. package/lib/esm/common/utils.js +11 -0
  155. package/lib/esm/common/utils.js.map +1 -1
  156. package/lib/esm/components/Constants.d.ts +4 -0
  157. package/lib/esm/components/Constants.js +10 -0
  158. package/lib/esm/components/Constants.js.map +1 -0
  159. package/lib/esm/components/GroupingMappingContext.d.ts +5 -0
  160. package/lib/esm/components/GroupingMappingContext.js +52 -26
  161. package/lib/esm/components/GroupingMappingContext.js.map +1 -1
  162. package/lib/esm/components/Groups/Editing/GroupAction.js +53 -57
  163. package/lib/esm/components/Groups/Editing/GroupAction.js.map +1 -1
  164. package/lib/esm/components/Groups/Editing/GroupDetailsActionPanel.d.ts +1 -1
  165. package/lib/esm/components/Groups/Editing/GroupDetailsActionPanel.js.map +1 -1
  166. package/lib/esm/components/Groups/GroupItem.js +1 -1
  167. package/lib/esm/components/Groups/GroupItem.js.map +1 -1
  168. package/lib/esm/components/Groups/Groups.d.ts +3 -2
  169. package/lib/esm/components/Groups/Groups.js +3 -3
  170. package/lib/esm/components/Groups/Groups.js.map +1 -1
  171. package/lib/esm/components/Groups/GroupsShowHideButtons.d.ts +2 -2
  172. package/lib/esm/components/Groups/GroupsShowHideButtons.js +3 -3
  173. package/lib/esm/components/Groups/GroupsShowHideButtons.js.map +1 -1
  174. package/lib/esm/components/Groups/GroupsView.js +1 -1
  175. package/lib/esm/components/Groups/GroupsView.js.map +1 -1
  176. package/lib/esm/components/Groups/GroupsVisualization.d.ts +1 -1
  177. package/lib/esm/components/Groups/GroupsVisualization.js +100 -68
  178. package/lib/esm/components/Groups/GroupsVisualization.js.map +1 -1
  179. package/lib/esm/components/Groups/GroupsVisualizationActions.d.ts +6 -4
  180. package/lib/esm/components/Groups/GroupsVisualizationActions.js +9 -7
  181. package/lib/esm/components/Groups/GroupsVisualizationActions.js.map +1 -1
  182. package/lib/esm/components/Groups/GroupsVisualizationActions.scss +1 -0
  183. package/lib/esm/components/Groups/groupsHelpers.d.ts +19 -7
  184. package/lib/esm/components/Groups/groupsHelpers.js +10 -67
  185. package/lib/esm/components/Groups/groupsHelpers.js.map +1 -1
  186. package/lib/esm/components/Groups/hooks/useFetchGroups.d.ts +5 -0
  187. package/lib/esm/components/Groups/hooks/useFetchGroups.js +13 -0
  188. package/lib/esm/components/Groups/hooks/useFetchGroups.js.map +1 -0
  189. package/lib/esm/components/Groups/hooks/useGroupsOperations.d.ts +1 -5
  190. package/lib/esm/components/Groups/hooks/useGroupsOperations.js +18 -32
  191. package/lib/esm/components/Groups/hooks/useGroupsOperations.js.map +1 -1
  192. package/lib/esm/components/Groups/hooks/useKeySetHiliteQueries.d.ts +32 -0
  193. package/lib/esm/components/Groups/hooks/useKeySetHiliteQueries.js +25 -0
  194. package/lib/esm/components/Groups/hooks/useKeySetHiliteQueries.js.map +1 -0
  195. package/lib/esm/components/Groups/hooks/useVisualization.js +4 -4
  196. package/lib/esm/components/Groups/hooks/useVisualization.js.map +1 -1
  197. package/lib/esm/components/Mappings/Editing/MappingAction.js +22 -31
  198. package/lib/esm/components/Mappings/Editing/MappingAction.js.map +1 -1
  199. package/lib/esm/components/Mappings/Extraction/ExtractionMessageModal.d.ts +6 -1
  200. package/lib/esm/components/Mappings/Extraction/ExtractionMessageModal.js +46 -39
  201. package/lib/esm/components/Mappings/Extraction/ExtractionMessageModal.js.map +1 -1
  202. package/lib/esm/components/Mappings/Extraction/ExtractionStatusIcon.d.ts +7 -1
  203. package/lib/esm/components/Mappings/Extraction/ExtractionStatusIcon.js.map +1 -1
  204. package/lib/esm/components/Mappings/{ConfirmMappingsImport.d.ts → Import/ConfirmMappingsImport.d.ts} +1 -1
  205. package/lib/esm/components/Mappings/{ConfirmMappingsImport.js → Import/ConfirmMappingsImport.js} +27 -20
  206. package/lib/esm/components/Mappings/Import/ConfirmMappingsImport.js.map +1 -0
  207. package/lib/esm/components/Mappings/Import/MappingImportWizardModal.js +4 -7
  208. package/lib/esm/components/Mappings/Import/MappingImportWizardModal.js.map +1 -1
  209. package/lib/esm/components/Mappings/Import/SelectIModel.js +31 -50
  210. package/lib/esm/components/Mappings/Import/SelectIModel.js.map +1 -1
  211. package/lib/esm/components/Mappings/Import/SelectITwin.d.ts +6 -1
  212. package/lib/esm/components/Mappings/Import/SelectITwin.js +39 -53
  213. package/lib/esm/components/Mappings/Import/SelectITwin.js.map +1 -1
  214. package/lib/esm/components/Mappings/Import/SelectMappings.js +14 -37
  215. package/lib/esm/components/Mappings/Import/SelectMappings.js.map +1 -1
  216. package/lib/esm/components/Mappings/Mappings.js +3 -9
  217. package/lib/esm/components/Mappings/Mappings.js.map +1 -1
  218. package/lib/esm/components/Mappings/MappingsView.d.ts +5 -4
  219. package/lib/esm/components/Mappings/MappingsView.js +10 -7
  220. package/lib/esm/components/Mappings/MappingsView.js.map +1 -1
  221. package/lib/esm/components/Mappings/hooks/useFetchExtractionStatus.d.ts +13 -0
  222. package/lib/esm/components/Mappings/hooks/useFetchExtractionStatus.js +46 -0
  223. package/lib/esm/components/Mappings/hooks/useFetchExtractionStatus.js.map +1 -0
  224. package/lib/esm/components/Mappings/hooks/useFetchMappings.d.ts +4 -0
  225. package/lib/esm/components/Mappings/hooks/useFetchMappings.js +10 -0
  226. package/lib/esm/components/Mappings/hooks/useFetchMappings.js.map +1 -0
  227. package/lib/esm/components/Mappings/hooks/useMappingsOperations.d.ts +9 -10
  228. package/lib/esm/components/Mappings/hooks/useMappingsOperations.js +36 -109
  229. package/lib/esm/components/Mappings/hooks/useMappingsOperations.js.map +1 -1
  230. package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyActionWithVisuals.js +13 -22
  231. package/lib/esm/components/Properties/CalculatedProperties/CalculatedPropertyActionWithVisuals.js.map +1 -1
  232. package/lib/esm/components/Properties/GroupColorToggle.js +9 -10
  233. package/lib/esm/components/Properties/GroupColorToggle.js.map +1 -1
  234. package/lib/esm/components/Properties/GroupProperties/GroupPropertyAction.js +3 -3
  235. package/lib/esm/components/Properties/GroupProperties/GroupPropertyAction.js.map +1 -1
  236. package/lib/esm/components/Properties/PropertyTable.js +2 -1
  237. package/lib/esm/components/Properties/PropertyTable.js.map +1 -1
  238. package/lib/esm/components/SharedComponents/DeleteModal.d.ts +2 -2
  239. package/lib/esm/components/SharedComponents/DeleteModal.js +16 -20
  240. package/lib/esm/components/SharedComponents/DeleteModal.js.map +1 -1
  241. package/lib/esm/components/context/GroupHilitedElementsContext.d.ts +9 -16
  242. package/lib/esm/components/context/GroupHilitedElementsContext.js +8 -9
  243. package/lib/esm/components/context/GroupHilitedElementsContext.js.map +1 -1
  244. package/lib/esm/formula/FormulaFunctionProvider.js +10 -1
  245. package/lib/esm/formula/FormulaFunctionProvider.js.map +1 -1
  246. package/lib/esm/test/PropertyFieldsHelpers.d.ts +4 -20
  247. package/lib/esm/test/test-utils.js +8 -0
  248. package/lib/esm/test/test-utils.js.map +1 -1
  249. package/package.json +35 -31
  250. package/lib/cjs/components/Mappings/ConfirmMappingsImport.js.map +0 -1
  251. package/lib/cjs/components/context/ExtractionStatusDataContext.d.ts +0 -20
  252. package/lib/cjs/components/context/ExtractionStatusDataContext.js +0 -26
  253. package/lib/cjs/components/context/ExtractionStatusDataContext.js.map +0 -1
  254. package/lib/esm/components/Mappings/ConfirmMappingsImport.js.map +0 -1
  255. package/lib/esm/components/context/ExtractionStatusDataContext.d.ts +0 -20
  256. package/lib/esm/components/context/ExtractionStatusDataContext.js +0 -22
  257. package/lib/esm/components/context/ExtractionStatusDataContext.js.map +0 -1
  258. /package/lib/cjs/components/Mappings/{ConfirmMappingsImport.scss → Import/ConfirmMappingsImport.scss} +0 -0
  259. /package/lib/esm/components/Mappings/{ConfirmMappingsImport.scss → Import/ConfirmMappingsImport.scss} +0 -0
@@ -3,9 +3,7 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import { FeatureOverrideType } from "@itwin/core-common";
6
- import { toaster } from "@itwin/itwinui-react";
7
- import { KeySet } from "@itwin/presentation-common";
8
- import { clearEmphasizedOverriddenElements, clearHiddenElements, emphasizeElements, getHiliteIds, hideElements, overrideElements, zoomToElements } from "../../common/viewerUtils";
6
+ import { clearEmphasizedOverriddenElements, clearHiddenElements, emphasizeElements, getHiliteIds, hideElements, overrideElements } from "../../common/viewerUtils";
9
7
  const GOLDEN_ANGLE_MULTIPLIER = 1.5; // Multiplier to spread colors more uniformly.
10
8
  const BASE_HUE_OFFSET = 60; // Initial hue offset to avoid certain colors e.g 0 offset would begin with red.
11
9
  const HUE_ADJUSTMENT_STEP = 15; // Step to adjust the hue to avoid the red spectrum.
@@ -22,34 +20,6 @@ export const getGroupColor = (index) => {
22
20
  }
23
21
  return generateHSL(hue);
24
22
  };
25
- export const getHiliteIdsFromGroups = async (iModelConnection, groups, hilitedElementsQueryCache) => {
26
- const distinctQueries = new Set();
27
- const promises = [];
28
- for (const group of groups) {
29
- if (!distinctQueries.has(group.query)) {
30
- distinctQueries.add(group.query);
31
- promises.push(getHiliteIdsAndKeysetFromGroup(iModelConnection, group, hilitedElementsQueryCache));
32
- }
33
- }
34
- const results = await Promise.all(promises);
35
- const allIds = results.flatMap((result) => result.ids);
36
- return allIds;
37
- };
38
- export const hideGroups = async (iModelConnection, viewGroups, hilitedElementsQueryCache) => {
39
- const distinctQueries = new Set();
40
- const promises = [];
41
- for (const viewGroup of viewGroups) {
42
- if (!distinctQueries.has(viewGroup.query)) {
43
- distinctQueries.add(viewGroup.query);
44
- promises.push(hideGroup(iModelConnection, viewGroup, hilitedElementsQueryCache));
45
- }
46
- }
47
- await Promise.all(promises);
48
- };
49
- export const hideGroup = async (iModelConnection, viewGroup, hilitedElementsQueryCache) => {
50
- const result = await getHiliteIdsAndKeysetFromGroup(iModelConnection, viewGroup, hilitedElementsQueryCache);
51
- hideElements(result.ids);
52
- };
53
23
  const processGroupVisualization = async (overlappedElementGroupPairs, hiddenGroupsIds, doEmphasizeElements, color, replace, setNumberOfVisualizedGroups) => {
54
24
  const hilitedIds = Array.from(overlappedElementGroupPairs.elementIds);
55
25
  overrideElements(hilitedIds, color, FeatureOverrideType.ColorAndAlpha, replace);
@@ -62,12 +32,8 @@ const processGroupVisualization = async (overlappedElementGroupPairs, hiddenGrou
62
32
  }
63
33
  return hilitedIds;
64
34
  };
65
- export const visualizeGroupColors = async (iModelConnection, groups, hiddenGroupsIds, hilitedElementsQueryCache, setNumberOfVisualizedGroups, setOverlappedElementsInfo, setGroupElementsInfo, setOverlappedElementGroupPairs, doEmphasizeElements = true) => {
35
+ export const visualizeGroupColors = async (hiddenGroupsIds, groupsWithGroupedOverlaps, setNumberOfVisualizedGroups, doEmphasizeElements = true) => {
66
36
  clearEmphasizedOverriddenElements();
67
- const { groupsWithGroupedOverlaps, overlappedElementsInfo, numberOfElementsInGroups } = await generateOverlappedGroups(groups, iModelConnection, hilitedElementsQueryCache);
68
- setOverlappedElementsInfo(overlappedElementsInfo);
69
- setGroupElementsInfo(numberOfElementsInGroups);
70
- setOverlappedElementGroupPairs(groupsWithGroupedOverlaps);
71
37
  const singleGroupPromises = groupsWithGroupedOverlaps
72
38
  .filter((group) => group.groupIds.size === 1)
73
39
  .map(async (group, index) => processGroupVisualization(group, hiddenGroupsIds, doEmphasizeElements, getGroupColor(index), // color for single group
@@ -78,36 +44,17 @@ export const visualizeGroupColors = async (iModelConnection, groups, hiddenGroup
78
44
  .map(async (group) => processGroupVisualization(group, hiddenGroupsIds, doEmphasizeElements, generateHSL(0), // color for group of overlapped elements
79
45
  false, setNumberOfVisualizedGroups));
80
46
  clearHiddenElements();
81
- hiddenGroupsIds.forEach(async (groupId) => {
82
- await hideGroupConsideringOverlaps(groupsWithGroupedOverlaps, groupId, hiddenGroupsIds);
47
+ hiddenGroupsIds.forEach((groupId) => {
48
+ hideGroupConsideringOverlaps(groupsWithGroupedOverlaps, groupId, hiddenGroupsIds);
83
49
  });
84
50
  const allPromises = [...singleGroupPromises, ...overlappedGroupPromises];
85
51
  const allIds = (await Promise.all(allPromises)).flat();
86
- await zoomToElements(allIds);
52
+ return allIds;
87
53
  };
88
- export const getHiliteIdsAndKeysetFromGroup = async (iModelConnection, group, hilitedElementsQueryCache) => {
54
+ export const getHiliteIdsAndKeysetFromGroup = async (iModelConnection, group) => {
89
55
  const query = group.query;
90
- if (hilitedElementsQueryCache.current.has(query)) {
91
- return hilitedElementsQueryCache.current.get(query) ?? ({ keySet: new KeySet(), ids: [] });
92
- }
93
- try {
94
- const queryRowCount = await iModelConnection.queryRowCount(query);
95
- if (queryRowCount === 0) {
96
- toaster.warning(`${group.groupName}'s query is valid but produced no results.`);
97
- }
98
- const result = await getHiliteIds(query, iModelConnection);
99
- hilitedElementsQueryCache.current.set(query, result);
100
- return result;
101
- }
102
- catch {
103
- toaster.negative(`Query could not be resolved.`);
104
- return ({ keySet: new KeySet(), ids: [] });
105
- }
106
- };
107
- const getHiliteIdsForGroup = async (iModelConnection, group, hilitedElementsQueryCache) => {
108
- const result = await getHiliteIdsAndKeysetFromGroup(iModelConnection, group, hilitedElementsQueryCache);
109
- const hilitedIds = result.ids;
110
- return hilitedIds;
56
+ const result = await getHiliteIds(query, iModelConnection);
57
+ return { group, result };
111
58
  };
112
59
  const getOverlappedElementsInfo = (overlappedElements) => {
113
60
  const overlappedElementsInfo = new Map();
@@ -137,11 +84,7 @@ const mergeElementsByGroup = (elems) => {
137
84
  });
138
85
  return mergedList;
139
86
  };
140
- const generateOverlappedGroups = async (groups, iModelConnection, hilitedElementsQueryCache) => {
141
- const groupsElementIds = await Promise.all(groups.map(async (group) => ({
142
- groupId: group.id,
143
- elementIds: await getHiliteIdsForGroup(iModelConnection, group, hilitedElementsQueryCache),
144
- })));
87
+ export const generateOverlappedGroups = (groupsElementIds) => {
145
88
  const elems = new Map();
146
89
  const groupElementCount = new Map();
147
90
  // Build the elems map for associations between elements and their groups.
@@ -163,7 +106,7 @@ const generateOverlappedGroups = async (groups, iModelConnection, hilitedElement
163
106
  const overlappedGroupsInformation = Array.from(mergedList.values()).filter((value) => value.groupIds.size > 1);
164
107
  return { groupsWithGroupedOverlaps: [...allGroups, ...overlappedGroupsInformation], overlappedElementsInfo: getOverlappedElementsInfo(overlappedGroupsInformation), numberOfElementsInGroups: groupElementCount };
165
108
  };
166
- export const hideGroupConsideringOverlaps = async (overlappedElementGroupPairs, groupIdToHide, hiddenGroupsIds) => {
109
+ export const hideGroupConsideringOverlaps = (overlappedElementGroupPairs, groupIdToHide, hiddenGroupsIds) => {
167
110
  const elementsToPotentiallyHide = new Set();
168
111
  // Check each entry in overlappedElementGroupPairs
169
112
  for (const entry of overlapp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Q,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;YACrC,4FAA4F;YAC5F,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE;gBAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,EAAE;oBACnC,yBAAyB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;iBACrC;aACF;iBAAM;gBACL,wEAAwE;gBACxE,MAAM,oBAAoB,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,CAC3D,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,KAAK,aAAa,IAAI,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAC5D,CAAC;gBACF,IAAI,oBAAoB,EAAE;oBACxB,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,EAAE;wBACnC,yBAAyB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;qBACrC;iBACF;aACF;SACF;KACF;IAED,qDAAqD;IACrD,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { FeatureOverrideType } from \"@itwin/core-common\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { Group } from \"@itwin/insights-client\";\nimport { toaster } from \"@itwin/itwinui-react\";\nimport { KeySet } from \"@itwin/presentation-common\";\nimport type { OverlappedElementGroupPairs, OverlappedInfo, QueryCacheItem } from \"../context/GroupHilitedElementsContext\";\nimport { clearEmphasizedOverriddenElements, clearHiddenElements, emphasizeElements, getHiliteIds, hideElements, overrideElements, zoomToElements } from \"../../common/viewerUtils\";\n\nconst GOLDEN_ANGLE_MULTIPLIER = 1.5; // Multiplier to spread colors more uniformly.\nconst BASE_HUE_OFFSET = 60; // Initial hue offset to avoid certain colors e.g 0 offset would begin with red.\nconst HUE_ADJUSTMENT_STEP = 15; // Step to adjust the hue to avoid the red spectrum.\nconst RED_HUE_LOWER_BOUND = 330; // Lower bound of the red hue spectrum to avoid.\nconst RED_HUE_UPPER_BOUND = 30; // Upper bound of the red hue spectrum to avoid.\nconst GOLDENANGLE = 180 * (3 - Math.sqrt(5));\n\nconst generateHSL = (hue: number, saturation: number = 100, lightness: number = 50) => {\n return `hsl(${hue}, ${saturation}%, ${lightness}%)`;\n};\n\nexport const getGroupColor = (index: number) => {\n let hue = (index * GOLDENANGLE * GOLDEN_ANGLE_MULTIPLIER + BASE_HUE_OFFSET) % 360;\n\n while (hue >= RED_HUE_LOWER_BOUND || hue <= RED_HUE_UPPER_BOUND) {\n hue = (hue + HUE_ADJUSTMENT_STEP) % 360;\n }\n\n return generateHSL(hue);\n};\n\nexport const getHiliteIdsFromGroups = async (\n iModelConnection: IModelConnection,\n groups: Group[],\n hilitedElementsQueryCache: React.MutableRefObject<Map<string, QueryCacheItem>>\n) => {\n const distinctQueries = new Set<string>();\n const promises: Promise<{ ids: string[] }>[] = [];\n for (const group of groups) {\n if (!distinctQueries.has(group.query)) {\n distinctQueries.add(group.query);\n promises.push(getHiliteIdsAndKeysetFromGroup(iModelConnection, group, hilitedElementsQueryCache));\n }\n }\n const results = await Promise.all(promises);\n const allIds = results.flatMap((result) => result.ids);\n return allIds;\n};\n\nexport const hideGroups = async (\n iModelConnection: IModelConnection,\n viewGroups: Group[],\n hilitedElementsQueryCache: React.MutableRefObject<Map<string, QueryCacheItem>>\n) => {\n const distinctQueries = new Set<string>();\n const promises: Promise<void>[] = [];\n\n for (const viewGroup of viewGroups) {\n if (!distinctQueries.has(viewGroup.query)) {\n distinctQueries.add(viewGroup.query);\n promises.push(hideGroup(iModelConnection, viewGroup, hilitedElementsQueryCache));\n }\n }\n await Promise.all(promises);\n};\n\nexport const hideGroup = async (\n iModelConnection: IModelConnection,\n viewGroup: Group,\n hilitedElementsQueryCache: React.MutableRefObject<Map<string, QueryCacheItem>>\n) => {\n const result = await getHiliteIdsAndKeysetFromGroup(iModelConnection, viewGroup, hilitedElementsQueryCache);\n hideElements(result.ids);\n};\n\nconst processGroupVisualization = async (\n overlappedElementGroupPairs: OverlappedElementGroupPairs,\n hiddenGroupsIds: Set<string>,\n doEmphasizeElements: boolean,\n color: string,\n replace: boolean,\n setNumberOfVisualizedGroups: (numberOfVisualizedGroups: number | ((numberOfVisualizedGroups: number) => number)) => void,\n) => {\n const hilitedIds = Array.from(overlappedElementGroupPairs.elementIds);\n\n overrideElements(hilitedIds, color, FeatureOverrideType.ColorAndAlpha, replace);\n setNumberOfVisualizedGroups((numberOfVisualizedGroups) => numberOfVisualizedGroups + 1);\n\n doEmphasizeElements && emphasizeElements(hilitedIds, undefined);\n\n for (const id of overlappedElementGroupPairs.groupIds) {\n if (hiddenGroupsIds.has(id)) {\n return [];\n }\n }\n return hilitedIds;\n};\n\nexport const visualizeGroupColors = async (\n iModelConnection: IModelConnection,\n groups: Group[],\n hiddenGroupsIds: Set<string>,\n hilitedElementsQueryCache: React.MutableRefObject<Map<string, QueryCacheItem>>,\n setNumberOfVisualizedGroups: (numberOfVisualizedGroups: number | ((numberOfVisualizedGroups: number) => number)) => void,\n setOverlappedElementsInfo: (overlappedElementsInfo: Map<string, OverlappedInfo[]> | ((overlappedElementsInfo: Map<string, OverlappedInfo[]>) => Map<string, OverlappedInfo[]>)) => void,\n setGroupElementsInfo: (groupElementsInfo: Map<string, number> | ((groupElementsInfo: Map<string, number>) => Map<string, number>)) => void,\n setOverlappedElementGroupPairs: (overlappedElementGroupPairs: OverlappedElementGroupPairs[]) => void,\n doEmphasizeElements: boolean = true,\n) => {\n clearEmphasizedOverriddenElements();\n\n const { groupsWithGroupedOverlaps, overlappedElementsInfo, numberOfElementsInGroups } = await generateOverlappedGroups(groups, iModelConnection, hilitedElementsQueryCache);\n setOverlappedElementsInfo(overlappedElementsInfo);\n setGroupElementsInfo(numberOfElementsInGroups);\n setOverlappedElementGroupPairs(groupsWithGroupedOverlaps);\n\n const singleGroupPromises = groupsWithGroupedOverlaps\n .filter((group) => group.groupIds.size === 1)\n .map(async (group, index) =>\n processGroupVisualization(\n group,\n hiddenGroupsIds,\n doEmphasizeElements,\n getGroupColor(index), // color for single group\n false, // Shouldn't matter as replacement only accounts for same colored overrides.\n setNumberOfVisualizedGroups,\n )\n );\n\n const overlappedGroupPromises = groupsWithGroupedOverlaps\n .filter((group) => group.groupIds.size !== 1)\n .map(async (group) =>\n processGroupVisualization(\n group,\n hiddenGroupsIds,\n doEmphasizeElements,\n generateHSL(0), // color for group of overlapped elements\n false,\n setNumberOfVisualizedGroups,\n )\n );\n\n clearHiddenElements();\n\n hiddenGroupsIds.forEach(async (groupId) => {\n await hideGroupConsideringOverlaps(groupsWithGroupedOverlaps, groupId, hiddenGroupsIds);\n });\n\n const allPromises = [...singleGroupPromises, ...overlappedGroupPromises];\n\n const allIds = (await Promise.all(allPromises)).flat();\n\n await zoomToElements(allIds);\n};\n\nexport const getHiliteIdsAndKeysetFromGroup = async (\n iModelConnection: IModelConnection,\n group: Group,\n hilitedElementsQueryCache: React.MutableRefObject<Map<string, QueryCacheItem>>\n) => {\n const query = group.query;\n if (hilitedElementsQueryCache.current.has(query)) {\n return hilitedElementsQueryCache.current.get(query) ?? ({ keySet: new KeySet(), ids: [] });\n }\n try {\n const queryRowCount = await iModelConnection.queryRowCount(query);\n if (queryRowCount === 0) {\n toaster.warning(\n `${group.groupName}'s query is valid but produced no results.`\n );\n }\n const result = await getHiliteIds(query, iModelConnection);\n hilitedElementsQueryCache.current.set(query, result);\n return result;\n } catch {\n toaster.negative(\n `Query could not be resolved.`\n );\n return ({ keySet: new KeySet(), ids: [] });\n }\n\n};\n\nconst getHiliteIdsForGroup = async (\n iModelConnection: IModelConnection,\n group: Group,\n hilitedElementsQueryCache: React.MutableRefObject<Map<string, QueryCacheItem>>,\n) => {\n const result = await getHiliteIdsAndKeysetFromGroup(iModelConnection, group, hilitedElementsQueryCache);\n const hilitedIds = result.ids;\n return hilitedIds;\n};\n\nconst getOverlappedElementsInfo = (overlappedElements: OverlappedElementGroupPairs[]) => {\n const overlappedElementsInfo: Map<string, OverlappedInfo[]> = new Map();\n\n overlappedElements.forEach((elementGroup) => {\n const { elementIds, groupIds } = elementGroup;\n\n groupIds.forEach((group) => {\n const otherGroups = Array.from(groupIds).filter((grp) => grp !== group);\n const overlappedInfoArray = overlappedElementsInfo.get(group) ?? [];\n overlappedInfoArray.push({ groupIds: otherGroups, elements: Array.from(elementIds) });\n overlappedElementsInfo.set(group, overlappedInfoArray);\n });\n });\n return overlappedElementsInfo;\n};\n\nconst mergeElementsByGroup = (elems: Map<string, Set<string>>) => {\n const mergedList: Map<string, OverlappedElementGroupPairs> = new Map();\n elems.forEach((groupIds, elementId) => {\n const sortedGroups = Array.from(groupIds).sort();\n const key = sortedGroups.join(\"-\");\n const overlap = mergedList.get(key);\n if (overlap) {\n overlap.elementIds.add(elementId);\n } else {\n mergedList.set(key, { elementIds: new Set([elementId]), groupIds });\n }\n });\n return mergedList;\n};\n\nconst generateOverlappedGroups = async (\n groups: Group[],\n iModelConnection: IModelConnection,\n hilitedElementsQueryCache: React.MutableRefObject<Map<string, QueryCacheItem>>,\n) => {\n const groupsElementIds: { groupId: string, elementIds: string[] }[] = await Promise.all(groups.map(async (group) => ({\n groupId: group.id,\n elementIds: await getHiliteIdsForGroup(iModelConnection, group, hilitedElementsQueryCache),\n })));\n\n const elems: Map<string, Set<string>> = new Map();\n const groupElementCount: Map<string, number> = new Map();\n\n // Build the elems map for associations between elements and their groups.\n for (const groupInfo of groupsElementIds) {\n for (const elem of groupInfo.elementIds) {\n const elemGroups = elems.get(elem) || new Set<string>();\n elemGroups.add(groupInfo.groupId);\n elems.set(elem, elemGroups);\n }\n groupElementCount.set(groupInfo.groupId, groupInfo.elementIds.length);\n }\n\n // Construct the unique list of all groups and their overlapped groups combinations\n const allGroups: OverlappedElementGroupPairs[] = groupsElementIds.map((groupInfo) => {\n const nonOverlappingElements = Array.from(new Set(groupInfo.elementIds)).filter((elem) => elems.get(elem)!.size === 1);\n groupElementCount.set(groupInfo.groupId, groupInfo.elementIds.length);\n return { elementIds: new Set(nonOverlappingElements), groupIds: new Set([groupInfo.groupId]) };\n });\n\n const mergedList = mergeElementsByGroup(elems);\n const overlappedGroupsInformation: OverlappedElementGroupPairs[] = Array.from(mergedList.values()).filter((value) => value.groupIds.size > 1);\n\n return { groupsWithGroupedOverlaps: [...allGroups, ...overlappedGroupsInformation], overlappedElementsInfo: getOverlappedElementsInfo(overlappedGroupsInformation), numberOfElementsInGroups: groupElementCount };\n};\n\nexport const hideGroupConsideringOverlaps = async (\n overlappedElementGroupPairs: OverlappedElementGroupPairs[],\n groupIdToHide: string,\n hiddenGroupsIds: Set<string>\n) => {\n const elementsToPotentiallyHide = new Set<string>();\n\n // Check each entry in overlappedElementGroupPairs\n for (const entry of overlappedElementGroupPairs) {\n // If the groupToHide is part of this entry\n if (entry.groupIds.has(groupIdToHide)) {\n // If this is a unique entry (no overlaps for this group), add all its elements to hide list\n if (entry.groupIds.size === 1) {\n for (const elem of entry.elementIds) {\n elementsToPotentiallyHide.add(elem);\n }\n } else {\n // If there are overlaps, only hide if all overlapping groups are hidden\n const allOtherGroupsHidden = Array.from(entry.groupIds).every(\n (groupId) =>\n groupId === groupIdToHide || hiddenGroupsIds.has(groupId)\n );\n if (allOtherGroupsHidden) {\n for (const elem of entry.elementIds) {\n elementsToPotentiallyHide.add(elem);\n }\n }\n }\n }\n }\n\n // Now hide all elements in elementsToPotentiallyHide\n hideElements(Array.from(elementsToPotentiallyHide));\n};\n"]}
1
+ {"version":3,"file":"groupsHelpers.js","sourceRoot":"","sources":["../../../../src/components/Groups/groupsHelpers.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAIzD,OAAO,EAAE,i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AE,iBAAiB,EAAE,CAAC;AACpN,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,2BAA0D,EAC1D,aAAqB,EACrB,eAA4B,EAC5B,EAAE;IACF,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAAU,CAAC;IAEpD,kDAAkD;IAClD,KAAK,MAAM,KAAK,IAAI,2BAA2B,EAAE;QAC/C,2CAA2C;QAC3C,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;YACrC,4FAA4F;YAC5F,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE;gBAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,EAAE;oBACnC,yBAAyB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;iBACrC;aACF;iBAAM;gBACL,wEAAwE;gBACxE,MAAM,oBAAoB,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,CAC3D,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,KAAK,aAAa,IAAI,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAC5D,CAAC;gBACF,IAAI,oBAAoB,EAAE;oBACxB,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,EAAE;wBACnC,yBAAyB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;qBACrC;iBACF;aACF;SACF;KACF;IAED,qDAAqD;IACrD,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { FeatureOverrideType } from \"@itwin/core-common\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { Group } from \"@itwin/insights-client\";\nimport type { OverlappedElementGroupPairs, OverlappedInfo } from \"../context/GroupHilitedElementsContext\";\nimport { clearEmphasizedOverriddenElements, clearHiddenElements, emphasizeElements, getHiliteIds, hideElements, overrideElements } from \"../../common/viewerUtils\";\n\nconst GOLDEN_ANGLE_MULTIPLIER = 1.5; // Multiplier to spread colors more uniformly.\nconst BASE_HUE_OFFSET = 60; // Initial hue offset to avoid certain colors e.g 0 offset would begin with red.\nconst HUE_ADJUSTMENT_STEP = 15; // Step to adjust the hue to avoid the red spectrum.\nconst RED_HUE_LOWER_BOUND = 330; // Lower bound of the red hue spectrum to avoid.\nconst RED_HUE_UPPER_BOUND = 30; // Upper bound of the red hue spectrum to avoid.\nconst GOLDENANGLE = 180 * (3 - Math.sqrt(5));\n\nconst generateHSL = (hue: number, saturation: number = 100, lightness: number = 50) => {\n return `hsl(${hue}, ${saturation}%, ${lightness}%)`;\n};\n\nexport const getGroupColor = (index: number) => {\n let hue = (index * GOLDENANGLE * GOLDEN_ANGLE_MULTIPLIER + BASE_HUE_OFFSET) % 360;\n\n while (hue >= RED_HUE_LOWER_BOUND || hue <= RED_HUE_UPPER_BOUND) {\n hue = (hue + HUE_ADJUSTMENT_STEP) % 360;\n }\n\n return generateHSL(hue);\n};\n\nconst processGroupVisualization = async (\n overlappedElementGroupPairs: OverlappedElementGroupPairs,\n hiddenGroupsIds: Set<string>,\n doEmphasizeElements: boolean,\n color: string,\n replace: boolean,\n setNumberOfVisualizedGroups: (numberOfVisualizedGroups: number | ((numberOfVisualizedGroups: number) => number)) => void,\n) => {\n const hilitedIds = Array.from(overlappedElementGroupPairs.elementIds);\n\n overrideElements(hilitedIds, color, FeatureOverrideType.ColorAndAlpha, replace);\n setNumberOfVisualizedGroups((numberOfVisualizedGroups) => numberOfVisualizedGroups + 1);\n\n doEmphasizeElements && emphasizeElements(hilitedIds, undefined);\n\n for (const id of overlappedElementGroupPairs.groupIds) {\n if (hiddenGroupsIds.has(id)) {\n return [];\n }\n }\n return hilitedIds;\n};\n\nexport type GroupsElementIds = {\n groupId: string;\n elementIds: string[];\n}[];\n\nexport const visualizeGroupColors = async (\n hiddenGroupsIds: Set<string>,\n groupsWithGroupedOverlaps: OverlappedElementGroupPairs[],\n setNumberOfVisualizedGroups: (numberOfVisualizedGroups: number | ((numberOfVisualizedGroups: number) => number)) => void,\n doEmphasizeElements: boolean = true,\n) => {\n clearEmphasizedOverriddenElements();\n\n const singleGroupPromises = groupsWithGroupedOverlaps\n .filter((group) => group.groupIds.size === 1)\n .map(async (group, index) =>\n processGroupVisualization(\n group,\n hiddenGroupsIds,\n doEmphasizeElements,\n getGroupColor(index), // color for single group\n false, // Shouldn't matter as replacement only accounts for same colored overrides.\n setNumberOfVisualizedGroups,\n )\n );\n\n const overlappedGroupPromises = groupsWithGroupedOverlaps\n .filter((group) => group.groupIds.size !== 1)\n .map(async (group) =>\n processGroupVisualization(\n group,\n hiddenGroupsIds,\n doEmphasizeElements,\n generateHSL(0), // color for group of overlapped elements\n false,\n setNumberOfVisualizedGroups,\n )\n );\n\n clearHiddenElements();\n\n hiddenGroupsIds.forEach((groupId) => {\n hideGroupConsideringOverlaps(groupsWithGroupedOverlaps, groupId, hiddenGroupsIds);\n });\n\n const allPromises = [...singleGroupPromises, ...overlappedGroupPromises];\n\n const allIds = (await Promise.all(allPromises)).flat();\n return allIds;\n};\n\nexport const getHiliteIdsAndKeysetFromGroup = async (\n iModelConnection: IModelConnection,\n group: Group,\n) => {\n const query = group.query;\n const result = await getHiliteIds(query, iModelConnection);\n return {group, result};\n\n};\n\nconst getOverlappedElementsInfo = (overlappedElements: OverlappedElementGroupPairs[]) => {\n const overlappedElementsInfo: Map<string, OverlappedInfo[]> = new Map();\n\n overlappedElements.forEach((elementGroup) => {\n const { elementIds, groupIds } = elementGroup;\n\n groupIds.forEach((group) => {\n const otherGroups = Array.from(groupIds).filter((grp) => grp !== group);\n const overlappedInfoArray = overlappedElementsInfo.get(group) ?? [];\n overlappedInfoArray.push({ groupIds: otherGroups, elements: Array.from(elementIds) });\n overlappedElementsInfo.set(group, overlappedInfoArray);\n });\n });\n return overlappedElementsInfo;\n};\n\nconst mergeElementsByGroup = (elems: Map<string, Set<string>>) => {\n const mergedList: Map<string, OverlappedElementGroupPairs> = new Map();\n elems.forEach((groupIds, elementId) => {\n const sortedGroups = Array.from(groupIds).sort();\n const key = sortedGroups.join(\"-\");\n const overlap = mergedList.get(key);\n if (overlap) {\n overlap.elementIds.add(elementId);\n } else {\n mergedList.set(key, { elementIds: new Set([elementId]), groupIds });\n }\n });\n return mergedList;\n};\n\nexport const generateOverlappedGroups = (\n groupsElementIds: GroupsElementIds,\n) => {\n const elems: Map<string, Set<string>> = new Map();\n const groupElementCount: Map<string, number> = new Map();\n\n // Build the elems map for associations between elements and their groups.\n for (const groupInfo of groupsElementIds) {\n for (const elem of groupInfo.elementIds) {\n const elemGroups = elems.get(elem) || new Set<string>();\n elemGroups.add(groupInfo.groupId);\n elems.set(elem, elemGroups);\n }\n groupElementCount.set(groupInfo.groupId, groupInfo.elementIds.length);\n }\n\n // Construct the unique list of all groups and their overlapped groups combinations\n const allGroups: OverlappedElementGroupPairs[] = groupsElementIds.map((groupInfo) => {\n const nonOverlappingElements = Array.from(new Set(groupInfo.elementIds)).filter((elem) => elems.get(elem)!.size === 1);\n groupElementCount.set(groupInfo.groupId, groupInfo.elementIds.length);\n return { elementIds: new Set(nonOverlappingElements), groupIds: new Set([groupInfo.groupId]) };\n });\n\n const mergedList = mergeElementsByGroup(elems);\n const overlappedGroupsInformation: OverlappedElementGroupPairs[] = Array.from(mergedList.values()).filter((value) => value.groupIds.size > 1);\n\n return { groupsWithGroupedOverlaps: [...allGroups, ...overlappedGroupsInformation], overlappedElementsInfo: getOverlappedElementsInfo(overlappedGroupsInformation), numberOfElementsInGroups: groupElementCount };\n};\n\nexport const hideGroupConsideringOverlaps = (\n overlappedElementGroupPairs: OverlappedElementGroupPairs[],\n groupIdToHide: string,\n hiddenGroupsIds: Set<string>\n) => {\n const elementsToPotentiallyHide = new Set<string>();\n\n // Check each entry in overlappedElementGroupPairs\n for (const entry of overlappedElementGroupPairs) {\n // If the groupToHide is part of this entry\n if (entry.groupIds.has(groupIdToHide)) {\n // If this is a unique entry (no overlaps for this group), add all its elements to hide list\n if (entry.groupIds.size === 1) {\n for (const elem of entry.elementIds) {\n elementsToPotentiallyHide.add(elem);\n }\n } else {\n // If there are overlaps, only hide if all overlapping groups are hidden\n const allOtherGroupsHidden = Array.from(entry.groupIds).every(\n (groupId) =>\n groupId === groupIdToHide || hiddenGroupsIds.has(groupId)\n );\n if (allOtherGroupsHidden) {\n for (const elem of entry.elementIds) {\n elementsToPotentiallyHide.add(elem);\n }\n }\n }\n }\n }\n\n // Now hide all elements in elementsToPotentiallyHide\n hideElements(Array.from(elementsToPotentiallyHide));\n};\n"]}
@@ -0,0 +1,5 @@
1
+ import type { IMappingsClient } from "@itwin/insights-client";
2
+ import type { GetAccessTokenFn } from "../../context/GroupingApiConfigContext";
3
+ export declare const fetchGroups: (iModelId: string, mappingId: string, getAccessToken: GetAccessTokenFn, mappingsClient: IMappingsClient) => Promise<import("@itwin/insights-client").Group[]>;
4
+ export declare const useFetchGroups: (iModelId: string, mappingId: string, getAccessToken: GetAccessTokenFn, mappingsClient: IMappingsClient) => import("@tanstack/react-query").UseQueryResult<import("@itwin/insights-client").Group[], unknown>;
5
+ //# sourceMappingURL=useFetchGroups.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { useQuery } from "@tanstack/react-query";
2
+ export const fetchGroups = async (iModelId, mappingId, getAccessToken, mappingsClient) => {
3
+ const accessToken = await getAccessToken();
4
+ const groups = await mappingsClient.getGroups(accessToken, iModelId, mappingId);
5
+ return groups;
6
+ };
7
+ export const useFetchGroups = (iModelId, mappingId, getAccessToken, mappingsClient) => {
8
+ return useQuery({
9
+ queryKey: ["groups", mappingId],
10
+ queryFn: async () => fetchGroups(iModelId, mappingId, getAccessToken, mappingsClient),
11
+ });
12
+ };
13
+ //# sourceMappingURL=useFetchGroups.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFetchGroups.js","sourceRoot":"","sources":["../../../../../src/components/Groups/hooks/useFetchGroups.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,QAAgB,EAChB,SAAiB,EACjB,cAAgC,EAChC,cAA+B,EAChC,EAAE;IACD,MAAM,WAAW,GAAG,MAAM,cAAc,EAAE,CAAC;IAC3C,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,SAAS,CAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAChF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,SAAiB,EAAE,cAAgC,EAAE,cAA+B,EAAE,EAAE;IACvI,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC;QAC/B,OAAO,EAAG,KAAK,IAAI,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,CAAC;KACvF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { IMappingsClient } from \"@itwin/insights-client\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport type { GetAccessTokenFn } from \"../../context/GroupingApiConfigContext\";\n\nexport const fetchGroups = async (\n iModelId: string,\n mappingId: string,\n getAccessToken: GetAccessTokenFn,\n mappingsClient: IMappingsClient\n)=> {\n const accessToken = await getAccessToken();\n const groups = await mappingsClient.getGroups(accessToken, iModelId, mappingId);\n return groups;\n};\n\nexport const useFetchGroups = (iModelId: string, mappingId: string, getAccessToken: GetAccessTokenFn, mappingsClient: IMappingsClient) => {\n return useQuery({\n queryKey: [\"groups\", mappingId],\n queryFn: async () => fetchGroups(iModelId, mappingId, getAccessToken, mappingsClient),\n });\n};\n"]}
@@ -5,7 +5,7 @@ export interface GroupsOperationsProps {
5
5
  mappingId: string;
6
6
  }
7
7
  export declare const useGroupsOperations: ({ mappingId, }: GroupsOperationsProps) => {
8
- groups: Group[];
8
+ groups: Group[] | undefined;
9
9
  isLoading: boolean;
10
10
  refresh: () => Promise<void>;
11
11
  onDeleteGroup: (group: Group) => Promise<void>;
@@ -18,9 +18,5 @@ export declare const useGroupsOperations: ({ mappingId, }: GroupsOperationsProps
18
18
  activeOverlapInfoPanelGroup: Group | undefined;
19
19
  setActiveOverlapInfoPanelGroup: import("react").Dispatch<import("react").SetStateAction<Group | undefined>>;
20
20
  overlappedElementsInfo: Map<string, import("../../context/GroupHilitedElementsContext").OverlappedInfo[]>;
21
- hilitedGroupsProgress: {
22
- currentHilitedGroups: number;
23
- totalNumberOfGroups: number;
24
- };
25
21
  };
26
22
  //# sourceMappingURL=useGroupsOperations.d.ts.map
@@ -2,51 +2,38 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- import { useCallback, useEffect, useState } from "react";
5
+ import { useCallback, useState } from "react";
6
6
  import { useGroupingMappingApiConfig } from "../../context/GroupingApiConfigContext";
7
- import { getErrorMessage } from "../../../common/utils";
8
7
  import { GroupingMappingCustomUIType } from "../../customUI/GroupingMappingCustomUI";
9
8
  import { useGroupingMappingCustomUI } from "../../context/GroupingMappingCustomUIContext";
10
9
  import { useGroupHilitedElementsContext } from "../../context/GroupHilitedElementsContext";
11
10
  import { useMappingClient } from "../../context/MappingClientContext";
12
- const fetchGroups = async (setGroups, iModelId, mappingId, setIsLoading, getAccessToken, mappingsClient, setErrorMessage) => {
13
- try {
14
- setIsLoading(true);
15
- const accessToken = await getAccessToken();
16
- const groups = await mappingsClient.getGroups(accessToken, iModelId, mappingId);
17
- setGroups(groups.sort((a, b) => a.groupName.localeCompare(b.groupName)));
18
- }
19
- catch (error) {
20
- setErrorMessage(getErrorMessage(error.status));
21
- }
22
- finally {
23
- setIsLoading(false);
24
- }
25
- };
11
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
12
+ import { useFetchGroups } from "./useFetchGroups";
26
13
  export const useGroupsOperations = ({ mappingId, }) => {
27
14
  const { getAccessToken, iModelId } = useGroupingMappingApiConfig();
28
- const { groups, setGroups, currentHilitedGroups, overlappedElementsInfo, overlappedElementGroupPairs } = useGroupHilitedElementsContext();
15
+ const { overlappedElementsMetadata: { overlappedElementsInfo } } = useGroupHilitedElementsContext();
29
16
  const mappingClient = useMappingClient();
30
17
  const groupUIs = useGroupingMappingCustomUI().customUIs.filter((p) => p.type === GroupingMappingCustomUIType.Grouping);
31
18
  const contextUIs = useGroupingMappingCustomUI().customUIs.filter((p) => p.type === GroupingMappingCustomUIType.Context);
32
19
  const [showDeleteModal, setShowDeleteModal] = useState(undefined);
33
- const [isLoading, setIsLoading] = useState(true);
34
20
  const [errorMessage, setErrorMessage] = useState(undefined);
35
21
  const [activeOverlapInfoPanelGroup, setActiveOverlapInfoPanelGroup] = useState(undefined);
36
- useEffect(() => {
37
- const initialize = async () => {
38
- await fetchGroups(setGroups, iModelId, mappingId, setIsLoading, getAccessToken, mappingClient, setErrorMessage);
39
- };
40
- void initialize();
41
- }, [getAccessToken, mappingClient, iModelId, mappingId, setGroups]);
22
+ const queryClient = useQueryClient();
23
+ const { data: groups, isLoading } = useFetchGroups(iModelId, mappingId, getAccessToken, mappingClient);
42
24
  const refresh = useCallback(async () => {
43
- await fetchGroups(setGroups, iModelId, mappingId, setIsLoading, getAccessToken, mappingClient, setErrorMessage);
44
- }, [getAccessToken, mappingClient, iModelId, mappingId, setGroups]);
45
- const onDeleteGroup = useCallback(async (group) => {
46
- const accessToken = await getAccessToken();
47
- await mappingClient.deleteGroup(accessToken, iModelId, mappingId, group.id);
48
- await refresh();
49
- }, [getAccessToken, iModelId, mappingClient, mappingId, refresh]);
25
+ await queryClient.invalidateQueries({ queryKey: ["groups", mappingId] });
26
+ }, [mappingId, queryClient]);
27
+ const deleteGroupMutation = useMutation({
28
+ mutationFn: async (group) => {
29
+ const accessToken = await getAccessToken();
30
+ await mappingClient.deleteGroup(accessToken, iModelId, mappingId, group.id);
31
+ },
32
+ onSuccess: refresh,
33
+ });
34
+ const onDeleteGroup = async (group) => {
35
+ deleteGroupMutation.mutate(group);
36
+ };
50
37
  return {
51
38
  groups,
52
39
  isLoading,
@@ -61,7 +48,6 @@ export const useGroupsOperations = ({ mappingId, }) => {
61
48
  activeOverlapInfoPanelGroup,
62
49
  setActiveOverlapInfoPanelGroup,
63
50
  overlappedElementsInfo,
64
- hilitedGroupsProgress: { currentHilitedGroups, totalNumberOfGroups: overlappedElementGroupPairs.length },
65
51
  };
66
52
  };
67
53
  //# sourceMappingURL=useGroupsOperations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useGroupsOperations.js","sourceRoot":"","sources":["../../../../../src/components/Groups/hooks/useGroupsOperations.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAC1F,OAAO,EAAE,8BAA8B,EAAE,MAAM,2CAA2C,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,MAAM,WAAW,GAAG,KAAK,EACvB,SAAoC,EACpC,QAAgB,EAChB,SAAiB,EACjB,YA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QACL,MAAM;QACN,SAAS;QACT,OAAO;QACP,aAAa;QACb,kBAAkB;QAClB,eAAe;QACf,QAAQ;QACR,UAAU;QACV,YAAY;QACZ,eAAe;QACf,2BAA2B;QAC3B,8BAA8B;QAC9B,sBAAsB;QACtB,qBAAqB,EAAE,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,2BAA2B,CAAC,MAAM,EAAE;KACzG,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { useCallback, useEffect, useState } from \"react\";\nimport type { Group, IMappingsClient } from \"@itwin/insights-client\";\nimport type { GetAccessTokenFn } from \"../../context/GroupingApiConfigContext\";\nimport { useGroupingMappingApiConfig } from \"../../context/GroupingApiConfigContext\";\nimport { getErrorMessage } from \"../../../common/utils\";\nimport type { ContextCustomUI, GroupingCustomUI } from \"../../customUI/GroupingMappingCustomUI\";\nimport { GroupingMappingCustomUIType } from \"../../customUI/GroupingMappingCustomUI\";\nimport { useGroupingMappingCustomUI } from \"../../context/GroupingMappingCustomUIContext\";\nimport { useGroupHilitedElementsContext } from \"../../context/GroupHilitedElementsContext\";\nimport { useMappingClient } from \"../../context/MappingClientContext\";\n\nconst fetchGroups = async (\n setGroups: (groups: Group[]) => void,\n iModelId: string,\n mappingId: string,\n setIsLoading: (isLoading: boolean) => void,\n getAccessToken: GetAccessTokenFn,\n mappingsClient: IMappingsClient,\n setErrorMessage: (message: string | undefined) => void\n): Promise<void> => {\n try {\n setIsLoading(true);\n const accessToken = await getAccessToken();\n const groups = await mappingsClient.getGroups(\n accessToken,\n iModelId,\n mappingId\n );\n setGroups(groups.sort((a, b) => a.groupName.localeCompare(b.groupName)));\n } catch (error: any) {\n setErrorMessage(getErrorMessage(error.status));\n } finally {\n setIsLoading(false);\n }\n};\n\nexport interface GroupsOperationsProps {\n mappingId: string;\n}\n\nexport const useGroupsOperations = ({\n mappingId,\n}: GroupsOperationsProps) => {\n const { getAccessToken, iModelId } = useGroupingMappingApiConfig();\n const { groups, setGroups, currentHilitedGroups, overlappedElementsInfo, overlappedElementGroupPairs } = useGroupHilitedElementsContext();\n const mappingClient = useMappingClient();\n const groupUIs: GroupingCustomUI[] =\n useGroupingMappingCustomUI().customUIs.filter(\n (p) => p.type === GroupingMappingCustomUIType.Grouping\n ) as GroupingCustomUI[];\n const contextUIs: ContextCustomUI[] =\n useGroupingMappingCustomUI().customUIs.filter(\n (p) => p.type === GroupingMappingCustomUIType.Context\n ) as ContextCustomUI[];\n const [showDeleteModal, setShowDeleteModal] = useState<Group | undefined>(\n undefined\n );\n const [isLoading, setIsLoading] = useState<boolean>(true);\n const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);\n const [activeOverlapInfoPanelGroup, setActiveOverlapInfoPanelGroup] = useState<Group | undefined>(undefined);\n\n useEffect(() => {\n const initialize = async () => {\n await fetchGroups(\n setGroups,\n iModelId,\n mappingId,\n setIsLoading,\n getAccessToken,\n mappingClient,\n setErrorMessage\n );\n };\n void initialize();\n }, [getAccessToken, mappingClient, iModelId, mappingId, setGroups]);\n\n const refresh = useCallback(async () => {\n await fetchGroups(\n setGroups,\n iModelId,\n mappingId,\n setIsLoading,\n getAccessToken,\n mappingClient,\n setErrorMessage\n );\n }, [getAccessToken, mappingClient, iModelId, mappingId, setGroups]);\n\n const onDeleteGroup = useCallback(async (group: Group) => {\n const accessToken = await getAccessToken();\n await mappingClient.deleteGroup(\n accessToken,\n iModelId,\n mappingId,\n group.id\n );\n await refresh();\n }, [getAccessToken, iModelId, mappingClient, mappingId, refresh]);\n\n return {\n groups,\n isLoading,\n refresh,\n onDeleteGroup,\n setShowDeleteModal,\n showDeleteModal,\n groupUIs,\n contextUIs,\n errorMessage,\n setErrorMessage,\n activeOverlapInfoPanelGroup,\n setActiveOverlapInfoPanelGroup,\n overlappedElementsInfo,\n hilitedGroupsProgress: { currentHilitedGroups, totalNumberOfGroups: overlappedElementGroupPairs.length },\n };\n};\n"]}
1
+ {"version":3,"file":"useGroupsOperations.js","sourceRoot":"","sources":["../../../../../src/components/Groups/hooks/useGroupsOperations.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AAErF,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAC1F,OAAO,EAAE,8BAA8B,EAAE,MAAM,2CAA2C,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAMlD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAClC,SAAS,GACa,EAAE,EAAE;IAC1B,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,2BAA2B,EAAE,CAAC;IACnE,MAAM,EAAE,0BAA0B,EAAE,EAAG,sBAAsB,EAAE,EAAE,GAAG,8BAA8B,EAAE,CAAC;IAErG,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IACzC,MAAM,QAAQ,GACZ,0BAA0B,EAAE,CAAC,SAAS,CAAC,MAAM,CAC3C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,2BAA2B,CAAC,QAAQ,CACjC,CAAC;IAC1B,MAAM,UAAU,GACd,0BAA0B,EAAE,CAAC,SAAS,CAAC,MAAM,CAC3C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,2BAA2B,CAAC,OAAO,CACjC,CAAC;IACzB,MAAM,CAAC,eAAe,EA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cesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { useCallback, useState } from \"react\";\nimport type { Group } from \"@itwin/insights-client\";\nimport { useGroupingMappingApiConfig } from \"../../context/GroupingApiConfigContext\";\nimport type { ContextCustomUI, GroupingCustomUI } from \"../../customUI/GroupingMappingCustomUI\";\nimport { GroupingMappingCustomUIType } from \"../../customUI/GroupingMappingCustomUI\";\nimport { useGroupingMappingCustomUI } from \"../../context/GroupingMappingCustomUIContext\";\nimport { useGroupHilitedElementsContext } from \"../../context/GroupHilitedElementsContext\";\nimport { useMappingClient } from \"../../context/MappingClientContext\";\nimport { useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport { useFetchGroups } from \"./useFetchGroups\";\n\nexport interface GroupsOperationsProps {\n mappingId: string;\n}\n\nexport const useGroupsOperations = ({\n mappingId,\n}: GroupsOperationsProps) => {\n const { getAccessToken, iModelId } = useGroupingMappingApiConfig();\n const { overlappedElementsMetadata: { overlappedElementsInfo } } = useGroupHilitedElementsContext();\n\n const mappingClient = useMappingClient();\n const groupUIs: GroupingCustomUI[] =\n useGroupingMappingCustomUI().customUIs.filter(\n (p) => p.type === GroupingMappingCustomUIType.Grouping\n ) as GroupingCustomUI[];\n const contextUIs: ContextCustomUI[] =\n useGroupingMappingCustomUI().customUIs.filter(\n (p) => p.type === GroupingMappingCustomUIType.Context\n ) as ContextCustomUI[];\n const [showDeleteModal, setShowDeleteModal] = useState<Group | undefined>(\n undefined\n );\n const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);\n const [activeOverlapInfoPanelGroup, setActiveOverlapInfoPanelGroup] = useState<Group | undefined>(undefined);\n const queryClient = useQueryClient();\n\n const { data: groups, isLoading } = useFetchGroups(iModelId, mappingId, getAccessToken, mappingClient);\n\n const refresh = useCallback(async () => {\n await queryClient.invalidateQueries({queryKey: [\"groups\", mappingId]});\n }, [mappingId, queryClient]);\n\n const deleteGroupMutation = useMutation(\n {\n mutationFn: async (group: Group) => {\n const accessToken = await getAccessToken();\n await mappingClient.deleteGroup(accessToken, iModelId, mappingId, group.id);\n },\n onSuccess: refresh,\n }\n );\n\n const onDeleteGroup = async (group: Group) => {\n deleteGroupMutation.mutate(group);\n };\n\n return {\n groups,\n isLoading,\n refresh,\n onDeleteGroup,\n setShowDeleteModal,\n showDeleteModal,\n groupUIs,\n contextUIs,\n errorMessage,\n setErrorMessage,\n activeOverlapInfoPanelGroup,\n setActiveOverlapInfoPanelGroup,\n overlappedElementsInfo,\n };\n};\n"]}
@@ -0,0 +1,32 @@
1
+ import type { IModelConnection } from "@itwin/core-frontend";
2
+ import type { Group } from "@itwin/insights-client";
3
+ import type { KeySet } from "@itwin/presentation-common";
4
+ import { TErrCodes } from "../../Constants";
5
+ export interface QueryResults {
6
+ group: Group;
7
+ result: {
8
+ keySet: KeySet;
9
+ ids: string[];
10
+ };
11
+ }
12
+ export declare const createQueryForHiliteIdsAndKeyset: (group: Group, iModelConnection: IModelConnection, enabled: boolean) => {
13
+ queryKey: string[];
14
+ queryFn: () => Promise<{
15
+ group: Group;
16
+ result: {
17
+ keySet: KeySet;
18
+ ids: string[];
19
+ };
20
+ }>;
21
+ enabled: boolean;
22
+ staleTime: number;
23
+ meta: {
24
+ errorCode: TErrCodes;
25
+ message: string;
26
+ };
27
+ };
28
+ export declare const useGroupKeySetQuery: (group: Group, iModelConnection: IModelConnection, enabled: boolean) => import("@tanstack/react-query").UseQueryResult<QueryResults, unknown>;
29
+ export declare const useKeySetHiliteQueries: (groups: Group[], enabled: boolean, iModelConnection: IModelConnection) => {
30
+ groupQueries: Pick<import("@tanstack/react-query").UseQueryResult<QueryResults, unknown>, "data" | "isFetching" | "isFetched" | "refetch">[];
31
+ };
32
+ //# sourceMappingURL=useKeySetHiliteQueries.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { useQuery } from "@tanstack/react-query";
2
+ import { useQueries } from "@tanstack/react-query";
3
+ import { useMemo } from "react";
4
+ import { useMemoizedCollectionPick } from "../../../common/hooks/useMemoizedCollectionPick";
5
+ import { TErrCodes } from "../../Constants";
6
+ import { getHiliteIdsAndKeysetFromGroup } from "../groupsHelpers";
7
+ [];
8
+ export const createQueryForHiliteIdsAndKeyset = (group, iModelConnection, enabled) => ({
9
+ queryKey: ["group", "hiliteids", group.query],
10
+ queryFn: async () => getHiliteIdsAndKeysetFromGroup(iModelConnection, group),
11
+ enabled,
12
+ staleTime: Infinity,
13
+ meta: { errorCode: TErrCodes.QUERY_HILITE_FETCH_FAILED, message: `Failed to resolve ${group.groupName}.` },
14
+ });
15
+ export const useGroupKeySetQuery = (group, iModelConnection, enabled) => {
16
+ const query = useMemo(() => createQueryForHiliteIdsAndKeyset(group, iModelConnection, enabled), [enabled, group, iModelConnection]);
17
+ return useQuery(query);
18
+ };
19
+ export const useKeySetHiliteQueries = (groups, enabled, iModelConnection) => {
20
+ const queries = useMemo(() => groups.map((group) => createQueryForHiliteIdsAndKeyset(group, iModelConnection, enabled)), [groups, iModelConnection, enabled]);
21
+ const useQueriesHook = useQueries({ queries });
22
+ const groupQueries = useMemoizedCollectionPick(useQueriesHook, ["data", "isFetching", "isFetched", "refetch"]);
23
+ return { groupQueries };
24
+ };
25
+ //# sourceMappingURL=useKeySetHiliteQueries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useKeySetHiliteQueries.js","sourceRoot":"","sources":["../../../../../src/components/Groups/hooks/useKeySetHiliteQueries.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,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yB,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC;IAE/G,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { Group } from \"@itwin/insights-client\";\nimport type { KeySet } from \"@itwin/presentation-common\";\nimport type { UseQueryOptions } from \"@tanstack/react-query\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useQueries } from \"@tanstack/react-query\";\nimport { useMemo } from \"react\";\nimport { useMemoizedCollectionPick } from \"../../../common/hooks/useMemoizedCollectionPick\";\nimport { TErrCodes } from \"../../Constants\";\nimport { getHiliteIdsAndKeysetFromGroup } from \"../groupsHelpers\";\n\nexport interface QueryResults {\n group: Group;\n result: {\n keySet: KeySet;\n ids: string[];\n };\n}[];\n\ntype TQueries = UseQueryOptions<QueryResults>[];\n\nexport const createQueryForHiliteIdsAndKeyset = (group: Group, iModelConnection: IModelConnection, enabled: boolean) => ({\n queryKey: [\"group\", \"hiliteids\", group.query],\n queryFn: async () => getHiliteIdsAndKeysetFromGroup(iModelConnection, group),\n enabled,\n staleTime: Infinity,\n meta: { errorCode:TErrCodes.QUERY_HILITE_FETCH_FAILED, message: `Failed to resolve ${group.groupName}.` },\n});\n\nexport const useGroupKeySetQuery = (group: Group, iModelConnection: IModelConnection, enabled: boolean) => {\n const query = useMemo(() => createQueryForHiliteIdsAndKeyset(group, iModelConnection, enabled), [enabled, group, iModelConnection]);\n\n return useQuery<QueryResults>(query);\n};\n\nexport const useKeySetHiliteQueries = (groups: Group[], enabled: boolean, iModelConnection: IModelConnection) => {\n const queries = useMemo(() => groups.map((group) => createQueryForHiliteIdsAndKeyset(group, iModelConnection, enabled)),\n [groups, iModelConnection, enabled]);\n\n const useQueriesHook = useQueries<TQueries>({ queries });\n\n const groupQueries = useMemoizedCollectionPick(useQueriesHook, [\"data\", \"isFetching\", \"isFetched\", \"refetch\"]);\n\n return { groupQueries };\n};\n"]}
@@ -6,19 +6,19 @@ import { visualizeGroupColors } from "../groupsHelpers";
6
6
  import { clearEmphasizedElements, clearOverriddenElements, transparentOverriddenElements, visualizeElementsByQuery, zoomToElements } from "../../../common/viewerUtils";
7
7
  export const useVisualization = (shouldVisualize, iModelConnection, query, queryGenerationType) => {
8
8
  const [isRendering, setIsRendering] = useState(false);
9
- const { showGroupColor, groups, hiddenGroupsIds, hilitedElementsQueryCache, setNumberOfVisualizedGroups, setOverlappedElementsInfo, setGroupElementsInfo, setOverlappedElementGroupPairs } = useGroupHilitedElementsContext();
9
+ const { showGroupColor, hiddenGroupsIds, overlappedElementsMetadata: { overlappedElementGroupPairs }, setNumberOfVisualizedGroups } = useGroupHilitedElementsContext();
10
10
  const [simpleSelectionQuery, setSimpleSelectionQuery] = useState("");
11
11
  const resetView = useCallback(async () => {
12
12
  if (!shouldVisualize)
13
13
  return;
14
14
  if (showGroupColor) {
15
- await visualizeGroupColors(iModelConnection, groups, hiddenGroupsIds, hilitedElementsQueryCache, setNumberOfVisualizedGroups, setOverlappedElementsInfo, setGroupElementsInfo, setOverlappedElementGroupPairs);
15
+ await visualizeGroupColors(hiddenGroupsIds, overlappedElementGroupPairs, setNumberOfVisualizedGroups);
16
16
  }
17
17
  else {
18
18
  clearOverriddenElements();
19
19
  }
20
20
  clearEmphasizedElements();
21
- }, [groups, hiddenGroupsIds, hilitedElementsQueryCache, iModelConnection, showGroupColor, shouldVisualize, setNumberOfVisualizedGroups, setOverlappedElementsInfo, setGroupElementsInfo, setOverlappedElementGroupPairs]);
21
+ }, [hiddenGroupsIds, overlappedElementGroupPairs, setNumberOfVisualizedGroups, shouldVisualize, showGroupColor]);
22
22
  useEffect(() => {
23
23
  if (!shouldVisualize)
24
24
  return;
@@ -47,7 +47,7 @@ export const useVisualization = (shouldVisualize, iModelConnection, query, query
47
47
  await zoomToElements(resolvedHiliteIds);
48
48
  }
49
49
  catch {
50
- toaster.negative("Sorry, we have failed to generate a valid query. 😔");
50
+ toaster.negative("Sorry, we have failed to generate a valid query.");
51
51
  }
52
52
  finally {
53
53
  setIsRendering(false);
@@ -1 +1 @@
1
- {"version":3,"file":"useVisualization.js","sourceRoot":"","sources":["../../../../../src/components/Groups/hooks/useVisualization.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,8BAA8B,EAAE,MAAM,2CAA2C,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAExK,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,eAAwB,EAAE,gBAAkC,EAAE,KAAa,EAAE,mBAA2B,EAAE,EAAE;IAC3I,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IAC/D,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,8BAA8B,EAAE,GAAG,8BAA8B,EAAE,CAAC;IAC9N,MAAM,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,GAAG,QAAQ,CAAS,EAAE,CAAC,CAAC;IAE7E,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACvC,IAAI,CAAC,eAAe;YAAE,OAAO;QAC7B,IAAI,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AAK,IAAI,KAAK,KAAK,EAAE,EAAE;oBAC1B,OAAO;iBACR;gBACD,cAAc,CAAC,IAAI,CAAC,CAAC;gBACrB,6BAA6B,EAAE,CAAC;gBAChC,MAAM,iBAAiB,GAAG,MAAM,wBAAwB,CACtD,KAAK,EACL,KAAK,EACL,gBAAgB,CACjB,CAAC;gBACF,MAAM,cAAc,CAAC,iBAAiB,CAAC,CAAC;aACzC;YAAC,MAAM;gBACN,OAAO,CAAC,QAAQ,CAAC,qDAAqD,CAAC,CAAC;aACzE;oBAAS;gBACR,cAAc,CAAC,KAAK,CAAC,CAAC;aACvB;QACH,CAAC,CAAC;QAEF,KAAK,WAAW,EAAE,CAAC;IACrB,CAAC,EAAE,CAAC,gBAAgB,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC;IAE/C,MAAM,0BAA0B,GAAG,WAAW,CAAC,GAAG,EAAE,CAClD,eAAe,IAAI,YAAY,CAAC,SAAS,CAAC,cAAc,CACtD,uBAAuB,EACvB,gBAAgB,CACjB,EAAE,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC;IAE1C,SAAS,CAAC,GAAG,EAAE;QACb,0BAA0B,EAAE,CAAC;IAC/B,CAAC,EAAE,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAEnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,SAAS,EAAE,CAAC;AAE/H,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport { toaster } from \"@itwin/itwinui-react\";\nimport type { ISelectionProvider, SelectionChangeEventArgs } from \"@itwin/presentation-frontend\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport { useGroupHilitedElementsContext } from \"../../context/GroupHilitedElementsContext\";\nimport { visualizeGroupColors } from \"../groupsHelpers\";\nimport { clearEmphasizedElements, clearOverriddenElements, transparentOverriddenElements, visualizeElementsByQuery, zoomToElements } from \"../../../common/viewerUtils\";\n\nexport const useVisualization = (shouldVisualize: boolean, iModelConnection: IModelConnection, query: string, queryGenerationType: string) => {\n const [isRendering, setIsRendering] = useState<boolean>(false);\n const { showGroupColor, groups, hiddenGroupsIds, hilitedElementsQueryCache, setNumberOfVisualizedGroups, setOverlappedElementsInfo, setGroupElementsInfo, setOverlappedElementGroupPairs } = useGroupHilitedElementsContext();\n const [simpleSelectionQuery, setSimpleSelectionQuery] = useState<string>(\"\");\n\n const resetView = useCallback(async () => {\n if (!shouldVisualize) return;\n if (showGroupColor) {\n await visualizeGroupColors(iModelConnection, groups, hiddenGroupsIds, hilitedElementsQueryCache, setNumberOfVisualizedGroups, setOverlappedElementsInfo, setGroupElementsInfo, setOverlappedElementGroupPairs);\n } else {\n clearOverriddenElements();\n }\n clearEmphasizedElements();\n }, [groups, hiddenGroupsIds, hilitedElementsQueryCache, iModelConnection, showGroupColor, shouldVisualize, setNumberOfVisualizedGroups, setOverlappedElementsInfo, setGroupElementsInfo, setOverlappedElementGroupPairs]);\n\n useEffect(() => {\n if (!shouldVisualize) return;\n const removeListener = Presentation.selection.selectionChange.addListener(\n async (\n evt: SelectionChangeEventArgs,\n selectionProvider: ISelectionProvider,\n ) => {\n if (queryGenerationType === \"Selection\") {\n const selection = selectionProvider.getSelection(\n evt.imodel,\n evt.level,\n );\n const query = selection.instanceKeys.size > 0\n ? `SELECT ECInstanceId FROM ${selection.instanceKeys.keys().next().value}`\n : \"\";\n setSimpleSelectionQuery(query);\n }\n },\n );\n return removeListener;\n }, [iModelConnection, queryGenerationType, shouldVisualize]);\n\n useEffect(() => {\n if (!shouldVisualize) return;\n const reemphasize = async () => {\n try {\n if (!query || query === \"\") {\n return;\n }\n setIsRendering(true);\n transparentOverriddenElements();\n const resolvedHiliteIds = await visualizeElementsByQuery(\n query,\n \"red\",\n iModelConnection,\n );\n await zoomToElements(resolvedHiliteIds);\n } catch {\n toaster.negative(\"Sorry, we have failed to generate a valid query. 😔\");\n } finally {\n setIsRendering(false);\n }\n };\n\n void reemphasize();\n }, [iModelConnection, query, shouldVisualize]);\n\n const clearPresentationSelection = useCallback(() =>\n shouldVisualize && Presentation.selection.clearSelection(\n \"GroupingMappingWidget\",\n iModelConnection,\n ), [iModelConnection, shouldVisualize]);\n\n useEffect(() => {\n clearPresentationSelection();\n }, [clearPresentationSelection, iModelConnection]);\n\n return { isRendering, setIsRendering, simpleSelectionQuery, setSimpleSelectionQuery, clearPresentationSelection, resetView };\n\n};\n"]}
1
+ {"version":3,"file":"useVisualization.js","sourceRoot":"","sources":["../../../../../src/components/Groups/hooks/useVisualization.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,8BAA8B,EAAE,MAAM,2CAA2C,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAExK,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,eAAwB,EAAE,gBAAkC,EAAE,KAAa,EAAE,mBAA2B,EAAE,EAAE;IAC3I,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IAC/D,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,0BAA0B,EAAE,EAAE,2BAA2B,EAAE,EAAE,2BAA2B,EAAC,GAAG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B,MAAM,WAAW,GAAG,KAAK,IAAI,EAAE;YAC7B,IAAI;gBACF,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,EAAE,EAAE;oBAC1B,OAAO;iBACR;gBACD,cAAc,CAAC,IAAI,CAAC,CAAC;gBACrB,6BAA6B,EAAE,CAAC;gBAChC,MAAM,iBAAiB,GAAG,MAAM,wBAAwB,CACtD,KAAK,EACL,KAAK,EACL,gBAAgB,CACjB,CAAC;gBACF,MAAM,cAAc,CAAC,iBAAiB,CAAC,CAAC;aACzC;YAAC,MAAM;gBACN,OAAO,CAAC,QAAQ,CAAC,kDAAkD,CAAC,CAAC;aACtE;oBAAS;gBACR,cAAc,CAAC,KAAK,CAAC,CAAC;aACvB;QACH,CAAC,CAAC;QAEF,KAAK,WAAW,EAAE,CAAC;IACrB,CAAC,EAAE,CAAC,gBAAgB,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC;IAE/C,MAAM,0BAA0B,GAAG,WAAW,CAAC,GAAG,EAAE,CAClD,eAAe,IAAI,YAAY,CAAC,SAAS,CAAC,cAAc,CACtD,uBAAuB,EACvB,gBAAgB,CACjB,EAAE,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC;IAE1C,SAAS,CAAC,GAAG,EAAE;QACb,0BAA0B,EAAE,CAAC;IAC/B,CAAC,EAAE,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAEnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,SAAS,EAAE,CAAC;AAE/H,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport { toaster } from \"@itwin/itwinui-react\";\nimport type { ISelectionProvider, SelectionChangeEventArgs } from \"@itwin/presentation-frontend\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport { useGroupHilitedElementsContext } from \"../../context/GroupHilitedElementsContext\";\nimport { visualizeGroupColors } from \"../groupsHelpers\";\nimport { clearEmphasizedElements, clearOverriddenElements, transparentOverriddenElements, visualizeElementsByQuery, zoomToElements } from \"../../../common/viewerUtils\";\n\nexport const useVisualization = (shouldVisualize: boolean, iModelConnection: IModelConnection, query: string, queryGenerationType: string) => {\n const [isRendering, setIsRendering] = useState<boolean>(false);\n const { showGroupColor, hiddenGroupsIds, overlappedElementsMetadata: { overlappedElementGroupPairs }, setNumberOfVisualizedGroups} = useGroupHilitedElementsContext();\n const [simpleSelectionQuery, setSimpleSelectionQuery] = useState<string>(\"\");\n\n const resetView = useCallback(async () => {\n if (!shouldVisualize) return;\n if (showGroupColor) {\n await visualizeGroupColors(hiddenGroupsIds, overlappedElementGroupPairs, setNumberOfVisualizedGroups);\n } else {\n clearOverriddenElements();\n }\n clearEmphasizedElements();\n }, [hiddenGroupsIds, overlappedElementGroupPairs, setNumberOfVisualizedGroups, shouldVisualize, showGroupColor]);\n\n useEffect(() => {\n if (!shouldVisualize) return;\n const removeListener = Presentation.selection.selectionChange.addListener(\n async (\n evt: SelectionChangeEventArgs,\n selectionProvider: ISelectionProvider,\n ) => {\n if (queryGenerationType === \"Selection\") {\n const selection = selectionProvider.getSelection(\n evt.imodel,\n evt.level,\n );\n const query = selection.instanceKeys.size > 0\n ? `SELECT ECInstanceId FROM ${selection.instanceKeys.keys().next().value}`\n : \"\";\n setSimpleSelectionQuery(query);\n }\n },\n );\n return removeListener;\n }, [iModelConnection, queryGenerationType, shouldVisualize]);\n\n useEffect(() => {\n if (!shouldVisualize) return;\n const reemphasize = async () => {\n try {\n if (!query || query === \"\") {\n return;\n }\n setIsRendering(true);\n transparentOverriddenElements();\n const resolvedHiliteIds = await visualizeElementsByQuery(\n query,\n \"red\",\n iModelConnection,\n );\n await zoomToElements(resolvedHiliteIds);\n } catch {\n toaster.negative(\"Sorry, we have failed to generate a valid query.\");\n } finally {\n setIsRendering(false);\n }\n };\n\n void reemphasize();\n }, [iModelConnection, query, shouldVisualize]);\n\n const clearPresentationSelection = useCallback(() =>\n shouldVisualize && Presentation.selection.clearSelection(\n \"GroupingMappingWidget\",\n iModelConnection,\n ), [iModelConnection, shouldVisualize]);\n\n useEffect(() => {\n clearPresentationSelection();\n }, [clearPresentationSelection, iModelConnection]);\n\n return { isRendering, setIsRendering, simpleSelectionQuery, setSimpleSelectionQuery, clearPresentationSelection, resetView };\n\n};\n"]}
@@ -9,7 +9,8 @@ import useValidator, { NAME_REQUIREMENTS } from "../../Properties/hooks/useValid
9
9
  import "./MappingAction.scss";
10
10
  import { useMappingClient } from "../../context/MappingClientContext";
11
11
  import { useGroupingMappingApiConfig } from "../../context/GroupingApiConfigContext";
12
- import { handleError, handleInputChange } from "../../../common/utils";
12
+ import { handleInputChange } from "../../../common/utils";
13
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
13
14
  const defaultDisplayStrings = {
14
15
  mappingDetails: "Mapping Details",
15
16
  };
@@ -22,40 +23,30 @@ export const MappingAction = ({ mapping, onSaveSuccess, onClickCancel, displaySt
22
23
  extractionEnabled: mapping?.extractionEnabled ?? true,
23
24
  });
24
25
  const [validator, showValidationMessage] = useValidator();
25
- const [isLoading, setIsLoading] = useState(false);
26
+ const queryClient = useQueryClient();
26
27
  const displayStrings = React.useMemo(() => ({ ...defaultDisplayStrings, ...userDisplayStrings }), [userDisplayStrings]);
27
- const onSave = async () => {
28
- try {
29
- if (!validator.allValid()) {
30
- showValidationMessage(true);
31
- return;
32
- }
33
- setIsLoading(true);
28
+ const { mutate: saveMutation, isLoading } = useMutation({
29
+ mutationFn: async (newMapping) => {
34
30
  const accessToken = await getAccessToken();
35
- mapping
36
- ? await mappingClient.updateMapping(accessToken, iModelId, mapping.id, {
37
- mappingName: values.name,
38
- description: values.description,
39
- extractionEnabled: values.extractionEnabled,
40
- })
41
- : await mappingClient.createMapping(accessToken, iModelId, {
42
- mappingName: values.name,
43
- description: values.description,
44
- extractionEnabled: values.extractionEnabled,
45
- });
46
- setValues({
47
- name: mapping?.mappingName ?? "",
48
- description: mapping?.description ?? "",
49
- extractionEnabled: mapping?.extractionEnabled ?? true,
50
- });
31
+ return mapping
32
+ ? mappingClient.updateMapping(accessToken, iModelId, mapping.id, newMapping)
33
+ : mappingClient.createMapping(accessToken, iModelId, newMapping);
34
+ },
35
+ onSuccess: async () => {
36
+ await queryClient.invalidateQueries({ queryKey: ["mappings"] });
51
37
  onSaveSuccess();
38
+ },
39
+ });
40
+ const onSave = async () => {
41
+ if (!validator.allValid()) {
42
+ showValidationMessage(true);
43
+ return;
52
44
  }
53
- catch (error) {
54
- handleError(error.status);
55
- }
56
- finally {
57
- setIsLoading(false);
58
- }
45
+ saveMutation({
46
+ mappingName: values.name,
47
+ description: values.description,
48
+ extractionEnabled: values.extractionEnabled,
49
+ });
59
50
  };
60
51
  return (React.createElement(React.Fragment, null,
61
52
  React.createElement("div", { className: 'gmw-details-form-container' },