lightning-base-components 1.14.6-alpha → 1.15.2-alpha

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 (169) hide show
  1. package/metadata/raptor.json +31 -4
  2. package/package.json +13 -2
  3. package/scopedImports/@salesforce-internal-core.appVersion.js +1 -1
  4. package/scopedImports/@salesforce-label-LightningMap.defaultTitle.js +1 -0
  5. package/scopedImports/@salesforce-label-LightningProgressBar.progressBar.js +1 -0
  6. package/src/lightning/alert/__docs__/alert.md +99 -0
  7. package/src/lightning/alert/__examples__disabled/basic/basic.css +7 -0
  8. package/src/lightning/alert/__examples__disabled/basic/basic.html +8 -0
  9. package/src/lightning/alert/__examples__disabled/basic/basic.js +14 -0
  10. package/src/lightning/alert/alert.html +3 -0
  11. package/src/lightning/alert/alert.js +78 -0
  12. package/src/lightning/alert/alert.js-meta.xml +6 -0
  13. package/src/lightning/baseCombobox/baseCombobox.html +2 -1
  14. package/src/lightning/baseCombobox/baseCombobox.js +41 -6
  15. package/src/lightning/button/__wdio__/utam/utam.html +3 -0
  16. package/src/lightning/button/__wdio__/utam/utam.js +3 -0
  17. package/src/lightning/button/__wdio__/utam/utam.spec.js +20 -0
  18. package/src/lightning/button/button.js +22 -1
  19. package/src/lightning/buttonMenu/buttonMenu.js +12 -0
  20. package/src/lightning/checkboxGroup/checkboxGroup.html +2 -2
  21. package/src/lightning/checkboxGroup/checkboxGroup.js +9 -5
  22. package/src/lightning/combobox/__docs__/combobox.md +3 -1
  23. package/src/lightning/combobox/combobox.js +0 -1
  24. package/src/lightning/confirm/__docs__/confirm.md +98 -0
  25. package/src/lightning/confirm/__examples__disabled/basic/basic.css +7 -0
  26. package/src/lightning/confirm/__examples__disabled/basic/basic.html +8 -0
  27. package/src/lightning/confirm/__examples__disabled/basic/basic.js +14 -0
  28. package/src/lightning/confirm/confirm.html +3 -0
  29. package/src/lightning/confirm/confirm.js +80 -0
  30. package/src/lightning/confirm/confirm.js-meta.xml +6 -0
  31. package/src/lightning/datatable/__docs__/datatable.md +45 -0
  32. package/src/lightning/datatable/__wdio__/utam/utam.html +32 -0
  33. package/src/lightning/datatable/__wdio__/utam/utam.js +91 -0
  34. package/src/lightning/datatable/__wdio__/utam/utam.spec.js +214 -0
  35. package/src/lightning/datatable/columns.js +166 -71
  36. package/src/lightning/datatable/datatable.js +103 -20
  37. package/src/lightning/datatable/headerActions.js +2 -2
  38. package/src/lightning/datatable/inlineEdit.js +0 -5
  39. package/src/lightning/datatable/inlineEditShared.js +4 -2
  40. package/src/lightning/datatable/keyboard.js +17 -13
  41. package/src/lightning/datatable/renderManager.js +45 -13
  42. package/src/lightning/datatable/resizeSensor.js +11 -3
  43. package/src/lightning/datatable/rowSelection.js +9 -3
  44. package/src/lightning/datatable/rowSelectionShared.js +33 -20
  45. package/src/lightning/datatable/rows.js +3 -2
  46. package/src/lightning/datatable/sort.js +8 -8
  47. package/src/lightning/datatable/state.js +9 -1
  48. package/src/lightning/datatable/templates/div/div.html +6 -2
  49. package/src/lightning/datatable/templates/table/table.html +7 -4
  50. package/src/lightning/datatable/tree.js +25 -0
  51. package/src/lightning/datatable/types.js +77 -9
  52. package/src/lightning/datatable/utils.js +51 -24
  53. package/src/lightning/datatable/virtualization.js +319 -0
  54. package/src/lightning/datatable/wrapText.js +54 -16
  55. package/src/lightning/datepicker/__perf__DISABLED/datepickerWithCalendarOpen.perf.js +55 -0
  56. package/src/lightning/datepicker/datepicker.html +1 -0
  57. package/src/lightning/datepicker/datepicker.js +10 -0
  58. package/src/lightning/datetimepicker/datetimepicker.html +2 -0
  59. package/src/lightning/datetimepicker/datetimepicker.js +8 -0
  60. package/src/lightning/dualListbox/dualListbox.js +2 -1
  61. package/src/lightning/formattedAddress/__docs__/formattedAddress.md +3 -0
  62. package/src/lightning/formattedAddress/__examples__/customLocale/customLocale.html +22 -0
  63. package/src/lightning/formattedAddress/__examples__/customLocale/customLocale.js +3 -0
  64. package/src/lightning/formattedAddress/formattedAddress.js +7 -1
  65. package/src/lightning/groupedCombobox/groupedCombobox.html +2 -1
  66. package/src/lightning/groupedCombobox/groupedCombobox.js +16 -2
  67. package/src/lightning/iconSvgTemplates/buildTemplates/standard/dashboard_component.html +7 -0
  68. package/src/lightning/iconSvgTemplates/buildTemplates/standard/slack.html +7 -0
  69. package/src/lightning/iconSvgTemplates/buildTemplates/standard/tableau.html +7 -0
  70. package/src/lightning/iconSvgTemplates/buildTemplates/standard/travel_mode.html +2 -2
  71. package/src/lightning/iconSvgTemplates/buildTemplates/templates.js +8 -1
  72. package/src/lightning/iconSvgTemplates/buildTemplates/utility/data_model.html +7 -0
  73. package/src/lightning/iconSvgTemplates/buildTemplates/utility/serialized_product.html +1 -1
  74. package/src/lightning/iconSvgTemplates/buildTemplates/utility/serialized_product_transaction.html +2 -1
  75. package/src/lightning/iconSvgTemplates/buildTemplates/utility/slack.html +7 -0
  76. package/src/lightning/iconSvgTemplates/buildTemplates/utility/tableau.html +7 -0
  77. package/src/lightning/iconSvgTemplates/buildTemplates/utility/video_off.html +7 -0
  78. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/dashboard_component.html +7 -0
  79. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/slack.html +7 -0
  80. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/tableau.html +7 -0
  81. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/travel_mode.html +2 -2
  82. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/templates.js +8 -1
  83. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/data_model.html +7 -0
  84. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/serialized_product.html +1 -1
  85. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/serialized_product_transaction.html +2 -1
  86. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/slack.html +7 -0
  87. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/tableau.html +7 -0
  88. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/video_off.html +7 -0
  89. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/dashboard_component.html +7 -0
  90. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/slack.html +7 -0
  91. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/tableau.html +7 -0
  92. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/travel_mode.html +2 -2
  93. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/templates.js +4 -1
  94. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/dashboard_component.html +7 -0
  95. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/slack.html +7 -0
  96. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/tableau.html +7 -0
  97. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/travel_mode.html +2 -2
  98. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/templates.js +4 -1
  99. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/templates.js +5 -1
  100. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/data_model.html +7 -0
  101. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/serialized_product.html +1 -1
  102. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/serialized_product_transaction.html +2 -1
  103. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/slack.html +7 -0
  104. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/tableau.html +7 -0
  105. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/video_off.html +7 -0
  106. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/templates.js +5 -1
  107. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/data_model.html +7 -0
  108. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/serialized_product.html +1 -1
  109. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/serialized_product_transaction.html +2 -1
  110. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/slack.html +7 -0
  111. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/tableau.html +7 -0
  112. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/video_off.html +7 -0
  113. package/src/lightning/input/__docs__/input.md +2 -0
  114. package/src/lightning/input/input.html +6 -0
  115. package/src/lightning/input/input.js +2 -1
  116. package/src/lightning/inputAddress/__docs__/inputAddress.md +5 -0
  117. package/src/lightning/inputAddress/__examples__/customLocale/customLocale.html +12 -0
  118. package/src/lightning/inputAddress/__examples__/customLocale/customLocale.js +3 -0
  119. package/src/lightning/inputAddress/inputAddress.html +2 -0
  120. package/src/lightning/inputAddress/inputAddress.js +26 -3
  121. package/src/lightning/inputName/__docs__/inputName.md +2 -0
  122. package/src/lightning/inputName/inputName.html +4 -1
  123. package/src/lightning/inputUtils/inputUtils.js +11 -0
  124. package/src/lightning/interactiveDialogBase/interactiveDialogBase.css +494 -0
  125. package/src/lightning/interactiveDialogBase/interactiveDialogBase.html +63 -0
  126. package/src/lightning/interactiveDialogBase/interactiveDialogBase.js +200 -0
  127. package/src/lightning/menuItem/menuItem.js +4 -1
  128. package/src/lightning/modalBase/modalBase.css +20 -0
  129. package/src/lightning/modalBase/modalBase.html +54 -0
  130. package/src/lightning/modalBase/modalBase.js +1039 -0
  131. package/src/lightning/overlay/__docs__/overlay.md +90 -0
  132. package/src/lightning/overlay/__examples__/alert/alert.html +27 -0
  133. package/src/lightning/overlay/__examples__/alert/alert.js +33 -0
  134. package/src/lightning/overlay/__examples__/basic/basic.css +7 -0
  135. package/src/lightning/overlay/__examples__/basic/basic.html +18 -0
  136. package/src/lightning/overlay/__examples__/basic/basic.js +61 -0
  137. package/src/lightning/overlay/__examples__/demo/demo.html +29 -0
  138. package/src/lightning/overlay/__examples__/demo/demo.js +40 -0
  139. package/src/lightning/overlay/__examples__/panel/panel.html +17 -0
  140. package/src/lightning/overlay/__examples__/panel/panel.js +21 -0
  141. package/src/lightning/overlay/overlay.html +3 -0
  142. package/src/lightning/overlay/overlay.js +45 -0
  143. package/src/lightning/overlayContainer/__docs__/overlayContainer.md +0 -0
  144. package/src/lightning/overlayContainer/overlayContainer.html +3 -0
  145. package/src/lightning/overlayContainer/overlayContainer.js +138 -0
  146. package/src/lightning/overlayManager/overlayManager.js +54 -0
  147. package/src/lightning/overlayUtils/overlayUtils.js +17 -0
  148. package/src/lightning/picklist/picklist.js +6 -1
  149. package/src/lightning/progressBar/progressBar.html +2 -1
  150. package/src/lightning/progressBar/progressBar.js +18 -1
  151. package/src/lightning/prompt/__docs__/prompt.md +100 -0
  152. package/src/lightning/prompt/__examples__disabled/basic/basic.css +7 -0
  153. package/src/lightning/prompt/__examples__disabled/basic/basic.html +8 -0
  154. package/src/lightning/prompt/__examples__disabled/basic/basic.js +15 -0
  155. package/src/lightning/prompt/prompt.css +81 -0
  156. package/src/lightning/prompt/prompt.html +8 -0
  157. package/src/lightning/prompt/prompt.js +92 -0
  158. package/src/lightning/prompt/prompt.js-meta.xml +6 -0
  159. package/src/lightning/radioGroup/radioGroup.js +9 -0
  160. package/src/lightning/select/select.html +3 -1
  161. package/src/lightning/select/select.js +5 -1
  162. package/src/lightning/textarea/textarea.html +1 -0
  163. package/src/lightning/textarea/textarea.js +5 -0
  164. package/src/lightning/timepicker/timepicker.html +3 -1
  165. package/src/lightning/timepicker/timepicker.js +8 -0
  166. package/src/lightning/utilsPrivate/aria.js +26 -0
  167. package/src/lightning/utilsPrivate/linkify.js +1 -1
  168. package/src/lightning/utilsPrivate/utilsPrivate.js +7 -1
  169. package/src/lightning/icon/__component__/icon-spirite.spec.js +0 -59
@@ -0,0 +1,214 @@
1
+ const Datatable = require('pageobjects/datatable');
2
+ const Button = require('pageobjects/button');
3
+
4
+ const tableTypes = {
5
+ default: '[data-render-mode="default"]',
6
+ roleBased: '[data-render-mode="role-based"]',
7
+ };
8
+
9
+ describe('Datatable UTAM Page Object Tests', () => {
10
+ Object.keys(tableTypes).forEach((type) => {
11
+ describe(`${type} table`, () => {
12
+ const TABLE_SELECTOR = tableTypes[type];
13
+
14
+ let root;
15
+
16
+ beforeEach(async () => {
17
+ await browser.url('/datatable/utam');
18
+ root = await $('datatable-utam');
19
+ await root.waitForDisplayed();
20
+ });
21
+
22
+ it('should get the cell value by row and column index', async () => {
23
+ const datatable = await utam.load(Datatable, {
24
+ element: await root.shadow$(TABLE_SELECTOR),
25
+ });
26
+
27
+ const cellValue = await datatable.getCellValueByIndex(1, 2);
28
+ expect(cellValue).toBe('Billy Simmons');
29
+ });
30
+ it('should get the cell value by row index and column label', async () => {
31
+ const datatable = await utam.load(Datatable, {
32
+ element: await root.shadow$(TABLE_SELECTOR),
33
+ });
34
+
35
+ const cellValue = await datatable.getCellValueByLabel(2, 'Age');
36
+ expect(cellValue).toBe('35');
37
+ });
38
+ it('should get the number of rows in the table', async () => {
39
+ const datatable = await utam.load(Datatable, {
40
+ element: await root.shadow$(TABLE_SELECTOR),
41
+ });
42
+
43
+ const cellValue = await datatable.getNumRows();
44
+ expect(cellValue).toBe(4);
45
+ });
46
+ it('should tell if the table has any rows', async () => {
47
+ const datatable = await utam.load(Datatable, {
48
+ element: await root.shadow$(TABLE_SELECTOR),
49
+ });
50
+
51
+ const cellValue = await datatable.hasRows();
52
+ expect(cellValue).toBe(true);
53
+ });
54
+ it('should toggle selection of row - comprehensive', async () => {
55
+ const datatable = await utam.load(Datatable, {
56
+ element: await root.shadow$(TABLE_SELECTOR),
57
+ });
58
+
59
+ for (let i = 1; i <= 4; i++) {
60
+ expect(await datatable.isRowSelected(i)).toBe('false');
61
+ }
62
+
63
+ await datatable.toggleRowSelection(1);
64
+ expect(await datatable.isRowSelected(1)).toBe('true');
65
+ [2, 3, 4].forEach(async (i) => {
66
+ expect(await datatable.isRowSelected(i)).toBe('false');
67
+ });
68
+
69
+ await datatable.toggleRowSelection(2);
70
+ expect(await datatable.isRowSelected(2)).toBe('true');
71
+ [3, 4].forEach(async (i) => {
72
+ expect(await datatable.isRowSelected(i)).toBe('false');
73
+ });
74
+
75
+ await datatable.toggleRowSelection(3);
76
+ expect(await datatable.isRowSelected(3)).toBe('true');
77
+ expect(await datatable.isRowSelected(4)).toBe('false');
78
+
79
+ await datatable.toggleRowSelection(4);
80
+ expect(await datatable.isRowSelected(4)).toBe('true');
81
+ });
82
+ it('should toggle selection of row', async () => {
83
+ const datatable = await utam.load(Datatable, {
84
+ element: await root.shadow$(TABLE_SELECTOR),
85
+ });
86
+
87
+ await datatable.toggleRowSelection(3);
88
+ expect(await datatable.isRowSelected(3)).toBe('true');
89
+
90
+ await datatable.toggleRowSelection(3);
91
+ expect(await datatable.isRowSelected(3)).toBe('false');
92
+ });
93
+ it('should get the number of selected rows when not all rows are selected', async () => {
94
+ const datatable = await utam.load(Datatable, {
95
+ element: await root.shadow$(TABLE_SELECTOR),
96
+ });
97
+
98
+ await datatable.toggleRowSelection(3);
99
+ expect(await datatable.getNumSelectedRows()).toBe(1);
100
+
101
+ await datatable.toggleRowSelection(2);
102
+ expect(await datatable.getNumSelectedRows()).toBe(2);
103
+ });
104
+ it('should get the number of selected rows when all rows are selected', async () => {
105
+ const datatable = await utam.load(Datatable, {
106
+ element: await root.shadow$(TABLE_SELECTOR),
107
+ });
108
+
109
+ await datatable.clickSelectAllCheckbox();
110
+ expect(await datatable.getNumSelectedRows()).toBe(4);
111
+ });
112
+ it('should get the number of columns in the table', async () => {
113
+ const datatable = await utam.load(Datatable, {
114
+ element: await root.shadow$(TABLE_SELECTOR),
115
+ });
116
+
117
+ expect(await datatable.getNumColumns()).toBe(5);
118
+ });
119
+ it('should tell whether or not a column is sortable', async () => {
120
+ const datatable = await utam.load(Datatable, {
121
+ element: await root.shadow$(TABLE_SELECTOR),
122
+ });
123
+
124
+ expect(await datatable.isSortableColumn('Age')).toBe(true);
125
+
126
+ // Need to speak to UTAM (about isPresent) or find a better way to write this method
127
+ // If column is not sortable, the test fails with the error:
128
+ // "Can't find elements with locator 'lightning-primitive-header-factory.slds-is-sortable' inside its scope element."
129
+ // expect(await datatable.isSortableColumn('Name')).toBe(false);
130
+ });
131
+ it('should tell whether or not the row is selectable', async () => {
132
+ const datatable = await utam.load(Datatable, {
133
+ element: await root.shadow$(TABLE_SELECTOR),
134
+ });
135
+
136
+ expect(await datatable.isSelectableRow(1)).toBe(true);
137
+ });
138
+ it('should get the width of a column', async () => {
139
+ const datatable = await utam.load(Datatable, {
140
+ element: await root.shadow$(TABLE_SELECTOR),
141
+ });
142
+
143
+ const datatableElement = await root.shadow$(
144
+ 'lightning-datatable'
145
+ );
146
+ const columnHeader = await datatableElement.shadow$(
147
+ '[aria-label="Name"]'
148
+ );
149
+
150
+ // Remove intermediate white spaces
151
+ let expectedWidth = await columnHeader.getAttribute('style');
152
+ expectedWidth = expectedWidth.replace(/\s/g, '');
153
+ let actualWidth = await datatable.getWidth('Name');
154
+ actualWidth = actualWidth.replace(/\s/g, '');
155
+
156
+ // Using indexOf in case of presence of ';'
157
+ expect(actualWidth.indexOf(expectedWidth) >= 0).toBe(true);
158
+ });
159
+ it('should tell whether or not a column has header actions', async () => {
160
+ const datatable = await utam.load(Datatable, {
161
+ element: await root.shadow$(TABLE_SELECTOR),
162
+ });
163
+
164
+ expect(await datatable.hasHeaderActions('Name')).toBe(true);
165
+ expect(await datatable.hasHeaderActions('Age')).toBe(true);
166
+ // false fails; need to check for true or null; check with UTAM if expected
167
+ expect(await datatable.hasHeaderActions('Email')).toBe(null);
168
+ });
169
+ it('should get the text of the rowheader cell of the specified row', async () => {
170
+ const datatable = await utam.load(Datatable, {
171
+ element: await root.shadow$(TABLE_SELECTOR),
172
+ });
173
+
174
+ expect(await datatable.getRowHeaderText(2)).toBe(
175
+ 'Kelsey Denesik'
176
+ );
177
+ });
178
+ it('should click column header of the sortable column', async () => {
179
+ const datatable = await utam.load(Datatable, {
180
+ element: await root.shadow$(TABLE_SELECTOR),
181
+ });
182
+
183
+ let cellValue = await datatable.getCellValueByLabel(1, 'Age');
184
+ expect(cellValue).toBe('40');
185
+
186
+ await datatable.clickSortHeaderButton('Age');
187
+
188
+ cellValue = await datatable.getCellValueByLabel(1, 'Age');
189
+ expect(cellValue).toBe('35');
190
+ });
191
+ it('should tell whether the specified row has row actions or not', async () => {
192
+ const datatable = await utam.load(Datatable, {
193
+ element: await root.shadow$(TABLE_SELECTOR),
194
+ });
195
+
196
+ expect(await datatable.hasRowActionInRow(2)).toBe(true);
197
+ });
198
+ it('should tell whether or not the datatable has the loading indicator visible', async () => {
199
+ const datatable = await utam.load(Datatable, {
200
+ element: await root.shadow$(TABLE_SELECTOR),
201
+ });
202
+
203
+ expect(await datatable.isLoading()).toBe(false);
204
+
205
+ const button = await utam.load(Button, {
206
+ element: await root.shadow$('lightning-button'),
207
+ });
208
+ await button.click();
209
+
210
+ expect(await datatable.isLoading()).toBe(true);
211
+ });
212
+ });
213
+ });
214
+ });
@@ -13,33 +13,62 @@ const i18n = {
13
13
  rowActionsDefaultAriaLabel,
14
14
  };
15
15
 
16
+ export const SELECTABLE_ROW_CHECKBOX = 'SELECTABLE_CHECKBOX';
17
+
18
+ const SELECTABLE_COLUMN = {
19
+ type: SELECTABLE_ROW_CHECKBOX,
20
+ fixedWidth: 32,
21
+ tabIndex: -1,
22
+ internal: true,
23
+ };
24
+
25
+ /**
26
+ * Returns the columns default state.
27
+ *
28
+ * @returns {Object} The default column state.
29
+ */
16
30
  export function getColumnsDefaultState() {
17
31
  return {
18
32
  columns: [],
19
33
  };
20
34
  }
21
35
 
36
+ /**
37
+ * Returns whether or not the datatable has columns.
38
+ *
39
+ * @param {Object} state The datatable's state.
40
+ * @returns {Boolean} Whether the datatable has columns.
41
+ */
22
42
  export function hasColumns(state) {
23
43
  return getColumns(state).length > 0;
24
44
  }
25
45
 
46
+ /**
47
+ * Returns whether or not the column has been specified by the customer.
48
+ *
49
+ * @param {Object} column The column definition object.
50
+ * @returns {Boolean} Whether the column is customer defined or not.
51
+ */
26
52
  export function isCustomerColumn(column) {
27
53
  return column.internal !== true;
28
54
  }
29
55
 
56
+ /**
57
+ * Returns the datatable's columns from state.
58
+ *
59
+ * @param {Object} state The datatable's state.
60
+ * @returns {Array} The datatable's columns definition.
61
+ */
30
62
  export function getColumns(state) {
31
63
  return state.columns;
32
64
  }
33
65
 
34
- export const SELECTABLE_ROW_CHECKBOX = 'SELECTABLE_CHECKBOX';
35
-
36
- const SELECTABLE_COLUMN = {
37
- type: SELECTABLE_ROW_CHECKBOX,
38
- fixedWidth: 32,
39
- tabIndex: -1,
40
- internal: true,
41
- };
42
-
66
+ /**
67
+ * Returns whether any of the datatable's columns are editable.
68
+ *
69
+ * @param {Array} columns The datatable's column definition.
70
+ * @returns {Boolean} Whether any of the columns are editable.
71
+ */
43
72
  export function hasEditableColumn(columns) {
44
73
  return columns.some((column) => column.editable);
45
74
  }
@@ -50,8 +79,8 @@ export function hasEditableColumn(columns) {
50
79
  * that are present in both the input and output array, the relative ordering between
51
80
  * them that existed in the input array is maintained in the output array.
52
81
  *
53
- * @param {Array} columns - the datatable's column definitions. Must be truthy and must be
54
- * filled with truthy column definition objects.
82
+ * @param {Array} columns The datatable's column definition. Must be truthy and must be
83
+ * filled with truthy column definition objects.
55
84
  */
56
85
  export function getEditableColumns(columns) {
57
86
  return columns.filter((column) => column.editable);
@@ -64,8 +93,8 @@ export function getEditableColumns(columns) {
64
93
  * the invocation of this function results in a no-op because we instead rely on later
65
94
  * row level checks to determine cell editability.
66
95
  *
67
- * @param {Object} column column metadata
68
- * @param {Object} types the DatatableTypes object
96
+ * @param {Object} column The column definition object.
97
+ * @param {Object} types The DatatableTypes object.
69
98
  */
70
99
  export function normalizeEditable(column, types) {
71
100
  if (types.isEditableType(column.type)) {
@@ -81,10 +110,24 @@ export function normalizeEditable(column, types) {
81
110
  }
82
111
  }
83
112
 
113
+ /**
114
+ * Steps through and corrects column definitions inconsistencies.
115
+ *
116
+ * For customer-specified columns, we verify all parameters are valid and set
117
+ * how we would expect them to prevent errors from bubbling up.
118
+ * See `normalizeColumnDataType`, `normalizeEditable`.
119
+ *
120
+ * For tree-types, we verify all sub-type attributes are within our allowed
121
+ * parameters. See `getNormalizedSubTypeAttribute`.
122
+ *
123
+ * @param {Object} state The datatable state.
124
+ * @param {Array} columns The datatable's column definitions.
125
+ * @param {Object} types The type handling factory.
126
+ */
84
127
  export function normalizeColumns(state, columns, types) {
85
128
  if (columns.length !== 0) {
86
129
  let firstColumnForReaders = 0;
87
- // workaround https://git.soma.salesforce.com/raptor/raptor/issues/763
130
+ // Workaround: https://git.soma.salesforce.com/raptor/raptor/issues/763
88
131
  const normalizedColumns = Object.assign([], columns);
89
132
 
90
133
  if (!state.hideCheckboxColumn) {
@@ -100,7 +143,7 @@ export function normalizeColumns(state, columns, types) {
100
143
 
101
144
  const columnKeyMap = {};
102
145
  state.columns = normalizedColumns.map((column, index) => {
103
- // Verify columnKey is unique
146
+ // Verify `columnKey` is unique
104
147
  const columnKey = column.columnKey;
105
148
  if (columnKey && columnKeyMap[columnKey]) {
106
149
  console.error(
@@ -115,7 +158,8 @@ export function normalizeColumns(state, columns, types) {
115
158
  );
116
159
  normalizedColumn.ariaLabel =
117
160
  normalizedColumn.label || normalizedColumn.ariaLabel || null;
118
- // customType attribute is needed to render default iedit component
161
+
162
+ // `customType` attribute is needed to render default iedit component
119
163
  normalizedColumn.editableCustomType =
120
164
  types.isStandardCellLayoutForCustomType(normalizedColumn.type);
121
165
 
@@ -131,6 +175,7 @@ export function normalizeColumns(state, columns, types) {
131
175
  normalizedColumn.typeAttributes
132
176
  );
133
177
  }
178
+
134
179
  return Object.assign(normalizedColumn, {
135
180
  tabIndex: -1,
136
181
  colKeyValue: generateColKeyValue(normalizedColumn, index),
@@ -142,17 +187,12 @@ export function normalizeColumns(state, columns, types) {
142
187
  }
143
188
  }
144
189
 
145
- function normalizeColumnDataType(column, types) {
146
- if (!types.isValidType(column.type)) {
147
- column.type = getRegularColumnDefaults().type;
148
- }
149
- }
150
-
151
190
  /**
152
191
  * Normalizes the subType and subTypeAttributes in the typeAttributes.
153
- * @param {String} type the type of this column
154
- * @param {Object} typeAttributes the type attributes of the column
155
- * @returns {Object} a new typeAttributes object with the sybtype and subTypeAttributes normalized.
192
+ *
193
+ * @param {String} type The type of this column
194
+ * @param {Object} typeAttributes The type attributes of the column
195
+ * @returns {Object} A new typeAttributes object with the sybtype and subTypeAttributes normalized.
156
196
  */
157
197
  export function getNormalizedSubTypeAttribute(type, typeAttributes) {
158
198
  const typeAttributesOverrides = {};
@@ -166,42 +206,12 @@ export function getNormalizedSubTypeAttribute(type, typeAttributes) {
166
206
  return Object.assign({}, typeAttributes, typeAttributesOverrides);
167
207
  }
168
208
 
169
- function getRegularColumnDefaults() {
170
- return {
171
- type: 'text',
172
- typeAttributes: {},
173
- cellAttributes: {},
174
- };
175
- }
176
-
177
- function getActionColumnDefaults() {
178
- return {
179
- fixedWidth: 50,
180
- resizable: false,
181
- ariaLabel: i18n.rowActionsDefaultAriaLabel,
182
- };
183
- }
184
-
185
- function getTreeColumnDefaults() {
186
- return {
187
- type: 'tree',
188
- subType: 'text',
189
- typeAttributes: {},
190
- cellAttributes: {},
191
- };
192
- }
193
-
194
- function getColumnDefaults(column) {
195
- switch (column.type) {
196
- case 'action':
197
- return getActionColumnDefaults();
198
- case 'tree':
199
- return getTreeColumnDefaults();
200
- default:
201
- return getRegularColumnDefaults();
202
- }
203
- }
204
-
209
+ /**
210
+ * Retrieves the type attributes for a given column.
211
+ *
212
+ * @param {Object} column The column definition object.
213
+ * @returns Type attributes for the given column, if they exist.
214
+ */
205
215
  export function getTypeAttributesValues(column) {
206
216
  if (isObjectLike(column.typeAttributes)) {
207
217
  return column.typeAttributes;
@@ -209,6 +219,12 @@ export function getTypeAttributesValues(column) {
209
219
  return {};
210
220
  }
211
221
 
222
+ /**
223
+ * Retrieves the sub-type attributes for a given column.
224
+ *
225
+ * @param {Object} column The column definition object.
226
+ * @returns {Object} Sub-type attributes for the given column, if they exist.
227
+ */
212
228
  export function getSubTypeAttributesValues(column) {
213
229
  if (isObjectLike(column.typeAttributes.subTypeAttributes)) {
214
230
  return column.typeAttributes.subTypeAttributes;
@@ -216,6 +232,12 @@ export function getSubTypeAttributesValues(column) {
216
232
  return {};
217
233
  }
218
234
 
235
+ /**
236
+ * Retrieves the cell attributes for a given column.
237
+ *
238
+ * @param {Object} column The column definition object.
239
+ * @returns {Object} Cell attributes for the given column, if they exist.
240
+ */
219
241
  export function getCellAttributesValues(column) {
220
242
  if (isObjectLike(column.cellAttributes)) {
221
243
  return column.cellAttributes;
@@ -226,9 +248,9 @@ export function getCellAttributesValues(column) {
226
248
  /**
227
249
  * Generates a unique column key value.
228
250
  *
229
- * @param {object} columnMetadata - the object for an specific column metadata
230
- * @param {int} index - optionally, the index of the column.
231
- * @returns {string} It generate the column key value based on the column field name and type.
251
+ * @param {Object} columnMetadata The object for an specific column metadata
252
+ * @param {Integer} index Optionally, the index of the column.
253
+ * @returns {String} It generates the column key value based on the column field name and type.
232
254
  */
233
255
  export function generateColKeyValue(columnMetadata, index) {
234
256
  const { columnKey, fieldName, type } = columnMetadata;
@@ -239,9 +261,10 @@ export function generateColKeyValue(columnMetadata, index) {
239
261
  /**
240
262
  * Return the index in dt.columns (user definition) related to colKeyValue.
241
263
  * -1 if no column with that key exist or if its internal.
264
+ *
242
265
  * @param {Object} state The datatable state
243
266
  * @param {String} colKeyValue The generated key for the column
244
- * @return {Number} The index in dt.columns. -1 if not found or if its internal.
267
+ * @returns {Number} The index in `dt.columns`. -1 if not found or if its internal.
245
268
  */
246
269
  export function getUserColumnIndex(state, colKeyValue) {
247
270
  const stateColumnIndex = getStateColumnIndex(state, colKeyValue);
@@ -267,8 +290,8 @@ export function getUserColumnIndex(state, colKeyValue) {
267
290
  *
268
291
  * These indexes are set in the state object - `state.headerIndexes`
269
292
  *
270
- * @param {object} columns - the current normalized column metadata
271
- * @returns {object} headerIndexes e.g. { 'name-text': 0, 'amount-number': 1 }
293
+ * @param {Object} columns The current normalized column metadata
294
+ * @returns {Object} headerIndexes e.g. { 'name-text': 0, 'amount-number': 1 }
272
295
  */
273
296
  export const generateHeaderIndexes = function (columns) {
274
297
  return columns.reduce((prev, col, index) => {
@@ -282,17 +305,18 @@ export const generateHeaderIndexes = function (columns) {
282
305
  *
283
306
  * @param {Object} state The datatable state
284
307
  * @param {String} colKeyValue The generated key for the column
285
- * @return {number} The index in state.columns.
308
+ * @returns {Number} The index in state.columns
286
309
  */
287
310
  export function getStateColumnIndex(state, colKeyValue) {
288
311
  return state.headerIndexes[colKeyValue];
289
312
  }
290
313
 
291
314
  /**
315
+ * Retrieves a column index number by its key.
292
316
  *
293
- * @param {Object} state - The datatable state
294
- * @param {String} key - the key of the column. Defaults to field name if 'columnKey' is not provided.
295
- * @returns {number} The index in state.columns, -1 if it does not exist
317
+ * @param {Object} state The datatable state
318
+ * @param {String} key The key of the column. Defaults to field name if 'columnKey' is not provided.
319
+ * @returns {Number} The index in state.columns, -1 if it does not exist
296
320
  */
297
321
  export function getColumnIndexByColumnKey(state, key) {
298
322
  let i = 0;
@@ -307,3 +331,74 @@ export function getColumnIndexByColumnKey(state, key) {
307
331
 
308
332
  return existFieldName ? i : -1;
309
333
  }
334
+
335
+ /************************** PRIVATE METHODS ***************************/
336
+
337
+ /**
338
+ * If the specified column type is not supported, resets it to default.
339
+ *
340
+ * @param {Object} column The column definition object.
341
+ * @param {Object} types The type handling factory.
342
+ */
343
+ function normalizeColumnDataType(column, types) {
344
+ if (!types.isValidType(column.type)) {
345
+ column.type = getRegularColumnDefaults().type;
346
+ }
347
+ }
348
+
349
+ /**
350
+ * Returns the column defaults based on its type.
351
+ *
352
+ * @param {Object} column The column definition object.
353
+ * @returns {Object} The column defaults.
354
+ */
355
+ function getColumnDefaults(column) {
356
+ switch (column.type) {
357
+ case 'action':
358
+ return getActionColumnDefaults();
359
+ case 'tree':
360
+ return getTreeColumnDefaults();
361
+ default:
362
+ return getRegularColumnDefaults();
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Retrieves the defaults for regular columns.
368
+ *
369
+ * @returns {Object} Regular column defaults
370
+ */
371
+ function getRegularColumnDefaults() {
372
+ return {
373
+ type: 'text',
374
+ typeAttributes: {},
375
+ cellAttributes: {},
376
+ };
377
+ }
378
+
379
+ /**
380
+ * Retrieves the defaults for action columns.
381
+ *
382
+ * @returns {Object} Action column defaults
383
+ */
384
+ function getActionColumnDefaults() {
385
+ return {
386
+ fixedWidth: 50,
387
+ resizable: false,
388
+ ariaLabel: i18n.rowActionsDefaultAriaLabel,
389
+ };
390
+ }
391
+
392
+ /**
393
+ * Retrieves the defaults for tree columns.
394
+ *
395
+ * @returns {Object} Tree column defaults
396
+ */
397
+ function getTreeColumnDefaults() {
398
+ return {
399
+ type: 'tree',
400
+ subType: 'text',
401
+ typeAttributes: {},
402
+ cellAttributes: {},
403
+ };
404
+ }