@adaptabletools/adaptable 18.0.0-canary.3 → 18.0.0-canary.30

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