@adaptabletools/adaptable-cjs 18.0.0-canary.2 → 18.0.0-canary.21

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