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