@adaptabletools/adaptable 18.0.0-canary.2 → 18.0.0-canary.20

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