@adaptabletools/adaptable-cjs 18.0.0-canary.3 → 18.0.0-canary.31

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 (482) hide show
  1. package/agGrid.d.ts +4 -21
  2. package/agGrid.js +5 -21
  3. package/base.css +27 -21
  4. package/base.css.map +1 -1
  5. package/index.css +108 -88
  6. package/index.css.map +1 -1
  7. package/package.json +4 -5
  8. package/src/AdaptableInterfaces/IAdaptable.d.ts +61 -109
  9. package/src/AdaptableOptions/ActionColumnOptions.d.ts +3 -2
  10. package/src/AdaptableOptions/AdaptableFrameworkComponent.d.ts +3 -0
  11. package/src/AdaptableOptions/AdaptableOptions.d.ts +7 -7
  12. package/src/AdaptableOptions/AdaptablePlugin.d.ts +2 -0
  13. package/src/AdaptableOptions/AdaptablePlugin.js +2 -0
  14. package/src/AdaptableOptions/ColumnFilterOptions.d.ts +11 -4
  15. package/src/AdaptableOptions/ColumnOptions.d.ts +9 -4
  16. package/src/AdaptableOptions/CommentOptions.d.ts +39 -0
  17. package/src/AdaptableOptions/CustomSortOptions.d.ts +2 -2
  18. package/src/AdaptableOptions/DataImportOptions.d.ts +2 -2
  19. package/src/AdaptableOptions/FormatColumnOptions.d.ts +2 -2
  20. package/src/AdaptableOptions/GroupingOptions.d.ts +0 -26
  21. package/src/AdaptableOptions/MenuOptions.d.ts +11 -71
  22. package/src/AdaptableOptions/MenuOptions.js +0 -101
  23. package/src/AdaptableOptions/NoteOptions.d.ts +25 -0
  24. package/src/AdaptableOptions/PredicateOptions.d.ts +2 -2
  25. package/src/AdaptableOptions/StateOptions.d.ts +6 -0
  26. package/src/AdaptableOptions/UserInterfaceOptions.d.ts +19 -2
  27. package/src/Api/AdaptableApi.d.ts +9 -4
  28. package/src/Api/BulkUpdateApi.d.ts +0 -5
  29. package/src/Api/ColumnApi.d.ts +13 -0
  30. package/src/Api/CommentApi.d.ts +20 -22
  31. package/src/Api/ConfigApi.d.ts +4 -5
  32. package/src/Api/EventApi.d.ts +7 -9
  33. package/src/Api/Events/AdaptableReady.d.ts +3 -3
  34. package/src/Api/Events/CommentChanged.d.ts +11 -0
  35. package/src/Api/Events/GridDataChanged.d.ts +4 -4
  36. package/src/Api/FlashingCellApi.d.ts +2 -2
  37. package/src/Api/GridApi.d.ts +42 -14
  38. package/src/Api/Implementation/ActionColumnApiImpl.d.ts +2 -0
  39. package/src/Api/Implementation/ActionColumnApiImpl.js +30 -0
  40. package/src/Api/Implementation/ActionRowApiImpl.js +3 -7
  41. package/src/Api/Implementation/AdaptableApiImpl.d.ts +3 -2
  42. package/src/Api/Implementation/AdaptableApiImpl.js +5 -2
  43. package/src/Api/Implementation/AlertApiImpl.js +5 -10
  44. package/src/Api/Implementation/ApiBase.d.ts +5 -3
  45. package/src/Api/Implementation/ApiBase.js +8 -2
  46. package/src/Api/Implementation/BulkUpdateApiImpl.d.ts +0 -1
  47. package/src/Api/Implementation/BulkUpdateApiImpl.js +0 -4
  48. package/src/Api/Implementation/CalendarApiImpl.js +1 -6
  49. package/src/Api/Implementation/CellSummaryApiImpl.d.ts +0 -5
  50. package/src/Api/Implementation/CellSummaryApiImpl.js +2 -23
  51. package/src/Api/Implementation/ChartingApiImpl.js +3 -3
  52. package/src/Api/Implementation/ColumnApiImpl.d.ts +5 -0
  53. package/src/Api/Implementation/ColumnApiImpl.js +48 -16
  54. package/src/Api/Implementation/ColumnFilterApiImpl.js +7 -7
  55. package/src/Api/Implementation/CommentsApiImpl.d.ts +8 -5
  56. package/src/Api/Implementation/CommentsApiImpl.js +12 -6
  57. package/src/Api/Implementation/ConfigApiImpl.d.ts +2 -2
  58. package/src/Api/Implementation/ConfigApiImpl.js +34 -30
  59. package/src/Api/Implementation/DashboardApiImpl.js +1 -6
  60. package/src/Api/Implementation/ExportApiImpl.js +5 -10
  61. package/src/Api/Implementation/ExpressionApiImpl.js +14 -19
  62. package/src/Api/Implementation/Fdc3ApiImpl.js +1 -1
  63. package/src/Api/Implementation/FlashingCellApiImpl.d.ts +2 -2
  64. package/src/Api/Implementation/FlashingCellApiImpl.js +3 -8
  65. package/src/Api/Implementation/FormatColumnApiImpl.js +4 -4
  66. package/src/Api/Implementation/FreeTextColumnApiImpl.js +1 -1
  67. package/src/Api/Implementation/GridApiImpl.d.ts +10 -3
  68. package/src/Api/Implementation/GridApiImpl.js +78 -23
  69. package/src/Api/Implementation/LayoutApiImpl.d.ts +4 -7
  70. package/src/Api/Implementation/LayoutApiImpl.js +19 -13
  71. package/src/Api/Implementation/NoteApiImpl.d.ts +18 -0
  72. package/src/Api/Implementation/NoteApiImpl.js +45 -0
  73. package/src/Api/Implementation/OptionsApiImpl.d.ts +4 -4
  74. package/src/Api/Implementation/OptionsApiImpl.js +4 -4
  75. package/src/Api/Implementation/PredicateApiImpl.js +2 -2
  76. package/src/Api/Implementation/ScheduleApiImpl.js +6 -6
  77. package/src/Api/Implementation/ScopeApiImpl.d.ts +26 -24
  78. package/src/Api/Implementation/ScopeApiImpl.js +64 -18
  79. package/src/Api/Implementation/StatusBarApiImpl.d.ts +0 -1
  80. package/src/Api/Implementation/StatusBarApiImpl.js +0 -3
  81. package/src/Api/Implementation/TeamSharingApiImpl.js +3 -15
  82. package/src/Api/Implementation/ThemeApiImpl.js +2 -7
  83. package/src/Api/Implementation/ToolPanelApiImpl.js +6 -6
  84. package/src/Api/Implementation/UserInterfaceApiImpl.d.ts +14 -8
  85. package/src/Api/Implementation/UserInterfaceApiImpl.js +30 -25
  86. package/src/Api/Internal/ActionRowInternalApi.d.ts +6 -1
  87. package/src/Api/Internal/ActionRowInternalApi.js +118 -38
  88. package/src/Api/Internal/AdaptableInternalApi.d.ts +6 -8
  89. package/src/Api/Internal/AdaptableInternalApi.js +25 -37
  90. package/src/Api/Internal/AlertInternalApi.d.ts +2 -2
  91. package/src/Api/Internal/AlertInternalApi.js +4 -17
  92. package/src/Api/Internal/CalculatedColumnInternalApi.d.ts +2 -0
  93. package/src/Api/Internal/CalculatedColumnInternalApi.js +79 -14
  94. package/src/Api/Internal/ChartingInternalApi.js +13 -13
  95. package/src/Api/Internal/ColumnFilterInternalApi.d.ts +2 -0
  96. package/src/Api/Internal/ColumnFilterInternalApi.js +35 -31
  97. package/src/Api/Internal/ColumnInternalApi.d.ts +6 -1
  98. package/src/Api/Internal/ColumnInternalApi.js +20 -1
  99. package/src/Api/Internal/CommentsInternalApi.d.ts +4 -0
  100. package/src/Api/Internal/CommentsInternalApi.js +18 -0
  101. package/src/Api/Internal/CustomSortInternalApi.d.ts +3 -2
  102. package/src/Api/Internal/CustomSortInternalApi.js +33 -2
  103. package/src/Api/Internal/DashboardInternalApi.js +5 -11
  104. package/src/Api/Internal/DataImportInternalApi.js +3 -9
  105. package/src/Api/Internal/DataSetInternalApi.js +3 -8
  106. package/src/Api/Internal/ExportInternalApi.d.ts +2 -1
  107. package/src/Api/Internal/ExportInternalApi.js +8 -5
  108. package/src/Api/Internal/ExpressionInternalApi.js +2 -12
  109. package/src/Api/Internal/Fdc3InternalApi.js +3 -12
  110. package/src/Api/Internal/FormatColumnInternalApi.d.ts +3 -6
  111. package/src/Api/Internal/FormatColumnInternalApi.js +39 -30
  112. package/src/Api/Internal/FreeTextColumnInternalApi.d.ts +2 -0
  113. package/src/Api/Internal/FreeTextColumnInternalApi.js +62 -1
  114. package/src/Api/Internal/GridFilterInternalApi.d.ts +5 -0
  115. package/src/Api/Internal/GridFilterInternalApi.js +9 -9
  116. package/src/Api/Internal/GridInternalApi.d.ts +23 -3
  117. package/src/Api/Internal/GridInternalApi.js +151 -44
  118. package/src/Api/Internal/LayoutInternalApi.d.ts +2 -0
  119. package/src/Api/Internal/LayoutInternalApi.js +26 -19
  120. package/src/Api/Internal/NoteInternalApi.d.ts +4 -0
  121. package/src/Api/Internal/NoteInternalApi.js +18 -0
  122. package/src/Api/Internal/PredicateInternalApi.d.ts +6 -6
  123. package/src/Api/Internal/PredicateInternalApi.js +5 -40
  124. package/src/Api/Internal/ScheduleInternalApi.js +1 -6
  125. package/src/Api/Internal/StyledColumnInternalApi.d.ts +2 -2
  126. package/src/Api/Internal/StyledColumnInternalApi.js +8 -9
  127. package/src/Api/Internal/SystemStatusInternalApi.js +1 -7
  128. package/src/Api/Internal/TeamSharingInternalApi.js +3 -8
  129. package/src/Api/Internal/ThemeInternalApi.js +1 -1
  130. package/src/Api/Internal/UserInterfaceInternalApi.js +1 -1
  131. package/src/Api/InteropioPluginApi.d.ts +2 -2
  132. package/src/Api/LayoutApi.d.ts +17 -9
  133. package/src/Api/NoteApi.d.ts +48 -0
  134. package/src/Api/OptionsApi.d.ts +8 -8
  135. package/src/Api/ScopeApi.d.ts +34 -24
  136. package/src/Api/UserInterfaceApi.d.ts +15 -13
  137. package/src/EnvVars.d.ts +3 -0
  138. package/src/EnvVars.js +8 -0
  139. package/src/PredefinedConfig/AdaptableState.d.ts +2 -2
  140. package/src/PredefinedConfig/AlertState.d.ts +2 -2
  141. package/src/PredefinedConfig/CommentState.d.ts +27 -23
  142. package/src/PredefinedConfig/Common/AdaptableColumn.d.ts +4 -0
  143. package/src/PredefinedConfig/Common/AdaptableIcon.d.ts +1 -1
  144. package/src/PredefinedConfig/Common/AdaptableObject.d.ts +4 -4
  145. package/src/PredefinedConfig/Common/AdaptablePredicate.d.ts +2 -2
  146. package/src/PredefinedConfig/Common/AggregationColumns.d.ts +1 -0
  147. package/src/PredefinedConfig/Common/AggregationColumns.js +5 -1
  148. package/src/PredefinedConfig/Common/CellSummary.d.ts +5 -14
  149. package/src/PredefinedConfig/Common/{AdaptableScope.d.ts → ColumnScope.d.ts} +4 -1
  150. package/src/PredefinedConfig/Common/DataUpdateConfig.d.ts +4 -0
  151. package/src/PredefinedConfig/Common/Enums.d.ts +4 -1
  152. package/src/PredefinedConfig/Common/Enums.js +3 -0
  153. package/src/PredefinedConfig/Common/Fdc3Intent.d.ts +2 -2
  154. package/src/PredefinedConfig/Common/Menu.d.ts +15 -1
  155. package/src/PredefinedConfig/Common/Menu.js +117 -0
  156. package/src/PredefinedConfig/Common/RowScope.d.ts +17 -0
  157. package/src/PredefinedConfig/Common/RowSummary.d.ts +21 -0
  158. package/src/PredefinedConfig/Common/RowSummary.js +20 -0
  159. package/src/PredefinedConfig/Common/TransposeConfig.d.ts +30 -0
  160. package/src/PredefinedConfig/Common/Types.d.ts +4 -4
  161. package/src/PredefinedConfig/Common/Types.js +4 -1
  162. package/src/PredefinedConfig/ExportState.d.ts +2 -2
  163. package/src/PredefinedConfig/FlashingCellState.d.ts +2 -2
  164. package/src/PredefinedConfig/FormatColumnState.d.ts +9 -5
  165. package/src/PredefinedConfig/LayoutState.d.ts +5 -0
  166. package/src/PredefinedConfig/{NotesState.d.ts → NoteState.d.ts} +12 -22
  167. package/src/PredefinedConfig/NoteState.js +2 -0
  168. package/src/PredefinedConfig/PlusMinusState.d.ts +2 -2
  169. package/src/PredefinedConfig/PopupState.d.ts +1 -2
  170. package/src/PredefinedConfig/PredefinedConfig.d.ts +3 -3
  171. package/src/PredefinedConfig/Selection/GridCell.d.ts +13 -0
  172. package/src/PredefinedConfig/ShortcutState.d.ts +2 -2
  173. package/src/PredefinedConfig/StyledColumnState.d.ts +5 -5
  174. package/src/PredefinedConfig/SystemState.d.ts +12 -4
  175. package/src/Redux/ActionsReducers/CommentsRedux.d.ts +0 -4
  176. package/src/Redux/ActionsReducers/CommentsRedux.js +1 -39
  177. package/src/Redux/ActionsReducers/LayoutRedux.d.ts +9 -0
  178. package/src/Redux/ActionsReducers/LayoutRedux.js +34 -11
  179. package/src/Redux/ActionsReducers/NoteRedux.d.ts +38 -0
  180. package/src/Redux/ActionsReducers/NoteRedux.js +89 -0
  181. package/src/Redux/ActionsReducers/PopupRedux.d.ts +5 -13
  182. package/src/Redux/ActionsReducers/PopupRedux.js +1 -22
  183. package/src/Redux/ActionsReducers/SystemRedux.d.ts +15 -4
  184. package/src/Redux/ActionsReducers/SystemRedux.js +27 -11
  185. package/src/Redux/Store/AdaptableStore.d.ts +4 -6
  186. package/src/Redux/Store/AdaptableStore.js +69 -79
  187. package/src/Redux/Store/Interface/IAdaptableStore.d.ts +8 -2
  188. package/src/Strategy/AdaptableModuleBase.d.ts +11 -12
  189. package/src/Strategy/AdaptableModuleBase.js +17 -23
  190. package/src/Strategy/AlertModule.d.ts +2 -3
  191. package/src/Strategy/AlertModule.js +4 -57
  192. package/src/Strategy/BulkUpdateModule.d.ts +1 -1
  193. package/src/Strategy/BulkUpdateModule.js +2 -1
  194. package/src/Strategy/CalculatedColumnModule.d.ts +4 -5
  195. package/src/Strategy/CalculatedColumnModule.js +8 -28
  196. package/src/Strategy/CellSummaryModule.d.ts +10 -8
  197. package/src/Strategy/CellSummaryModule.js +85 -70
  198. package/src/Strategy/ChartingModule.d.ts +0 -1
  199. package/src/Strategy/ChartingModule.js +2 -22
  200. package/src/Strategy/ColumnFilterModule.d.ts +3 -4
  201. package/src/Strategy/ColumnFilterModule.js +37 -121
  202. package/src/Strategy/ColumnInfoModule.d.ts +2 -2
  203. package/src/Strategy/ColumnInfoModule.js +6 -4
  204. package/src/Strategy/CommentModule.d.ts +11 -0
  205. package/src/Strategy/CommentModule.js +75 -0
  206. package/src/Strategy/CustomSortModule.d.ts +1 -1
  207. package/src/Strategy/CustomSortModule.js +4 -3
  208. package/src/Strategy/DashboardModule.d.ts +3 -4
  209. package/src/Strategy/DashboardModule.js +11 -28
  210. package/src/Strategy/DataChangeHistoryModule.d.ts +1 -0
  211. package/src/Strategy/DataChangeHistoryModule.js +3 -1
  212. package/src/Strategy/DataImportModule.d.ts +4 -4
  213. package/src/Strategy/DataImportModule.js +8 -8
  214. package/src/Strategy/DataSetModule.d.ts +1 -1
  215. package/src/Strategy/DataSetModule.js +1 -1
  216. package/src/Strategy/ExportModule.d.ts +1 -2
  217. package/src/Strategy/ExportModule.js +37 -40
  218. package/src/Strategy/Fdc3Module.d.ts +1 -1
  219. package/src/Strategy/Fdc3Module.js +3 -13
  220. package/src/Strategy/FlashingCellModule.d.ts +3 -4
  221. package/src/Strategy/FlashingCellModule.js +8 -21
  222. package/src/Strategy/FormatColumnModule.d.ts +1 -3
  223. package/src/Strategy/FormatColumnModule.js +27 -91
  224. package/src/Strategy/FreeTextColumnModule.d.ts +1 -2
  225. package/src/Strategy/FreeTextColumnModule.js +2 -32
  226. package/src/Strategy/GridFilterModule.d.ts +0 -1
  227. package/src/Strategy/GridFilterModule.js +0 -37
  228. package/src/Strategy/GridInfoModule.d.ts +2 -2
  229. package/src/Strategy/GridInfoModule.js +5 -3
  230. package/src/Strategy/Interface/IModule.d.ts +3 -4
  231. package/src/Strategy/LayoutModule.d.ts +5 -6
  232. package/src/Strategy/LayoutModule.js +77 -122
  233. package/src/Strategy/NamedQueryModule.d.ts +0 -1
  234. package/src/Strategy/NamedQueryModule.js +0 -19
  235. package/src/Strategy/{NotesModule.d.ts → NoteModule.d.ts} +3 -3
  236. package/src/Strategy/NoteModule.js +60 -0
  237. package/src/Strategy/PlusMinusModule.d.ts +2 -2
  238. package/src/Strategy/PlusMinusModule.js +3 -3
  239. package/src/Strategy/ScheduleModule.d.ts +1 -1
  240. package/src/Strategy/ScheduleModule.js +1 -1
  241. package/src/Strategy/SettingsPanelModule.d.ts +3 -3
  242. package/src/Strategy/SettingsPanelModule.js +6 -6
  243. package/src/Strategy/ShortcutModule.d.ts +1 -1
  244. package/src/Strategy/ShortcutModule.js +1 -1
  245. package/src/Strategy/SmartEditModule.d.ts +1 -1
  246. package/src/Strategy/SmartEditModule.js +2 -1
  247. package/src/Strategy/StyledColumnModule.d.ts +2 -2
  248. package/src/Strategy/StyledColumnModule.js +47 -40
  249. package/src/Strategy/SystemStatusModule.d.ts +2 -2
  250. package/src/Strategy/SystemStatusModule.js +4 -3
  251. package/src/Strategy/TeamSharingModule.d.ts +1 -0
  252. package/src/Strategy/TeamSharingModule.js +5 -5
  253. package/src/Strategy/ToolPanelModule.d.ts +0 -1
  254. package/src/Strategy/ToolPanelModule.js +0 -23
  255. package/src/Strategy/Utilities/FormatColumn/getFormatColumnSettingsViewItems.js +4 -2
  256. package/src/Strategy/Utilities/getScopeViewItems.d.ts +2 -2
  257. package/src/Strategy/Utilities/getScopeViewItems.js +3 -0
  258. package/src/Utilities/Constants/DocumentationLinkConstants.js +1 -1
  259. package/src/Utilities/Constants/GeneralConstants.d.ts +2 -0
  260. package/src/Utilities/Constants/GeneralConstants.js +4 -2
  261. package/src/Utilities/Constants/ModuleConstants.d.ts +6 -6
  262. package/src/Utilities/Constants/ModuleConstants.js +7 -7
  263. package/src/Utilities/Defaults/DefaultSettingsPanel.js +7 -6
  264. package/src/Utilities/ExpressionFunctions/aggregatedScalarExpressionFunctions.d.ts +3 -2
  265. package/src/Utilities/ExpressionFunctions/aggregatedScalarExpressionFunctions.js +434 -3
  266. package/src/Utilities/ExpressionFunctions/observableExpressionFunctions.js +3 -3
  267. package/src/Utilities/ExpressionFunctions/scalarAggregationHelper.js +1 -1
  268. package/src/Utilities/ExpressionFunctions/scalarExpressionFunctions.d.ts +1 -1
  269. package/src/Utilities/ExpressionFunctions/scalarExpressionFunctions.js +15 -0
  270. package/src/Utilities/Extensions/ArrayExtensions.d.ts +2 -0
  271. package/src/Utilities/Extensions/ArrayExtensions.js +6 -1
  272. package/src/Utilities/Helpers/AdaptableHelper.d.ts +3 -4
  273. package/src/Utilities/Helpers/AdaptableHelper.js +21 -60
  274. package/src/Utilities/Helpers/Helper.d.ts +2 -0
  275. package/src/Utilities/Helpers/Helper.js +6 -1
  276. package/src/Utilities/Interface/MessagePopups.d.ts +0 -3
  277. package/src/Utilities/MenuItem.d.ts +7 -4
  278. package/src/Utilities/MenuItem.js +6 -3
  279. package/src/Utilities/ObjectFactory.d.ts +3 -3
  280. package/src/Utilities/ObjectFactory.js +7 -25
  281. package/src/Utilities/Services/AggregatedScalarLiveValue.d.ts +4 -2
  282. package/src/Utilities/Services/AggregatedScalarLiveValue.js +26 -19
  283. package/src/Utilities/Services/CellPopupService.js +2 -3
  284. package/src/Utilities/Services/Interface/IQueryLanguageService.d.ts +1 -1
  285. package/src/Utilities/Services/Interface/IReportService.d.ts +1 -4
  286. package/src/Utilities/Services/LicenseService/index.d.ts +3 -0
  287. package/src/Utilities/Services/LicenseService/index.js +1 -186
  288. package/src/Utilities/Services/MetamodelService.d.ts +1 -1
  289. package/src/Utilities/Services/MetamodelService.js +6 -3
  290. package/src/Utilities/Services/ModuleService.js +6 -2
  291. package/src/Utilities/Services/QueryLanguageService.d.ts +1 -1
  292. package/src/Utilities/Services/QueryLanguageService.js +4 -3
  293. package/src/Utilities/Services/ReportService.d.ts +7 -5
  294. package/src/Utilities/Services/ReportService.js +243 -24
  295. package/src/Utilities/Services/RowEditService.d.ts +3 -2
  296. package/src/Utilities/Services/RowEditService.js +3 -1
  297. package/src/Utilities/Services/RowSummaryService.d.ts +22 -0
  298. package/src/Utilities/Services/RowSummaryService.js +146 -0
  299. package/src/Utilities/adaptableQlUtils.d.ts +2 -0
  300. package/src/Utilities/adaptableQlUtils.js +18 -0
  301. package/src/Utilities/license/decode.js +1 -70
  302. package/src/Utilities/license/hashing.js +1 -47
  303. package/src/View/AdaptableView.js +1 -3
  304. package/src/View/AdaptableViewFactory.js +2 -2
  305. package/src/View/AdaptableWizardView/AdaptableConfigurationDialog/ConfigurationWizard.js +2 -2
  306. package/src/View/AdaptableWizardView/AdaptableConfigurationDialog/UIOptions/UIOptionsStatusbarForm.js +1 -1
  307. package/src/View/Alert/Utilities/getAvailablePredicates.d.ts +2 -2
  308. package/src/View/Alert/Utilities/getDefaultAlertDefinition.d.ts +1 -1
  309. package/src/View/BulkUpdate/BulkUpdatePopup.js +1 -1
  310. package/src/View/CalculatedColumn/Wizard/CalculatedColumnWizard.d.ts +1 -1
  311. package/src/View/CalculatedColumn/Wizard/CalculatedColumnWizard.js +3 -3
  312. package/src/View/CalculatedColumn/utils.d.ts +1 -1
  313. package/src/View/CellSummary/CellSummaryPopup.js +1 -1
  314. package/src/View/Comments/CommentsEditor.js +28 -17
  315. package/src/View/Comments/CommentsPopup.js +25 -13
  316. package/src/View/Components/AdaptableDateInput/index.d.ts +1 -1
  317. package/src/View/Components/AdaptableInput/AdaptableDateInlineInput.d.ts +5 -0
  318. package/src/View/Components/AdaptableInput/AdaptableDateInlineInput.js +46 -0
  319. package/src/View/Components/AdaptableObjectList/AdaptableObjectList.js +5 -2
  320. package/src/View/Components/CellPopup/index.d.ts +1 -0
  321. package/src/View/Components/CellPopup/index.js +6 -3
  322. package/src/View/Components/EntityRulesEditor/EntityRulePredicatesEditor/EntityRulePredicatesEditor.d.ts +3 -3
  323. package/src/View/Components/EntityRulesEditor/index.d.ts +3 -3
  324. package/src/View/Components/FilterForm/FilterForm.js +20 -12
  325. package/src/View/Components/FilterForm/QuickFilterForm.js +15 -8
  326. package/src/View/Components/FilterForm/QuickFilterValues.js +39 -23
  327. package/src/View/Components/NewScopeComponent.d.ts +5 -5
  328. package/src/View/Components/NewScopeComponent.js +34 -1
  329. package/src/View/Components/Popups/AdaptableLoadingScreen.d.ts +6 -5
  330. package/src/View/Components/Popups/AdaptableLoadingScreen.js +19 -9
  331. package/src/View/Components/Popups/AdaptablePopup/useMenuItems.js +9 -1
  332. package/src/View/Components/Popups/AdaptableToaster.js +1 -1
  333. package/src/View/Components/Popups/GridCellPopup/GridCellPopup.js +7 -7
  334. package/src/View/Components/Popups/WindowPopups/windowFactory.d.ts +1 -0
  335. package/src/View/Components/Popups/WindowPopups/windowFactory.js +4 -1
  336. package/src/View/Components/RangesComponent.d.ts +2 -2
  337. package/src/View/Components/Selectors/PermittedValuesSelector.js +2 -2
  338. package/src/View/Components/SharedProps/WizardScopeState.d.ts +2 -2
  339. package/src/View/Components/ValueSelector/index.d.ts +1 -0
  340. package/src/View/Components/ValueSelector/index.js +2 -2
  341. package/src/View/CustomSort/CustomSortSummary.js +1 -1
  342. package/src/View/DataChangeHistory/DataChangeHistoryGrid.js +12 -10
  343. package/src/View/DataImport/DataImportWizard/DataImportWizard.js +1 -1
  344. package/src/View/FormatColumn/Wizard/FormatColumnFormatWizardSection.d.ts +2 -2
  345. package/src/View/FormatColumn/Wizard/FormatColumnFormatWizardSection.js +19 -6
  346. package/src/View/FormatColumn/Wizard/FormatColumnSettingsWizardSection.js +27 -12
  347. package/src/View/FreeTextColumn/FreeTextColumnSummary.js +1 -1
  348. package/src/View/FreeTextColumn/Wizard/FreeTextColumnWizard.js +3 -1
  349. package/src/View/GridFilter/GridFilterViewPanel.js +9 -5
  350. package/src/View/GridFilter/useGridFilterExpressionEditor.js +1 -1
  351. package/src/View/GridInfo/GridInfoPopup/GridInfoPopup.js +2 -3
  352. package/src/View/Layout/LayoutViewPanel.js +2 -1
  353. package/src/View/Layout/TransposedPopup.d.ts +3 -0
  354. package/src/View/Layout/TransposedPopup.js +200 -0
  355. package/src/View/Layout/Wizard/LayoutWizard.js +38 -3
  356. package/src/View/Layout/Wizard/sections/ColumnsSection.js +1 -1
  357. package/src/View/Layout/Wizard/sections/FilterSection.js +1 -1
  358. package/src/View/Layout/Wizard/sections/RowGroupingSection.js +17 -1
  359. package/src/View/Layout/Wizard/sections/RowSummarySection.d.ts +9 -0
  360. package/src/View/Layout/Wizard/sections/RowSummarySection.js +181 -0
  361. package/src/View/License/LicenseWatermark.js +1 -66
  362. package/src/View/Note/NotePopup.d.ts +2 -0
  363. package/src/View/{Notes/NotesPopup.js → Note/NotePopup.js} +22 -19
  364. package/src/View/SpecialColumnSettingsWizardStep.js +4 -4
  365. package/src/View/StyledColumn/Wizard/StyledColumnWizard.js +1 -1
  366. package/src/View/StyledColumn/Wizard/StyledColumnWizardSettingsSection.js +38 -14
  367. package/src/View/Theme/ThemeSelector.js +2 -2
  368. package/src/agGrid/ActionColumnRenderer.js +48 -10
  369. package/src/agGrid/Adaptable.d.ts +3 -455
  370. package/src/agGrid/Adaptable.js +7 -5291
  371. package/src/agGrid/AdaptableAgGrid.d.ts +346 -0
  372. package/src/agGrid/AdaptableAgGrid.js +3915 -0
  373. package/src/agGrid/AdaptableLogger.js +78 -13
  374. package/src/agGrid/AgGridAdapter.d.ts +64 -0
  375. package/src/agGrid/AgGridAdapter.js +594 -0
  376. package/src/agGrid/AgGridColumnAdapter.d.ts +54 -0
  377. package/src/agGrid/AgGridColumnAdapter.js +800 -0
  378. package/src/agGrid/AgGridMenuAdapter.d.ts +44 -0
  379. package/src/agGrid/AgGridMenuAdapter.js +605 -0
  380. package/src/agGrid/AgGridOptionsService.d.ts +15 -0
  381. package/src/agGrid/AgGridOptionsService.js +80 -0
  382. package/src/agGrid/BadgeRenderer.d.ts +2 -2
  383. package/src/agGrid/BadgeRenderer.js +26 -12
  384. package/src/agGrid/CheckboxRenderer.js +1 -1
  385. package/src/agGrid/FilterWrapper.d.ts +2 -2
  386. package/src/agGrid/FilterWrapper.js +1 -1
  387. package/src/agGrid/PercentBarRenderer.js +2 -1
  388. package/src/agGrid/attachAddaptableColumnTypes.d.ts +12 -12
  389. package/src/agGrid/buildSortedColumnStateForLayout.d.ts +7 -0
  390. package/src/agGrid/buildSortedColumnStateForLayout.js +124 -0
  391. package/src/agGrid/defaultAdaptableOptions.d.ts +3 -0
  392. package/src/{Utilities/Defaults/DefaultAdaptableOptions.js → agGrid/defaultAdaptableOptions.js} +74 -19
  393. package/src/agGrid/editors/AdaptableDateEditor/index.d.ts +1 -1
  394. package/src/agGrid/editors/AdaptableDateEditor/index.js +3 -3
  395. package/src/agGrid/editors/AdaptableNumberEditor/index.d.ts +2 -2
  396. package/src/agGrid/editors/AdaptableNumberEditor/index.js +2 -2
  397. package/src/agGrid/sortColumnStateForVisibleColumns.d.ts +12 -0
  398. package/src/agGrid/sortColumnStateForVisibleColumns.js +50 -0
  399. package/src/agGrid/weightedAverage.d.ts +0 -2
  400. package/src/agGrid/weightedAverage.js +1 -56
  401. package/src/components/ColorPicker/ColorPicker.d.ts +1 -1
  402. package/src/components/Datepicker/index.d.ts +1 -1
  403. package/src/components/Datepicker/index.js +10 -2
  404. package/src/components/ExpressionEditor/QueryBuilder/QueryPredicateBuilder.js +2 -1
  405. package/src/components/ExpressionEditor/QueryBuilder/utils.d.ts +0 -1
  406. package/src/components/ExpressionEditor/QueryBuilder/utils.js +3 -17
  407. package/src/components/InfiniteTable/index.js +2 -2
  408. package/src/components/Input/index.d.ts +1 -2
  409. package/src/components/List/ListGroupItem/index.d.ts +1 -1
  410. package/src/components/Modal/index.d.ts +1 -0
  411. package/src/components/Modal/index.js +6 -4
  412. package/src/components/ProgressIndicator/ProgressIndicator.js +15 -6
  413. package/src/components/Select/Select.d.ts +3 -1
  414. package/src/components/Select/Select.js +4 -2
  415. package/src/components/Textarea/index.d.ts +2 -2
  416. package/src/components/icons/copy.d.ts +3 -0
  417. package/src/components/icons/copy.js +7 -0
  418. package/src/components/icons/filter-off.d.ts +3 -0
  419. package/src/components/icons/filter-off.js +7 -0
  420. package/src/components/icons/grid-info.d.ts +3 -0
  421. package/src/components/icons/grid-info.js +7 -0
  422. package/src/components/icons/index.js +14 -0
  423. package/src/components/icons/note.js +2 -2
  424. package/src/components/icons/rows.d.ts +3 -0
  425. package/src/components/icons/rows.js +7 -0
  426. package/src/components/icons/select-all.d.ts +3 -0
  427. package/src/components/icons/select-all.js +7 -0
  428. package/src/components/icons/select-fwd.d.ts +3 -0
  429. package/src/components/icons/select-fwd.js +7 -0
  430. package/src/components/icons/select-off.d.ts +3 -0
  431. package/src/components/icons/select-off.js +7 -0
  432. package/src/env.js +2 -2
  433. package/src/metamodel/adaptable.metamodel.d.ts +222 -73
  434. package/src/metamodel/adaptable.metamodel.js +1 -9316
  435. package/src/migration/AdaptableUpgradeHelper.d.ts +38 -0
  436. package/src/migration/AdaptableUpgradeHelper.js +52 -0
  437. package/src/migration/VersionUpgrade.d.ts +8 -0
  438. package/src/migration/VersionUpgrade.js +15 -0
  439. package/src/migration/VersionUpgrade17.d.ts +18 -0
  440. package/src/migration/VersionUpgrade17.js +347 -0
  441. package/src/migration/VersionUpgrade18.d.ts +5 -0
  442. package/src/migration/VersionUpgrade18.js +10 -0
  443. package/src/parser/src/parser.js +576 -553
  444. package/src/parser/src/predicate/mapExpressionToQlPredicate.js +1 -1
  445. package/src/parser/src/predicate/mapQlPredicateToExpression.js +3 -4
  446. package/src/parser/src/types.d.ts +7 -2
  447. package/src/parser/src/types.js +1 -2
  448. package/src/types.d.ts +29 -21
  449. package/tsconfig.cjs.tsbuildinfo +1 -1
  450. package/src/AdaptableOptions/CommentsOptions.d.ts +0 -28
  451. package/src/AdaptableOptions/NotesOptions.d.ts +0 -16
  452. package/src/Api/Events/CommentsChangedInfo.d.ts +0 -5
  453. package/src/Api/Implementation/NotesApiImpl.d.ts +0 -16
  454. package/src/Api/Implementation/NotesApiImpl.js +0 -44
  455. package/src/Api/NotesApi.d.ts +0 -48
  456. package/src/PredefinedConfig/CellAddress.d.ts +0 -13
  457. package/src/PredefinedConfig/CellAddress.js +0 -5
  458. package/src/Redux/ActionsReducers/NotesRedux.d.ts +0 -39
  459. package/src/Redux/ActionsReducers/NotesRedux.js +0 -87
  460. package/src/Strategy/CommentsModule.d.ts +0 -16
  461. package/src/Strategy/CommentsModule.js +0 -82
  462. package/src/Strategy/NotesModule.js +0 -62
  463. package/src/Utilities/Defaults/DefaultAdaptableOptions.d.ts +0 -2
  464. package/src/Utilities/Services/Interface/IRowEditService.d.ts +0 -3
  465. package/src/View/Components/ScopeComponent.d.ts +0 -24
  466. package/src/View/Components/ScopeComponent.js +0 -138
  467. package/src/View/Export/Wizard/ReportScopeWizard.d.ts +0 -17
  468. package/src/View/Export/Wizard/ReportScopeWizard.js +0 -52
  469. package/src/View/Notes/NotesPopup.d.ts +0 -2
  470. package/src/agGrid/agGridHelper.d.ts +0 -57
  471. package/src/agGrid/agGridHelper.js +0 -691
  472. package/src/agGrid/agGridMenuHelper.d.ts +0 -46
  473. package/src/agGrid/agGridMenuHelper.js +0 -673
  474. /package/src/AdaptableOptions/{CommentsOptions.js → CommentOptions.js} +0 -0
  475. /package/src/AdaptableOptions/{NotesOptions.js → NoteOptions.js} +0 -0
  476. /package/src/Api/Events/{CommentsChangedInfo.js → CommentChanged.js} +0 -0
  477. /package/src/Api/{NotesApi.js → NoteApi.js} +0 -0
  478. /package/src/PredefinedConfig/Common/{AdaptableScope.js → ColumnScope.js} +0 -0
  479. /package/src/PredefinedConfig/{NotesState.js → Common/RowScope.js} +0 -0
  480. /package/src/{Utilities/Services/Interface/IRowEditService.js → PredefinedConfig/Common/TransposeConfig.js} +0 -0
  481. /package/src/View/{Notes → Note}/NoteEditor.d.ts +0 -0
  482. /package/src/View/{Notes → Note}/NoteEditor.js +0 -0
@@ -0,0 +1,3915 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdaptableAgGrid = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const throttle_1 = tslib_1.__importDefault(require("lodash/throttle"));
6
+ const debounce_1 = tslib_1.__importDefault(require("lodash/debounce"));
7
+ const core_1 = require("ag-grid-community");
8
+ const AdaptableLogger_1 = require("./AdaptableLogger");
9
+ const DocumentationLinkConstants_1 = require("../Utilities/Constants/DocumentationLinkConstants");
10
+ const StringExtensions_1 = tslib_1.__importDefault(require("../Utilities/Extensions/StringExtensions"));
11
+ const Emitter_1 = tslib_1.__importDefault(require("../Utilities/Emitter"));
12
+ const defaultAdaptableOptions_1 = require("./defaultAdaptableOptions");
13
+ const AgGridAdapter_1 = require("./AgGridAdapter");
14
+ const GeneralConstants = tslib_1.__importStar(require("../Utilities/Constants/GeneralConstants"));
15
+ const GeneralConstants_1 = require("../Utilities/Constants/GeneralConstants");
16
+ const DataService_1 = require("../Utilities/Services/DataService");
17
+ const AdaptableStore_1 = require("../Redux/Store/AdaptableStore");
18
+ const AdaptableApiImpl_1 = require("../Api/Implementation/AdaptableApiImpl");
19
+ const Fdc3Service_1 = require("../Utilities/Services/Fdc3Service");
20
+ const CellPopupService_1 = require("../Utilities/Services/CellPopupService");
21
+ const ChartingService_1 = require("../Utilities/Services/ChartingService");
22
+ const ThemeService_1 = require("../Utilities/Services/ThemeService");
23
+ const ValidationService_1 = require("../Utilities/Services/ValidationService");
24
+ const ReportService_1 = require("../Utilities/Services/ReportService");
25
+ const ModuleService_1 = require("../Utilities/Services/ModuleService");
26
+ const CalculatedColumnExpressionService_1 = require("../Utilities/Services/CalculatedColumnExpressionService");
27
+ const EntitlementService_1 = require("../Utilities/Services/EntitlementService");
28
+ const QueryLanguageService_1 = require("../Utilities/Services/QueryLanguageService");
29
+ const AlertService_1 = require("../Utilities/Services/AlertService");
30
+ const TeamSharingService_1 = require("../Utilities/Services/TeamSharingService");
31
+ const MetamodelService_1 = require("../Utilities/Services/MetamodelService");
32
+ const LicenseService_1 = require("../Utilities/Services/LicenseService");
33
+ const Types_1 = require("../PredefinedConfig/Common/Types");
34
+ const ModuleConstants = tslib_1.__importStar(require("../Utilities/Constants/ModuleConstants"));
35
+ const ModuleConstants_1 = require("../Utilities/Constants/ModuleConstants");
36
+ const DashboardModule_1 = require("../Strategy/DashboardModule");
37
+ const AlertModule_1 = require("../Strategy/AlertModule");
38
+ const FlashingCellModule_1 = require("../Strategy/FlashingCellModule");
39
+ const BulkUpdateModule_1 = require("../Strategy/BulkUpdateModule");
40
+ const CalculatedColumnModule_1 = require("../Strategy/CalculatedColumnModule");
41
+ const CellSummaryModule_1 = require("../Strategy/CellSummaryModule");
42
+ const CustomSortModule_1 = require("../Strategy/CustomSortModule");
43
+ const DataChangeHistoryModule_1 = require("../Strategy/DataChangeHistoryModule");
44
+ const DataImportModule_1 = require("../Strategy/DataImportModule");
45
+ const DataSetModule_1 = require("../Strategy/DataSetModule");
46
+ const ExportModule_1 = require("../Strategy/ExportModule");
47
+ const ColumnFilterModule_1 = require("../Strategy/ColumnFilterModule");
48
+ const FormatColumnModule_1 = require("../Strategy/FormatColumnModule");
49
+ const FreeTextColumnModule_1 = require("../Strategy/FreeTextColumnModule");
50
+ const LayoutModule_1 = require("../Strategy/LayoutModule");
51
+ const PlusMinusModule_1 = require("../Strategy/PlusMinusModule");
52
+ const QuickSearchModule_1 = require("../Strategy/QuickSearchModule");
53
+ const ScheduleModule_1 = require("../Strategy/ScheduleModule");
54
+ const SmartEditModule_1 = require("../Strategy/SmartEditModule");
55
+ const ShortcutModule_1 = require("../Strategy/ShortcutModule");
56
+ const StateManagementModule_1 = require("../Strategy/StateManagementModule");
57
+ const TeamSharingModule_1 = require("../Strategy/TeamSharingModule");
58
+ const ToolPanelModule_1 = require("../Strategy/ToolPanelModule");
59
+ const SystemStatusModule_1 = require("../Strategy/SystemStatusModule");
60
+ const ThemeModule_1 = require("../Strategy/ThemeModule");
61
+ const GridInfoModule_1 = require("../Strategy/GridInfoModule");
62
+ const ColumnInfoModule_1 = require("../Strategy/ColumnInfoModule");
63
+ const SettingsPanelModule_1 = require("../Strategy/SettingsPanelModule");
64
+ const StatusBarModule_1 = require("../Strategy/StatusBarModule");
65
+ const ChartingModule_1 = require("../Strategy/ChartingModule");
66
+ const NoteModule_1 = require("../Strategy/NoteModule");
67
+ const StyledColumnModule_1 = require("../Strategy/StyledColumnModule");
68
+ const Fdc3Module_1 = require("../Strategy/Fdc3Module");
69
+ const GridFilterModule_1 = require("../Strategy/GridFilterModule");
70
+ const NamedQueryModule_1 = require("../Strategy/NamedQueryModule");
71
+ const CommentModule_1 = require("../Strategy/CommentModule");
72
+ const AdaptableNumberEditor_1 = require("./editors/AdaptableNumberEditor");
73
+ const AdaptableDateEditor_1 = require("./editors/AdaptableDateEditor");
74
+ const Helper_1 = require("../Utilities/Helpers/Helper");
75
+ const uuid_1 = require("../components/utils/uuid");
76
+ const UIHelper_1 = tslib_1.__importDefault(require("../View/UIHelper"));
77
+ const AdaptableToolPanel_1 = require("../View/Components/ToolPanel/AdaptableToolPanel");
78
+ const StatusBarState_1 = require("../PredefinedConfig/StatusBarState");
79
+ const createAgStatusPanelComponent_1 = require("./createAgStatusPanelComponent");
80
+ const AdaptableStatusBar_1 = require("../View/StatusBar/AdaptableStatusBar");
81
+ const ArrayExtensions_1 = tslib_1.__importDefault(require("../Utilities/Extensions/ArrayExtensions"));
82
+ const AgGridMenuAdapter_1 = require("./AgGridMenuAdapter");
83
+ const AdaptableView_1 = require("../View/AdaptableView");
84
+ const renderReactRoot_1 = require("../renderReactRoot");
85
+ const AgGridOptionsService_1 = require("./AgGridOptionsService");
86
+ const DateHelper_1 = require("../Utilities/Helpers/DateHelper");
87
+ const AgGridColumnAdapter_1 = require("./AgGridColumnAdapter");
88
+ const uniqBy_1 = tslib_1.__importDefault(require("lodash/uniqBy"));
89
+ const getScrollbarSize_1 = tslib_1.__importDefault(require("../Utilities/getScrollbarSize"));
90
+ const AggregationColumns_1 = require("../PredefinedConfig/Common/AggregationColumns");
91
+ const isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
92
+ const RowEditService_1 = require("../Utilities/Services/RowEditService");
93
+ const weightedAverage_1 = require("./weightedAverage");
94
+ const sortWithOrder_1 = require("../Utilities/sortWithOrder");
95
+ const Enums_1 = require("../PredefinedConfig/Common/Enums");
96
+ const ObjectFactory_1 = tslib_1.__importDefault(require("../Utilities/ObjectFactory"));
97
+ const EnvVars_1 = require("../EnvVars");
98
+ const AdaptableUpgradeHelper_1 = require("../migration/AdaptableUpgradeHelper");
99
+ const Modal_1 = require("../components/Modal");
100
+ const AdaptableLoadingScreen_1 = require("../View/Components/Popups/AdaptableLoadingScreen");
101
+ const react_1 = require("react");
102
+ const AdaptableHelper_1 = require("../Utilities/Helpers/AdaptableHelper");
103
+ const buildSortedColumnStateForLayout_1 = require("./buildSortedColumnStateForLayout");
104
+ const RowNodeProto = core_1.RowNode.prototype;
105
+ const RowNode_dispatchLocalEvent = RowNodeProto.dispatchLocalEvent;
106
+ /**
107
+ * AgGrid does not expose 'cellChanged' and 'dataChanged'
108
+ * so we have to override `dispatchLocalEvent`
109
+ * and hook our own functionality into it
110
+ */
111
+ RowNodeProto.dispatchLocalEvent = function (event) {
112
+ const node = event.node;
113
+ const result = RowNode_dispatchLocalEvent.apply(this, arguments);
114
+ const extractGridApiFromRowNode = (rowNode) => {
115
+ var _a;
116
+ // starting with AG Grid 26.1.0 the gridApi is wrapped in a Beans property
117
+ const rowNodeApi = (_a = rowNode === null || rowNode === void 0 ? void 0 : rowNode.beans) === null || _a === void 0 ? void 0 : _a.gridApi;
118
+ if (!rowNodeApi) {
119
+ AdaptableLogger_1.AdaptableLogger.consoleErrorBase(`No GridAPI found in passed RowNode, this should never happen!`, rowNode);
120
+ }
121
+ return rowNodeApi;
122
+ };
123
+ // we don't know from which instance of aggrid this is coming,
124
+ // as this fn is shared by all instances
125
+ if (node) {
126
+ AdaptableAgGrid.forEachAdaptable((adaptable) => {
127
+ var _a;
128
+ if (extractGridApiFromRowNode(node) !== ((_a = adaptable.agGridAdapter) === null || _a === void 0 ? void 0 : _a.getAgGridApi(true))) {
129
+ // the event is coming from another aggrid instance
130
+ // so IGNORE IT
131
+ return;
132
+ }
133
+ // we're on the correct instance, so do this
134
+ //@ts-ignore
135
+ const fn = adaptable.rowListeners ? adaptable.rowListeners[event.type] : null;
136
+ if (fn) {
137
+ fn(event);
138
+ }
139
+ });
140
+ }
141
+ return result;
142
+ };
143
+ const adaptableInstances = {};
144
+ const publishTimestamp = Number(EnvVars_1.ADAPTABLE_PUBLISH_TIMESTAMP);
145
+ class AdaptableAgGrid {
146
+ constructor() {
147
+ /**
148
+ * once layouts are properly handled with the new aggrid methods & events
149
+ * we can remove this hack
150
+ */
151
+ this.previousAgGridLayoutState = '';
152
+ this.columnMinMaxValuesCache = {};
153
+ this.renderReactRoot = (node, container) => (0, renderReactRoot_1.renderReactRoot)(node, container);
154
+ /**
155
+ * Temporary, these are MIGRATION technical debts, and should be removed as soon as possible
156
+ */
157
+ this.adaptableStatusPanelKeys = [];
158
+ // only for our private / internal events used within Adaptable
159
+ // public events are emitted through the EventApi
160
+ this._emit = (eventName, data) => {
161
+ if (this.emitter) {
162
+ return this.emitter.emit(eventName, data);
163
+ }
164
+ };
165
+ this._emitSync = (eventName, data) => {
166
+ if (this.emitter) {
167
+ return this.emitter.emitSync(eventName, data);
168
+ }
169
+ };
170
+ this._on = (eventName, callback) => {
171
+ if (!this.emitter) {
172
+ return () => { };
173
+ }
174
+ return this.emitter.on(eventName, callback);
175
+ };
176
+ this._onIncludeFired = (eventName, callback) => {
177
+ if (!this.emitter) {
178
+ return () => { };
179
+ }
180
+ return this.emitter.onIncludeFired(eventName, callback);
181
+ };
182
+ this.lifecycleState = 'initial';
183
+ this.emitter = new Emitter_1.default();
184
+ this.agGridOptionsService = new AgGridOptionsService_1.AgGridOptionsService(this);
185
+ this.agGridAdapter = new AgGridAdapter_1.AgGridAdapter(this);
186
+ this.agGridMenuAdapter = new AgGridMenuAdapter_1.AgGridMenuAdapter(this);
187
+ this.agGridColumnAdapter = new AgGridColumnAdapter_1.AgGridColumnAdapter(this);
188
+ this.DataService = new DataService_1.DataService(this);
189
+ }
190
+ static forEachAdaptable(fn) {
191
+ Object.keys(adaptableInstances).forEach((key) => {
192
+ fn(adaptableInstances[key]);
193
+ });
194
+ }
195
+ static collectInstance(adaptable, adaptableId) {
196
+ adaptable._id = adaptableId;
197
+ adaptableInstances[adaptable._id] = adaptable;
198
+ }
199
+ static dismissInstance(adaptable) {
200
+ delete adaptableInstances[adaptable._id];
201
+ }
202
+ get isReady() {
203
+ return this.lifecycleState === 'ready';
204
+ }
205
+ get isAvailable() {
206
+ return this.lifecycleState === 'available' || this.lifecycleState === 'ready';
207
+ }
208
+ get isDestroyed() {
209
+ return this.lifecycleState === 'preDestroyed';
210
+ }
211
+ /**
212
+ * Internal initializer for Adaptable, directly called by the React and Angular Adaptable wrappers
213
+ * @private
214
+ */
215
+ static async _initInternal(config) {
216
+ let promise = null;
217
+ if (Array.isArray(config.adaptableOptions.plugins)) {
218
+ const agGridOptions = {
219
+ gridOptions: config.gridOptions,
220
+ modules: config.modules,
221
+ };
222
+ for (let plugin of config.adaptableOptions.plugins) {
223
+ promise =
224
+ promise && promise.then
225
+ ? promise.then(() => {
226
+ return plugin.beforeInit(config.adaptableOptions, agGridOptions);
227
+ })
228
+ : plugin.beforeInit(config.adaptableOptions, agGridOptions);
229
+ }
230
+ // if gridOptions changed, we need to update the runtimeConfig
231
+ if (agGridOptions.gridOptions !== config.gridOptions) {
232
+ // This allows plugins to modify
233
+ // FIXME AFL MIG: clarify if this is still needed (for NoCode Plugin?)
234
+ // it looks like a code smell, ideally we should get rid of it
235
+ config.gridOptions = agGridOptions.gridOptions;
236
+ }
237
+ }
238
+ const doInit = (adaptableInstance) => {
239
+ return adaptableInstance._initAdaptableAgGrid(config).then((api) => {
240
+ if (Array.isArray(config.adaptableOptions.plugins)) {
241
+ config.adaptableOptions.plugins.forEach((plugin) => {
242
+ plugin.afterInit(adaptableInstance);
243
+ });
244
+ }
245
+ return api;
246
+ });
247
+ };
248
+ if (promise && promise.then) {
249
+ return promise.then(() => {
250
+ const adaptableInstance = new AdaptableAgGrid();
251
+ return doInit(adaptableInstance);
252
+ });
253
+ }
254
+ else {
255
+ const adaptableInstance = new AdaptableAgGrid();
256
+ return doInit(adaptableInstance);
257
+ }
258
+ }
259
+ async _initAdaptableAgGrid(config) {
260
+ var _a, _b;
261
+ // Phase 1: Preprocess Adaptable Options
262
+ this._isDetailGrid = config.isDetailGrid === true;
263
+ this.lifecycleState = 'preprocessOptions';
264
+ this._rawAdaptableOptions = config.adaptableOptions;
265
+ if (StringExtensions_1.default.IsNullOrEmptyOrWhiteSpace(this._rawAdaptableOptions.adaptableId)) {
266
+ this._rawAdaptableOptions.adaptableId = `adaptable_id_${Date.now()}`;
267
+ }
268
+ this.logger = (_a = this.logger) !== null && _a !== void 0 ? _a : new AdaptableLogger_1.AdaptableLogger(this._rawAdaptableOptions.adaptableId);
269
+ const perfInitAdaptableAgGrid = this.logger.beginPerf(`Adaptable._initAdaptableAgGrid()`);
270
+ AdaptableAgGrid.collectInstance(this, this._rawAdaptableOptions.adaptableId);
271
+ this.variant = config.variant;
272
+ this.initWithLazyData =
273
+ config.gridOptions.rowData == undefined || config.gridOptions.rowData.length === 0;
274
+ this.hasAutogeneratedPrimaryKey = !!this._rawAdaptableOptions.autogeneratePrimaryKey;
275
+ this.adaptableOptions = (0, defaultAdaptableOptions_1.applyDefaultAdaptableOptions)(this._rawAdaptableOptions);
276
+ this.adaptableOptions = this.normalizeAdaptableOptions(this.adaptableOptions);
277
+ const { showLoadingScreen, loadingScreenDelay, loadingScreenText, loadingScreenTitle } = this.adaptableOptions.userInterfaceOptions;
278
+ if (showLoadingScreen) {
279
+ const portalElement = (0, Modal_1.ensurePortalElement)();
280
+ if (portalElement) {
281
+ this.unmountLoadingScreen = this.renderReactRoot((0, react_1.createElement)(AdaptableLoadingScreen_1.AdaptableLoadingScreen, {
282
+ showLoadingScreen,
283
+ loadingScreenDelay,
284
+ loadingScreenText,
285
+ loadingScreenTitle,
286
+ }), portalElement);
287
+ }
288
+ }
289
+ this.forPlugins((plugin) => plugin.afterInitOptions(this, this.adaptableOptions));
290
+ this.api = new AdaptableApiImpl_1.AdaptableApiImpl(this);
291
+ this.forPlugins((plugin) => plugin.afterInitApi(this, this.api));
292
+ this.lifecycleState = 'initAdaptableState';
293
+ // just in case Adaptable was destroyed while loading the store (which is an async operation)
294
+ if (this.isDestroyed) {
295
+ return Promise.reject('Adaptable was destroyed while loading the store.');
296
+ // FIXME AFL MIG: is this enough?! talk with the team
297
+ }
298
+ this.initServices();
299
+ this.forPlugins((plugin) => plugin.afterInitServices(this));
300
+ this.adaptableModules = this.initModules();
301
+ this.forPlugins((plugin) => plugin.afterInitModules(this, this.adaptableModules));
302
+ const perfLoadStore = this.logger.beginPerf(`loadStore()`);
303
+ this.adaptableStore = this.initAdaptableStore();
304
+ this.forPlugins((plugin) => plugin.afterInitStore(this));
305
+ await this.adaptableStore.loadStore({
306
+ adaptable: this,
307
+ adaptableStateKey: this.adaptableOptions.adaptableStateKey,
308
+ /**
309
+ * This method is called after the store is loaded;
310
+ * it allows to modify the state before it is used by the application
311
+ * e.g. adding default Layout, migrating deprecated state, etc.
312
+ */
313
+ postLoadHook: (state) => {
314
+ if (this.adaptableOptions.stateOptions.autoMigrateState) {
315
+ state = AdaptableUpgradeHelper_1.AdaptableUpgradeHelper.migrateAdaptableState(state, {
316
+ // version 16 actually includes all versions up until 16
317
+ fromVersion: 16,
318
+ logger: this.logger,
319
+ });
320
+ }
321
+ state = this.normalizeAdaptableState(state, config.gridOptions);
322
+ return state;
323
+ },
324
+ });
325
+ perfLoadStore.end();
326
+ // just in case Adaptable was destroyed while loading the store (which is an async operation)
327
+ if (this.isDestroyed) {
328
+ return Promise.reject('Adaptable was destroyed while loading the store.');
329
+ // FIXME AFL MIG: is this enough?! talk with the team
330
+ }
331
+ this.forPlugins((plugin) => plugin.afterInitialStateLoaded(this));
332
+ // do this now so it sets module entitlements
333
+ this.EntitlementService.setModulesEntitlements();
334
+ /**
335
+ * At this point it's mandatory to have the ALL the Adaptable blocks initialized:
336
+ * Store, APIs, Services, Modules
337
+ */
338
+ this.lifecycleState = 'setupAgGrid';
339
+ const gridOptions = config.gridOptions;
340
+ // Needed here because special column defs are required for deriving the adaptable column state
341
+ const columnDefs = this.getAllColumnDefinitions(gridOptions.columnDefs || []);
342
+ gridOptions.columnDefs = columnDefs;
343
+ this.setInitialGridOptions(gridOptions, config.variant);
344
+ gridOptions.initialState = this.mapAdaptableStateToAgGridState(this.adaptableStore.TheStore.getState(), gridOptions.columnDefs);
345
+ this.lifecycleState = 'initAgGrid';
346
+ this.agGridAdapter.initialGridOptions = gridOptions;
347
+ const perfInitAgGrid = this.logger.beginPerf(`initAgGrid()`);
348
+ const agGridApi = await this.initializeAgGrid(gridOptions, config.modules, config.renderAgGridFrameworkComponent);
349
+ (_b = this.unmountLoadingScreen) === null || _b === void 0 ? void 0 : _b.call(this);
350
+ perfInitAgGrid.end();
351
+ if (agGridApi === false) {
352
+ this.logger.consoleError(`Adaptable failed to initialize AG Grid!`);
353
+ return Promise.reject('Adaptable failed to initialize AG Grid!');
354
+ }
355
+ this.agGridAdapter.setAgGridApi(agGridApi);
356
+ this.logger.info(`Registered AG Grid modules: `, this.agGridAdapter.getRegisteredModuleNames().sort());
357
+ /**
358
+ * At this point AG Grid is initialized!
359
+ */
360
+ this.deriveAdaptableColumnStateFromAgGrid();
361
+ this.agGridColumnAdapter.setupColumns();
362
+ // we need this because we need the internal Column state to be ready before doing any extra business logic
363
+ this.lifecycleState = 'available';
364
+ this.api.themeApi.applyCurrentTheme();
365
+ this.validatePrimaryKey();
366
+ this.embedColumnMenu = this.agGridAdapter.isModulePresent(core_1.ModuleNames.MenuModule);
367
+ this.api.internalApi.setTreeMode(!!this.agGridAdapter.getAgGridApi().getGridOption('treeData'));
368
+ // TODO AFL MIG: we could just patch the defautl Layout on init? instead
369
+ this.checkShouldClearExistingFiltersOrSearches();
370
+ this.applyColumnFiltering();
371
+ this.addGridEventListeners();
372
+ this.temporaryAdaptableStateUpdates();
373
+ this.redrawBody();
374
+ this.refreshHeader();
375
+ const currentLayout = this.api.layoutApi.getCurrentLayout();
376
+ if (currentLayout.EnablePivot) {
377
+ // this is very very strange!
378
+ // for some projects, if the initial layout is pivot, the columnDefs of the pivot resutl columns are NOT derived correctly from the main colDefs
379
+ // doing the following line fixes the issue because it foces the pivot columns to be created again
380
+ // this proj works without the hack: /tests/pages/format-column/initial-pivot-layout.page.tsx
381
+ // but this proj needs the hack: /tests/pages/format-column/initial-pivot-layout-docs.page.tsx
382
+ this.agGridAdapter.setGridOption('pivotMode', false);
383
+ this.agGridAdapter.setGridOption('pivotMode', true);
384
+ }
385
+ // create the module menu (for use in the dashboard and the toolpanel)
386
+ // TODO see #create-create-module-menu - make sure it's the same here and there
387
+ this.ModuleService.createModuleMenus();
388
+ // update initial mode of DataChangeHistory
389
+ this.api.internalApi.initializeDataChangeHistory();
390
+ const adaptableContainerElem = this.getAdaptableContainerElement();
391
+ if (adaptableContainerElem != null) {
392
+ adaptableContainerElem.innerHTML = '';
393
+ this.unmountReactRoot = this.renderReactRoot((0, AdaptableView_1.AdaptableApp)({ Adaptable: this }), adaptableContainerElem);
394
+ }
395
+ this.lifecycleState = 'ready';
396
+ this.forPlugins((plugin) => plugin.onAdaptableReady(this, this.adaptableOptions));
397
+ this.api.eventApi.emit('AdaptableReady', {
398
+ adaptableApi: this.api,
399
+ agGridApi: this.agGridAdapter.getAgGridApi(),
400
+ });
401
+ this.api.userInterfaceApi.hideLoadingScreen();
402
+ perfInitAdaptableAgGrid.end();
403
+ return Promise.resolve(this.api);
404
+ }
405
+ normalizeAdaptableState(state, gridOptions) {
406
+ state = this.normaliseLayoutState(state, gridOptions);
407
+ state = this.normaliseToolPanelState(state);
408
+ return state;
409
+ }
410
+ normaliseLayoutState(state, gridOptions) {
411
+ var _a, _b, _c, _d, _e, _f;
412
+ if (this.shouldCreateDefaultLayout(state, this.adaptableOptions)) {
413
+ const defaultLayout = this.createDefaultLayout(state, gridOptions.columnDefs);
414
+ const layoutState = state.Layout || {};
415
+ const availableLayouts = layoutState.Layouts || [];
416
+ availableLayouts.push(defaultLayout);
417
+ layoutState.Layouts = availableLayouts;
418
+ layoutState.CurrentLayout = defaultLayout.Name;
419
+ state.Layout = layoutState;
420
+ }
421
+ else {
422
+ const layoutState = state.Layout;
423
+ // ensure CurrentLayout is valid
424
+ if (!layoutState.CurrentLayout ||
425
+ !layoutState.Layouts.find((l) => l.Name === layoutState.CurrentLayout)) {
426
+ layoutState.CurrentLayout = (_b = (_a = layoutState.Layouts) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.Name;
427
+ }
428
+ }
429
+ // for the initial state, we need to dynamically add the ActionRowColumn (if necessary)
430
+ // for subsequent layout changes, the `Adaptable.setLayout()` method handles this
431
+ // this is a serious code smell, hopefully we will delete `setLayout()` at some point
432
+ const hasActionRowButtons = !!((_c = this.adaptableOptions.actionRowOptions) === null || _c === void 0 ? void 0 : _c.actionRowButtons);
433
+ if (hasActionRowButtons) {
434
+ const currentLayout = state.Layout.Layouts.find((l) => l.Name === state.Layout.CurrentLayout);
435
+ if (currentLayout && !currentLayout.Columns.includes(GeneralConstants_1.ADAPTABLE_ROW_ACTION_BUTTONS)) {
436
+ currentLayout.Columns.push(GeneralConstants_1.ADAPTABLE_ROW_ACTION_BUTTONS);
437
+ const columnPosition = (_e = (_d = this.adaptableOptions.actionRowOptions) === null || _d === void 0 ? void 0 : _d.actionRowButtonOptions) === null || _e === void 0 ? void 0 : _e.position;
438
+ currentLayout.PinnedColumnsMap = currentLayout.PinnedColumnsMap || {};
439
+ currentLayout.PinnedColumnsMap[GeneralConstants_1.ADAPTABLE_ROW_ACTION_BUTTONS] =
440
+ columnPosition === 'pinnedRight' ? 'right' : 'left';
441
+ }
442
+ }
443
+ /**
444
+ * Viewport mode does not support a few
445
+ * features instead of complicating the
446
+ * logic where layout is applied, it is easier and
447
+ * less error prone to just remove it.
448
+ */
449
+ if (gridOptions.rowModelType === 'viewport') {
450
+ (_f = state.Layout.Layouts) === null || _f === void 0 ? void 0 : _f.forEach((layout) => {
451
+ if (layout.RowGroupedColumns) {
452
+ delete layout.RowGroupedColumns;
453
+ }
454
+ if (layout.AggregationColumns) {
455
+ delete layout.AggregationColumns;
456
+ }
457
+ if (layout.PivotColumns) {
458
+ delete layout.PivotColumns;
459
+ delete layout.EnablePivot;
460
+ }
461
+ });
462
+ }
463
+ return state;
464
+ }
465
+ normaliseToolPanelState(state) {
466
+ var _a, _b, _c;
467
+ if ((_a = state === null || state === void 0 ? void 0 : state.ToolPanel) === null || _a === void 0 ? void 0 : _a.ToolPanels) {
468
+ return state;
469
+ }
470
+ // no predefined config provided, we will display all the panels collapsed (custom & module)
471
+ const defaultToolPanels = [];
472
+ (_c = (_b = this.adaptableOptions.toolPanelOptions) === null || _b === void 0 ? void 0 : _b.customToolPanels) === null || _c === void 0 ? void 0 : _c.forEach((customToolPanel) => defaultToolPanels.push({ Name: customToolPanel.name }));
473
+ Types_1.ALL_TOOL_PANELS.forEach((moduleToolPanel) => defaultToolPanels.push({ Name: moduleToolPanel }));
474
+ const toolPanelState = state.ToolPanel || {};
475
+ toolPanelState.ToolPanels = defaultToolPanels;
476
+ state.ToolPanel = toolPanelState;
477
+ return state;
478
+ }
479
+ refreshQuickFilter() {
480
+ const isQuickFilterVisible = this.api.internalApi.getSystemState().IsQuickFilterVisible;
481
+ if (this.isQuickFilterAvailable()) {
482
+ if (isQuickFilterVisible) {
483
+ this.api.columnFilterApi.showQuickFilterBar();
484
+ }
485
+ else {
486
+ this.api.columnFilterApi.hideQuickFilterBar();
487
+ }
488
+ }
489
+ }
490
+ applyColumnFiltering() {
491
+ this.refreshQuickFilter();
492
+ this.applyGridFiltering();
493
+ this.agGridAdapter.updateColumnFilterActiveState();
494
+ }
495
+ applyGridFiltering() {
496
+ this.agGridAdapter.getAgGridApi().onFilterChanged();
497
+ this._emit('AdapTableFiltersApplied');
498
+ this.refreshSelectedCellsState();
499
+ this.refreshSelectedRowsState();
500
+ }
501
+ // refreshAgGridWithAdaptableState() {
502
+ // this.refreshColDefs();
503
+ // this.api.themeApi.applyCurrentTheme();
504
+ // this.api.internalApi.setTreeMode(this.agGridAdapter.initialGridOptions.treeData);
505
+ // this.checkShouldClearExistingFiltersOrSearches();
506
+ // this.applyColumnFiltering();
507
+ // }
508
+ refreshColDefs() {
509
+ const freshColDefs = this.getAllColumnDefinitions();
510
+ this.agGridAdapter.setGridOption('columnDefs', freshColDefs);
511
+ }
512
+ showQuickFilter() {
513
+ const height = this.api.optionsApi.getColumnFilterOptions().quickFilterOptions.quickFilterHeight;
514
+ this.agGridAdapter.getAgGridApi().setGridOption('floatingFiltersHeight', height);
515
+ }
516
+ hideQuickFilter() {
517
+ this.agGridAdapter.getAgGridApi().setGridOption('floatingFiltersHeight', 0);
518
+ }
519
+ normalizeAdaptableOptions(adaptableOptions) {
520
+ if (this.hasAutogeneratedPrimaryKey) {
521
+ this.logger
522
+ .warn(`Autogenerated primary key (adaptableOptions.autogeneratedPrimaryKey = TRUE) should be used only as a last resort,
523
+ when no unique column is available, as it limits some Adaptable functionalities!
524
+
525
+ For more details see: ${DocumentationLinkConstants_1.PrimaryKeyDocsLink}`);
526
+ this.adaptableOptions.primaryKey = GeneralConstants_1.AUTOGENERATED_PK_COLUMN;
527
+ return this.adaptableOptions;
528
+ }
529
+ if (StringExtensions_1.default.IsNullOrEmpty(adaptableOptions.primaryKey)) {
530
+ this.logger.consoleError(`AdaptableOptions.primaryKey is required and cannot be empty or null!
531
+ As a fallback, you can set adaptableOptions.autogeneratedPrimaryKey = TRUE
532
+
533
+ For more details see: ${DocumentationLinkConstants_1.PrimaryKeyDocsLink}`);
534
+ }
535
+ return adaptableOptions;
536
+ }
537
+ setInitialGridOptions(gridOptions, variant) {
538
+ /**
539
+ * set Adaptable instance on the AG Grid context
540
+ */
541
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'context', (original_context) => {
542
+ const userContext = original_context || {};
543
+ return Object.assign(Object.assign({}, userContext), { __adaptable: this });
544
+ });
545
+ /**
546
+ * `gridId`
547
+ */
548
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'gridId', (original_gridId) => {
549
+ return original_gridId || this.adaptableOptions.adaptableId;
550
+ });
551
+ /**
552
+ * `getRowId`
553
+ */
554
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'getRowId', (original_getRowId) => {
555
+ if (original_getRowId) {
556
+ return original_getRowId;
557
+ }
558
+ const primaryKey = this.adaptableOptions.primaryKey;
559
+ if (StringExtensions_1.default.IsNullOrEmpty(primaryKey)) {
560
+ // if no valid PK then do nothing
561
+ return original_getRowId;
562
+ }
563
+ if (this.hasAutogeneratedPrimaryKey) {
564
+ return (params) => {
565
+ // if the PK value is autogenerated, we need to make sure that the rowData has a valid PK value
566
+ // this should be taken care of in the Adaptable.[loadDataSource/setDataSource/updateRows]() methods, but the users will always make silly decisions
567
+ // so just to be safe we'll check here and add a PK value is missing
568
+ // thus adding a side-effect in a getter, but what can we do against it?! :)
569
+ if (Helper_1.Helper.objectNotExists(params.data[primaryKey])) {
570
+ params.data[primaryKey] = (0, uuid_1.createUuid)();
571
+ }
572
+ return params.data[primaryKey];
573
+ };
574
+ }
575
+ return (params) => {
576
+ var _a;
577
+ if (params.data[primaryKey]) {
578
+ return params.data[primaryKey];
579
+ }
580
+ // row does not have primary key => might be a group row
581
+ const parentKeys = (_a = params.parentKeys) !== null && _a !== void 0 ? _a : [];
582
+ const values = Object.values(params.data);
583
+ if (values.length) {
584
+ const id = [...parentKeys, values[0]].join('/');
585
+ return id;
586
+ }
587
+ };
588
+ });
589
+ /**
590
+ * `suppressAggFuncInHeader`
591
+ */
592
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'suppressAggFuncInHeader', (original_suppressAggFuncInHeader) => {
593
+ const currentLayout = this.api.layoutApi.getCurrentLayout();
594
+ if (!currentLayout) {
595
+ return original_suppressAggFuncInHeader;
596
+ }
597
+ return currentLayout.SuppressAggFuncInHeader;
598
+ });
599
+ /**
600
+ * `aggFuncs`
601
+ */
602
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'aggFuncs', (original_aggFuncs) => {
603
+ const aggregationFunctions = original_aggFuncs || {};
604
+ aggregationFunctions[AggregationColumns_1.WEIGHTED_AVERAGE_AGG_FN_NAME] = (params) => {
605
+ const columnId = params.column.getColId();
606
+ const adaptableAggFunc = this.getActiveAdaptableAggFuncForCol(columnId);
607
+ if (!adaptableAggFunc) {
608
+ return undefined;
609
+ }
610
+ if (adaptableAggFunc.type === 'weightedAverage') {
611
+ return (0, weightedAverage_1.weightedAverage)(params, params.colDef.colId, adaptableAggFunc.weightedColumnId);
612
+ }
613
+ return undefined;
614
+ };
615
+ return aggregationFunctions;
616
+ });
617
+ /**
618
+ * `allowContextMenuWithControlKey`
619
+ */
620
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'allowContextMenuWithControlKey', (original_allowContextMenuWithControlKey) => {
621
+ return original_allowContextMenuWithControlKey === undefined
622
+ ? true
623
+ : original_allowContextMenuWithControlKey;
624
+ });
625
+ /**
626
+ * `isExternalFilterPresent`
627
+ */
628
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'isExternalFilterPresent', (original_isExternalFilterPresent) => {
629
+ return (params) => {
630
+ if (!this.isAvailable) {
631
+ return true;
632
+ }
633
+ const columnFilters = this.api.columnFilterApi.getActiveColumnFilters();
634
+ const isColumnFiltersActive = ArrayExtensions_1.default.IsNotNullOrEmpty(columnFilters);
635
+ const isGridFilterActive = StringExtensions_1.default.IsNotNullOrEmpty(this.api.gridFilterApi.getCurrentGridFilterExpression());
636
+ return (isColumnFiltersActive ||
637
+ isGridFilterActive ||
638
+ // it means that userPropertyValue will be called so we re-init that collection
639
+ (original_isExternalFilterPresent ? original_isExternalFilterPresent(params) : false));
640
+ };
641
+ });
642
+ /**
643
+ * `doesExternalFilterPass`
644
+ */
645
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'doesExternalFilterPass', (original_doesExternalFilterPass) => {
646
+ return (node) => {
647
+ if (!this.isAvailable) {
648
+ return true;
649
+ }
650
+ // first we assess a Grid Filter (if its running locally)
651
+ if (!this.isGroupRowNode(node)) {
652
+ const currentGridFilter = this.api.gridFilterApi.getCurrentGridFilterExpression();
653
+ if (currentGridFilter) {
654
+ const evaluateGridFilterOnClient = this.api.expressionApi.internalApi.evaluateExpressionInAdaptableQL('GridFilter', undefined, currentGridFilter);
655
+ if (evaluateGridFilterOnClient) {
656
+ const isCurrentGridFilterValid = this.api.expressionApi.isValidBooleanExpression(currentGridFilter, ModuleConstants_1.GridFilterModuleId, `Invalid Grid Filter '${currentGridFilter}'`);
657
+ if (!isCurrentGridFilterValid ||
658
+ !this.api.internalApi
659
+ .getQueryLanguageService()
660
+ .evaluateBooleanExpression(currentGridFilter, ModuleConstants_1.GridFilterModuleId, node)) {
661
+ return false;
662
+ }
663
+ }
664
+ }
665
+ }
666
+ const columnFilters = this.api.columnFilterApi.getActiveColumnFilters();
667
+ try {
668
+ if (columnFilters.length > 0) {
669
+ for (const columnFilter of columnFilters) {
670
+ const evaluateFilterOnClient = this.api.expressionApi.internalApi.evaluatePredicatesInAdaptableQL('ColumnFilter', columnFilter, [columnFilter.Predicate]);
671
+ if (evaluateFilterOnClient) {
672
+ // we then assess filters (if running locally)
673
+ if (!this.api.columnFilterApi.internalApi.evaluateColumnFilter(columnFilter, node)) {
674
+ return false;
675
+ }
676
+ }
677
+ }
678
+ }
679
+ }
680
+ catch (ex) {
681
+ this.logger.error(ex);
682
+ return false;
683
+ }
684
+ return original_doesExternalFilterPass ? original_doesExternalFilterPass(node) : true;
685
+ };
686
+ });
687
+ /**
688
+ * `getMainMenuItems`
689
+ */
690
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'getMainMenuItems', (original_getMainMenuItems) => {
691
+ return (params) => {
692
+ // couldnt find a way to listen for menu close. There is a Menu Item Select, but you can also close menu from filter and clicking outside menu....
693
+ return this.agGridMenuAdapter.buildColumnMenu(params, original_getMainMenuItems);
694
+ };
695
+ });
696
+ /**
697
+ * `getContextMenuItems`
698
+ */
699
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'getContextMenuItems', (original_getContextMenuItems) => {
700
+ return (params) => {
701
+ return this.agGridMenuAdapter.buildContextMenu(params, original_getContextMenuItems);
702
+ };
703
+ });
704
+ /**
705
+ * `initialGroupOrderComparator
706
+ */
707
+ // Build the default group sort comparator - will get custom sort values (but not functions) in real time
708
+ // TODO: if a custom 'aggFunc' property is defined (see setupColumnAggFunc()), it won't be evaluated
709
+ if (this.adaptableOptions.groupingOptions.autoOrderGroupedColumns) {
710
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'initialGroupOrderComparator', (original_initialGroupOrderComparator) => {
711
+ if (original_initialGroupOrderComparator) {
712
+ return original_initialGroupOrderComparator;
713
+ }
714
+ return (params) => {
715
+ const { nodeA, nodeB } = params;
716
+ const firstGroupedColumnId = this.agGridAdapter.getFirstGroupedColumn();
717
+ if (firstGroupedColumnId) {
718
+ const definedColumnComparator = this.api.columnApi.internalApi.getActiveColumnComparator(firstGroupedColumnId, this.api.customSortApi.getCustomSortForColumn(firstGroupedColumnId), this.api.customSortApi.internalApi.getCustomSortComparer(firstGroupedColumnId));
719
+ if (definedColumnComparator) {
720
+ return definedColumnComparator(nodeA.key, nodeB.key);
721
+ }
722
+ const sortOder = this.api.layoutApi.getCurrentLayoutColumnSort(firstGroupedColumnId);
723
+ if (sortOder === 'Desc') {
724
+ return nodeA.key > nodeB.key ? -1 : 1;
725
+ }
726
+ }
727
+ // if no comparator available, just sort alphanumerically
728
+ if (nodeA.key == nodeB.key) {
729
+ return 0;
730
+ }
731
+ return nodeA.key < nodeB.key ? -1 : 1;
732
+ };
733
+ });
734
+ /**
735
+ * `autoSizeStrategy`
736
+ *
737
+ * This is needed here, even if we do auto sizing on FIRST_DATA_RENDERED.
738
+ * Sometimes FIRST_DATA_RENDERED is triggered too early and autoSizing doesn't work initially
739
+ * so we need this block
740
+ */
741
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'autoSizeStrategy', (original_autoSizeStrategy) => {
742
+ return this.shouldAutoSizeLayout()
743
+ ? {
744
+ type: 'fitCellContents',
745
+ }
746
+ : original_autoSizeStrategy;
747
+ });
748
+ }
749
+ /**
750
+ * `components`
751
+ */
752
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'components', (original_components) => {
753
+ const AdaptableToolPanel = (0, AdaptableToolPanel_1.getAdaptableToolPanelAgGridComponent)(this);
754
+ const components = original_components || {};
755
+ const adaptableComponents = Object.assign(Object.assign({}, components), { AdaptableToolPanel });
756
+ return adaptableComponents;
757
+ });
758
+ if (variant === 'react') {
759
+ // TODO very soon we have to transition to reactiveCustomComponents in React
760
+ // but for now, if we simply set it to true, it will break our editors, etc
761
+ // this.agGridOptionsService.setGridOptionsProperty(
762
+ // gridOptions,
763
+ // 'reactiveCustomComponents',
764
+ // () => true
765
+ // );
766
+ }
767
+ /**
768
+ * `sidebar`
769
+ */
770
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'sideBar', (original_sideBar) => {
771
+ var _a, _b;
772
+ if (!original_sideBar) {
773
+ // lucky us, no sideBar is defined, so we don't have to do anything
774
+ return original_sideBar;
775
+ }
776
+ const isAdaptableToolPanelHidden = this.EntitlementService.isModuleHiddenEntitlement('ToolPanel');
777
+ const adaptableToolPanelDef = {
778
+ id: GeneralConstants.ADAPTABLE_TOOLPANEL_ID,
779
+ toolPanel: GeneralConstants.ADAPTABLE_TOOLPANEL_COMPONENT,
780
+ labelDefault: GeneralConstants.ADAPTABLE,
781
+ labelKey: 'adaptable',
782
+ iconKey: 'menu',
783
+ width: UIHelper_1.default.getAdaptableToolPanelWidth(),
784
+ minWidth: UIHelper_1.default.getAdaptableToolPanelWidth(),
785
+ // maxWidth = undefined,
786
+ };
787
+ const mapToolPanelDefs = (toolPanelDefs = []) => {
788
+ // if it's an alias for the adaptable tool panel, map it to a ToolPanelDef, otherwise return it as it is
789
+ return toolPanelDefs.map((toolPanelDef) => toolPanelDef === GeneralConstants.ADAPTABLE_TOOLPANEL_ID
790
+ ? adaptableToolPanelDef
791
+ : toolPanelDef);
792
+ };
793
+ const isSideBarDefObject = (sidebarDef) => {
794
+ return Array.isArray(sidebarDef === null || sidebarDef === void 0 ? void 0 : sidebarDef.toolPanels);
795
+ };
796
+ let result;
797
+ if (original_sideBar === true) {
798
+ // create all tool panels with default settings
799
+ const toolPanels = [];
800
+ toolPanels.push(GeneralConstants.AGGRID_TOOLPANEL_FILTERS);
801
+ toolPanels.push(GeneralConstants.AGGRID_TOOLPANEL_COLUMNS);
802
+ if (!isAdaptableToolPanelHidden) {
803
+ toolPanels.push(adaptableToolPanelDef);
804
+ }
805
+ result = {
806
+ toolPanels: toolPanels,
807
+ };
808
+ }
809
+ // if there is only one tool panel, and it's the adaptable one => we have to handle it
810
+ else if (typeof original_sideBar === 'string') {
811
+ if (gridOptions.sideBar === GeneralConstants.ADAPTABLE_TOOLPANEL_ID) {
812
+ if (!isAdaptableToolPanelHidden)
813
+ result = {
814
+ toolPanels: [adaptableToolPanelDef],
815
+ };
816
+ }
817
+ else {
818
+ result = original_sideBar;
819
+ }
820
+ }
821
+ // if it's an array, process the tool panel definitions
822
+ else if (Array.isArray(original_sideBar)) {
823
+ if (!original_sideBar.includes(GeneralConstants.ADAPTABLE_TOOLPANEL_ID) ||
824
+ isAdaptableToolPanelHidden) {
825
+ result = original_sideBar;
826
+ }
827
+ // if it's an array, process the tool panel definitions
828
+ const sidebarDef = {};
829
+ sidebarDef.toolPanels = mapToolPanelDefs(original_sideBar);
830
+ result = sidebarDef;
831
+ }
832
+ // if it's fully-fledged SideBarDef, process its tool panel definitions
833
+ else if (isSideBarDefObject(original_sideBar)) {
834
+ if ((_a = original_sideBar.toolPanels) === null || _a === void 0 ? void 0 : _a.some((toolpanelDef) => typeof toolpanelDef !== 'string' &&
835
+ toolpanelDef.id === GeneralConstants.ADAPTABLE_TOOLPANEL_ID &&
836
+ !isAdaptableToolPanelHidden)) {
837
+ // if there is an Adaptable SideBarDef, don't touch it as it may contain user-defined properties
838
+ result = original_sideBar;
839
+ }
840
+ else {
841
+ result = Object.assign(Object.assign({}, original_sideBar), { toolPanels: mapToolPanelDefs(original_sideBar.toolPanels) });
842
+ }
843
+ }
844
+ this.hasAdaptableToolPanel =
845
+ isSideBarDefObject(result) &&
846
+ ((_b = result.toolPanels) === null || _b === void 0 ? void 0 : _b.some((toolPanelDef) => typeof toolPanelDef !== 'string' &&
847
+ toolPanelDef.id === GeneralConstants.ADAPTABLE_TOOLPANEL_ID));
848
+ return result;
849
+ });
850
+ /**
851
+ * `statusBar`
852
+ */
853
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'statusBar', (original_statusBar) => {
854
+ var _a, _b;
855
+ const statusPanels = (_b = ((_a = original_statusBar === null || original_statusBar === void 0 ? void 0 : original_statusBar.statusPanels) !== null && _a !== void 0 ? _a : [])) === null || _b === void 0 ? void 0 : _b.map((statusPanel) => {
856
+ if (statusPanel.statusPanel === StatusBarState_1.ADAPTABLE_STATUS_PANEL) {
857
+ this.adaptableStatusPanelKeys.push(statusPanel.key);
858
+ const context = {
859
+ Key: statusPanel.key,
860
+ };
861
+ return Object.assign(Object.assign({}, statusPanel), { statusPanel: (0, createAgStatusPanelComponent_1.createAgStatusPanelComponent)(AdaptableStatusBar_1.AdaptableStatusBar, this, context) });
862
+ }
863
+ return statusPanel;
864
+ });
865
+ return Object.assign(Object.assign({}, original_statusBar), { statusPanels });
866
+ });
867
+ /**
868
+ * `getRowStyle`
869
+ */
870
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'getRowStyle', (original_getRowStyle) => {
871
+ return (params) => {
872
+ const result = Object.assign(Object.assign(Object.assign({}, original_getRowStyle === null || original_getRowStyle === void 0 ? void 0 : original_getRowStyle(params)), this.api.gridApi.internalApi.getRowHighlightStyle(params)), this.api.gridApi.internalApi.getAlertRowStyle(params));
873
+ return result;
874
+ };
875
+ });
876
+ /**
877
+ * `getRowClass`
878
+ */
879
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'getRowClass', (original_getRowClass) => {
880
+ return (params) => {
881
+ const alertHighlightClassName = this.api.gridApi.internalApi.getAlertRowClass(params);
882
+ const highlightClassName = this.api.gridApi.internalApi.getRowHighlightClass(params);
883
+ const returnValue = [
884
+ typeof original_getRowClass === 'function'
885
+ ? original_getRowClass(params)
886
+ : original_getRowClass,
887
+ highlightClassName,
888
+ alertHighlightClassName,
889
+ ]
890
+ // we flatten it because 'original_getRowClass' might return a string[]
891
+ .flat()
892
+ .filter((x) => !!x);
893
+ return (returnValue === null || returnValue === void 0 ? void 0 : returnValue.length) ? returnValue : undefined;
894
+ };
895
+ });
896
+ /**
897
+ * `floatingFiltersHeight`
898
+ */
899
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'floatingFiltersHeight', (original_floatingFiltersHeight) => {
900
+ if (this.api.layoutApi.getCurrentLayout().EnablePivot) {
901
+ // if the default layout is a pivot on, hide the floating filters from the beginning, otherwise we get an annoying flicker
902
+ return 0;
903
+ }
904
+ return original_floatingFiltersHeight;
905
+ });
906
+ /**
907
+ * `excelStyles`
908
+ */
909
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'excelStyles', (original_excelStyles) => {
910
+ // we need this here just to register the original excelStyles in the service
911
+ return original_excelStyles;
912
+ });
913
+ /**
914
+ * `processPivotResultColDef`
915
+ */
916
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'processPivotResultColDef', () => {
917
+ return (colDef) => {
918
+ if (this.adaptableOptions.columnFilterOptions.useAdaptableColumnFiltering) {
919
+ colDef.floatingFilter = false;
920
+ colDef.filter = false;
921
+ }
922
+ };
923
+ });
924
+ /**
925
+ * `columnTypes`
926
+ */
927
+ // this will have to go/be heavily extended with https://github.com/AdaptableTools/adaptable/issues/2230
928
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'columnTypes', (original_columnTypes) => {
929
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
930
+ const providedColumnTypes = original_columnTypes || {};
931
+ const gridOptionsColumnTypes = gridOptions.columnTypes || {};
932
+ const patchedColumnTypes = Object.assign(providedColumnTypes, {
933
+ [GeneralConstants_1.AB_SPECIAL_COLUMN]: {},
934
+ [GeneralConstants_1.AB_FDC3_COLUMN]: {},
935
+ abColDefNumber: (_a = gridOptionsColumnTypes.abColDefNumber) !== null && _a !== void 0 ? _a : {},
936
+ abColDefString: (_b = gridOptionsColumnTypes.abColDefString) !== null && _b !== void 0 ? _b : {},
937
+ abColDefBoolean: (_c = gridOptionsColumnTypes.abColDefBoolean) !== null && _c !== void 0 ? _c : {},
938
+ abColDefDate: (_d = gridOptionsColumnTypes.abColDefDate) !== null && _d !== void 0 ? _d : {},
939
+ abColDefObject: (_e = gridOptionsColumnTypes.abColDefObject) !== null && _e !== void 0 ? _e : {},
940
+ abColDefCustom: (_f = gridOptionsColumnTypes.abColDefCustom) !== null && _f !== void 0 ? _f : {},
941
+ abColDefStringArray: (_g = gridOptionsColumnTypes.abColDefStringArray) !== null && _g !== void 0 ? _g : {},
942
+ abColDefNumberArray: (_h = gridOptionsColumnTypes.abColDefNumberArray) !== null && _h !== void 0 ? _h : {},
943
+ abColDefTupleNumberArray: (_j = gridOptionsColumnTypes.abColDefTupleNumberArray) !== null && _j !== void 0 ? _j : {},
944
+ abColDefObjectNumberArray: (_k = gridOptionsColumnTypes.abColDefObjectNumberArray) !== null && _k !== void 0 ? _k : {},
945
+ });
946
+ const customColumnTypes = (_l = this.api.columnApi.getColumnTypes()) !== null && _l !== void 0 ? _l : [];
947
+ for (const customColumnType of customColumnTypes) {
948
+ if (!patchedColumnTypes[customColumnType]) {
949
+ patchedColumnTypes[customColumnType] = {};
950
+ }
951
+ }
952
+ if (patchedColumnTypes.abColDefNumber.cellEditor == undefined) {
953
+ patchedColumnTypes.abColDefNumber.cellEditor =
954
+ this.variant === 'react' ? AdaptableNumberEditor_1.ReactAdaptableNumberEditor : AdaptableNumberEditor_1.AdaptableNumberEditor;
955
+ }
956
+ if (patchedColumnTypes.abColDefDate.cellEditor == undefined) {
957
+ patchedColumnTypes.abColDefDate.cellEditor =
958
+ this.variant === 'react' ? AdaptableDateEditor_1.ReactAdaptableDateEditor : AdaptableDateEditor_1.AdaptableDateEditor;
959
+ }
960
+ return patchedColumnTypes;
961
+ });
962
+ /**
963
+ * `dataTypeDefinitions`
964
+ */
965
+ this.agGridOptionsService.setGridOptionsProperty(gridOptions, 'dataTypeDefinitions', () => {
966
+ // temporary workaround until https://github.com/AdaptableTools/adaptable/issues/2230
967
+ const revertedDateTypeDefinitions = {
968
+ date: {
969
+ baseDataType: 'date',
970
+ extendsDataType: 'date',
971
+ valueParser: null,
972
+ valueFormatter: null,
973
+ suppressDefaultProperties: true,
974
+ },
975
+ dateString: {
976
+ baseDataType: 'dateString',
977
+ extendsDataType: 'dateString',
978
+ valueParser: null,
979
+ valueFormatter: null,
980
+ suppressDefaultProperties: true,
981
+ },
982
+ };
983
+ return revertedDateTypeDefinitions;
984
+ });
985
+ }
986
+ isDetailGrid() {
987
+ return this._isDetailGrid;
988
+ }
989
+ /**
990
+ * Either initializes the AG Grid instance or delegates it to the framework wrappers (React/Anglar)
991
+ */
992
+ async initializeAgGrid(gridOptions, modules, renderAgGridFrameworkComponent) {
993
+ if (renderAgGridFrameworkComponent) {
994
+ const result = await renderAgGridFrameworkComponent(gridOptions);
995
+ if (result === false) {
996
+ return false;
997
+ }
998
+ const agGridApi = result;
999
+ // framework wrapper may pass the rowData as a prop
1000
+ const rowData = agGridApi.getGridOption('rowData');
1001
+ this.initWithLazyData = rowData == undefined || rowData.length === 0;
1002
+ if (this.initWithLazyData) {
1003
+ this.logger.info('initWithLazyData = TRUE');
1004
+ }
1005
+ if (!this.getAgGridContainerElement()) {
1006
+ // initialize the agGridContainerElement from the AgGrid instance
1007
+ // @ts-ignore
1008
+ const gridRoot = agGridApi.ctrlsService.gridBodyCtrl.eGridBody;
1009
+ const gridContainer = gridRoot === null || gridRoot === void 0 ? void 0 : gridRoot.closest('[class*="ag-theme"]');
1010
+ if (!gridContainer) {
1011
+ this.logger.consoleError(`No AG Grid container could be derived from the Adaptable framework wrapper.
1012
+ Please contact AdapTable Support and in the meantime provide a valid container element in 'ContainerOptions.agGridContainer'!`);
1013
+ }
1014
+ this.DANGER_USE_GETTER_agGridContainerElement = gridContainer;
1015
+ }
1016
+ return agGridApi;
1017
+ }
1018
+ const agGridContainer = this.getAgGridContainerElement();
1019
+ if (!agGridContainer) {
1020
+ this.logger.consoleError('No AG Grid container element found in the DOM. Please provide a valid container element in `ContainerOptions.agGridContainer`');
1021
+ return Promise.resolve(false);
1022
+ }
1023
+ let gridParams;
1024
+ if (modules === null || modules === void 0 ? void 0 : modules.length) {
1025
+ gridParams = { modules };
1026
+ }
1027
+ const agGridApi = (0, core_1.createGrid)(agGridContainer, gridOptions, gridParams);
1028
+ return agGridApi;
1029
+ }
1030
+ getAllColumnDefinitions(agGridColDefs) {
1031
+ const allColDefs = this.enhanceColDefsWithSpecialColumns(agGridColDefs !== null && agGridColDefs !== void 0 ? agGridColDefs : this.agGridAdapter.getAgGridApi().getColumnDefs());
1032
+ return allColDefs;
1033
+ }
1034
+ getSpecialColDefs() {
1035
+ const specialColDefs = [
1036
+ ...this.api.calculatedColumnApi.internalApi.getColDefsForCalculatedColumns(),
1037
+ ...this.api.actionColumnApi.getColDefsForActionColumns(),
1038
+ ...this.api.freeTextColumnApi.internalApi.getColDefsForFreeTextColumns(),
1039
+ ...this.api.actionRowApi.internalApi.getColDefsForActionRowColumns(),
1040
+ ...this.api.fdc3Api.internalApi.getFdc3ActionColDefs(),
1041
+ ];
1042
+ this.agGridAdapter.assignColumnIdsToColDefs(specialColDefs);
1043
+ return specialColDefs;
1044
+ }
1045
+ enhanceColDefsWithSpecialColumns(agGridColDefs) {
1046
+ this.agGridAdapter.assignColumnIdsToColDefs(agGridColDefs);
1047
+ const specialColDefs = this.getSpecialColDefs();
1048
+ const isSpecialColDef = (colDef) => {
1049
+ const { type } = colDef;
1050
+ if (type === GeneralConstants_1.AB_SPECIAL_COLUMN || (Array.isArray(type) && type.includes(GeneralConstants_1.AB_SPECIAL_COLUMN))) {
1051
+ return true;
1052
+ }
1053
+ return false;
1054
+ };
1055
+ const isColGroupDef = (columnDefinition) => {
1056
+ // @ts-ignore
1057
+ return columnDefinition['children'] != null;
1058
+ };
1059
+ const processedSpecialColDefIds = [];
1060
+ const mapColDefs = (colDefs) => {
1061
+ return colDefs.map((colDef) => {
1062
+ if (isColGroupDef(colDef)) {
1063
+ // if it's a group column, recursively map its children
1064
+ colDef.children = mapColDefs(colDef.children);
1065
+ return colDef;
1066
+ }
1067
+ else {
1068
+ if (!isSpecialColDef(colDef)) {
1069
+ // if it's not a special column, return it as is
1070
+ // without a minWidth, columns in details grid are VERY wide
1071
+ // so the line below fixes https://github.com/AdaptableTools/adaptable/issues/2559
1072
+ return Object.assign({ minWidth: 10 }, colDef);
1073
+ }
1074
+ const newlyCreatedSpecialColDef = specialColDefs.find((specialColDef) => specialColDef.colId === colDef.colId);
1075
+ if (newlyCreatedSpecialColDef) {
1076
+ // if it's a special column and we have a special col def for it, return the special col def
1077
+ processedSpecialColDefIds.push(colDef.colId);
1078
+ // merge the user defined colDef with the special col def
1079
+ // this way the user may provide some custom settings for the special col def (tooltip, etc)
1080
+ const mergedColDef = Object.assign(Object.assign({
1081
+ // see above comment for minWidth
1082
+ minWidth: 10 }, colDef), newlyCreatedSpecialColDef);
1083
+ return mergedColDef;
1084
+ }
1085
+ else {
1086
+ // otherwise, return the original col def
1087
+ return colDef;
1088
+ }
1089
+ }
1090
+ });
1091
+ };
1092
+ let resultColDefs = mapColDefs(agGridColDefs);
1093
+ // check if there are any special colDefs that were not processed
1094
+ // in that case, add them to the end of the colDefs
1095
+ specialColDefs.forEach((specialColDef) => {
1096
+ if (!processedSpecialColDefIds.includes(specialColDef.colId)) {
1097
+ resultColDefs.push(specialColDef);
1098
+ }
1099
+ });
1100
+ // remove special column that are no longer defined
1101
+ resultColDefs = resultColDefs.filter((colDef) => {
1102
+ if (isSpecialColDef(colDef)) {
1103
+ // must be in specialColDefs
1104
+ return specialColDefs.some((specialColDef) => specialColDef.colId === colDef.colId);
1105
+ }
1106
+ return true;
1107
+ });
1108
+ return resultColDefs;
1109
+ }
1110
+ useRowNodeLookUp() {
1111
+ return this.agGridAdapter.getAgGridApi().getGridOption('getRowId') != undefined;
1112
+ }
1113
+ getAgGridContainerElement() {
1114
+ if (!this.DANGER_USE_GETTER_agGridContainerElement) {
1115
+ this.DANGER_USE_GETTER_agGridContainerElement =
1116
+ typeof this.adaptableOptions.containerOptions.agGridContainer === 'string'
1117
+ ? document.getElementById(this.adaptableOptions.containerOptions.agGridContainer)
1118
+ : this.adaptableOptions.containerOptions.agGridContainer;
1119
+ }
1120
+ return this.DANGER_USE_GETTER_agGridContainerElement;
1121
+ }
1122
+ getAdaptableContainerElement() {
1123
+ if (!this.DANGER_USE_GETTER_adaptableContainerElement) {
1124
+ this.DANGER_USE_GETTER_adaptableContainerElement =
1125
+ typeof this.adaptableOptions.containerOptions.adaptableContainer === 'string'
1126
+ ? document.getElementById(this.adaptableOptions.containerOptions.adaptableContainer)
1127
+ : this.adaptableOptions.containerOptions.adaptableContainer;
1128
+ }
1129
+ return this.DANGER_USE_GETTER_adaptableContainerElement;
1130
+ }
1131
+ // This method returns selected cells ONLY (if selection mode is cells or multiple cells).
1132
+ // If the selection mode is row it will returns nothing - use the setSelectedRows() method
1133
+ refreshSelectedCellsState() {
1134
+ if (!this.isGridRangeSelectable()) {
1135
+ return;
1136
+ }
1137
+ const selectedCellInfo = this.agGridAdapter.deriveSelectedCellInfoFromAgGrid();
1138
+ this.api.gridApi.internalApi.setSelectedCells(selectedCellInfo);
1139
+ this._emit('CellsSelected');
1140
+ let cellSelectionChangedInfo = Object.assign(Object.assign({}, this.api.internalApi.buildBaseContext()), { selectedCellInfo: this.api.gridApi.getGridState().SelectedCellInfo });
1141
+ this.api.eventApi.emit('CellSelectionChanged', cellSelectionChangedInfo);
1142
+ return selectedCellInfo;
1143
+ }
1144
+ refreshSelectedRowsState() {
1145
+ if (!this.isGridRowSelectable()) {
1146
+ return;
1147
+ }
1148
+ const selectedRowInfo = this.agGridAdapter.deriveSelectedRowInfoFromAgGrid();
1149
+ this.api.gridApi.internalApi.setSelectedRows(selectedRowInfo);
1150
+ const rowSelectionChangedInfo = Object.assign(Object.assign({}, this.api.internalApi.buildBaseContext()), { selectedRowInfo: this.api.gridApi.getGridState().SelectedRowInfo });
1151
+ this.api.eventApi.emit('RowSelectionChanged', rowSelectionChangedInfo);
1152
+ return selectedRowInfo;
1153
+ }
1154
+ isGridRowSelectable() {
1155
+ const rowSelection = this.agGridAdapter.getAgGridApi().getGridOption('rowSelection');
1156
+ return rowSelection === 'single' || rowSelection === 'multiple';
1157
+ }
1158
+ isGridRangeSelectable() {
1159
+ return (this.agGridAdapter.isModulePresent(core_1.ModuleNames.RangeSelectionModule) &&
1160
+ this.agGridAdapter.getGridOption('enableRangeSelection'));
1161
+ }
1162
+ initAdaptableStore() {
1163
+ const perfNewAdaptableStore = this.logger.beginPerf(`initAdaptableStore()`);
1164
+ const adaptableStore = new AdaptableStore_1.AdaptableStore(this);
1165
+ adaptableStore.onAny((eventName, data) => {
1166
+ this.performAudit(data.action, data.state, data.newState);
1167
+ this.forPlugins((plugin) => plugin.onStoreEvent(eventName, data, this.adaptableStore));
1168
+ });
1169
+ perfNewAdaptableStore.end();
1170
+ return adaptableStore;
1171
+ }
1172
+ mapAdaptableStateToAgGridState(adaptableState, agGridColDefs) {
1173
+ var _a, _b, _c;
1174
+ const agGridState = {};
1175
+ const currentLayoutName = (_a = adaptableState.Layout) === null || _a === void 0 ? void 0 : _a.CurrentLayout;
1176
+ const _currentLayout = currentLayoutName &&
1177
+ ((_c = (_b = adaptableState.Layout) === null || _b === void 0 ? void 0 : _b.Layouts) === null || _c === void 0 ? void 0 : _c.find((l) => l.Name === currentLayoutName));
1178
+ if (!_currentLayout) {
1179
+ return agGridState;
1180
+ }
1181
+ const currentLayout = (0, AdaptableHelper_1.removeUuidAndSource)(_currentLayout);
1182
+ const allAgGridFlattenedColDefs = this.agGridAdapter.getFlattenedColDefs(agGridColDefs);
1183
+ const allAgGridColDefIds = allAgGridFlattenedColDefs.map((colDef) => colDef.colId);
1184
+ const { columnApi } = this.api;
1185
+ // also add the row group columns, if they are specified in the layout
1186
+ currentLayout.Columns.forEach((colId) => {
1187
+ if (columnApi.isAutoRowGroupColumn(colId)) {
1188
+ allAgGridColDefIds.push(colId);
1189
+ }
1190
+ });
1191
+ const getColDef = (colId) => allAgGridFlattenedColDefs.find((colDef) => colDef.colId === colId);
1192
+ agGridState.columnVisibility = {
1193
+ hiddenColIds: allAgGridFlattenedColDefs
1194
+ .filter((colDef) => { var _a; return !((_a = currentLayout.Columns) === null || _a === void 0 ? void 0 : _a.includes(colDef.colId)) || colDef.hide || colDef.initialHide; })
1195
+ .map((colDef) => colDef.colId),
1196
+ };
1197
+ agGridState.columnOrder = {
1198
+ orderedColIds: (0, sortWithOrder_1.sortWithOrderArray)(allAgGridColDefIds, currentLayout.Columns || [], {
1199
+ sortUnorderedItems: false,
1200
+ }),
1201
+ };
1202
+ if (currentLayout.ColumnWidthMap) {
1203
+ agGridState.columnSizing = {
1204
+ columnSizingModel: Object.keys(currentLayout.ColumnWidthMap).map((colId) => {
1205
+ const width = currentLayout.ColumnWidthMap[colId];
1206
+ return {
1207
+ colId,
1208
+ width,
1209
+ };
1210
+ }),
1211
+ };
1212
+ }
1213
+ if (currentLayout.ColumnSorts) {
1214
+ agGridState.sort = {
1215
+ sortModel: currentLayout.ColumnSorts.map((columnSort) => {
1216
+ return {
1217
+ colId: columnSort.ColumnId,
1218
+ sort: columnSort.SortOrder === 'Asc' ? 'asc' : 'desc',
1219
+ };
1220
+ }),
1221
+ };
1222
+ }
1223
+ if (currentLayout.RowGroupedColumns) {
1224
+ agGridState.rowGroup = {
1225
+ groupColIds: currentLayout.RowGroupedColumns,
1226
+ };
1227
+ }
1228
+ if (currentLayout.AggregationColumns) {
1229
+ agGridState.aggregation = {
1230
+ aggregationModel: Object.keys(currentLayout.AggregationColumns).map((colId) => {
1231
+ let aggFunc = currentLayout.AggregationColumns[colId];
1232
+ if (aggFunc === true) {
1233
+ const colDef = getColDef(colId);
1234
+ // fallback to SUM if no defaultAggFunc is defined
1235
+ aggFunc = (colDef === null || colDef === void 0 ? void 0 : colDef.defaultAggFunc) || 'sum';
1236
+ }
1237
+ if ((0, AggregationColumns_1.isWeightedAverageAggregation)(aggFunc)) {
1238
+ aggFunc = AggregationColumns_1.WEIGHTED_AVERAGE_AGG_FN_NAME;
1239
+ }
1240
+ return {
1241
+ colId,
1242
+ aggFunc,
1243
+ };
1244
+ }),
1245
+ };
1246
+ }
1247
+ if (currentLayout.PivotColumns || currentLayout.EnablePivot) {
1248
+ agGridState.pivot = {
1249
+ pivotMode: currentLayout.EnablePivot,
1250
+ pivotColIds: currentLayout.PivotColumns || [],
1251
+ };
1252
+ }
1253
+ if (currentLayout.PinnedColumnsMap) {
1254
+ const columnPinning = {
1255
+ leftColIds: [],
1256
+ rightColIds: [],
1257
+ };
1258
+ Object.keys(currentLayout.PinnedColumnsMap).forEach((colId) => {
1259
+ const pinned = currentLayout.PinnedColumnsMap[colId];
1260
+ if (pinned === 'left') {
1261
+ columnPinning.leftColIds.push(colId);
1262
+ }
1263
+ else if (pinned === 'right') {
1264
+ columnPinning.rightColIds.push(colId);
1265
+ }
1266
+ });
1267
+ agGridState.columnPinning = columnPinning;
1268
+ }
1269
+ return agGridState;
1270
+ }
1271
+ addGridEventListeners() {
1272
+ /**
1273
+ * Intercept DOM events and emit them as Adaptable events
1274
+ */
1275
+ const gridContainerElement = this.getAgGridContainerElement();
1276
+ if (gridContainerElement) {
1277
+ gridContainerElement.addEventListener('keydown', (this.agGridListenerKeydown = (event) => this._emit('KeyDown', event)),
1278
+ // This is needed to be able to prevent the editor to be opened
1279
+ // in bubling phase the opening is not prevented with ag-grid v30
1280
+ true);
1281
+ gridContainerElement.addEventListener('mouseenter', (this.agGridListenerMouseEnter = (event) => {
1282
+ this._emit('MouseEnter', event);
1283
+ }), true);
1284
+ gridContainerElement.addEventListener('mouseleave', (this.agGridListenerMouseLeave = (event) => this._emit('MouseLeave', event)));
1285
+ }
1286
+ this.throttleFilterOnEditDataChange = (0, throttle_1.default)(
1287
+ // the extra function is to make sure we have a reference to ag-grid-api
1288
+ () => { var _a; return (_a = this.agGridAdapter.getAgGridApi()) === null || _a === void 0 ? void 0 : _a.onFilterChanged(); }, this.adaptableOptions.columnFilterOptions.filterActionOnUserDataChange.throttleDelay, {
1289
+ trailing: true,
1290
+ leading: false,
1291
+ });
1292
+ this.throttleFilterOnTickingDataChange = (0, throttle_1.default)(() => { var _a; return (_a = this.agGridAdapter.getAgGridApi()) === null || _a === void 0 ? void 0 : _a.onFilterChanged(); }, this.adaptableOptions.columnFilterOptions.filterActionOnExternalDataChange.throttleDelay, {
1293
+ trailing: true,
1294
+ leading: false,
1295
+ });
1296
+ /**
1297
+ * Use Case: AG Grid columns have changed
1298
+ * Action: Set Columns in store and filter grid
1299
+ */
1300
+ this.debouncedSetColumnIntoStore = (0, debounce_1.default)(() => {
1301
+ if (!this.isReady) {
1302
+ return;
1303
+ }
1304
+ this.deriveAdaptableColumnStateFromAgGrid();
1305
+ }, GeneralConstants_1.HALF_SECOND);
1306
+ const columnEventsThatTriggersStateChange = [
1307
+ core_1.Events.EVENT_COLUMN_MOVED,
1308
+ core_1.Events.EVENT_GRID_COLUMNS_CHANGED,
1309
+ core_1.Events.EVENT_COLUMN_EVERYTHING_CHANGED,
1310
+ core_1.Events.EVENT_DISPLAYED_COLUMNS_CHANGED,
1311
+ core_1.Events.EVENT_COLUMN_VISIBLE,
1312
+ core_1.Events.EVENT_NEW_COLUMNS_LOADED,
1313
+ ];
1314
+ this.agGridAdapter.getAgGridApi().addGlobalListener((this.listenerGlobalColumnEventsThatTriggerStateChange = (type) => {
1315
+ if (columnEventsThatTriggersStateChange.indexOf(type) > -1) {
1316
+ this.debouncedSetColumnIntoStore();
1317
+ }
1318
+ }));
1319
+ /**
1320
+ * Use Case: User has started inline editing but its distabled in Action Row Options
1321
+ * Action: Stop editing
1322
+ */
1323
+ this.agGridAdapter.getAgGridApi().addEventListener(core_1.Events.EVENT_CELL_EDITING_STARTED, (this.listenerCellEditingStarted = () => {
1324
+ var _a;
1325
+ if ((_a = this.adaptableOptions.actionRowOptions) === null || _a === void 0 ? void 0 : _a.disableInlineEditing)
1326
+ this.agGridAdapter.getAgGridApi().stopEditing();
1327
+ }));
1328
+ /**
1329
+ * Use Case: initial data has been displayed in grid
1330
+ * Action1: Set the Layout
1331
+ * Action2: Ensure that we have set column data types
1332
+ * Note: Deals with scenario where the data is provided to AdapTable after grid has been setup
1333
+ */
1334
+ this.agGridAdapter.getAgGridApi().addEventListener(core_1.Events.EVENT_FIRST_DATA_RENDERED, (this.listenerFirstDataRendered = () => {
1335
+ if (this.initWithLazyData) {
1336
+ this.updateColumnModelAndRefreshGrid();
1337
+ this.api.calculatedColumnApi.refreshAggregatedCalculatedColumns();
1338
+ this._emit('FirstDataRendered');
1339
+ }
1340
+ this.autoSizeLayoutIfNeeded();
1341
+ }));
1342
+ /**
1343
+ * Use Case: Entered or Left Pivot Mode
1344
+ * Action 1: Autosize pivot columns when entering pivot mode (if autosize pivot in Layout is true)
1345
+ * Action 2: Set pivot mode on / off in api as necessary
1346
+ */
1347
+ this.agGridAdapter.getAgGridApi().addEventListener(core_1.Events.EVENT_COLUMN_PIVOT_MODE_CHANGED, (this.listenerPivotModeChanged = (params) => {
1348
+ if (params.type == 'columnPivotModeChanged' &&
1349
+ params.columnApi != null &&
1350
+ params.columnApi.columnController != null &&
1351
+ params.columnApi.columnController.pivotMode == true) {
1352
+ if (this.adaptableOptions.layoutOptions.autoSizeColumnsInPivotLayout == true) {
1353
+ this.agGridAdapter.getAgGridApi().autoSizeAllColumns();
1354
+ }
1355
+ this.api.internalApi.setPivotModeOn();
1356
+ }
1357
+ else {
1358
+ this.api.internalApi.setPivotModeOff();
1359
+ }
1360
+ }));
1361
+ /**
1362
+ * Use Case: A pivot column has changed
1363
+ * Action: Autosize pivot columns (if autosize pivot in Layout is true)
1364
+ */
1365
+ this.agGridAdapter.getAgGridApi().addEventListener(core_1.Events.EVENT_COLUMN_PIVOT_CHANGED, (this.listenerPivotChanged = (params) => {
1366
+ if (params.type == 'columnPivotChanged' &&
1367
+ params.columnApi != null &&
1368
+ params.columnApi.columnController != null &&
1369
+ params.columnApi.columnController.pivotMode == true) {
1370
+ if (this.adaptableOptions.layoutOptions.autoSizeColumnsInPivotLayout == true) {
1371
+ this.agGridAdapter.getAgGridApi().autoSizeAllColumns();
1372
+ }
1373
+ }
1374
+ }));
1375
+ /**
1376
+ * Use Case: Things have changed in the grid that require the Layout to be saved
1377
+ * Action: Save the Layout (on a debounce)
1378
+ */
1379
+ const columnEventsThatTriggersAutoLayoutSave = [
1380
+ core_1.Events.EVENT_COLUMN_PINNED,
1381
+ core_1.Events.EVENT_COLUMN_PIVOT_CHANGED,
1382
+ core_1.Events.EVENT_COLUMN_PIVOT_MODE_CHANGED,
1383
+ core_1.Events.EVENT_DISPLAYED_COLUMNS_CHANGED,
1384
+ core_1.Events.EVENT_SORT_CHANGED,
1385
+ core_1.Events.EVENT_COLUMN_ROW_GROUP_CHANGED,
1386
+ core_1.Events.EVENT_COLUMN_VALUE_CHANGED,
1387
+ ];
1388
+ // ADD filter event
1389
+ this.agGridAdapter.getAgGridApi().addGlobalListener((this.listenerGlobalColumnEventsThatTriggerAutoLayoutSave = (type) => {
1390
+ if (columnEventsThatTriggersAutoLayoutSave.indexOf(type) > -1) {
1391
+ this.debouncedSaveGridLayout(type);
1392
+ }
1393
+ }));
1394
+ /**
1395
+ * Save Layout if Display Row Groups is "dynamic
1396
+ */
1397
+ this.debouncedSaveGridLayout = (0, debounce_1.default)((type) => {
1398
+ if (!this.isReady) {
1399
+ return;
1400
+ }
1401
+ this.logger.info('Event Triggering Auto Layout Save', type || '');
1402
+ this.updateLayoutFromGrid();
1403
+ }, GeneralConstants_1.HALF_SECOND);
1404
+ const rowGroupEventsThatTriggersAutoLayoutSave = [
1405
+ core_1.Events.EVENT_ROW_GROUP_OPENED,
1406
+ core_1.Events.EVENT_EXPAND_COLLAPSE_ALL,
1407
+ ];
1408
+ this.agGridAdapter.getAgGridApi().addGlobalListener((this.listenerGlobalRowGroupEventsThatTriggerAutoLayoutSave = (type) => {
1409
+ if (rowGroupEventsThatTriggersAutoLayoutSave.indexOf(type) > -1) {
1410
+ if (this.adaptableOptions.layoutOptions.displayRowGroups == 'dynamic') {
1411
+ this.debouncedSaveGridLayout(type);
1412
+ }
1413
+ }
1414
+ }));
1415
+ /**
1416
+ * Use Case: Column Row Grouping changes and 'restoreUngroupedColumns' is true
1417
+ * Action: Make the column invisiblel
1418
+ */
1419
+ this.agGridAdapter.getAgGridApi().addEventListener(core_1.Events.EVENT_COLUMN_ROW_GROUP_CHANGED, (this.listenerColumnRowGroupChanged = (params) => {
1420
+ var _a, _b;
1421
+ if (this.api.internalApi.isGridInPivotMode()) {
1422
+ return;
1423
+ }
1424
+ if ((_b = (_a = this.adaptableOptions) === null || _a === void 0 ? void 0 : _a.groupingOptions) === null || _b === void 0 ? void 0 : _b.restoreUngroupedColumns) {
1425
+ this.persistColumnIndexBeforeGrouping(params);
1426
+ }
1427
+ }));
1428
+ /**
1429
+ * Use Case: A Column has finished being resized
1430
+ * Action 1: Save the Layout (on a debounce)
1431
+ * Action 2: Emit the internal ColumnResized event - used by Sparkline Column (in Charts)
1432
+ */
1433
+ this.agGridAdapter.getAgGridApi().addEventListener(core_1.Events.EVENT_COLUMN_RESIZED, (this.listenerColumnResized = (params) => {
1434
+ if (params.finished == true && params.type == 'columnResized' && params.column) {
1435
+ this.debouncedSaveGridLayout(params.type);
1436
+ }
1437
+ }));
1438
+ /**
1439
+ * Use Case: Row Selection has changed
1440
+ * Action: Set Selected Rows (on a debeounce)
1441
+ */
1442
+ this.debouncedSetSelectedRows = (0, debounce_1.default)(() => {
1443
+ if (!this.isReady) {
1444
+ return;
1445
+ }
1446
+ this.refreshSelectedRowsState();
1447
+ }, GeneralConstants_1.HALF_SECOND);
1448
+ const columnEventsThatTriggerSetRowSelection = [
1449
+ core_1.Events.EVENT_ROW_GROUP_OPENED,
1450
+ core_1.Events.EVENT_SELECTION_CHANGED,
1451
+ core_1.Events.EVENT_ROW_SELECTED,
1452
+ ];
1453
+ this.agGridAdapter.getAgGridApi().addGlobalListener((this.listenerGlobalSetRowSelection = (type) => {
1454
+ if (ArrayExtensions_1.default.ContainsItem(columnEventsThatTriggerSetRowSelection, type)) {
1455
+ this.debouncedSetSelectedRows();
1456
+ }
1457
+ }));
1458
+ /**
1459
+ * Use Case: User has selected a range of cells
1460
+ * Action: Set Selected Cells (on a debounce)
1461
+ */
1462
+ this.debouncedSetSelectedCells = (0, debounce_1.default)(() => {
1463
+ if (!this.isReady) {
1464
+ return;
1465
+ }
1466
+ this.refreshSelectedCellsState();
1467
+ }, 250);
1468
+ this.agGridAdapter.getAgGridApi().addEventListener(core_1.Events.EVENT_RANGE_SELECTION_CHANGED, (this.listenerRangeSelectionChanged = (params) => {
1469
+ if (params.finished == true) {
1470
+ this.debouncedSetSelectedCells();
1471
+ }
1472
+ }));
1473
+ /**
1474
+ * Use Case: Sort has changed in the Grid
1475
+ * Action1: Update AdapTable Sort Info
1476
+ * Action2: Set Selected Cells (on a debounce)
1477
+ */
1478
+ this.agGridAdapter.getAgGridApi().addEventListener(core_1.Events.EVENT_SORT_CHANGED, (this.listenerSortChanged = () => {
1479
+ this.onSortChanged();
1480
+ this.debouncedSetSelectedCells();
1481
+ }));
1482
+ const eventsThatTriggerChartingChanges = [
1483
+ core_1.Events.EVENT_CHART_CREATED,
1484
+ /** Chart Range selection has changed */
1485
+ core_1.Events.EVENT_CHART_RANGE_SELECTION_CHANGED,
1486
+ /** Chart Options have changed */
1487
+ core_1.Events.EVENT_CHART_OPTIONS_CHANGED,
1488
+ /** Chart was destroyed */
1489
+ core_1.Events.EVENT_CHART_DESTROYED,
1490
+ ];
1491
+ const chartingModule = this.ModuleService.getModuleById('Charting');
1492
+ if (chartingModule.isModuleAvailable()) {
1493
+ this.agGridAdapter.getAgGridApi().addGlobalListener((type, params) => {
1494
+ if (ArrayExtensions_1.default.ContainsItem(eventsThatTriggerChartingChanges, type)) {
1495
+ this.ChartingService.onChartModelChange(this.getChartModels(), type, params);
1496
+ }
1497
+ });
1498
+ }
1499
+ /**
1500
+ * Row and Cell listeners created in 2020
1501
+ * These have supplanted many of the events we previously had and simplified things
1502
+ */
1503
+ this.rowListeners = {
1504
+ dataChanged: (event) => {
1505
+ this.onRowDataChanged({
1506
+ rowNode: event.node,
1507
+ oldData: event.oldData,
1508
+ newData: event.newData,
1509
+ });
1510
+ },
1511
+ cellChanged: (event) => {
1512
+ if (event.column) {
1513
+ this.onCellDataChanged({
1514
+ rowNode: event.node,
1515
+ oldValue: event.oldValue,
1516
+ newValue: event.newValue,
1517
+ colId: event.column.colId,
1518
+ });
1519
+ }
1520
+ },
1521
+ };
1522
+ }
1523
+ shouldAutoSizeLayout() {
1524
+ const { layoutApi } = this.api;
1525
+ const { layoutOptions } = this.adaptableOptions;
1526
+ const currentLayout = layoutApi.getCurrentLayout();
1527
+ if (currentLayout.ColumnWidthMap && Object.keys(currentLayout.ColumnWidthMap).length > 0) {
1528
+ return;
1529
+ }
1530
+ const autoSize = currentLayout.EnablePivot
1531
+ ? layoutOptions.autoSizeColumnsInPivotLayout
1532
+ : layoutOptions.autoSizeColumnsInLayout;
1533
+ return autoSize;
1534
+ }
1535
+ autoSizeLayoutIfNeeded() {
1536
+ if (this.shouldAutoSizeLayout()) {
1537
+ requestAnimationFrame(() => {
1538
+ this.autoSizeAllColumns();
1539
+ });
1540
+ }
1541
+ }
1542
+ performAudit(action, oldState, newState) {
1543
+ if (this.isReady) {
1544
+ const adaptableStateChangedInfo = {
1545
+ adaptableApi: this.api,
1546
+ actionName: action.type,
1547
+ clientTimestamp: new Date(),
1548
+ userName: this.adaptableOptions.userName,
1549
+ adaptableId: this.adaptableOptions.adaptableId,
1550
+ adaptableStateKey: this.adaptableOptions.adaptableStateKey,
1551
+ action: action,
1552
+ oldState: oldState,
1553
+ newState: newState,
1554
+ };
1555
+ this.api.eventApi.emit('AdaptableStateChanged', adaptableStateChangedInfo);
1556
+ }
1557
+ }
1558
+ forPlugins(callback) {
1559
+ if (Array.isArray(this.adaptableOptions.plugins)) {
1560
+ this.adaptableOptions.plugins.forEach((plugin) => {
1561
+ callback(plugin);
1562
+ });
1563
+ }
1564
+ }
1565
+ getPluginProperty(pluginId, propertyName, ...args) {
1566
+ const plugins = this.adaptableOptions.plugins || [];
1567
+ const thePlugin = plugins.filter((p) => p.pluginId === pluginId)[0];
1568
+ if (!thePlugin) {
1569
+ throw `Cannot find plugin "${pluginId}". Make sure you spelled it right!`;
1570
+ }
1571
+ if (thePlugin && thePlugin.hasProperty(propertyName)) {
1572
+ return thePlugin.getProperty(propertyName)(...args);
1573
+ }
1574
+ }
1575
+ getPlugin(pluginId) {
1576
+ const plugins = this.adaptableOptions.plugins || [];
1577
+ const thePlugin = plugins.filter((p) => p.pluginId === pluginId)[0];
1578
+ if (!thePlugin) {
1579
+ throw `Cannot find plugin "${pluginId}". Make sure you spelled it right!`;
1580
+ }
1581
+ return thePlugin;
1582
+ }
1583
+ initServices() {
1584
+ // create the services
1585
+ this.LicenseService = this.initLicenseService();
1586
+ this.ChartingService = new ChartingService_1.ChartingService(this.api);
1587
+ this.ThemeService = new ThemeService_1.ThemeService(this.api);
1588
+ this.ValidationService = new ValidationService_1.ValidationService(this.api);
1589
+ this.ReportService = new ReportService_1.ReportService(this.api);
1590
+ this.ModuleService = new ModuleService_1.ModuleService(this.api);
1591
+ this.CalculatedColumnExpressionService = new CalculatedColumnExpressionService_1.CalculatedColumnExpressionService(this.api);
1592
+ this.EntitlementService = new EntitlementService_1.EntitlementService(this.api);
1593
+ this.QueryLanguageService = new QueryLanguageService_1.QueryLanguageService(this.api);
1594
+ this.AlertService = new AlertService_1.AlertService(this.api);
1595
+ this.TeamSharingService = new TeamSharingService_1.TeamSharingService(this.api);
1596
+ this.Fdc3Service = new Fdc3Service_1.Fdc3Service(this.api);
1597
+ this.CellPopupService = new CellPopupService_1.CellPopupService(this.api);
1598
+ this.RowEditService = new RowEditService_1.RowEditService(this.api);
1599
+ this.MetamodelService = new MetamodelService_1.MetamodelService(() => this.api.optionsApi.getAdaptableOptions(), true);
1600
+ }
1601
+ initLicenseService() {
1602
+ const globalObject = typeof globalThis !== 'undefined' ? globalThis : window;
1603
+ const licenseKey = globalObject.ADAPTABLE_LICENSE_KEY || this.api.optionsApi.getLicenseKey();
1604
+ return new LicenseService_1.LicenseService(this, licenseKey, {
1605
+ publishedAt: publishTimestamp,
1606
+ });
1607
+ }
1608
+ initModules() {
1609
+ const modules = new Map();
1610
+ modules.set(ModuleConstants.AlertModuleId, new AlertModule_1.AlertModule(this.api));
1611
+ modules.set(ModuleConstants.BulkUpdateModuleId, new BulkUpdateModule_1.BulkUpdateModule(this.api));
1612
+ modules.set(ModuleConstants.CalculatedColumnModuleId, new CalculatedColumnModule_1.CalculatedColumnModule(this.api));
1613
+ modules.set(ModuleConstants.CellSummaryModuleId, new CellSummaryModule_1.CellSummaryModule(this.api));
1614
+ modules.set(ModuleConstants.ChartingModuleId, new ChartingModule_1.ChartingModule(this.api));
1615
+ modules.set(ModuleConstants.ColumnFilterModuleId, new ColumnFilterModule_1.ColumnFilterModule(this.api));
1616
+ modules.set(ModuleConstants.ColumnInfoModuleId, new ColumnInfoModule_1.ColumnInfoModule(this.api));
1617
+ modules.set(ModuleConstants.CommentModuleId, new CommentModule_1.CommentModule(this.api));
1618
+ modules.set(ModuleConstants.CustomSortModuleId, new CustomSortModule_1.CustomSortModule(this.api));
1619
+ modules.set(ModuleConstants.DashboardModuleId, new DashboardModule_1.DashboardModule(this.api));
1620
+ modules.set(ModuleConstants.DataChangeHistoryModuleId, new DataChangeHistoryModule_1.DataChangeHistoryModule(this.api));
1621
+ modules.set(ModuleConstants.DataImportModuleId, new DataImportModule_1.DataImportModule(this.api));
1622
+ modules.set(ModuleConstants.DataSetModuleId, new DataSetModule_1.DataSetModule(this.api));
1623
+ modules.set(ModuleConstants.ExportModuleId, new ExportModule_1.ExportModule(this.api));
1624
+ modules.set(ModuleConstants.Fdc3ModuleId, new Fdc3Module_1.Fdc3Module(this.api));
1625
+ modules.set(ModuleConstants.FlashingCellModuleId, new FlashingCellModule_1.FlashingCellModule(this.api));
1626
+ modules.set(ModuleConstants.FormatColumnModuleId, new FormatColumnModule_1.FormatColumnModule(this.api));
1627
+ modules.set(ModuleConstants.FreeTextColumnModuleId, new FreeTextColumnModule_1.FreeTextColumnModule(this.api));
1628
+ modules.set(ModuleConstants.GridFilterModuleId, new GridFilterModule_1.GridFilterModule(this.api));
1629
+ modules.set(ModuleConstants.GridInfoModuleId, new GridInfoModule_1.GridInfoModule(this.api));
1630
+ modules.set(ModuleConstants.LayoutModuleId, new LayoutModule_1.LayoutModule(this.api));
1631
+ modules.set(ModuleConstants.NamedQueryModuleId, new NamedQueryModule_1.NamedQueryModule(this.api));
1632
+ modules.set(ModuleConstants.NoteModuleId, new NoteModule_1.NoteModule(this.api));
1633
+ modules.set(ModuleConstants.PlusMinusModuleId, new PlusMinusModule_1.PlusMinusModule(this.api));
1634
+ modules.set(ModuleConstants.QuickSearchModuleId, new QuickSearchModule_1.QuickSearchModule(this.api));
1635
+ modules.set(ModuleConstants.ScheduleModuleId, new ScheduleModule_1.ScheduleModule(this.api));
1636
+ modules.set(ModuleConstants.SettingsPanelModuleId, new SettingsPanelModule_1.SettingsPanelModule(this.api));
1637
+ modules.set(ModuleConstants.ShortcutModuleId, new ShortcutModule_1.ShortcutModule(this.api));
1638
+ modules.set(ModuleConstants.SmartEditModuleId, new SmartEditModule_1.SmartEditModule(this.api));
1639
+ modules.set(ModuleConstants.StateManagementModuleId, new StateManagementModule_1.StateManagementModule(this.api));
1640
+ modules.set(ModuleConstants.StatusBarModuleId, new StatusBarModule_1.StatusBarModule(this.api));
1641
+ modules.set(ModuleConstants.StyledColumnModuleId, new StyledColumnModule_1.StyledColumnModule(this.api));
1642
+ modules.set(ModuleConstants.SystemStatusModuleId, new SystemStatusModule_1.SystemStatusModule(this.api));
1643
+ modules.set(ModuleConstants.TeamSharingModuleId, new TeamSharingModule_1.TeamSharingModule(this.api));
1644
+ modules.set(ModuleConstants.ThemeModuleId, new ThemeModule_1.ThemeModule(this.api));
1645
+ modules.set(ModuleConstants.ToolPanelModuleId, new ToolPanelModule_1.ToolPanelModule(this.api));
1646
+ return modules;
1647
+ }
1648
+ /**
1649
+ * This method contains all the updates on the AdaptableState which were made AFTER Adaptbale was ready
1650
+ * This was contidioned because we required AG Grid to be ready before we could make these updates
1651
+ * We should be able to refactor the code, no that we no fore sure that Adaptable State is ready BEFORE AG Grid init
1652
+ */
1653
+ temporaryAdaptableStateUpdates() {
1654
+ this.api.eventApi.on('AdaptableReady', () => {
1655
+ var _a, _b;
1656
+ // update status bar state
1657
+ const adaptableStatusPanels = (_b = (_a = this.agGridAdapter
1658
+ .getAgGridApi()
1659
+ .getGridOption('statusBar')) === null || _a === void 0 ? void 0 : _a.statusPanels) === null || _b === void 0 ? void 0 : _b.filter((statusPanel) => this.adaptableStatusPanelKeys.includes(statusPanel.key));
1660
+ const statusBarModule = this.ModuleService.getModuleById(ModuleConstants.StatusBarModuleId);
1661
+ // need to add only the adaptable panels
1662
+ statusBarModule.syncStateWithOptions(adaptableStatusPanels);
1663
+ });
1664
+ }
1665
+ validatePrimaryKey() {
1666
+ if (this.hasAutogeneratedPrimaryKey) {
1667
+ return;
1668
+ }
1669
+ const primaryKey = this.adaptableOptions.primaryKey;
1670
+ const primaryKeyColDef = this.agGridAdapter.getAgGridApi().getColumnDef(primaryKey);
1671
+ if (!primaryKeyColDef) {
1672
+ const errorMessage = `The Primary Key Column '${this.adaptableOptions.primaryKey}' does not exist. This will affect many functions in Adaptable.`;
1673
+ if (this.adaptableOptions.alertOptions.showMissingPrimaryKeyAlert) {
1674
+ // show an alert if that is the option
1675
+ this.api.alertApi.showAlertError('No Primary Key', errorMessage);
1676
+ }
1677
+ else {
1678
+ if (this.adaptableOptions.columnOptions.showMissingColumnsWarning) {
1679
+ this.logger.consoleError(errorMessage);
1680
+ }
1681
+ }
1682
+ }
1683
+ }
1684
+ deriveAdaptableColumnStateFromAgGrid() {
1685
+ const allColumns = [];
1686
+ const agGridCols = this.agGridAdapter.getAgGridApi().getColumns();
1687
+ const columnGroupChildren = this.agGridAdapter
1688
+ .getAgGridApi()
1689
+ // TODO AFL MIG: check why this assertion is here
1690
+ .getAllDisplayedColumnGroups();
1691
+ const groupsCount = {};
1692
+ const colsToGroups = (columnGroupChildren !== null && columnGroupChildren !== void 0 ? columnGroupChildren : []).reduce((acc, columnGroup) => {
1693
+ var _a, _b, _c;
1694
+ if (!((_b = (_a = columnGroup.getProvidedColumnGroup) === null || _a === void 0 ? void 0 : _a.call(columnGroup)) === null || _b === void 0 ? void 0 : _b.getColGroupDef())) {
1695
+ return acc;
1696
+ }
1697
+ const ColumnGroupId = columnGroup.getGroupId();
1698
+ const AllowGroupSplit = !columnGroup.getProvidedColumnGroup().getColGroupDef()
1699
+ .marryChildren;
1700
+ const FriendlyName = (_c = columnGroup.getProvidedColumnGroup().getColGroupDef().headerName) !== null && _c !== void 0 ? _c : ColumnGroupId;
1701
+ const columnsInGroup = columnGroup.getLeafColumns();
1702
+ columnsInGroup.forEach((col) => {
1703
+ const group = {
1704
+ columnGroupId: ColumnGroupId,
1705
+ friendlyName: FriendlyName,
1706
+ allowGroupSplit: AllowGroupSplit,
1707
+ groupCount: 0,
1708
+ };
1709
+ groupsCount[group.columnGroupId] = groupsCount[group.columnGroupId] || 0;
1710
+ groupsCount[group.columnGroupId] += columnsInGroup.length;
1711
+ acc[col.getColId()] = group;
1712
+ });
1713
+ return acc;
1714
+ }, {});
1715
+ Object.keys(colsToGroups).forEach((colId) => {
1716
+ colsToGroups[colId].groupCount = groupsCount[colsToGroups[colId].columnGroupId];
1717
+ });
1718
+ // TODO sort the visible columns by layout order
1719
+ agGridCols.forEach((agGridColumn) => {
1720
+ const colId = agGridColumn.getColId();
1721
+ if (!this.api.columnApi.isAutoRowGroupColumn(colId)) {
1722
+ allColumns.push(this.agGridAdapter.createAdaptableColumnFromAgGridColumn(agGridColumn, colsToGroups));
1723
+ }
1724
+ });
1725
+ this.api.gridApi.internalApi.setColumns(allColumns);
1726
+ }
1727
+ checkShouldClearExistingFiltersOrSearches() {
1728
+ // if they have selected to clear column filters on startup then do it
1729
+ if (this.adaptableOptions.columnFilterOptions.clearColumnFiltersOnStartUp) {
1730
+ if (ArrayExtensions_1.default.IsNotNullOrEmpty(this.api.columnFilterApi.getColumnFilters())) {
1731
+ this.logger.warn('Clearing existing Column Filters as "clearColumnFiltersOnStartUp" is true');
1732
+ this.api.columnFilterApi.clearColumnFilters();
1733
+ }
1734
+ }
1735
+ // if they have selected to clear the Grid filter on startup then do it
1736
+ if (this.adaptableOptions.gridFilterOptions.clearGridFilterOnStartUp) {
1737
+ if (StringExtensions_1.default.IsNotNullOrEmpty(this.api.gridFilterApi.getCurrentGridFilterExpression())) {
1738
+ this.logger.warn('Clearing existing Grid Filter as "clearGridFilterOnStartUp" is true');
1739
+ this.api.gridFilterApi.setGridFilterExpression('');
1740
+ }
1741
+ }
1742
+ // if they have selected to clear searches on startup then do it
1743
+ if (this.adaptableOptions.quickSearchOptions.clearQuickSearchOnStartUp) {
1744
+ if (StringExtensions_1.default.IsNotNullOrEmpty(this.api.quickSearchApi.getQuickSearchState().QuickSearchText)) {
1745
+ this.logger.warn('Clearing existing Searches as "clearQuickSearchOnStartUp" is true');
1746
+ this.api.quickSearchApi.clearQuickSearch();
1747
+ }
1748
+ }
1749
+ }
1750
+ getGridCellFromRowNode(rowNode, columnId) {
1751
+ if (rowNode == null) {
1752
+ return undefined;
1753
+ }
1754
+ const abColumn = this.api.columnApi.getColumnWithColumnId(columnId);
1755
+ const pkValue = this.getPrimaryKeyValueFromRowNode(rowNode);
1756
+ const rawValue = this.getRawValueFromRowNode(rowNode, columnId);
1757
+ const displayValue = this.getDisplayValueFromRawValue(rowNode, columnId, rawValue);
1758
+ const normalisedValue = this.getNormalisedValueFromRawValue(rawValue, abColumn);
1759
+ const isPivotCell = this.api.columnApi.isAutoPivotColumn(columnId);
1760
+ const isRowGroupCell = rowNode.group;
1761
+ return {
1762
+ rawValue: rawValue,
1763
+ displayValue: displayValue,
1764
+ normalisedValue: normalisedValue,
1765
+ column: abColumn,
1766
+ primaryKeyValue: pkValue,
1767
+ rowNode: rowNode,
1768
+ isPivotCell,
1769
+ isRowGroupCell,
1770
+ };
1771
+ }
1772
+ getPrimaryKeyValueFromRowNode(rowNode, gridApi) {
1773
+ if (!rowNode) {
1774
+ return null;
1775
+ }
1776
+ const agGridApi = gridApi || this.agGridAdapter.getAgGridApi();
1777
+ let result;
1778
+ if (!this.hasAutogeneratedPrimaryKey) {
1779
+ result = agGridApi.getValue(this.adaptableOptions.primaryKey, rowNode);
1780
+ }
1781
+ if (result == undefined && rowNode.data) {
1782
+ result = rowNode.data[this.adaptableOptions.primaryKey];
1783
+ }
1784
+ return result;
1785
+ }
1786
+ getRawValueFromRowNode(rowNode, columnId) {
1787
+ if (rowNode == null) {
1788
+ return undefined;
1789
+ }
1790
+ return this.agGridAdapter.getAgGridApi().getValue(columnId, rowNode);
1791
+ }
1792
+ getDisplayValueFromRowNode(rowNode, columnId) {
1793
+ if (rowNode == null) {
1794
+ return undefined;
1795
+ }
1796
+ const rawValue = this.getRawValueFromRowNode(rowNode, columnId);
1797
+ return this.getDisplayValueFromRawValue(rowNode, columnId, rawValue);
1798
+ }
1799
+ getDisplayValueFromRawValue(rowNode, columnId, rawValue) {
1800
+ var _a;
1801
+ const isActionColumn = this.api.columnApi.isActionColumn(columnId);
1802
+ if (isActionColumn) {
1803
+ return this.getCleanValue(rawValue);
1804
+ }
1805
+ const colDef = this.agGridAdapter.getAgGridApi().getColumnDef(columnId);
1806
+ if (colDef) {
1807
+ if (typeof colDef.valueFormatter == 'function') {
1808
+ const column = this.agGridAdapter.getAgGridApi().getColumn(columnId);
1809
+ const params = {
1810
+ value: rawValue,
1811
+ node: rowNode,
1812
+ data: rowNode.data,
1813
+ colDef,
1814
+ column,
1815
+ api: this.agGridAdapter.getAgGridApi(),
1816
+ columnApi: (_a = this.agGridAdapter.getLiveGridOptions()) === null || _a === void 0 ? void 0 : _a.columnApi,
1817
+ context: this.agGridAdapter.getLiveGridOptions().context,
1818
+ };
1819
+ const formattedValue = colDef.valueFormatter(params);
1820
+ return formattedValue || '';
1821
+ }
1822
+ }
1823
+ return this.getCleanValue(rawValue);
1824
+ }
1825
+ getCleanValue(value) {
1826
+ if (typeof value === 'string') {
1827
+ return value;
1828
+ }
1829
+ if (value == null || value == 'null' || value == undefined || value == 'undefined') {
1830
+ return undefined;
1831
+ }
1832
+ return String(value) || '';
1833
+ }
1834
+ getNormalisedValueFromRawValue(rawValue, column) {
1835
+ if (!column) {
1836
+ return rawValue;
1837
+ }
1838
+ // prevents from null
1839
+ if (rawValue === undefined || rawValue === null) {
1840
+ return rawValue;
1841
+ }
1842
+ const dataType = column.dataType;
1843
+ if (dataType === 'String') {
1844
+ return typeof rawValue !== 'string' ? String(rawValue) : rawValue;
1845
+ }
1846
+ if (dataType === 'Number') {
1847
+ // empty string or space should not be converted to 0
1848
+ return typeof rawValue !== 'number' && StringExtensions_1.default.IsNumeric(rawValue)
1849
+ ? Number(rawValue)
1850
+ : rawValue;
1851
+ }
1852
+ if (dataType === 'Boolean') {
1853
+ return typeof rawValue !== 'boolean' ? Boolean(rawValue) : rawValue;
1854
+ }
1855
+ if (dataType === 'Date') {
1856
+ return rawValue instanceof Date ? rawValue : (0, DateHelper_1.parseDateValue)(rawValue);
1857
+ }
1858
+ return rawValue;
1859
+ }
1860
+ updateColumnModelAndRefreshGrid(config) {
1861
+ if (!(config === null || config === void 0 ? void 0 : config.skipColDefsRefresh)) {
1862
+ this.refreshColDefs();
1863
+ }
1864
+ this.deriveAdaptableColumnStateFromAgGrid();
1865
+ this.agGridColumnAdapter.setupColumns();
1866
+ this.redrawBody();
1867
+ this.refreshHeader();
1868
+ }
1869
+ redrawBody() {
1870
+ this.redrawRows();
1871
+ this._emit('GridRefreshed');
1872
+ }
1873
+ refreshHeader() {
1874
+ this.agGridAdapter.getAgGridApi().refreshHeader();
1875
+ }
1876
+ // TODO AFL: this method seems to be used A LOT
1877
+ // we should check if we couldn't use the `refresh` method instead for some cases
1878
+ // see https://www.ag-grid.com/react-data-grid/view-refresh/#redraw-rows
1879
+ redrawRows(rowNodes) {
1880
+ const redrawRowsParams = rowNodes
1881
+ ? {
1882
+ rowNodes,
1883
+ }
1884
+ : undefined;
1885
+ try {
1886
+ this.agGridAdapter.getAgGridApi().redrawRows(redrawRowsParams);
1887
+ }
1888
+ catch (ex) {
1889
+ this.logger.consoleError('AG Grid redrawRows was unable to find some row nodes. Tried to redraw row nodes: ', rowNodes, ex);
1890
+ }
1891
+ }
1892
+ redrawRow(rowNode) {
1893
+ this.redrawRows([rowNode]);
1894
+ }
1895
+ refreshCells(rowNodes, columns, forceUpdate, suppressFlash = false) {
1896
+ const refreshCellParams = {
1897
+ rowNodes,
1898
+ columns: columns,
1899
+ force: forceUpdate,
1900
+ suppressFlash,
1901
+ };
1902
+ this.agGridAdapter.getAgGridApi().refreshCells(refreshCellParams);
1903
+ }
1904
+ refreshColumns(columns, forceUpdate, suppressFlash) {
1905
+ this.refreshCells(null, columns, forceUpdate, suppressFlash);
1906
+ }
1907
+ jumpToRow(rowNode) {
1908
+ this.agGridAdapter.getAgGridApi().ensureNodeVisible(rowNode, 'middle');
1909
+ }
1910
+ jumpToColumn(columnId) {
1911
+ this.agGridAdapter.getAgGridApi().ensureColumnVisible(columnId);
1912
+ }
1913
+ jumpToCell(columnId, rowNode) {
1914
+ this.jumpToRow(rowNode);
1915
+ this.jumpToColumn(columnId);
1916
+ }
1917
+ selectColumn(columnId, config) {
1918
+ if (!(config === null || config === void 0 ? void 0 : config.keepExistingSelection)) {
1919
+ this.agGridAdapter.getAgGridApi().clearRangeSelection();
1920
+ }
1921
+ const cellRangeParams = {
1922
+ rowStartIndex: 0,
1923
+ rowEndIndex: this.agGridAdapter.getAgGridApi().getDisplayedRowCount() - 1,
1924
+ columnStart: columnId,
1925
+ columnEnd: columnId,
1926
+ };
1927
+ this.agGridAdapter.getAgGridApi().addCellRange(cellRangeParams);
1928
+ }
1929
+ selectColumns(columnIds, config) {
1930
+ if (!(config === null || config === void 0 ? void 0 : config.keepExistingSelection)) {
1931
+ this.agGridAdapter.getAgGridApi().clearRangeSelection();
1932
+ }
1933
+ const rowCount = this.agGridAdapter.getAgGridApi().getDisplayedRowCount();
1934
+ columnIds.forEach((colId) => {
1935
+ const cellRangeParams = {
1936
+ rowStartIndex: 0,
1937
+ rowEndIndex: rowCount - 1,
1938
+ columnStart: colId,
1939
+ columnEnd: colId,
1940
+ };
1941
+ this.agGridAdapter.getAgGridApi().addCellRange(cellRangeParams);
1942
+ });
1943
+ }
1944
+ selectAll() {
1945
+ this.agGridAdapter.getAgGridApi().selectAll();
1946
+ }
1947
+ deselectAll() {
1948
+ // need to do both as first just clears selected rows and second clears ranges
1949
+ this.agGridAdapter.getAgGridApi().deselectAll();
1950
+ this.agGridAdapter.getAgGridApi().clearRangeSelection();
1951
+ }
1952
+ setGridData(dataSource) {
1953
+ if (!this.isReady) {
1954
+ return;
1955
+ }
1956
+ if (this.hasAutogeneratedPrimaryKey) {
1957
+ this.addSyntheticPrimaryKey(dataSource);
1958
+ }
1959
+ this.agGridAdapter.setGridOption('rowData', dataSource);
1960
+ this.updateRowGroupsExpandedState();
1961
+ this.updateColumnModelAndRefreshGrid();
1962
+ }
1963
+ getGridData() {
1964
+ const data = [];
1965
+ this.agGridAdapter.getAgGridApi().forEachNode((rowNode) => {
1966
+ if (!this.isGroupRowNode(rowNode)) {
1967
+ data.push(rowNode.data);
1968
+ }
1969
+ });
1970
+ return data;
1971
+ }
1972
+ addSyntheticPrimaryKey(rowData = []) {
1973
+ for (let i = 0; i < rowData.length; i++) {
1974
+ rowData[i][GeneralConstants_1.AUTOGENERATED_PK_COLUMN] = (0, uuid_1.createUuid)();
1975
+ }
1976
+ }
1977
+ // add a synthetic PK only if missing (useful in case of updating row data)
1978
+ addSyntheticPrimaryKeyIfMissing(rowData = []) {
1979
+ this.adaptableOptions.primaryKey = GeneralConstants_1.AUTOGENERATED_PK_COLUMN;
1980
+ for (let i = 0; i < rowData.length; i++) {
1981
+ if (!rowData[i][GeneralConstants_1.AUTOGENERATED_PK_COLUMN]) {
1982
+ rowData[i][GeneralConstants_1.AUTOGENERATED_PK_COLUMN] = (0, uuid_1.createUuid)();
1983
+ }
1984
+ }
1985
+ }
1986
+ getFirstDisplayedRowNode() {
1987
+ const firstDisplayedRowIndex = this.agGridAdapter
1988
+ .getAgGridApi()
1989
+ .getFirstDisplayedRowIndex();
1990
+ return this.agGridAdapter.getAgGridApi().getDisplayedRowAtIndex(firstDisplayedRowIndex);
1991
+ }
1992
+ getFirstRowNode() {
1993
+ let firstRowNode = this.getFirstDisplayedRowNode();
1994
+ if (firstRowNode === null || firstRowNode === void 0 ? void 0 : firstRowNode.group) {
1995
+ // all groups may be closed so it is safer to get first leaf node
1996
+ // all groups must have at least one leafe node
1997
+ firstRowNode = firstRowNode.allLeafChildren[0];
1998
+ }
1999
+ return firstRowNode;
2000
+ }
2001
+ updateRowGroupsExpandedState(layout) {
2002
+ if (!layout) {
2003
+ layout = this.api.layoutApi.getCurrentLayout();
2004
+ }
2005
+ if (this.api.layoutApi.internalApi.areExpandedRowGroupsSavedInLayouts() &&
2006
+ ArrayExtensions_1.default.IsNotNullOrEmpty(layout.ExpandedRowGroupValues)) {
2007
+ this.expandRowGroupsForValues(layout.ExpandedRowGroupValues);
2008
+ }
2009
+ if (this.adaptableOptions.layoutOptions.displayRowGroups === 'expanded') {
2010
+ this.expandAllRowGroups();
2011
+ }
2012
+ }
2013
+ isGroupRowNode(rowNode) {
2014
+ if (!rowNode) {
2015
+ return false;
2016
+ }
2017
+ if (rowNode.isEmptyRowGroupNode()) {
2018
+ return true;
2019
+ }
2020
+ if (rowNode.group && rowNode.group === true) {
2021
+ return true;
2022
+ }
2023
+ if (rowNode.leafGroup && rowNode.leafGroup === true) {
2024
+ return true;
2025
+ }
2026
+ return false;
2027
+ }
2028
+ getFilteredData() {
2029
+ const data = [];
2030
+ this.agGridAdapter.getAgGridApi().forEachNodeAfterFilter((rowNode) => {
2031
+ if (!this.isGroupRowNode(rowNode)) {
2032
+ data.push(rowNode.data);
2033
+ }
2034
+ });
2035
+ return data;
2036
+ }
2037
+ updateRows(dataRows, dataUpdateConfig) {
2038
+ if (this.hasAutogeneratedPrimaryKey) {
2039
+ this.addSyntheticPrimaryKeyIfMissing(dataRows);
2040
+ }
2041
+ dataUpdateConfig = dataUpdateConfig || {};
2042
+ if (dataUpdateConfig.runAsync) {
2043
+ return new Promise((resolve) => {
2044
+ this.agGridAdapter
2045
+ .getAgGridApi()
2046
+ .applyTransactionAsync({ update: dataRows }, (transaction) => {
2047
+ if (typeof dataUpdateConfig.callback === 'function') {
2048
+ dataUpdateConfig.callback(transaction);
2049
+ }
2050
+ resolve(transaction === null || transaction === void 0 ? void 0 : transaction.update);
2051
+ });
2052
+ if (dataUpdateConfig.flushAsync) {
2053
+ this.agGridAdapter.getAgGridApi().flushAsyncTransactions();
2054
+ }
2055
+ });
2056
+ }
2057
+ else {
2058
+ const transaction = this.agGridAdapter.getAgGridApi().applyTransaction({
2059
+ update: dataRows,
2060
+ });
2061
+ if (dataUpdateConfig.flushAsync) {
2062
+ this.agGridAdapter.getAgGridApi().flushAsyncTransactions();
2063
+ }
2064
+ return Promise.resolve(transaction === null || transaction === void 0 ? void 0 : transaction.update);
2065
+ }
2066
+ }
2067
+ addRows(dataRows, dataUpdateConfig) {
2068
+ if (this.hasAutogeneratedPrimaryKey) {
2069
+ this.addSyntheticPrimaryKey(dataRows);
2070
+ }
2071
+ dataUpdateConfig = dataUpdateConfig || {};
2072
+ const newData = { add: dataRows };
2073
+ if (dataUpdateConfig.addIndex !== undefined) {
2074
+ newData.addIndex = dataUpdateConfig.addIndex;
2075
+ }
2076
+ if (dataUpdateConfig.runAsync) {
2077
+ return new Promise((resolve) => {
2078
+ this.agGridAdapter.getAgGridApi().applyTransactionAsync(newData, (transaction) => {
2079
+ if (typeof dataUpdateConfig.callback === 'function') {
2080
+ dataUpdateConfig.callback(transaction);
2081
+ }
2082
+ resolve(transaction === null || transaction === void 0 ? void 0 : transaction.add);
2083
+ this.updateRowGroupsExpandedState();
2084
+ });
2085
+ if (dataUpdateConfig.flushAsync) {
2086
+ this.agGridAdapter.getAgGridApi().flushAsyncTransactions();
2087
+ }
2088
+ });
2089
+ }
2090
+ else {
2091
+ const transaction = this.agGridAdapter.getAgGridApi().applyTransaction(newData);
2092
+ if (dataUpdateConfig.flushAsync) {
2093
+ this.agGridAdapter.getAgGridApi().flushAsyncTransactions();
2094
+ }
2095
+ this.updateRowGroupsExpandedState();
2096
+ return Promise.resolve(transaction === null || transaction === void 0 ? void 0 : transaction.add);
2097
+ }
2098
+ }
2099
+ addOrUpdateRows(dataRows, dataUpdateConfig) {
2100
+ const addDataRows = [];
2101
+ const updateDataRows = [];
2102
+ const primaryKey = this.adaptableOptions.primaryKey;
2103
+ dataRows.forEach((dataRow) => {
2104
+ const node = this.getRowNodeForPrimaryKey(dataRow[primaryKey]);
2105
+ if (node) {
2106
+ updateDataRows.push(dataRow);
2107
+ }
2108
+ else {
2109
+ addDataRows.push(dataRow);
2110
+ }
2111
+ });
2112
+ if (this.hasAutogeneratedPrimaryKey) {
2113
+ this.addSyntheticPrimaryKeyIfMissing(addDataRows);
2114
+ }
2115
+ dataUpdateConfig = dataUpdateConfig || {};
2116
+ if (dataUpdateConfig.runAsync) {
2117
+ return new Promise((resolve) => {
2118
+ this.agGridAdapter
2119
+ .getAgGridApi()
2120
+ .applyTransactionAsync({ update: updateDataRows, add: addDataRows, addIndex: dataUpdateConfig.addIndex }, (transaction) => {
2121
+ if (typeof dataUpdateConfig.callback === 'function') {
2122
+ dataUpdateConfig.callback(transaction);
2123
+ }
2124
+ if (transaction === null || transaction === void 0 ? void 0 : transaction.add) {
2125
+ this.updateRowGroupsExpandedState();
2126
+ }
2127
+ resolve({
2128
+ added: transaction === null || transaction === void 0 ? void 0 : transaction.add,
2129
+ updated: transaction === null || transaction === void 0 ? void 0 : transaction.update,
2130
+ });
2131
+ });
2132
+ if (dataUpdateConfig.flushAsync) {
2133
+ this.agGridAdapter.getAgGridApi().flushAsyncTransactions();
2134
+ }
2135
+ });
2136
+ }
2137
+ else {
2138
+ const transaction = this.agGridAdapter.getAgGridApi().applyTransaction({
2139
+ update: updateDataRows,
2140
+ add: addDataRows,
2141
+ addIndex: dataUpdateConfig.addIndex,
2142
+ });
2143
+ if (transaction === null || transaction === void 0 ? void 0 : transaction.add) {
2144
+ this.updateRowGroupsExpandedState();
2145
+ }
2146
+ if (dataUpdateConfig.flushAsync) {
2147
+ this.agGridAdapter.getAgGridApi().flushAsyncTransactions();
2148
+ }
2149
+ return Promise.resolve({
2150
+ added: transaction === null || transaction === void 0 ? void 0 : transaction.add,
2151
+ updated: transaction === null || transaction === void 0 ? void 0 : transaction.update,
2152
+ });
2153
+ }
2154
+ }
2155
+ deleteRows(dataRows, dataUpdateConfig) {
2156
+ dataUpdateConfig = dataUpdateConfig || {};
2157
+ if (dataUpdateConfig.runAsync) {
2158
+ return new Promise((resolve) => {
2159
+ this.agGridAdapter
2160
+ .getAgGridApi()
2161
+ .applyTransactionAsync({ remove: dataRows }, (transaction) => {
2162
+ if (typeof dataUpdateConfig.callback === 'function') {
2163
+ dataUpdateConfig.callback(transaction);
2164
+ }
2165
+ resolve(transaction === null || transaction === void 0 ? void 0 : transaction.remove);
2166
+ });
2167
+ if (dataUpdateConfig.flushAsync) {
2168
+ this.agGridAdapter.getAgGridApi().flushAsyncTransactions();
2169
+ }
2170
+ });
2171
+ }
2172
+ else {
2173
+ const transaction = this.agGridAdapter.getAgGridApi().applyTransaction({
2174
+ remove: dataRows,
2175
+ });
2176
+ if (dataUpdateConfig.flushAsync) {
2177
+ this.agGridAdapter.getAgGridApi().flushAsyncTransactions();
2178
+ }
2179
+ return Promise.resolve(transaction.remove);
2180
+ }
2181
+ }
2182
+ getRowNodeForPrimaryKey(primaryKeyValue) {
2183
+ if (this.useRowNodeLookUp) {
2184
+ return this.agGridAdapter.getAgGridApi().getRowNode(primaryKeyValue);
2185
+ }
2186
+ else {
2187
+ this.agGridAdapter.getAgGridApi().forEachNode((rowNode) => {
2188
+ if (primaryKeyValue == this.getPrimaryKeyValueFromRowNode(rowNode)) {
2189
+ return rowNode;
2190
+ }
2191
+ });
2192
+ }
2193
+ }
2194
+ hideColumn(columnId) {
2195
+ let agGridColumn = this.agGridAdapter.getAgGridApi().getColumn(columnId);
2196
+ if (agGridColumn) {
2197
+ this.agGridAdapter.getAgGridApi().setColumnsVisible([columnId], false);
2198
+ this.deriveAdaptableColumnStateFromAgGrid();
2199
+ }
2200
+ }
2201
+ showColumn(columnId) {
2202
+ let agGridColumn = this.agGridAdapter.getAgGridApi().getColumn(columnId);
2203
+ if (agGridColumn) {
2204
+ this.agGridAdapter.getAgGridApi().setColumnsVisible([columnId], true);
2205
+ this.deriveAdaptableColumnStateFromAgGrid();
2206
+ }
2207
+ }
2208
+ autoSizeColumn(columnId) {
2209
+ this.autoSizeColumns([columnId]);
2210
+ }
2211
+ autoSizeColumns(columnIds) {
2212
+ this.agGridAdapter.getAgGridApi().autoSizeColumns(columnIds);
2213
+ }
2214
+ autoSizeAllColumns() {
2215
+ this.agGridAdapter.getAgGridApi().autoSizeAllColumns();
2216
+ }
2217
+ setColumnOrder(VisibleColumnList) {
2218
+ const newColumnState = this.getSortedColumnStateForVisibleColumns(VisibleColumnList);
2219
+ this.agGridAdapter.getAgGridApi().applyColumnState({
2220
+ state: newColumnState,
2221
+ applyOrder: true,
2222
+ });
2223
+ this.deriveAdaptableColumnStateFromAgGrid();
2224
+ }
2225
+ getSortedColumnStateForVisibleColumns(visibleColumnList, columnState, layout) {
2226
+ layout = layout || this.api.layoutApi.getCurrentLayout();
2227
+ visibleColumnList = visibleColumnList || layout.Columns;
2228
+ columnState = columnState || this.agGridAdapter.getAgGridApi().getColumnState();
2229
+ return (0, buildSortedColumnStateForLayout_1.buildSortedColumnStateForLayout)({
2230
+ columnState: columnState.map((colState) => {
2231
+ return {
2232
+ colId: colState.colId,
2233
+ hide: colState.hide,
2234
+ };
2235
+ }),
2236
+ layout: Object.assign(Object.assign({}, layout), { Columns: visibleColumnList }),
2237
+ gridOptions: this.agGridAdapter.getLiveGridOptions(),
2238
+ });
2239
+ }
2240
+ getDistinctValuesForColumn(column, distinctValuesParams) {
2241
+ let gridCells = this.getGridCellsForPermittedValues(column, distinctValuesParams);
2242
+ if (ArrayExtensions_1.default.IsNullOrEmpty(gridCells)) {
2243
+ gridCells = this.getDistinctGridCellsForColumn(column, distinctValuesParams);
2244
+ }
2245
+ return this.getUniqueGridCells(column, gridCells);
2246
+ }
2247
+ getGridCellsForPermittedValues(column, distinctValuesParams) {
2248
+ var _a;
2249
+ let gridCells = [];
2250
+ const permittedValues = (_a = distinctValuesParams.permittedValues) !== null && _a !== void 0 ? _a : this.api.userInterfaceApi.getPermittedValuesForColumn(column);
2251
+ if (ArrayExtensions_1.default.IsNotNullOrEmpty(permittedValues)) {
2252
+ gridCells = permittedValues.map((pv) => {
2253
+ return {
2254
+ rawValue: pv,
2255
+ displayValue: pv,
2256
+ normalisedValue: pv,
2257
+ columnId: column.columnId,
2258
+ column: column,
2259
+ rowNode: undefined,
2260
+ isPivotCell: false,
2261
+ isRowGroupCell: false,
2262
+ };
2263
+ });
2264
+ return gridCells;
2265
+ }
2266
+ }
2267
+ getDistinctGridCellsForColumn(column, distinctValuesParams) {
2268
+ let gridCells = [];
2269
+ if (distinctValuesParams.visibleRowsOnly) {
2270
+ this.agGridAdapter.getAgGridApi().forEachNodeAfterFilter((rowNode) => {
2271
+ const gridCell = this.addDistinctColumnValue(rowNode, column.columnId);
2272
+ if (gridCell &&
2273
+ gridCell.rawValue != undefined &&
2274
+ gridCell.rowNode !== distinctValuesParams.skipRowNode) {
2275
+ gridCells.push(gridCell);
2276
+ }
2277
+ });
2278
+ }
2279
+ else {
2280
+ this.agGridAdapter.getAgGridApi().forEachNode((rowNode) => {
2281
+ const gridCell = this.addDistinctColumnValue(rowNode, column.columnId);
2282
+ if (gridCell && gridCell.rowNode !== distinctValuesParams.skipRowNode) {
2283
+ if (gridCell.rawValue == undefined &&
2284
+ this.adaptableOptions.columnFilterOptions.valuesFilterOptions.includeBlankFilterValues) {
2285
+ gridCell.rawValue = GeneralConstants_1.BLANK_DISTINCT_COLUMN_VALUE;
2286
+ gridCell.displayValue = GeneralConstants_1.BLANK_DISTINCT_COLUMN_VALUE;
2287
+ gridCell.normalisedValue = GeneralConstants_1.BLANK_DISTINCT_COLUMN_VALUE;
2288
+ }
2289
+ gridCells.push(gridCell);
2290
+ }
2291
+ });
2292
+ }
2293
+ return gridCells;
2294
+ }
2295
+ addDistinctColumnValue(rowNode, columnId) {
2296
+ // we do not return the values of the aggregates when in grouping mode
2297
+ // otherwise they would appear in the filter dropdown etc....
2298
+ if (rowNode && !this.isGroupRowNode(rowNode)) {
2299
+ const returnValue = this.getGridCellFromRowNode(rowNode, columnId);
2300
+ if (Helper_1.Helper.objectExists(returnValue)) {
2301
+ return returnValue;
2302
+ }
2303
+ }
2304
+ else {
2305
+ return undefined;
2306
+ }
2307
+ }
2308
+ getUniqueGridCells(column, gridCells) {
2309
+ let uniqueVals = (0, uniqBy_1.default)(gridCells, (dataItem) => {
2310
+ const value = dataItem.rawValue;
2311
+ if (value instanceof Date) {
2312
+ return value.toISOString();
2313
+ }
2314
+ return value;
2315
+ });
2316
+ if (column.dataType == 'String' && this.api.predicateApi.useCaseSensitivity()) {
2317
+ uniqueVals = (0, uniqBy_1.default)(uniqueVals, (d) => d.displayValue.toLowerCase());
2318
+ }
2319
+ return uniqueVals.slice(0, this.api.columnFilterApi.internalApi.getFilterValuesMaxNumberOfItems(column));
2320
+ }
2321
+ getGridCellsForColumn(columnId) {
2322
+ let returnValues = [];
2323
+ this.agGridAdapter.getAgGridApi().forEachNode((rowNode) => {
2324
+ const gridCell = this.getGridCellFromRowNode(rowNode, columnId);
2325
+ if (gridCell && gridCell.rawValue != undefined) {
2326
+ returnValues.push(gridCell);
2327
+ }
2328
+ });
2329
+ return returnValues;
2330
+ }
2331
+ getRowNodesForPrimaryKeys(primaryKeyValues) {
2332
+ let rowNodes = [];
2333
+ if (this.useRowNodeLookUp) {
2334
+ primaryKeyValues.forEach((pkValue) => {
2335
+ const rowNode = this.agGridAdapter.getAgGridApi().getRowNode(pkValue);
2336
+ if (rowNode) {
2337
+ rowNodes.push(rowNode);
2338
+ }
2339
+ });
2340
+ }
2341
+ else {
2342
+ primaryKeyValues.forEach((pkValue) => {
2343
+ let foundRow = false;
2344
+ this.agGridAdapter.getAgGridApi().forEachNode((rowNode) => {
2345
+ if (!foundRow && pkValue == this.getPrimaryKeyValueFromRowNode(rowNode)) {
2346
+ rowNodes.push(rowNode);
2347
+ foundRow = true;
2348
+ }
2349
+ });
2350
+ });
2351
+ }
2352
+ return rowNodes;
2353
+ }
2354
+ getRowNodeByIndex(index) {
2355
+ return this.agGridAdapter.getAgGridApi().getDisplayedRowAtIndex(index);
2356
+ }
2357
+ getAgGridStatusPanels() {
2358
+ var _a, _b, _c;
2359
+ return (_c = (_b = (_a = this.agGridAdapter.getLiveGridOptions()) === null || _a === void 0 ? void 0 : _a.statusBar) === null || _b === void 0 ? void 0 : _b.statusPanels) !== null && _c !== void 0 ? _c : [];
2360
+ }
2361
+ setDataValue(value, column, primaryKeyValue, rowNode) {
2362
+ // note: because we use RowNode.setDataValue() this will cause Validation to fire
2363
+ // see https://www.ag-grid.com/javascript-data-grid/change-detection/#triggering-value-change-detection
2364
+ let newValue;
2365
+ let dataType = column.dataType;
2366
+ newValue = dataType == 'Number' ? Number(value) : value;
2367
+ if (dataType == undefined) {
2368
+ return; // no point continuing as probably a wrong column
2369
+ }
2370
+ if (rowNode) {
2371
+ rowNode.setDataValue(column.columnId, newValue);
2372
+ }
2373
+ else {
2374
+ if (this.useRowNodeLookUp) {
2375
+ const rowNode = this.agGridAdapter.getAgGridApi().getRowNode(primaryKeyValue);
2376
+ if (rowNode != null) {
2377
+ rowNode.setDataValue(column.columnId, newValue);
2378
+ }
2379
+ }
2380
+ else {
2381
+ let isUpdated = false;
2382
+ // prefer not to use this method but if we do then at least we can prevent further lookups once we find
2383
+ this.agGridAdapter.getAgGridApi().forEachNode((rowNode) => {
2384
+ if (!isUpdated) {
2385
+ if (primaryKeyValue == this.getPrimaryKeyValueFromRowNode(rowNode)) {
2386
+ rowNode.setDataValue(column.columnId, newValue);
2387
+ isUpdated = true;
2388
+ }
2389
+ }
2390
+ });
2391
+ }
2392
+ }
2393
+ }
2394
+ isCellEditable(rowNode, column) {
2395
+ // it's safe to rely on the AG Grid implementation because we override the colDef.editable property, which is in this case the single source of truth
2396
+ return column === null || column === void 0 ? void 0 : column.isCellEditable(rowNode);
2397
+ }
2398
+ forAllRowNodesDo(func, config) {
2399
+ this.agGridAdapter.getAgGridApi().forEachNode((rowNode, rowIndex) => {
2400
+ const includeGroupRows = (config === null || config === void 0 ? void 0 : config.includeGroupRows) || !this.isGroupRowNode(rowNode);
2401
+ const filterFnFulfilled = !(config === null || config === void 0 ? void 0 : config.filterFn) || (config === null || config === void 0 ? void 0 : config.filterFn(rowNode));
2402
+ if (includeGroupRows && filterFnFulfilled) {
2403
+ func(rowNode, rowIndex);
2404
+ }
2405
+ });
2406
+ }
2407
+ forAllVisibleRowNodesDo(func, config) {
2408
+ if (this.getAgGridRowModelType() !== 'clientSide') {
2409
+ // only in client-side row model can we loop through filtered&sorted rows
2410
+ // see https://www.ag-grid.com/javascript-data-grid/accessing-data/#iterating-rows
2411
+ this.logger.warn('`forAllVisibleRowNodesDo()` is only supported in client-side row model. `forAllRowNodesDo` will be used instead.');
2412
+ return this.forAllRowNodesDo(func, config);
2413
+ }
2414
+ this.agGridAdapter.getAgGridApi().forEachNodeAfterFilterAndSort((rowNode, rowIndex) => {
2415
+ const includeGroupRows = (config === null || config === void 0 ? void 0 : config.includeGroupRows) || !this.isGroupRowNode(rowNode);
2416
+ const filterFnFulfilled = !(config === null || config === void 0 ? void 0 : config.filterFn) || (config === null || config === void 0 ? void 0 : config.filterFn(rowNode));
2417
+ if (includeGroupRows && filterFnFulfilled) {
2418
+ func(rowNode, rowIndex);
2419
+ }
2420
+ });
2421
+ }
2422
+ getAgGridRowModelType() {
2423
+ var _a;
2424
+ // it seems that this can be null so we need explicitly to return "clientSide" in this case
2425
+ // need to check that for ServerSideRowModel it is ALWAYS returned...
2426
+ return (_a = this.agGridAdapter.getAgGridApi().getGridOption('rowModelType')) !== null && _a !== void 0 ? _a : 'clientSide';
2427
+ }
2428
+ getAllRowNodes(config) {
2429
+ let rowNodes = [];
2430
+ this.forAllRowNodesDo((rowNode) => rowNodes.push(rowNode), config);
2431
+ return rowNodes;
2432
+ }
2433
+ getGroupRowNodes() {
2434
+ return this.getAllRowNodes({
2435
+ includeGroupRows: true,
2436
+ filterFn: (rowNode) => this.isGroupRowNode(rowNode),
2437
+ });
2438
+ }
2439
+ getRowsInViewport() {
2440
+ return this.agGridAdapter.getAgGridApi().getRenderedNodes();
2441
+ }
2442
+ isRowNodeVisible(rowNode) {
2443
+ const foundNode = this.agGridAdapter
2444
+ .getAgGridApi()
2445
+ .getRenderedNodes()
2446
+ .find((n) => n.id == rowNode.id);
2447
+ return foundNode != null;
2448
+ }
2449
+ selectNodes(rowNodes, clearSelection) {
2450
+ if (ArrayExtensions_1.default.IsNotNullOrEmpty(rowNodes)) {
2451
+ rowNodes.forEach((node) => this.selectNode(node, clearSelection));
2452
+ }
2453
+ }
2454
+ deSelectNodes(rowNodes, clearSelection) {
2455
+ if (ArrayExtensions_1.default.IsNotNullOrEmpty(rowNodes)) {
2456
+ rowNodes.forEach((node) => this.deSelectNode(node, clearSelection));
2457
+ }
2458
+ }
2459
+ selectNode(rowNode, clearSelection) {
2460
+ if (!rowNode) {
2461
+ this.logger.error('No node to select');
2462
+ return;
2463
+ }
2464
+ rowNode.setSelected(true, clearSelection);
2465
+ }
2466
+ deSelectNode(rowNode, clearSelection) {
2467
+ if (!rowNode) {
2468
+ this.logger.error('No node to deselect');
2469
+ return;
2470
+ }
2471
+ rowNode.setSelected(false, clearSelection);
2472
+ }
2473
+ selectCells(columnIds, startNode, endNode, clearSelection) {
2474
+ if (clearSelection) {
2475
+ this.agGridAdapter.getAgGridApi().clearRangeSelection();
2476
+ }
2477
+ const cellRangeParams = {
2478
+ rowStartIndex: startNode.rowIndex,
2479
+ rowEndIndex: endNode.rowIndex,
2480
+ columns: columnIds,
2481
+ };
2482
+ this.agGridAdapter.getAgGridApi().addCellRange(cellRangeParams);
2483
+ }
2484
+ getAgGridColumnType(columnId) {
2485
+ var _a;
2486
+ const { type } = (_a = this.agGridAdapter.getAgGridApi().getColumnDef(columnId)) !== null && _a !== void 0 ? _a : {};
2487
+ return type || '';
2488
+ }
2489
+ setColumnSort(columnSorts) {
2490
+ if (!this.isReady) {
2491
+ return;
2492
+ }
2493
+ const columnSortsMap = columnSorts === null || columnSorts === void 0 ? void 0 : columnSorts.reduce((acc, columnSort, index) => {
2494
+ acc[columnSort.ColumnId] = Object.assign(Object.assign({}, columnSort), { SortIndex: index });
2495
+ return acc;
2496
+ }, {});
2497
+ const newColumnState = this.agGridAdapter
2498
+ .getAgGridApi()
2499
+ .getColumnState()
2500
+ .map((colState) => {
2501
+ const { colId } = colState;
2502
+ const state = Object.assign({}, colState);
2503
+ const colSort = columnSortsMap ? columnSortsMap[colId] : undefined;
2504
+ if (colSort) {
2505
+ state.sort = colSort.SortOrder === 'Asc' ? 'asc' : 'desc';
2506
+ state.sortIndex = colSort.SortIndex;
2507
+ }
2508
+ else {
2509
+ state.sort = null;
2510
+ state.sortIndex = null;
2511
+ }
2512
+ return state;
2513
+ });
2514
+ this.agGridAdapter.getAgGridApi().applyColumnState({
2515
+ state: newColumnState,
2516
+ applyOrder: true,
2517
+ });
2518
+ this.agGridAdapter.getAgGridApi().onSortChanged();
2519
+ }
2520
+ clearColumnSort() {
2521
+ this.setColumnSort(null);
2522
+ }
2523
+ hideColumnFilterForm() {
2524
+ if (this.hideFilterFormPopup) {
2525
+ this.hideFilterFormPopup();
2526
+ }
2527
+ }
2528
+ clearColumnFiltering() {
2529
+ this.agGridAdapter
2530
+ .getAgGridApi()
2531
+ .getColumns()
2532
+ .forEach((c) => {
2533
+ this.agGridAdapter.getAgGridApi().destroyFilter(c);
2534
+ });
2535
+ }
2536
+ clearColumnFilteringForColumns(columnIds) {
2537
+ columnIds.forEach((c) => {
2538
+ const column = this.agGridAdapter
2539
+ .getAgGridApi()
2540
+ .getColumns()
2541
+ .find((col) => col.getColId() === c);
2542
+ if (column) {
2543
+ this.agGridAdapter.getAgGridApi().destroyFilter(column);
2544
+ }
2545
+ });
2546
+ }
2547
+ canGenerateCharts() {
2548
+ return (this.agGridAdapter.isModulePresent(core_1.ModuleNames.GridChartsModule) &&
2549
+ this.agGridAdapter.getAgGridApi().getGridOption('enableCharts'));
2550
+ }
2551
+ canDisplaySparklines() {
2552
+ return this.agGridAdapter.isModulePresent(core_1.ModuleNames.SparklinesModule);
2553
+ }
2554
+ showCharts(chartsDefinitions, chartContainer) {
2555
+ return chartsDefinitions.map((chartDefinition) => this.showChart(chartDefinition, chartContainer));
2556
+ }
2557
+ showChart(chartDefinition, container) {
2558
+ if (!this.isReady) {
2559
+ this.logger.consoleError('Adaptable must be instantiated before calling showChart');
2560
+ return null;
2561
+ }
2562
+ /**
2563
+ * Ag-grid always creates new charts behind the sences.
2564
+ * So we need to update the model inside adaptable state.
2565
+ * This is important to be done as soon as possible so it is not considered new.
2566
+ */
2567
+ const chartRef = this.agGridAdapter
2568
+ .getAgGridApi()
2569
+ .restoreChart(chartDefinition.Model, container);
2570
+ const chartModel = this.getChartModels().find((chartModel) => chartModel.chartId === chartRef.chartId);
2571
+ // Update the definition in state so it is not considered new
2572
+ this.api.chartingApi.editChartDefinition(Object.assign(Object.assign({}, chartDefinition), { Model: chartModel }));
2573
+ return chartRef;
2574
+ }
2575
+ updateChart(chart) {
2576
+ const upgradableProperties = {
2577
+ // Only Range charts are supported to be created at run time
2578
+ // the other two are pivot & cross-filter
2579
+ type: 'rangeChartUpdate',
2580
+ chartId: chart.Model.chartId,
2581
+ unlinkChart: Boolean(chart.Model.unlinkChart),
2582
+ suppressChartRanges: Boolean(chart.Model.suppressChartRanges),
2583
+ aggFunc: chart.Model.aggFunc,
2584
+ };
2585
+ this.agGridAdapter.getAgGridApi().updateChart(upgradableProperties);
2586
+ }
2587
+ getChartModels() {
2588
+ if (!this.isReady) {
2589
+ this.logger.consoleError('Adaptable must be instantiated before calling getChartModels');
2590
+ return [];
2591
+ }
2592
+ return this.agGridAdapter.getAgGridApi().getChartModels();
2593
+ }
2594
+ getRowCount() {
2595
+ return this.agGridAdapter.getAgGridApi().getDisplayedRowCount();
2596
+ }
2597
+ getColumnCount() {
2598
+ var _a, _b;
2599
+ return (_b = (_a = this.agGridAdapter.getAgGridApi().getColumns()) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
2600
+ }
2601
+ getVisibleColumnCount() {
2602
+ var _a, _b;
2603
+ return ((_b = (_a = this.agGridAdapter
2604
+ .getAgGridApi()
2605
+ .getColumns()) === null || _a === void 0 ? void 0 : _a.filter((c) => c.isVisible()).length) !== null && _b !== void 0 ? _b : 0);
2606
+ }
2607
+ isGridGroupable() {
2608
+ return !this.api.internalApi.isGridInTreeMode();
2609
+ }
2610
+ isGridGroupingActive() {
2611
+ let isGroupedActive = false;
2612
+ this.agGridAdapter.getAgGridApi().forEachNode((node) => {
2613
+ if (!isGroupedActive) {
2614
+ if (node.group) {
2615
+ isGroupedActive = true;
2616
+ }
2617
+ }
2618
+ });
2619
+ return isGroupedActive;
2620
+ }
2621
+ setAgGridQuickSearch(searchText) {
2622
+ this.agGridAdapter.setGridOption('quickFilterText', searchText);
2623
+ }
2624
+ getAgGridCurrentThemeName() {
2625
+ const container = this.getAgGridContainerElement();
2626
+ if (container && container.classList) {
2627
+ // we detect the ag theme class
2628
+ const classList = container.classList;
2629
+ for (let i = 0, len = classList.length; i < len; i++) {
2630
+ const cls = classList[i];
2631
+ if (cls.indexOf('ag-theme-') === 0) {
2632
+ return cls;
2633
+ }
2634
+ }
2635
+ }
2636
+ return this.getAgGridLightThemeName();
2637
+ }
2638
+ getAgGridLightThemeName() {
2639
+ const container = this.getAgGridContainerElement();
2640
+ if (container && container.classList) {
2641
+ // we detect the ag theme class
2642
+ const classList = container.classList;
2643
+ for (let i = 0, len = classList.length; i < len; i++) {
2644
+ const cls = classList[i];
2645
+ if (cls.indexOf('ag-theme-') === 0) {
2646
+ // even if dark theme is included, we compute the light theme name out of it
2647
+ return cls.replace('-dark', '');
2648
+ }
2649
+ }
2650
+ }
2651
+ else {
2652
+ this.logger.warn('No AgGrid container found, defaulting to ag-theme-balham for the light theme');
2653
+ }
2654
+ this.logger.warn('No ag-theme- class found on the grid container, defaulting to ag-theme-balham');
2655
+ // fallback to the default light theme
2656
+ return 'ag-theme-balham';
2657
+ }
2658
+ applyAdaptableTheme(theme) {
2659
+ theme = this.ThemeService.mapOsTheme(theme);
2660
+ const themeName = typeof theme === 'string' ? theme : theme.Name;
2661
+ const isSystemTheme = this.api.themeApi.internalApi.isSystemTheme(themeName);
2662
+ const themeClassNamesToRemove = [];
2663
+ const themesToRemove = [];
2664
+ const allThemes = this.api.themeApi.getThemes().map((t) => {
2665
+ // we mutate the theme later,
2666
+ // and since we don't want the mutation to end up in state
2667
+ // we better clone it here
2668
+ return Object.assign({}, t);
2669
+ });
2670
+ const allThemesMap = allThemes.reduce((acc, theme) => {
2671
+ acc[theme.Name] = theme;
2672
+ return acc;
2673
+ }, {});
2674
+ const themeObject = allThemesMap[themeName];
2675
+ // REMOVE PREVIOUS THEME
2676
+ // const themePrefix = 'ab--theme-'
2677
+ const el = document.documentElement;
2678
+ el.classList.forEach((cssClassName) => {
2679
+ const index = cssClassName.indexOf(GeneralConstants.THEME_STYLE);
2680
+ if (index === 0) {
2681
+ themeClassNamesToRemove.push(cssClassName);
2682
+ const themeName = cssClassName.substring(GeneralConstants.THEME_STYLE.length);
2683
+ if (allThemesMap[themeName]) {
2684
+ themesToRemove.push(allThemesMap[themeName]);
2685
+ }
2686
+ }
2687
+ });
2688
+ themeClassNamesToRemove.forEach((cssClassName) => el.classList.remove(cssClassName));
2689
+ // remove infinite table classnames
2690
+ themesToRemove.forEach((theme) => {
2691
+ el.classList.remove(`infinite-${theme.Name}`);
2692
+ });
2693
+ // VARIANT
2694
+ let variantTheme = '';
2695
+ if (!isSystemTheme && themeObject.Variant) {
2696
+ variantTheme = themeObject.Variant;
2697
+ }
2698
+ // APPLY NEW THEME
2699
+ const newTheme = allThemesMap[themeName];
2700
+ const getClassName = (theme) => GeneralConstants.THEME_STYLE + theme;
2701
+ el.classList.add(getClassName(themeName));
2702
+ if (variantTheme) {
2703
+ el.classList.add(getClassName(variantTheme));
2704
+ }
2705
+ if (isSystemTheme) {
2706
+ // add infinite table classname for theme
2707
+ el.classList.add(`infinite-${themeName}`);
2708
+ }
2709
+ else if (variantTheme) {
2710
+ el.classList.add(`infinite-${variantTheme}`);
2711
+ }
2712
+ // AG THEME CLASS NAME
2713
+ const container = this.getAgGridContainerElement();
2714
+ const getAgGridLightThemeName = () => this.getAgGridLightThemeName();
2715
+ const getAgGridDarkThemeName = () => getAgGridLightThemeName() + '-dark';
2716
+ if (newTheme && (isSystemTheme || variantTheme)) {
2717
+ if ((variantTheme || themeName) === GeneralConstants_1.LIGHT_THEME) {
2718
+ newTheme.AgGridClassName = newTheme.AgGridClassName || getAgGridLightThemeName();
2719
+ }
2720
+ if ((variantTheme || themeName) === GeneralConstants_1.DARK_THEME) {
2721
+ newTheme.AgGridClassName = newTheme.AgGridClassName || getAgGridDarkThemeName();
2722
+ }
2723
+ }
2724
+ if (!newTheme.AgGridClassName) {
2725
+ // default AG Grid to its light theme
2726
+ newTheme.AgGridClassName = getAgGridLightThemeName();
2727
+ }
2728
+ if (container != null) {
2729
+ if (themesToRemove.length) {
2730
+ themesToRemove.forEach((theme) => {
2731
+ if (theme.AgGridClassName) {
2732
+ container.classList.remove(theme.AgGridClassName);
2733
+ }
2734
+ });
2735
+ }
2736
+ // also remove all AG Grid theme class names
2737
+ const agGridClassNamesToRemove = [];
2738
+ container.classList.forEach((x) => {
2739
+ if (x && x.indexOf('ag-theme-') === 0) {
2740
+ agGridClassNamesToRemove.push(x);
2741
+ }
2742
+ });
2743
+ agGridClassNamesToRemove.forEach((x) => container.classList.remove(x));
2744
+ if (newTheme && newTheme.AgGridClassName) {
2745
+ container.classList.add(newTheme.AgGridClassName);
2746
+ }
2747
+ container.classList.add('ab-Grid');
2748
+ if (this.adaptableOptions.columnFilterOptions.indicateFilteredColumns) {
2749
+ container.classList.add('ab-Grid--indicate-filtered-columns');
2750
+ }
2751
+ }
2752
+ // MAC LIKE SCROLLBARS
2753
+ if (this.adaptableOptions.userInterfaceOptions &&
2754
+ this.adaptableOptions.userInterfaceOptions.useCustomMacLikeScrollbars &&
2755
+ (0, getScrollbarSize_1.default)() > 0) {
2756
+ el.classList.add('ab--custom-mac-like-scrollbars');
2757
+ }
2758
+ else {
2759
+ el.classList.remove('ab--custom-mac-like-scrollbars');
2760
+ }
2761
+ }
2762
+ setRowGroupColumns(columnIds) {
2763
+ this.agGridAdapter.getAgGridApi().setRowGroupColumns(columnIds);
2764
+ }
2765
+ getAllGridColumns() {
2766
+ return this.agGridAdapter.getAgGridApi().getAllGridColumns();
2767
+ }
2768
+ clearRowGroupColumns() {
2769
+ this.agGridAdapter
2770
+ .getAgGridApi()
2771
+ .removeRowGroupColumns(this.agGridAdapter.getAgGridApi().getRowGroupColumns());
2772
+ }
2773
+ expandAllRowGroups() {
2774
+ this.agGridAdapter.getAgGridApi().forEachNode((node) => {
2775
+ if (node.group) {
2776
+ node.expanded = true;
2777
+ }
2778
+ });
2779
+ this.agGridAdapter.getAgGridApi().onGroupExpandedOrCollapsed();
2780
+ }
2781
+ closeAllRowGroups() {
2782
+ this.agGridAdapter.getAgGridApi().forEachNode((node) => {
2783
+ if (node.group) {
2784
+ node.expanded = false;
2785
+ }
2786
+ });
2787
+ this.agGridAdapter.getAgGridApi().onGroupExpandedOrCollapsed();
2788
+ }
2789
+ expandRowGroupsForValues(columnValues) {
2790
+ if (ArrayExtensions_1.default.IsNotNullOrEmpty(columnValues)) {
2791
+ const expandedKeys = columnValues.reduce((acc, key) => {
2792
+ acc[key] = true;
2793
+ return acc;
2794
+ }, {});
2795
+ this.agGridAdapter.getAgGridApi().forEachNode((node) => {
2796
+ if (node.group && !node.expanded) {
2797
+ const nodePath = [];
2798
+ let current = node;
2799
+ while (current) {
2800
+ nodePath.push(current.key);
2801
+ current = current.parent;
2802
+ }
2803
+ const nodeKey = nodePath
2804
+ .filter((x) => !!x)
2805
+ .reverse()
2806
+ .join(GeneralConstants_1.GROUP_PATH_SEPARATOR);
2807
+ if (expandedKeys[nodeKey]) {
2808
+ node.setExpanded(true);
2809
+ }
2810
+ }
2811
+ });
2812
+ this.agGridAdapter.getAgGridApi().onGroupExpandedOrCollapsed();
2813
+ }
2814
+ }
2815
+ getExpandRowGroupsKeys() {
2816
+ let returnValues = [];
2817
+ if (this.api.layoutApi.internalApi.areExpandedRowGroupsSavedInLayouts()) {
2818
+ this.agGridAdapter.getAgGridApi().forEachNode((node) => {
2819
+ if (node.group && node.expanded) {
2820
+ let current = node;
2821
+ const path = [];
2822
+ while (current) {
2823
+ path.push(current.key);
2824
+ current = current.parent;
2825
+ }
2826
+ returnValues.push(path
2827
+ .filter((x) => !!x)
2828
+ .reverse()
2829
+ .join(GeneralConstants_1.GROUP_PATH_SEPARATOR));
2830
+ }
2831
+ });
2832
+ }
2833
+ return returnValues;
2834
+ }
2835
+ getAgGridColumnForColumnId(columnId) {
2836
+ return this.agGridAdapter.getAgGridApi().getColumn(columnId);
2837
+ }
2838
+ getMinMaxCachedValueForColumn(column, minMax) {
2839
+ var _a;
2840
+ const { columnId, dataType } = column;
2841
+ if (dataType !== 'Number') {
2842
+ return undefined;
2843
+ }
2844
+ let value = (_a = this.columnMinMaxValuesCache[columnId]) === null || _a === void 0 ? void 0 : _a[minMax];
2845
+ if (value !== undefined) {
2846
+ return value;
2847
+ }
2848
+ const distinctRawValues = this.api.gridApi.internalApi
2849
+ .getUnsortedDistinctRawValuesForColumn(columnId)
2850
+ .map((item) => item.rawValue);
2851
+ value = minMax === 'min' ? Math.min(...distinctRawValues) : Math.max(...distinctRawValues);
2852
+ this.columnMinMaxValuesCache[columnId] = Object.assign(Object.assign({}, this.columnMinMaxValuesCache[columnId]), { [minMax]: value });
2853
+ return value;
2854
+ }
2855
+ getAgGridRegisteredModules() {
2856
+ return this.agGridAdapter.getRegisteredModules();
2857
+ }
2858
+ destroy(config) {
2859
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
2860
+ if ((_a = this.agGridAdapter) === null || _a === void 0 ? void 0 : _a.getAgGridApi()) {
2861
+ this.agGridAdapter
2862
+ .getAgGridApi()
2863
+ .removeEventListener(core_1.Events.EVENT_FIRST_DATA_RENDERED, this.listenerFirstDataRendered);
2864
+ this.agGridAdapter
2865
+ .getAgGridApi()
2866
+ .removeEventListener(core_1.Events.EVENT_COLUMN_PIVOT_MODE_CHANGED, this.listenerPivotModeChanged);
2867
+ this.agGridAdapter
2868
+ .getAgGridApi()
2869
+ .removeEventListener(core_1.Events.EVENT_COLUMN_PIVOT_CHANGED, this.listenerPivotChanged);
2870
+ this.agGridAdapter
2871
+ .getAgGridApi()
2872
+ .removeEventListener(core_1.Events.EVENT_CELL_EDITING_STARTED, this.listenerCellEditingStarted);
2873
+ this.agGridAdapter
2874
+ .getAgGridApi()
2875
+ .removeEventListener(core_1.Events.EVENT_COLUMN_ROW_GROUP_CHANGED, this.listenerColumnRowGroupChanged);
2876
+ this.agGridAdapter
2877
+ .getAgGridApi()
2878
+ .removeEventListener(core_1.Events.EVENT_RANGE_SELECTION_CHANGED, this.listenerRangeSelectionChanged);
2879
+ this.agGridAdapter
2880
+ .getAgGridApi()
2881
+ .removeEventListener(core_1.Events.EVENT_COLUMN_RESIZED, this.listenerColumnResized);
2882
+ this.agGridAdapter
2883
+ .getAgGridApi()
2884
+ .removeEventListener(core_1.Events.EVENT_SORT_CHANGED, this.listenerSortChanged);
2885
+ this.agGridAdapter
2886
+ .getAgGridApi()
2887
+ .removeEventListener(core_1.Events.EVENT_MODEL_UPDATED, this.listenerModelUpdated);
2888
+ this.agGridAdapter.getAgGridApi().removeGlobalListener(this.listenerGlobalSetRowSelection);
2889
+ this.agGridAdapter
2890
+ .getAgGridApi()
2891
+ .removeGlobalListener(this.listenerGlobalColumnEventsThatTriggerStateChange);
2892
+ this.agGridAdapter
2893
+ .getAgGridApi()
2894
+ .removeGlobalListener(this.listenerGlobalColumnEventsThatTriggerAutoLayoutSave);
2895
+ this.agGridAdapter
2896
+ .getAgGridApi()
2897
+ .removeGlobalListener(this.listenerGlobalRowGroupEventsThatTriggerAutoLayoutSave);
2898
+ this.listenerFirstDataRendered = null;
2899
+ this.listenerPivotModeChanged = null;
2900
+ this.listenerPivotChanged = null;
2901
+ this.listenerCellEditingStarted = null;
2902
+ this.listenerColumnRowGroupChanged = null;
2903
+ this.listenerRangeSelectionChanged = null;
2904
+ this.listenerColumnResized = null;
2905
+ this.listenerGlobalSetRowSelection = null;
2906
+ this.listenerSortChanged = null;
2907
+ this.listenerModelUpdated = null;
2908
+ this.listenerGlobalColumnEventsThatTriggerStateChange = null;
2909
+ this.listenerGlobalColumnEventsThatTriggerAutoLayoutSave = null;
2910
+ this.listenerGlobalRowGroupEventsThatTriggerAutoLayoutSave = null;
2911
+ this.throttleFilterOnEditDataChange = null;
2912
+ this.throttleFilterOnTickingDataChange = null;
2913
+ const liveGridOptions = this.agGridAdapter.getLiveGridOptions();
2914
+ if (liveGridOptions) {
2915
+ this.agGridOptionsService.revertGridOptionsPropertiesToUserValue(liveGridOptions, [
2916
+ 'aggFuncs',
2917
+ 'allowContextMenuWithControlKey',
2918
+ 'columnTypes',
2919
+ 'components',
2920
+ 'context',
2921
+ 'dataTypeDefinitions',
2922
+ 'doesExternalFilterPass',
2923
+ 'excelStyles',
2924
+ 'getContextMenuItems',
2925
+ 'getMainMenuItems',
2926
+ 'getRowClass',
2927
+ 'getRowId',
2928
+ 'getRowStyle',
2929
+ 'gridId',
2930
+ 'initialGroupOrderComparator',
2931
+ 'isExternalFilterPresent',
2932
+ 'sideBar',
2933
+ 'statusBar',
2934
+ 'suppressAggFuncInHeader',
2935
+ ]);
2936
+ if (liveGridOptions.components) {
2937
+ liveGridOptions.components.AdaptableToolPanel = null;
2938
+ }
2939
+ }
2940
+ }
2941
+ if (config && config.destroyApi === false) {
2942
+ }
2943
+ else {
2944
+ (_b = this.agGridAdapter.getAgGridApi()) === null || _b === void 0 ? void 0 : _b.destroy();
2945
+ }
2946
+ this.previousAgGridLayoutState = '';
2947
+ const gridContainerElement = this.getAgGridContainerElement();
2948
+ if (gridContainerElement) {
2949
+ gridContainerElement.removeEventListener('keydown', this.agGridListenerKeydown);
2950
+ gridContainerElement.removeEventListener('mouseenter', this.agGridListenerMouseEnter);
2951
+ gridContainerElement.removeEventListener('mouseleave', this.agGridListenerMouseLeave);
2952
+ this.agGridListenerKeydown = null;
2953
+ this.agGridListenerMouseEnter = null;
2954
+ this.agGridListenerMouseLeave = null;
2955
+ }
2956
+ this.api.internalDestroySelf();
2957
+ (_c = this.agGridOptionsService) === null || _c === void 0 ? void 0 : _c.destroy();
2958
+ this.agGridOptionsService = null;
2959
+ (_d = this.agGridAdapter) === null || _d === void 0 ? void 0 : _d.destroy();
2960
+ this.agGridAdapter = null;
2961
+ (_e = this.agGridMenuAdapter) === null || _e === void 0 ? void 0 : _e.destroy();
2962
+ this.agGridMenuAdapter = null;
2963
+ (_f = this.agGridColumnAdapter) === null || _f === void 0 ? void 0 : _f.destroy();
2964
+ this.agGridColumnAdapter = null;
2965
+ this.rowListeners = null;
2966
+ this.emitter.destroy();
2967
+ this.emitter = null;
2968
+ this.adaptableOptions = null;
2969
+ this.columnMinMaxValuesCache = null;
2970
+ this.lifecycleState = 'preDestroyed';
2971
+ AdaptableAgGrid.dismissInstance(this);
2972
+ (_g = this.unmountLoadingScreen) === null || _g === void 0 ? void 0 : _g.call(this);
2973
+ this.unmountLoadingScreen = null;
2974
+ const abContainerElement = this.getAdaptableContainerElement();
2975
+ if (config && !config.unmount) {
2976
+ return;
2977
+ }
2978
+ if (abContainerElement != null) {
2979
+ (_h = this.unmountReactRoot) === null || _h === void 0 ? void 0 : _h.call(this);
2980
+ }
2981
+ this.unmountReactRoot = null;
2982
+ this.DANGER_USE_GETTER_adaptableContainerElement = null;
2983
+ this.DANGER_USE_GETTER_agGridContainerElement = null;
2984
+ (_j = this.adaptableStore) === null || _j === void 0 ? void 0 : _j.destroy();
2985
+ this.adaptableStore = null;
2986
+ this.adaptableOptions = null;
2987
+ this.adaptableStatusPanelKeys = null;
2988
+ (_l = (_k = this.CalculatedColumnExpressionService) === null || _k === void 0 ? void 0 : _k.destroy) === null || _l === void 0 ? void 0 : _l.call(_k);
2989
+ this.CalculatedColumnExpressionService = null;
2990
+ (_o = (_m = this.DataService) === null || _m === void 0 ? void 0 : _m.destroy) === null || _o === void 0 ? void 0 : _o.call(_m);
2991
+ this.DataService = null;
2992
+ (_q = (_p = this.EntitlementService) === null || _p === void 0 ? void 0 : _p.destroy) === null || _q === void 0 ? void 0 : _q.call(_p);
2993
+ this.EntitlementService = null;
2994
+ (_s = (_r = this.Fdc3Service) === null || _r === void 0 ? void 0 : _r.destroy) === null || _s === void 0 ? void 0 : _s.call(_r);
2995
+ this.Fdc3Service = null;
2996
+ (_u = (_t = this.ReportService) === null || _t === void 0 ? void 0 : _t.destroy) === null || _u === void 0 ? void 0 : _u.call(_t);
2997
+ this.ReportService = null;
2998
+ (_w = (_v = this.ModuleService) === null || _v === void 0 ? void 0 : _v.destroy) === null || _w === void 0 ? void 0 : _w.call(_v);
2999
+ this.ModuleService = null;
3000
+ (_y = (_x = this.ValidationService) === null || _x === void 0 ? void 0 : _x.destroy) === null || _y === void 0 ? void 0 : _y.call(_x);
3001
+ this.ValidationService = null;
3002
+ (_0 = (_z = this.QueryLanguageService) === null || _z === void 0 ? void 0 : _z.destroy) === null || _0 === void 0 ? void 0 : _0.call(_z);
3003
+ this.QueryLanguageService = null;
3004
+ (_2 = (_1 = this.AlertService) === null || _1 === void 0 ? void 0 : _1.destroy) === null || _2 === void 0 ? void 0 : _2.call(_1);
3005
+ this.AlertService = null;
3006
+ (_4 = (_3 = this.TeamSharingService) === null || _3 === void 0 ? void 0 : _3.destroy) === null || _4 === void 0 ? void 0 : _4.call(_3);
3007
+ this.TeamSharingService = null;
3008
+ (_6 = (_5 = this.RowEditService) === null || _5 === void 0 ? void 0 : _5.destroy) === null || _6 === void 0 ? void 0 : _6.call(_5);
3009
+ this.RowEditService = null;
3010
+ (_8 = (_7 = this.MetamodelService) === null || _7 === void 0 ? void 0 : _7.destroy) === null || _8 === void 0 ? void 0 : _8.call(_7);
3011
+ this.MetamodelService = null;
3012
+ (_10 = (_9 = this.LicenseService) === null || _9 === void 0 ? void 0 : _9.destroy) === null || _10 === void 0 ? void 0 : _10.call(_9);
3013
+ this.LicenseService = null;
3014
+ }
3015
+ canExportToExcel() {
3016
+ return this.agGridAdapter.isModulePresent(core_1.ModuleNames.ExcelExportModule);
3017
+ }
3018
+ exportToExcel(reportData, fileName) {
3019
+ const columnDefs = reportData.columns.map((column) => ({
3020
+ field: column.columnId,
3021
+ headerName: column.friendlyName,
3022
+ }));
3023
+ const NESTED_COL_SEPARATOR = '.';
3024
+ const nestedColumns = reportData.columns.filter((column) => column.columnId.includes(NESTED_COL_SEPARATOR));
3025
+ if (nestedColumns.length) {
3026
+ // the rowData of nested fields (containing dots) was flattened during the report data extraction and we need to un-flatten it back
3027
+ // ex.
3028
+ // current state: { field: 'outerKey.innerKey', value: 2}
3029
+ // original (desired) state: { field: 'outerKey.innerKey', value: {outerKey: {innerKey: 2}}}
3030
+ reportData.rows.forEach((rowDataEntry) => nestedColumns.forEach((nestedColumn) => {
3031
+ const cellExportValue = rowDataEntry[nestedColumn.columnId];
3032
+ let intermediaryValue = rowDataEntry;
3033
+ // augment the rowDataEntry with the new object
3034
+ nestedColumn.columnId
3035
+ .split(NESTED_COL_SEPARATOR)
3036
+ .forEach((nestedKey, index, nestedCols) => {
3037
+ // we reached the leaf node, so we set the cell value and break
3038
+ if (index === nestedCols.length - 1) {
3039
+ intermediaryValue[nestedKey] = cellExportValue;
3040
+ return;
3041
+ }
3042
+ if (intermediaryValue[nestedKey] == undefined) {
3043
+ intermediaryValue[nestedKey] = {};
3044
+ } // else means that the object already has a property with this key
3045
+ intermediaryValue = intermediaryValue[nestedKey];
3046
+ });
3047
+ // delete the obsolete flattened property
3048
+ delete rowDataEntry[nestedColumn.columnId];
3049
+ }));
3050
+ }
3051
+ const gridOptions = {
3052
+ columnDefs,
3053
+ rowData: reportData.rows,
3054
+ };
3055
+ let gridParams = { modules: this.getAgGridRegisteredModules() };
3056
+ const ephemeralGridApi = (0, core_1.createGrid)(document.createElement('div'), gridOptions, gridParams);
3057
+ ephemeralGridApi.exportDataAsExcel({
3058
+ sheetName: 'Sheet 1',
3059
+ fileName: fileName,
3060
+ });
3061
+ ephemeralGridApi.destroy();
3062
+ }
3063
+ exportVisualDataToExcel() {
3064
+ try {
3065
+ const exportExcelStyles = this.ReportService.buildExcelStylesForVisualReports();
3066
+ this.agGridOptionsService.CAREFUL_patchGridOptionsProperty('excelStyles', exportExcelStyles);
3067
+ this.agGridAdapter.getAgGridApi().exportDataAsExcel({
3068
+ sheetName: 'Sheet 1',
3069
+ fileName: this.ReportService.getReportFileName(this.adaptableOptions.adaptableId, 'Excel'),
3070
+ // delegate the cell value processing to Adaptable
3071
+ processCellCallback: ({ node, column, value }) => {
3072
+ var _a;
3073
+ const columnId = column.getColId();
3074
+ if ((node === null || node === void 0 ? void 0 : node.group) &&
3075
+ (this.api.columnApi.isAutoRowGroupColumn(columnId) ||
3076
+ // we would still need to process the cell if this is a group row with an aggregated value
3077
+ ((_a = node === null || node === void 0 ? void 0 : node.aggData) === null || _a === void 0 ? void 0 : _a[columnId]) == undefined)) {
3078
+ // skip processing of row groups, this was already handled in processRowGroupCallback()
3079
+ return value;
3080
+ }
3081
+ return this.processCellForExcelExport(node, columnId);
3082
+ },
3083
+ processRowGroupCallback: (params) => {
3084
+ var _a;
3085
+ // recreating the standard AG Grid styling for row groups: 'Parent -> Child'
3086
+ // additionally the values are formatted
3087
+ let rowGroupNode = params.node;
3088
+ const isFooterRow = rowGroupNode.footer;
3089
+ const rowGroupSummary = [(_a = this.processRowGroupForExcelExport(rowGroupNode)) !== null && _a !== void 0 ? _a : ''];
3090
+ while (rowGroupNode.parent) {
3091
+ rowGroupNode = rowGroupNode.parent;
3092
+ const formattedParentNode = this.processRowGroupForExcelExport(rowGroupNode);
3093
+ if (formattedParentNode) {
3094
+ rowGroupSummary.push(formattedParentNode);
3095
+ }
3096
+ }
3097
+ let summary = rowGroupSummary.reverse().join(' -> ');
3098
+ if (isFooterRow) {
3099
+ summary = `Total: ${summary}`;
3100
+ }
3101
+ return summary;
3102
+ },
3103
+ });
3104
+ this.agGridOptionsService.revertGridOptionsPropertyToUserValue('excelStyles');
3105
+ }
3106
+ catch (error) {
3107
+ this.logger.consoleError('Error exporting visual data to Excel', error);
3108
+ }
3109
+ }
3110
+ processRowGroupForExcelExport(rowNode) {
3111
+ var _a, _b, _c, _d, _e;
3112
+ const columnId = (_c = (_a = rowNode.field) !== null && _a !== void 0 ? _a : (_b = rowNode.rowGroupColumn) === null || _b === void 0 ? void 0 : _b.getColId()) !== null && _c !== void 0 ? _c : (_e = (_d = rowNode.rowGroupColumn) === null || _d === void 0 ? void 0 : _d.getColDef()) === null || _e === void 0 ? void 0 : _e.field;
3113
+ if (!columnId || !rowNode.key) {
3114
+ return;
3115
+ }
3116
+ let rawValue = rowNode.key;
3117
+ if (this.api.columnApi.getColumnDataTypeForColumnId(columnId) === 'Date' &&
3118
+ typeof rawValue === 'string' &&
3119
+ // rawValue is composed only of digits
3120
+ /^\d+$/.test(rawValue)) {
3121
+ // AG-Grid converts the value to string, we have to reconvert it back
3122
+ const dateRawValue = parseInt(rawValue);
3123
+ if (dateRawValue != undefined) {
3124
+ // @ts-ignore
3125
+ rawValue = dateRawValue;
3126
+ }
3127
+ }
3128
+ return this.ReportService.getCellExportValueFromRawValue(rowNode, rawValue, columnId);
3129
+ }
3130
+ processCellForExcelExport(rowNode, columnId) {
3131
+ if (this.api.exportApi.internalApi.isVisualDataExportInProgress()) {
3132
+ const cellKey = this.agGridColumnAdapter.getExcelClassNameForCell(columnId, this.getPrimaryKeyValueFromRowNode(rowNode));
3133
+ const isoFormattedDate = this.ReportService.getExcelStyleWithFormattedDate(cellKey);
3134
+ if (isoFormattedDate) {
3135
+ // this is a Date cell which will be formatted by Excel
3136
+ return isoFormattedDate;
3137
+ }
3138
+ }
3139
+ return this.ReportService.getCellExportValueFromRowNode(rowNode, columnId);
3140
+ }
3141
+ isQuickFilterAvailable() {
3142
+ if (this.api.layoutApi.isCurrentLayoutPivot() &&
3143
+ this.adaptableOptions.columnFilterOptions.useAdaptableColumnFiltering) {
3144
+ // hide completely the quick filter if pivot is enabled
3145
+ return false;
3146
+ }
3147
+ return this.hasFloatingFilterOnAtLeastOneColumn(this.agGridAdapter.getAgGridApi().getColumnDefs());
3148
+ }
3149
+ hasFloatingFilterOnAtLeastOneColumn(columnDefs) {
3150
+ let col;
3151
+ for (col of columnDefs) {
3152
+ if (col.floatingFilter) {
3153
+ return true;
3154
+ }
3155
+ if (col.children) {
3156
+ if (this.hasFloatingFilterOnAtLeastOneColumn(col.children)) {
3157
+ return true;
3158
+ }
3159
+ }
3160
+ }
3161
+ return false;
3162
+ }
3163
+ getChartRef(chartId) {
3164
+ return this.agGridAdapter.getAgGridApi().getChartRef(chartId);
3165
+ }
3166
+ setLayout(layout) {
3167
+ var _a, _b, _c, _d, _e, _f;
3168
+ if (!layout) {
3169
+ layout = this.api.layoutApi.getCurrentLayout();
3170
+ }
3171
+ const perfSetLayout = this.logger.beginPerf(`setLayout(${layout.Name})`);
3172
+ layout.Columns = layout.Columns || [];
3173
+ const actionRowColumn = this.api.actionRowApi.internalApi.getColDefsForActionRowColumns()[0];
3174
+ if (actionRowColumn) {
3175
+ layout.Columns.push(actionRowColumn.colId);
3176
+ layout.PinnedColumnsMap = layout.PinnedColumnsMap || {};
3177
+ layout.PinnedColumnsMap[actionRowColumn.colId] = actionRowColumn.pinned;
3178
+ }
3179
+ const columnsState = this.agGridAdapter.getAgGridApi().getColumnState();
3180
+ const columnsStateIndexes = {};
3181
+ const columnsStateMap = columnsState.reduce((acc, colState, index) => {
3182
+ columnsStateIndexes[colState.colId] = index;
3183
+ acc[colState.colId] = colState;
3184
+ return acc;
3185
+ }, {});
3186
+ let sortIndex = 0;
3187
+ const sortModelMap = ((_a = layout.ColumnSorts) !== null && _a !== void 0 ? _a : []).reduce((acc, customSort) => {
3188
+ const colId = customSort.ColumnId;
3189
+ acc[colId] = {
3190
+ colId,
3191
+ sort: customSort.SortOrder === 'Asc' ? 'asc' : 'desc',
3192
+ sortIndex,
3193
+ };
3194
+ sortIndex++;
3195
+ return acc;
3196
+ }, {});
3197
+ const groupedColumnsIndexesMap = (layout.RowGroupedColumns || []).reduce((acc, colId, index) => {
3198
+ acc[colId] = index;
3199
+ return acc;
3200
+ }, {});
3201
+ let pivotedColumnsIndexesMap = {};
3202
+ const aggregationFunctionsColumnsMap = layout.AggregationColumns || {};
3203
+ const columnsToShow = !layout.EnablePivot
3204
+ ? layout.Columns
3205
+ : ((_b = this.agGridAdapter
3206
+ .getAgGridApi()
3207
+ .getPivotResultColumns()) === null || _b === void 0 ? void 0 : _b.map((column) => column.getColId())) || [];
3208
+ let isChanged = false;
3209
+ const colsToAutoSize = {};
3210
+ let newColumnsState = this.getSortedColumnStateForVisibleColumns(columnsToShow, columnsState, layout);
3211
+ newColumnsState = newColumnsState
3212
+ .map((colState) => {
3213
+ var _a, _b, _c;
3214
+ const { colId } = colState;
3215
+ const oldColState = columnsStateMap[colId];
3216
+ // it's important to have width here, so it's not inherited from the existing colState
3217
+ // which could be from a different layout
3218
+ const newColState = Object.assign(Object.assign(Object.assign({}, oldColState), { width: null }), colState);
3219
+ if (layout.ColumnWidthMap && layout.ColumnWidthMap[colId] != null) {
3220
+ newColState.width = layout.ColumnWidthMap[colId];
3221
+ }
3222
+ else if (!colState.hide) {
3223
+ // autosize only the columns which are part of the selected layout
3224
+ colsToAutoSize[colId] = true;
3225
+ }
3226
+ if (actionRowColumn && actionRowColumn.colId === colId) {
3227
+ newColState.width = actionRowColumn.width;
3228
+ }
3229
+ newColState.rowGroupIndex =
3230
+ groupedColumnsIndexesMap[colId] != null ? groupedColumnsIndexesMap[colId] : null;
3231
+ newColState.rowGroup = newColState.rowGroupIndex != null;
3232
+ const normalizePinned = (pinnedValue) => {
3233
+ if (typeof pinnedValue === 'string') {
3234
+ return pinnedValue;
3235
+ }
3236
+ return pinnedValue == true ? 'left' : !!pinnedValue;
3237
+ };
3238
+ const newValuePinned = normalizePinned(layout.PinnedColumnsMap ? layout.PinnedColumnsMap[colId] : false);
3239
+ const stateValuePinned = normalizePinned(newColState.pinned);
3240
+ if (newValuePinned !== stateValuePinned) {
3241
+ newColState.pinned = newValuePinned;
3242
+ }
3243
+ newColState.pivotIndex = null;
3244
+ if (pivotedColumnsIndexesMap[colId] != null) {
3245
+ newColState.pivotIndex = pivotedColumnsIndexesMap[colId];
3246
+ }
3247
+ newColState.aggFunc = null;
3248
+ if (aggregationFunctionsColumnsMap[colId] != null) {
3249
+ const colDef = this.agGridAdapter.getAgGridApi().getColumnDef(colId);
3250
+ let aggFunc = null;
3251
+ const aggFuncFromLayout = aggregationFunctionsColumnsMap[colId];
3252
+ const adaptableAggFunc = this.getActiveAdaptableAggFuncForCol(colId);
3253
+ if (aggFuncFromLayout === true) {
3254
+ // if we have true, it means - take the default aggFunc from colDef
3255
+ // NOTE: colState gives us the current aggFunc, which can be null,
3256
+ // while the colDef gives us the initially configured aggFunc for that column
3257
+ aggFunc =
3258
+ (_c = (_b = (_a = colState.aggFunc) !== null && _a !== void 0 ? _a : colDef === null || colDef === void 0 ? void 0 : colDef.aggFunc) !== null && _b !== void 0 ? _b :
3259
+ // @ts-ignore available only wth ag-Grid v27.3.x
3260
+ colDef === null || colDef === void 0 ? void 0 : colDef.defaultAggFunc) !== null && _c !== void 0 ? _c : 'sum';
3261
+ }
3262
+ else if (adaptableAggFunc && adaptableAggFunc.type === 'weightedAverage') {
3263
+ aggFunc = AggregationColumns_1.WEIGHTED_AVERAGE_AGG_FN_NAME;
3264
+ }
3265
+ else if (typeof aggFuncFromLayout === 'string') {
3266
+ aggFunc = aggFuncFromLayout;
3267
+ }
3268
+ newColState.aggFunc = aggFunc;
3269
+ }
3270
+ if (sortModelMap[colId]) {
3271
+ newColState.sort = sortModelMap[colId].sort;
3272
+ newColState.sortIndex = sortModelMap[colId].sortIndex;
3273
+ }
3274
+ else {
3275
+ newColState.sort = null;
3276
+ newColState.sortIndex = null;
3277
+ }
3278
+ isChanged = isChanged || !(0, isEqual_1.default)(newColState, oldColState);
3279
+ return newColState;
3280
+ })
3281
+ .filter((x) => !!x);
3282
+ if (!isChanged) {
3283
+ // order changed
3284
+ const toString = (c) => `${c.colId}-${c.rowGroupIndex}-${c.pivotIndex}-${c.aggFunc}-${c.pinned}-${c.width}-${c.hide}`;
3285
+ const oldColStateString = columnsState.map(toString).join(',');
3286
+ const newColStateString = newColumnsState.map(toString).join(',');
3287
+ isChanged = newColStateString != oldColStateString;
3288
+ }
3289
+ const pivoted = !!layout.EnablePivot;
3290
+ const shouldUpdatePivoted = this.agGridAdapter.getAgGridApi().isPivotMode() !== pivoted;
3291
+ /**
3292
+ * Pivot columns are secondary columns that are created on the fly and base
3293
+ * their configuration on the main columns by copying that configuration.
3294
+ * Because they copy the colDefs they might have an old copy of the colldefs.
3295
+ * This is why when the layout is pivoted we need to set columns before pivoting is applied.
3296
+ * e.g. {
3297
+ * field: 'pivot-1',
3298
+ * pivotValueColumn: {
3299
+ * colDef: {
3300
+ * field: 'price',
3301
+ * // this is a copy of the original column
3302
+ * }
3303
+ * }
3304
+ *
3305
+ */
3306
+ if (shouldUpdatePivoted) {
3307
+ this.updateColumnModelAndRefreshGrid();
3308
+ }
3309
+ isChanged = isChanged || shouldUpdatePivoted;
3310
+ let shouldUpdateHeaders = false;
3311
+ // update the header name for all columns
3312
+ // there should be a simpler solution for this, once the Layout Management is refactored
3313
+ this.agGridAdapter
3314
+ .getAgGridApi()
3315
+ .getColumns()
3316
+ .forEach((col) => {
3317
+ const colDef = col.getColDef();
3318
+ const colId = col.getColId();
3319
+ const abColumn = this.api.columnApi.getColumnWithColumnId(colId);
3320
+ const colSetupInfo = {
3321
+ col,
3322
+ colDef,
3323
+ colId,
3324
+ abColumn,
3325
+ };
3326
+ shouldUpdateHeaders =
3327
+ this.agGridColumnAdapter.setupColumnHeader(colSetupInfo) || shouldUpdateHeaders;
3328
+ });
3329
+ isChanged = isChanged || shouldUpdateHeaders;
3330
+ if (isChanged) {
3331
+ // it's important we set pivot mode
3332
+ // before we set column state
3333
+ // as otherwise column order is not preserved properly when
3334
+ // going from pivoted to unpivoted layout
3335
+ if (shouldUpdatePivoted) {
3336
+ this.agGridAdapter.setGridOption('pivotMode', pivoted);
3337
+ }
3338
+ const perfApplyColumnState = this.logger.beginPerf('applyColumnState (layout.isChanged)');
3339
+ this.agGridAdapter.getAgGridApi().applyColumnState({
3340
+ state: newColumnsState,
3341
+ applyOrder: true,
3342
+ });
3343
+ perfApplyColumnState.end();
3344
+ this.api.gridApi.setColumnSorts(layout.ColumnSorts);
3345
+ this.agGridAdapter.getAgGridApi().setPivotColumns(layout.PivotColumns || []);
3346
+ // aggrid 25.1.0 introduced a bug such that a layout that has a grouped column, if the column has enableRowGroup: true but not rowGroup: true
3347
+ // the group column is not possitioned correctly at the start of the layout
3348
+ // see the test in layout/layout-switch/"should be able to switch from grouped to non-grouped and back"
3349
+ // so we figured out the following line fixes the issue
3350
+ // this.gridOptions.api.setColumnDefs(this.gridOptions.api.getColumnDefs()); //TODO find a solution for weighted averages - column floating filters are not showing
3351
+ // these updates need to be at the end, the methods are based on the grid state/col defs
3352
+ // the layout needs to be applied for them to work
3353
+ this.updateRowGroupsExpandedState(layout);
3354
+ }
3355
+ const colsToAutoSizeArray = Object.keys(colsToAutoSize);
3356
+ if (pivoted && ((_d = (_c = this.adaptableOptions) === null || _c === void 0 ? void 0 : _c.layoutOptions) === null || _d === void 0 ? void 0 : _d.autoSizeColumnsInPivotLayout)) {
3357
+ // when a pivoted layout loads, autosize all cols
3358
+ requestAnimationFrame(() => {
3359
+ this.agGridAdapter.getAgGridApi().autoSizeAllColumns();
3360
+ });
3361
+ // //but if it's also the first time the grid is loading
3362
+ // //it's not timely enough the above call, so we keep trying... I know it's ugly, we need to find a better way
3363
+ // setTimeout(() => {
3364
+ // this.agGridAdapter.getAgGridApi().autoSizeAllColumns();
3365
+ // setTimeout(() => {
3366
+ // this.agGridAdapter.getAgGridApi().autoSizeAllColumns();
3367
+ // }, 200);
3368
+ // }, 100);
3369
+ }
3370
+ else {
3371
+ if (((_f = (_e = this.adaptableOptions) === null || _e === void 0 ? void 0 : _e.layoutOptions) === null || _f === void 0 ? void 0 : _f.autoSizeColumnsInLayout) &&
3372
+ colsToAutoSizeArray.length) {
3373
+ requestAnimationFrame(() => {
3374
+ this.autoSizeColumns(colsToAutoSizeArray);
3375
+ });
3376
+ }
3377
+ }
3378
+ this.forPlugins((plugin) => {
3379
+ if (plugin.afterSetLayout) {
3380
+ plugin.afterSetLayout(this, layout);
3381
+ }
3382
+ });
3383
+ perfSetLayout.end();
3384
+ }
3385
+ getActiveAdaptableAggFuncForCol(columnId) {
3386
+ if (!columnId) {
3387
+ return null;
3388
+ }
3389
+ const currentLayout = this.api.layoutApi.getCurrentLayout();
3390
+ const aggregationFunctionsColumnsMap = currentLayout.AggregationColumns || {};
3391
+ const adaptableAggFunc = aggregationFunctionsColumnsMap[columnId];
3392
+ if (typeof adaptableAggFunc === 'object' &&
3393
+ 'type' in adaptableAggFunc &&
3394
+ adaptableAggFunc.type === 'weightedAverage') {
3395
+ return adaptableAggFunc;
3396
+ }
3397
+ return null;
3398
+ }
3399
+ onRowDataChanged({ rowNode, oldData, newData, }) {
3400
+ if (oldData == null || oldData == undefined) {
3401
+ return;
3402
+ }
3403
+ if (oldData == newData) {
3404
+ return;
3405
+ }
3406
+ const primaryKeyValue = this.getPrimaryKeyValueFromRowNode(rowNode);
3407
+ if (!primaryKeyValue) {
3408
+ return;
3409
+ }
3410
+ // rowNode = this.getRowNodeForPrimaryKey(primaryKeyValue);
3411
+ let cellDataChangedInfos = [];
3412
+ Object.keys(oldData).forEach((key) => {
3413
+ if (this.api.columnApi.isColumnInGrid(key)) {
3414
+ const oldValue = oldData[key];
3415
+ const newValue = newData[key];
3416
+ if (oldValue != newValue) {
3417
+ const cellDataChangedInfo = this.api.internalApi.buildDataChangedInfo({
3418
+ oldValue: oldValue,
3419
+ newValue: newValue,
3420
+ column: this.api.columnApi.getColumnWithColumnId(key),
3421
+ primaryKeyValue: primaryKeyValue,
3422
+ rowNode: rowNode,
3423
+ trigger: 'tick',
3424
+ });
3425
+ if (this.isUndoChange(cellDataChangedInfo)) {
3426
+ cellDataChangedInfo.trigger = 'undo';
3427
+ }
3428
+ cellDataChangedInfos.push(cellDataChangedInfo);
3429
+ }
3430
+ }
3431
+ });
3432
+ this.performPostEditChecks(cellDataChangedInfos);
3433
+ }
3434
+ onCellDataChanged({ rowNode, oldValue, newValue, colId, }) {
3435
+ if (oldValue == newValue) {
3436
+ return;
3437
+ }
3438
+ const abColumn = this.api.columnApi.getColumnWithColumnId(colId);
3439
+ if (!abColumn) {
3440
+ return;
3441
+ }
3442
+ if (this.isGroupRowNode(rowNode)) {
3443
+ const cellDataChangedInfo = this.api.internalApi.buildDataChangedInfo({
3444
+ oldValue: oldValue,
3445
+ newValue: newValue,
3446
+ column: abColumn,
3447
+ /**
3448
+ * A grouped row does not have an underling data item.
3449
+ * Because of this we use the rowNode.id as an identifier.
3450
+ */
3451
+ primaryKeyValue: rowNode.id,
3452
+ rowNode: rowNode,
3453
+ trigger: 'aggChange',
3454
+ });
3455
+ this.DataService.CreateDataChangedEvent(cellDataChangedInfo);
3456
+ return;
3457
+ }
3458
+ const primaryKeyValue = this.getPrimaryKeyValueFromRowNode(rowNode);
3459
+ if (!primaryKeyValue) {
3460
+ return;
3461
+ }
3462
+ const cellDataChangedInfo = this.api.internalApi.buildDataChangedInfo({
3463
+ oldValue: oldValue,
3464
+ newValue: newValue,
3465
+ column: abColumn,
3466
+ primaryKeyValue: primaryKeyValue,
3467
+ rowNode: rowNode,
3468
+ trigger: 'edit',
3469
+ });
3470
+ if (this.isUndoChange(cellDataChangedInfo)) {
3471
+ cellDataChangedInfo.trigger = 'undo';
3472
+ }
3473
+ this.performPostEditChecks([cellDataChangedInfo]);
3474
+ }
3475
+ isUndoChange(dataChange) {
3476
+ // check if this is not a reverted change
3477
+ const undoChange = this.api.internalApi.getDataService().extractUndoChange(dataChange);
3478
+ return !!undoChange;
3479
+ }
3480
+ /**
3481
+ * There are a few things that we need to do AFTER we edit a cell and it makes sense to put them in one place
3482
+ */
3483
+ performPostEditChecks(cellDataChangedInfos) {
3484
+ const firstInfo = cellDataChangedInfos[0];
3485
+ if (!firstInfo || !firstInfo.rowNode) {
3486
+ return;
3487
+ }
3488
+ cellDataChangedInfos.forEach((cellDataChangedInfo) => {
3489
+ if (cellDataChangedInfo.trigger === 'undo') {
3490
+ this.logger.info(`Undo data change: PK(${cellDataChangedInfo.primaryKeyValue}) Col(${cellDataChangedInfo.column}) RevertedValue(${cellDataChangedInfo.oldValue}) OriginalValue(${cellDataChangedInfo.newValue})`);
3491
+ }
3492
+ if (cellDataChangedInfo.trigger === 'edit' || cellDataChangedInfo.trigger === 'undo') {
3493
+ this.checkChangedCellCurrentlySelected(cellDataChangedInfo);
3494
+ this.api.freeTextColumnApi.internalApi.handleFreeTextColumnDataChange(cellDataChangedInfo);
3495
+ }
3496
+ this.DataService.CreateDataChangedEvent(cellDataChangedInfo);
3497
+ this.resetMinMaxCachedValueForColumn(cellDataChangedInfo.column);
3498
+ });
3499
+ this.refreshCellsBasedOnCellDataChange(cellDataChangedInfos);
3500
+ firstInfo.trigger == 'tick' ? this.filterOnTickingDataChange() : this.filterOnEditDataChange();
3501
+ }
3502
+ refreshCellsBasedOnCellDataChange(cellDataChangedInfos) {
3503
+ const [firstInfo] = cellDataChangedInfos;
3504
+ // if node is visible then check if need to refresh other columns / whole row if the updating column is:
3505
+ // 1. referenced in Format Column Styles that have Expressions (refreshing whole row if Scope is All)
3506
+ // 2. referenced in Format Column styles that use Column Comparisons (which might also be calculated columns)
3507
+ if (this.agGridAdapter.isVisibleNode(firstInfo.rowNode)) {
3508
+ let dataChangedScope = {
3509
+ wholeRow: false,
3510
+ columnIds: new Set(),
3511
+ };
3512
+ this.getFormatColumnExpressionStylesChanges(dataChangedScope, cellDataChangedInfos);
3513
+ if (dataChangedScope.wholeRow === false) {
3514
+ this.getFormatColumnPredicateStyleChanges(dataChangedScope, cellDataChangedInfos);
3515
+ }
3516
+ if (dataChangedScope.wholeRow) {
3517
+ this.redrawRow(firstInfo.rowNode);
3518
+ }
3519
+ else {
3520
+ this.getStyledColumnComparisonChanges(dataChangedScope, cellDataChangedInfos);
3521
+ if (dataChangedScope.columnIds.size > 0) {
3522
+ this.refreshCells([firstInfo.rowNode], Array.from(dataChangedScope.columnIds.values()), true);
3523
+ }
3524
+ }
3525
+ }
3526
+ this.refreshColumnForRelativeRangeStyledColumns(cellDataChangedInfos);
3527
+ }
3528
+ refreshColumnForRelativeRangeStyledColumns(cellDataChangedInfos) {
3529
+ const columnIdMap = new Set();
3530
+ cellDataChangedInfos.forEach((cellDataChangeInfo) => {
3531
+ const styledColumn = this.api.styledColumnApi.getActiveStyledColumnForColumn(cellDataChangeInfo.column);
3532
+ if (styledColumn &&
3533
+ this.api.styledColumnApi.internalApi.hasStyledColumnRelativeCellRange(styledColumn)) {
3534
+ columnIdMap.add(styledColumn.ColumnId);
3535
+ }
3536
+ });
3537
+ const columnIdsToUpdate = [...columnIdMap];
3538
+ if (columnIdsToUpdate.length) {
3539
+ this.refreshColumns(columnIdsToUpdate, true);
3540
+ }
3541
+ }
3542
+ getStyledColumnComparisonChanges(dataChangedScope, cellDataChangedInfos) {
3543
+ this.api.styledColumnApi.getStyledColumns().forEach((sc) => {
3544
+ let columnComparison = this.api.styledColumnApi.internalApi.getColumnComparisonForStyledColumn(sc);
3545
+ if (columnComparison) {
3546
+ let affectedColumnIds = this.api.styledColumnApi.internalApi.getColumnIdsFromColumnComparison(columnComparison);
3547
+ if (ArrayExtensions_1.default.IsNotNullOrEmpty(affectedColumnIds)) {
3548
+ cellDataChangedInfos.forEach((cellDataChangedInfo) => {
3549
+ if (affectedColumnIds.includes(cellDataChangedInfo.column.columnId)) {
3550
+ dataChangedScope.columnIds.add(sc.ColumnId);
3551
+ }
3552
+ });
3553
+ }
3554
+ }
3555
+ });
3556
+ }
3557
+ getFormatColumnPredicateStyleChanges(dataChangedScope, cellDataChangedInfos) {
3558
+ cellDataChangedInfos.forEach((cellDataChangeInfo) => {
3559
+ const dependentColumns = this.api.formatColumnApi.internalApi.getFormatColumnColumnsDependentOnColumnChange(cellDataChangeInfo.column);
3560
+ for (let colId of dependentColumns) {
3561
+ dataChangedScope.columnIds.add(colId);
3562
+ }
3563
+ });
3564
+ }
3565
+ getFormatColumnExpressionStylesChanges(dataChangedScope, cellDataChangedInfos) {
3566
+ const formatColumnsWithExpression = [];
3567
+ formatColumnsWithExpression.push(...this.api.formatColumnApi.internalApi.getFormatColumnsWithExpression());
3568
+ if (ArrayExtensions_1.default.IsNullOrEmpty(formatColumnsWithExpression)) {
3569
+ return;
3570
+ }
3571
+ cellDataChangedInfos.forEach((cellDataChangedInfo) => {
3572
+ if (!dataChangedScope.wholeRow) {
3573
+ formatColumnsWithExpression.forEach((styleModule) => {
3574
+ if (!dataChangedScope.wholeRow) {
3575
+ const columnIds = this.api.expressionApi.getColumnsFromExpression(styleModule.Rule.BooleanExpression);
3576
+ if (columnIds.includes(cellDataChangedInfo.column.columnId)) {
3577
+ if (this.api.scopeApi.scopeIsAll(styleModule.Scope)) {
3578
+ dataChangedScope.wholeRow = true;
3579
+ return;
3580
+ }
3581
+ else {
3582
+ this.api.scopeApi
3583
+ .getColumnsForScope(styleModule.Scope)
3584
+ .map((c) => c.columnId)
3585
+ .forEach((colId) => {
3586
+ dataChangedScope.columnIds.add(colId);
3587
+ });
3588
+ }
3589
+ }
3590
+ }
3591
+ });
3592
+ }
3593
+ });
3594
+ }
3595
+ checkChangedCellCurrentlySelected(cellDataChangedInfo) {
3596
+ let selectedCellInfo = this.api.gridApi.getSelectedCellInfo();
3597
+ if (selectedCellInfo && ArrayExtensions_1.default.IsNotNullOrEmpty(selectedCellInfo.gridCells)) {
3598
+ let matchingCell = selectedCellInfo.gridCells.find((gc) => gc.primaryKeyValue == cellDataChangedInfo.primaryKeyValue &&
3599
+ gc.column == cellDataChangedInfo.column);
3600
+ if (matchingCell) {
3601
+ this.refreshSelectedCellsState();
3602
+ }
3603
+ }
3604
+ let selectedRowInfo = this.api.gridApi.getSelectedRowInfo();
3605
+ if (selectedRowInfo && ArrayExtensions_1.default.IsNotNullOrEmpty(selectedRowInfo.gridRows)) {
3606
+ let matchingRow = selectedRowInfo.gridRows.find((gr) => gr.primaryKeyValue == cellDataChangedInfo.primaryKeyValue);
3607
+ if (matchingRow) {
3608
+ this.refreshSelectedRowsState();
3609
+ }
3610
+ }
3611
+ }
3612
+ resetMinMaxCachedValueForColumn(column) {
3613
+ if (!column) {
3614
+ this.columnMinMaxValuesCache[column.columnId] = {};
3615
+ }
3616
+ if (this.columnMinMaxValuesCache[column.columnId]) {
3617
+ this.columnMinMaxValuesCache[column.columnId] = undefined;
3618
+ }
3619
+ }
3620
+ filterOnTickingDataChange() {
3621
+ var _a;
3622
+ if (this.adaptableOptions.columnFilterOptions.filterActionOnExternalDataChange.applyFilter ==
3623
+ Enums_1.FilterOnDataChangeOptions.Always) {
3624
+ (_a = this.agGridAdapter.getAgGridApi()) === null || _a === void 0 ? void 0 : _a.onFilterChanged();
3625
+ }
3626
+ else if (this.adaptableOptions.columnFilterOptions.filterActionOnExternalDataChange.applyFilter ==
3627
+ Enums_1.FilterOnDataChangeOptions.Throttle) {
3628
+ this.throttleFilterOnTickingDataChange();
3629
+ }
3630
+ }
3631
+ filterOnEditDataChange() {
3632
+ var _a;
3633
+ if (this.adaptableOptions.columnFilterOptions.filterActionOnUserDataChange.applyFilter ==
3634
+ Enums_1.FilterOnDataChangeOptions.Always) {
3635
+ (_a = this.agGridAdapter.getAgGridApi()) === null || _a === void 0 ? void 0 : _a.onFilterChanged();
3636
+ }
3637
+ else if (this.adaptableOptions.columnFilterOptions.filterActionOnUserDataChange.applyFilter ==
3638
+ Enums_1.FilterOnDataChangeOptions.Throttle) {
3639
+ this.throttleFilterOnEditDataChange();
3640
+ }
3641
+ }
3642
+ shouldCreateDefaultLayout(adaptableState, adaptableOptions) {
3643
+ var _a, _b, _c;
3644
+ const layoutState = adaptableState.Layout || {};
3645
+ if (((_a = adaptableOptions.layoutOptions) === null || _a === void 0 ? void 0 : _a.createDefaultLayout) &&
3646
+ !((_b = layoutState.Layouts) === null || _b === void 0 ? void 0 : _b.find((layout) => layout.Name === GeneralConstants_1.DEFAULT_LAYOUT))) {
3647
+ return true;
3648
+ }
3649
+ return !((_c = layoutState.Layouts) === null || _c === void 0 ? void 0 : _c.length);
3650
+ }
3651
+ createDefaultLayout(state, gridOptionsColDefs) {
3652
+ var _a, _b;
3653
+ const allColumnDefs = this.agGridAdapter.getFlattenedColDefs(gridOptionsColDefs);
3654
+ const defaultLayout = ObjectFactory_1.default.CreateEmptyLayout({
3655
+ Name: GeneralConstants_1.DEFAULT_LAYOUT,
3656
+ Columns: allColumnDefs.map((c) => c.colId),
3657
+ AggregationColumns: allColumnDefs.reduce((acc, col) => {
3658
+ if (typeof col.aggFunc === 'string') {
3659
+ acc[col.colId] = col.aggFunc;
3660
+ }
3661
+ return acc;
3662
+ }, {}),
3663
+ PinnedColumnsMap: allColumnDefs.reduce((acc, col) => {
3664
+ const pinned = col.pinned;
3665
+ if (pinned) {
3666
+ acc[col.colId] = pinned === true ? 'left' : pinned;
3667
+ }
3668
+ return acc;
3669
+ }, {}),
3670
+ RowGroupedColumns: allColumnDefs.reduce((acc, col) => {
3671
+ if (col.rowGroup) {
3672
+ acc.push(col.colId);
3673
+ }
3674
+ return acc;
3675
+ }, []),
3676
+ });
3677
+ // ADD special columns
3678
+ const calculatedColumns = ((_a = state.CalculatedColumn) === null || _a === void 0 ? void 0 : _a.CalculatedColumns) || [];
3679
+ if (calculatedColumns.length) {
3680
+ defaultLayout.Columns.push(...calculatedColumns.map((c) => c.ColumnId));
3681
+ }
3682
+ const freeTextColumns = ((_b = state.FreeTextColumn) === null || _b === void 0 ? void 0 : _b.FreeTextColumns) || [];
3683
+ if (freeTextColumns.length) {
3684
+ defaultLayout.Columns.push(...freeTextColumns.map((c) => c.ColumnId));
3685
+ }
3686
+ return defaultLayout;
3687
+ }
3688
+ /*
3689
+ * This is the opposite of setLayout
3690
+ */
3691
+ updateLayoutFromGrid() {
3692
+ var _a, _b;
3693
+ const agGridApi = this.agGridAdapter.getAgGridApi();
3694
+ const columnState = agGridApi.getColumnState();
3695
+ const expandedState = agGridApi.getState().rowGroupExpansion || { expandedRowGroupIds: [] };
3696
+ const currentLayoutState = { columnState, expandedState };
3697
+ try {
3698
+ // TODO
3699
+ const stringifiedLayoutState = JSON.stringify(currentLayoutState);
3700
+ if (stringifiedLayoutState === this.previousAgGridLayoutState) {
3701
+ // same grid column state as a previous,
3702
+ // so no need to update, as the layout has already been updated
3703
+ // for this grid column state
3704
+ return;
3705
+ }
3706
+ this.previousAgGridLayoutState = stringifiedLayoutState;
3707
+ }
3708
+ catch (ex) {
3709
+ this.logger.consoleError('Error stringifying column state', ex);
3710
+ }
3711
+ const currentLayout = this.api.layoutApi.getCurrentLayout();
3712
+ if (currentLayout.IsReadOnly) {
3713
+ // reaply the layout so the grid is reverted
3714
+ this.setLayout();
3715
+ return;
3716
+ }
3717
+ const layout = Object.assign({}, currentLayout);
3718
+ let columnOrder = [];
3719
+ const columnFlexes = {};
3720
+ const pinnedColumns = {};
3721
+ const columnSorts = [];
3722
+ let groupedColumns = [...new Array(columnState.length)];
3723
+ let pivotedColumns = [...new Array(columnState.length)];
3724
+ const pivotColumns = [];
3725
+ const aggregatedColumns = {};
3726
+ const columnWidths = columnState.reduce((acc, colState) => {
3727
+ const { colId } = colState;
3728
+ if (colState.sort && colState.sortIndex != null) {
3729
+ columnSorts.push({
3730
+ ColumnId: colId,
3731
+ SortOrder: colState.sort === 'asc' ? 'Asc' : 'Desc',
3732
+ SortIndex: colState.sortIndex,
3733
+ });
3734
+ }
3735
+ if (colState.width != null) {
3736
+ acc[colId] = colState.width;
3737
+ }
3738
+ if (colState.flex != null) {
3739
+ columnFlexes[colId] = colState.flex;
3740
+ }
3741
+ if (colState.pinned === 'left') {
3742
+ pinnedColumns[colId] = 'left';
3743
+ }
3744
+ if (colState.pinned === 'right') {
3745
+ pinnedColumns[colId] = 'right';
3746
+ }
3747
+ if (!colState.hide) {
3748
+ columnOrder.push(colId);
3749
+ }
3750
+ if (colState.rowGroupIndex != null) {
3751
+ groupedColumns[colState.rowGroupIndex] = colId;
3752
+ }
3753
+ if (colState.pivotIndex != null) {
3754
+ pivotedColumns[colState.pivotIndex] = colId;
3755
+ }
3756
+ if (colState.aggFunc && typeof colState.aggFunc === 'string') {
3757
+ aggregatedColumns[colId] = colState.aggFunc;
3758
+ }
3759
+ return acc;
3760
+ }, {});
3761
+ columnSorts.sort((a, b) => a.SortIndex - b.SortIndex);
3762
+ this.agGridAdapter
3763
+ .getAgGridApi()
3764
+ .getPivotColumns()
3765
+ .forEach((col) => {
3766
+ pivotColumns.push(col.getColId());
3767
+ });
3768
+ groupedColumns = groupedColumns.filter((x) => !!x);
3769
+ pivotedColumns = pivotedColumns.filter((x) => !!x);
3770
+ if ((_b = (_a = this.adaptableOptions) === null || _a === void 0 ? void 0 : _a.groupingOptions) === null || _b === void 0 ? void 0 : _b.restoreUngroupedColumns) {
3771
+ columnOrder = this.restoreUnGroupColumnOrder({
3772
+ columnOrder,
3773
+ newGroupColumns: groupedColumns,
3774
+ });
3775
+ }
3776
+ layout.ColumnWidthMap = columnWidths;
3777
+ // layout.ColumnFlexMap = columnFlexes;
3778
+ layout.PinnedColumnsMap = pinnedColumns;
3779
+ layout.Columns = columnOrder;
3780
+ layout.ColumnSorts = columnSorts;
3781
+ layout.RowGroupedColumns = groupedColumns;
3782
+ if (Object.keys(aggregatedColumns).length) {
3783
+ // AG Grid aggregations are not 1-1 with adaptable column-aggregations
3784
+ layout.AggregationColumns = this.mapAggregationColumnsFromGrid(aggregatedColumns, currentLayout);
3785
+ }
3786
+ else {
3787
+ layout.AggregationColumns = {};
3788
+ }
3789
+ layout.EnablePivot = this.agGridAdapter.getAgGridApi().isPivotMode();
3790
+ layout.PivotColumns = pivotColumns;
3791
+ if (
3792
+ // check first row node for presence of data without iterating over whole grid
3793
+ this.api.layoutApi.internalApi.areExpandedRowGroupsSavedInLayouts() &&
3794
+ this.api.gridApi.getFirstDisplayedRowNode()) {
3795
+ layout.ExpandedRowGroupValues = this.getExpandRowGroupsKeys();
3796
+ }
3797
+ const previousVisibleColumns = currentLayout.Columns;
3798
+ const newVisibleColumns = layout.Columns;
3799
+ // check if all new columns were previously visible
3800
+ const someColumnsAreNew = newVisibleColumns.some((colId) => !previousVisibleColumns.includes(colId));
3801
+ if (someColumnsAreNew) {
3802
+ this.updateColumnModelAndRefreshGrid();
3803
+ }
3804
+ this.persistLayout(layout);
3805
+ }
3806
+ persistLayout(layout) {
3807
+ if (this.api.layoutApi.shouldAutoSaveLayouts()) {
3808
+ this.api.layoutApi.createOrUpdateLayout(layout);
3809
+ }
3810
+ else {
3811
+ this.api.layoutApi.internalApi.updateCurrentDraftLayout(layout);
3812
+ }
3813
+ }
3814
+ /**
3815
+ * When reading the state from the grid, we have to make sure 'avg' is not overriden with the 'avg' string.
3816
+ */
3817
+ mapAggregationColumnsFromGrid(aggFuncFromGrid, currentLayout) {
3818
+ return Object.entries(aggFuncFromGrid).reduce((acc, [colId, agg]) => {
3819
+ const adaptableAggFunc = this.getActiveAdaptableAggFuncForCol(colId);
3820
+ if ((adaptableAggFunc === null || adaptableAggFunc === void 0 ? void 0 : adaptableAggFunc.type) === 'weightedAverage' && agg === AggregationColumns_1.WEIGHTED_AVERAGE_AGG_FN_NAME) {
3821
+ // do not override the agg func
3822
+ acc[colId] = currentLayout.AggregationColumns[colId];
3823
+ }
3824
+ else {
3825
+ acc[colId] = agg;
3826
+ }
3827
+ return acc;
3828
+ }, {});
3829
+ }
3830
+ persistColumnIndexBeforeGrouping(params) {
3831
+ const layout = this.api.layoutApi.getCurrentLayout();
3832
+ const columnGroupsInLayout = layout.RowGroupedColumns;
3833
+ const columnGroupsInGrid = params.columns.map((col) => col.getColId());
3834
+ // what is new
3835
+ const newGroups = columnGroupsInGrid.filter((colId) => !columnGroupsInLayout.includes(colId));
3836
+ newGroups.forEach((colId) => {
3837
+ const columnIndex = layout.Columns.filter((colId) => !(this.api.columnApi.isAutoRowGroupColumn(colId) ||
3838
+ this.api.columnApi.isAutoPivotColumn(colId))).findIndex((columnIdInLayout) => columnIdInLayout === colId);
3839
+ // user may group after a column not in layout
3840
+ if (columnIndex !== -1) {
3841
+ this.api.internalApi.persistPreviousGroupedColumnsIndex(layout.Uuid, colId, columnIndex);
3842
+ }
3843
+ });
3844
+ }
3845
+ /**
3846
+ * Restores the order previous grouping order.
3847
+ */
3848
+ restoreUnGroupColumnOrder({ newGroupColumns, columnOrder, }) {
3849
+ var _a;
3850
+ const newColumnOrder = [...columnOrder];
3851
+ const currentLayout = this.api.layoutApi.getCurrentLayout();
3852
+ const previousGroupedColumnsIndex = this.api.internalApi.getPreviousGroupedColumnsIndex(currentLayout.Uuid);
3853
+ const isUnGroup = newGroupColumns.length < ((_a = currentLayout === null || currentLayout === void 0 ? void 0 : currentLayout.RowGroupedColumns) === null || _a === void 0 ? void 0 : _a.length);
3854
+ if (!isUnGroup) {
3855
+ return columnOrder;
3856
+ }
3857
+ if (!previousGroupedColumnsIndex) {
3858
+ return columnOrder;
3859
+ }
3860
+ for (let [colId, previousIndex] of Object.entries(previousGroupedColumnsIndex)) {
3861
+ const isStillGrouped = newGroupColumns.includes(colId);
3862
+ const isAlreadyInGrid = currentLayout.Columns.includes(colId); // was not just added by ungrouping
3863
+ if (isStillGrouped) {
3864
+ continue;
3865
+ }
3866
+ if (isAlreadyInGrid) {
3867
+ // no longer grouped, but already in grid, this means it was already in grid before ungrouping
3868
+ // in this case the state can be cleared
3869
+ this.api.internalApi.persistPreviousGroupedColumnsIndex(currentLayout.Uuid, colId, null);
3870
+ continue;
3871
+ }
3872
+ // need to ajust index based if grouped
3873
+ const numberOfGroupedColumns = newColumnOrder.filter((colId) => this.api.columnApi.isAutoRowGroupColumn(colId)).length;
3874
+ const adjustedPreviousIndex = previousIndex + numberOfGroupedColumns;
3875
+ const indexInGrid = newColumnOrder.indexOf(colId);
3876
+ const hasDifferentPositionAsPreviousLayout = adjustedPreviousIndex !== null && // if null, the reorder was already applied
3877
+ indexInGrid > 0 && // needs to be in grid
3878
+ adjustedPreviousIndex !== indexInGrid;
3879
+ const isPreviousPositionInRange = adjustedPreviousIndex < newColumnOrder.length;
3880
+ if (hasDifferentPositionAsPreviousLayout && isPreviousPositionInRange) {
3881
+ newColumnOrder.splice(indexInGrid, 1);
3882
+ newColumnOrder.splice(adjustedPreviousIndex, 0, colId);
3883
+ }
3884
+ this.api.internalApi.persistPreviousGroupedColumnsIndex(currentLayout.Uuid, colId, null);
3885
+ }
3886
+ return newColumnOrder;
3887
+ }
3888
+ onSortChanged() {
3889
+ const columnSorts = this.getColumnSorts();
3890
+ this.api.gridApi.setColumnSorts(columnSorts);
3891
+ this._emit('SortChanged', columnSorts);
3892
+ }
3893
+ getColumnSorts() {
3894
+ const columnSorts = [];
3895
+ const columnState = this.agGridAdapter.getAgGridApi().getColumnState();
3896
+ columnState.forEach((colState) => {
3897
+ const { colId } = colState;
3898
+ if (colState.sort && colState.sortIndex != null) {
3899
+ columnSorts.push({
3900
+ ColumnId: colId,
3901
+ SortOrder: colState.sort === 'asc' ? 'Asc' : 'Desc',
3902
+ SortIndex: colState.sortIndex,
3903
+ });
3904
+ }
3905
+ });
3906
+ columnSorts.sort((a, b) => a.SortIndex - b.SortIndex);
3907
+ return columnSorts.map((c) => {
3908
+ return {
3909
+ ColumnId: c.ColumnId,
3910
+ SortOrder: c.SortOrder,
3911
+ };
3912
+ });
3913
+ }
3914
+ }
3915
+ exports.AdaptableAgGrid = AdaptableAgGrid;