@zohodesk/library-platform 1.1.0 → 1.1.1

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 (41) hide show
  1. package/es/bc/list-selection/Constants.js +8 -1
  2. package/es/bc/list-selection/Properties.js +6 -2
  3. package/es/bc/zlist/Properties.js +9 -0
  4. package/es/cc/table-connected/constants/Events.js +7 -0
  5. package/es/cc/table-connected/constants/index.js +1 -0
  6. package/es/cc/table-connected/index.js +4 -0
  7. package/es/cc/table-list/Properties.js +42 -0
  8. package/es/desk-frameworks/table-connected/frameworks/EventHandlersFactory.js +33 -1
  9. package/es/desk-frameworks/table-connected/frameworks/ListSdkFactory.js +46 -17
  10. package/es/desk-frameworks/table-connected/frameworks/TableConnectedFactory.js +2 -1
  11. package/es/desk-frameworks/table-connected/frameworks/TableConnectedView.js +2 -0
  12. package/es/library/behaviours/list-selection/adapters/controllers/AllSelectionController.js +5 -2
  13. package/es/library/behaviours/list-selection/adapters/controllers/DeselectController.js +26 -0
  14. package/es/library/behaviours/list-selection/adapters/controllers/RangeSelectionController.js +4 -2
  15. package/es/library/behaviours/list-selection/adapters/controllers/SelectController.js +26 -0
  16. package/es/library/behaviours/list-selection/adapters/controllers/SelectionController.js +4 -2
  17. package/es/library/behaviours/list-selection/adapters/gateways/Repository.js +3 -3
  18. package/es/library/behaviours/list-selection/adapters/gateways/Service.js +8 -0
  19. package/es/library/behaviours/list-selection/applications/interfaces/input/DeselectInputModel.js +1 -0
  20. package/es/library/behaviours/list-selection/applications/interfaces/input/SelectInputModel.js +1 -0
  21. package/es/library/behaviours/list-selection/applications/usecases/AllItemSelection.js +5 -1
  22. package/es/library/behaviours/list-selection/applications/usecases/Deselect.js +21 -0
  23. package/es/library/behaviours/list-selection/applications/usecases/ItemsSelection.js +3 -1
  24. package/es/library/behaviours/list-selection/applications/usecases/RangeSelection.js +3 -1
  25. package/es/library/behaviours/list-selection/applications/usecases/Select.js +21 -0
  26. package/es/library/behaviours/list-selection/domain/entities/ListItemSelection.js +86 -28
  27. package/es/library/behaviours/list-selection/frameworks/ActionHandlerFactory.js +5 -1
  28. package/es/library/custom-component/domain/entities/{Events.js → Event.js} +12 -3
  29. package/es/library/custom-component/domain/entities/interfaces/EventModel.js +1 -0
  30. package/es/library/dot/components/table-list/adapters/presenters/TableTranslator.js +9 -4
  31. package/es/library/dot/components/table-list/frameworks/ui/TableList.js +1 -2
  32. package/es/library/dot/components/table-list/frameworks/ui/TableListView.js +3 -2
  33. package/es/library/dot/components/table-list/frameworks/ui/sub-components/Header.js +4 -2
  34. package/es/library/dot/components/table-list/frameworks/ui/sub-components/header/SelectAll.js +2 -1
  35. package/es/library/dot/components/table-list/frameworks/ui/sub-components/row/RowSelection.js +1 -2
  36. package/es/platform/zlist/adapters/gateways/Repository.js +4 -2
  37. package/es/platform/zlist/adapters/presenters/TableTranslator.js +1 -0
  38. package/es/platform/zlist/applications/entities-factory/ListFactory.js +2 -2
  39. package/es/platform/zlist/domain/entities/List.js +17 -18
  40. package/package.json +2 -2
  41. package/es/cc/table-connected/Constants.js +0 -4
@@ -1,3 +1,10 @@
1
1
  export const LIST_SELECTION_TOGGLE_ITEMS = 'LIST_SELECTION#TOGGLE_ITEMS';
2
2
  export const LIST_SELECTION_TOGGLE_ALL = 'LIST_SELECTION#TOGGLE_ALL';
3
- export const LIST_SELECTION_TOGGLE_ITEMS_IN_RANGE = 'LIST_SELECTION#TOGGLE_ITEMS_IN_RANGE';
3
+ export const LIST_SELECTION_TOGGLE_ITEMS_IN_RANGE = 'LIST_SELECTION#TOGGLE_ITEMS_IN_RANGE';
4
+ export const LIST_SELECTION_SELECT_ITEM = 'LIST_SELECTION#SELECT_ITEM';
5
+ export const LIST_SELECTION_DESELECT_ITEM = 'LIST_SELECTION#DESELECT_ITEM';
6
+ export const LIST_SELECTION_SELECT_ALL = 'LIST_SELECTION#SELECT_ALL';
7
+ export const LIST_SELECTION_DESELECT_ALL = 'LIST_SELECTION#DESELECT_ALL';
8
+ export const LIST_SELECTION_RECORDS_SELECTED = 'LIST_SELECTION#RECORDS_SELECTED';
9
+ export const LIST_SELECTION_RECORDS_DESELECTED = 'LIST_SELECTION#RECORDS_DESELECTED';
10
+ export const LIST_SELECTION_SELECTION_LIMIT_EXCEEDED = 'LIST_SELECTION#SELECTION_LIMIT_EXCEEDED';
@@ -2,9 +2,10 @@ export default {
2
2
  selectionConfig: {
3
3
  required: false,
4
4
  defaultValue: {
5
- isEnabled: false,
6
5
  maxSelectionCount: 50,
7
- limitExceedAlertMessage: 'Max records selected'
6
+ limitExceedAlertMessage: 'Max records selected',
7
+ isEnabled: false,
8
+ isSelectAllEnabled: false
8
9
  },
9
10
  typeMetadata: {
10
11
  schema: {
@@ -18,6 +19,9 @@ export default {
18
19
  },
19
20
  limitExceedAlertMessage: {
20
21
  type: 'string'
22
+ },
23
+ isSelectAllEnabled: {
24
+ type: 'boolean'
21
25
  }
22
26
  }
23
27
  }
@@ -23,6 +23,15 @@ export default {
23
23
  }
24
24
  }
25
25
  },
26
+ query: {
27
+ required: false,
28
+ defaultValue: {},
29
+ typeMetadata: {
30
+ schema: {
31
+ type: 'object'
32
+ }
33
+ }
34
+ },
26
35
  context: {
27
36
  required: true,
28
37
  typeMetadata: {
@@ -0,0 +1,7 @@
1
+ export default {
2
+ DELETE_RECORDS_SUCCESS: 'SMART_TABLE#RECORD_DELETED',
3
+ UPDATE_RECORDS_SUCCESS: 'SMART_TABLE#RECORD_UPDATED',
4
+ RECORDS_SELECTED: 'SMART_TABLE#RECORDS_SELECTED',
5
+ RECORDS_DESELECTED: 'SMART_TABLE#RECORDS_DESELECTED',
6
+ SELECTION_LIMIT_EXCEEDED: 'SMART_TABLE#SELECTION_LIMIT_EXCEEDED'
7
+ };
@@ -0,0 +1 @@
1
+ export { default as Events } from "./Events";
@@ -0,0 +1,4 @@
1
+ import * as _SmartTableConstants from "./constants";
2
+ export { _SmartTableConstants as SmartTableConstants };
3
+ import * as _SmartTableProperties from "./Properties";
4
+ export { _SmartTableProperties as SmartTableProperties };
@@ -192,6 +192,9 @@ const TableListProperties = {
192
192
  },
193
193
  selectionTooltip: {
194
194
  type: 'string'
195
+ },
196
+ isSelectAllEnabled: {
197
+ type: 'boolean'
195
198
  }
196
199
  },
197
200
  required: ['id', 'columns']
@@ -201,6 +204,45 @@ const TableListProperties = {
201
204
  required: ['headers', 'rows']
202
205
  }
203
206
  }
207
+ },
208
+ selection: {
209
+ required: true,
210
+ typeMetadata: {
211
+ schema: {
212
+ type: 'object',
213
+ properties: {
214
+ selected: {
215
+ type: 'array',
216
+ items: {
217
+ type: 'string'
218
+ }
219
+ },
220
+ hasAllSelected: {
221
+ type: 'boolean'
222
+ }
223
+ },
224
+ required: ['selected', 'hasAllSelected']
225
+ }
226
+ }
227
+ },
228
+ selectionConfig: {
229
+ required: true,
230
+ typeMetadata: {
231
+ schema: {
232
+ type: 'object',
233
+ properties: {
234
+ maxSelectionCount: {
235
+ type: 'number'
236
+ },
237
+ isEnabled: {
238
+ type: 'boolean'
239
+ },
240
+ isSelectAllEnabled: {
241
+ type: 'boolean'
242
+ }
243
+ }
244
+ }
245
+ }
204
246
  }
205
247
  };
206
248
  export default TableListProperties;
@@ -1,4 +1,6 @@
1
+ import { LIST_SELECTION_RECORDS_DESELECTED, LIST_SELECTION_RECORDS_SELECTED, LIST_SELECTION_SELECTION_LIMIT_EXCEEDED } from "../../../bc/list-selection/Constants";
1
2
  import ListSdkFactory from "./ListSdkFactory";
3
+ import { SmartTableConstants } from "../../../cc/table-connected";
2
4
 
3
5
  function createHandlerWithSdk(handler) {
4
6
  return input => {
@@ -20,7 +22,37 @@ export default class EventHandlersFactory {
20
22
  return [eventName, handler];
21
23
  }));
22
24
  return { ...wrapped,
23
- NAVIGATION: NavigationHandler
25
+ NAVIGATION: NavigationHandler,
26
+ [LIST_SELECTION_RECORDS_SELECTED]: _ref => {
27
+ let {
28
+ action,
29
+ dispatch
30
+ } = _ref;
31
+ return dispatch({
32
+ type: SmartTableConstants.Events.RECORDS_SELECTED,
33
+ payload: action.payload
34
+ });
35
+ },
36
+ [LIST_SELECTION_RECORDS_DESELECTED]: _ref2 => {
37
+ let {
38
+ action,
39
+ dispatch
40
+ } = _ref2;
41
+ return dispatch({
42
+ type: SmartTableConstants.Events.RECORDS_DESELECTED,
43
+ payload: action.payload
44
+ });
45
+ },
46
+ [LIST_SELECTION_SELECTION_LIMIT_EXCEEDED]: _ref3 => {
47
+ let {
48
+ action,
49
+ dispatch
50
+ } = _ref3;
51
+ return dispatch({
52
+ type: SmartTableConstants.Events.SELECTION_LIMIT_EXCEEDED,
53
+ payload: action.payload
54
+ });
55
+ }
24
56
  };
25
57
  }
26
58
 
@@ -1,3 +1,4 @@
1
+ import { LIST_SELECTION_DESELECT_ITEM, LIST_SELECTION_SELECT_ITEM } from "../../../bc/list-selection/Constants";
1
2
  import { ZLIST_DELETE_RECORD, ZLIST_DELETE_RECORDS, ZLIST_RECORD_UPDATE } from "../../../bc/zlist/Constants";
2
3
  import { RECORD_LOCAL_MULTIPLE_DELETE, RECORD_LOCAL_UPDATE } from "../../../bc/zrecord/Constants";
3
4
  /* eslint-disable max-lines-per-function */
@@ -44,10 +45,10 @@ export default class ListSdkFactory {
44
45
 
45
46
  deleteRecord(recordId) {
46
47
  let output = {
47
- "data": [{
48
- "id": recordId,
49
- "Success": true,
50
- "error": null
48
+ data: [{
49
+ id: recordId,
50
+ Success: true,
51
+ error: null
51
52
  }]
52
53
  };
53
54
  dispatch({
@@ -70,7 +71,7 @@ export default class ListSdkFactory {
70
71
  deleteRecords(recordIds) {
71
72
  let shouldFetch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
72
73
  let output = {
73
- "data": []
74
+ data: []
74
75
  };
75
76
  let DELETE_ACTION = shouldFetch ? ZLIST_DELETE_RECORDS : RECORD_LOCAL_MULTIPLE_DELETE;
76
77
  dispatch({
@@ -82,9 +83,9 @@ export default class ListSdkFactory {
82
83
 
83
84
  for (let recordId of recordIds) {
84
85
  let recordUpdateDetail = {
85
- "id": recordId,
86
- "Success": true,
87
- "error": null
86
+ id: recordId,
87
+ Success: true,
88
+ error: null
88
89
  };
89
90
  output.data.push(recordUpdateDetail);
90
91
  }
@@ -94,10 +95,10 @@ export default class ListSdkFactory {
94
95
 
95
96
  updateRecord(recordId, record) {
96
97
  let output = {
97
- "results": [{
98
- "id": recordId,
99
- "Success": true,
100
- "error": null
98
+ results: [{
99
+ id: recordId,
100
+ Success: true,
101
+ error: null
101
102
  }]
102
103
  };
103
104
  dispatch({
@@ -113,7 +114,7 @@ export default class ListSdkFactory {
113
114
  updateRecords(recordsMap) {
114
115
  let shouldFetch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
115
116
  let output = {
116
- "results": []
117
+ results: []
117
118
  };
118
119
  let UPDATE_ACTION = shouldFetch ? ZLIST_RECORD_UPDATE : RECORD_LOCAL_UPDATE;
119
120
 
@@ -126,16 +127,44 @@ export default class ListSdkFactory {
126
127
  }
127
128
  });
128
129
  let recordUpdateDetail = {
129
- "id": record.id,
130
- "Success": true,
131
- "error": null
130
+ id: record.id,
131
+ Success: true,
132
+ error: null
132
133
  };
133
134
  output.results.push(recordUpdateDetail);
134
135
  }
135
136
 
136
137
  return output;
137
- }
138
+ },
138
139
 
140
+ selectRecords: ids => {
141
+ dispatch({
142
+ type: LIST_SELECTION_SELECT_ITEM,
143
+ payload: {
144
+ ids
145
+ }
146
+ });
147
+ },
148
+ deselectRecords: ids => {
149
+ dispatch({
150
+ type: LIST_SELECTION_DESELECT_ITEM,
151
+ payload: {
152
+ ids
153
+ }
154
+ });
155
+ },
156
+ selectAllRecords: () => {
157
+ dispatch({
158
+ type: LIST_SELECTION_SELECT_ITEM,
159
+ payload: {}
160
+ });
161
+ },
162
+ deselectAllRecords: () => {
163
+ dispatch({
164
+ type: LIST_SELECTION_DESELECT_ITEM,
165
+ payload: {}
166
+ });
167
+ }
139
168
  }
140
169
  };
141
170
  }
@@ -10,6 +10,7 @@ import TableConnectedView from "./TableConnectedView";
10
10
  import defaultDataSource from "../../../platform/data-source";
11
11
  import DataSourceBehaviourFactory from "../../../platform/zdata-source/frameworks/DataBrokerBehaviourFactory";
12
12
  import ClientActionsBehaviourFactory from "../../../platform/client-actions/behaviour/zclient-actions/frameworks/ClientActionsBehaviourFactory";
13
+ import ListItemSelectionBehaviourFactory from "../../../library/behaviours/list-selection/frameworks/ListItemSelectionBehaviourFactory";
13
14
  export default class TableConnectedFactory {
14
15
  static create(_ref) {
15
16
  var _dataSource2;
@@ -43,7 +44,7 @@ export default class TableConnectedFactory {
43
44
  }), ZFieldBehaviourFactory.create({
44
45
  availableFields: _dataSource.httpTemplates.getAvailableFields,
45
46
  selectedFields: _dataSource.httpTemplates.getSelectedFields
46
- }), ZListBehaviourFactory.create()]
47
+ }), ZListBehaviourFactory.create(), ListItemSelectionBehaviourFactory.create()]
47
48
  });
48
49
  }
49
50
 
@@ -11,6 +11,7 @@ function View(_ref, ref) {
11
11
  data = [],
12
12
  rowActionsConfig,
13
13
  rowCursor,
14
+ selection,
14
15
  properties,
15
16
  emptyStateUiType
16
17
  } = state;
@@ -29,6 +30,7 @@ function View(_ref, ref) {
29
30
  rowActionsConfig: rowActionsConfig,
30
31
  isLoading: isLoading,
31
32
  emptyStateUiType: emptyStateUiType,
33
+ selection: selection,
32
34
  selectionConfig: selectionConfig
33
35
  });
34
36
  }
@@ -4,13 +4,16 @@ class AllSelectionController extends AbstractController {
4
4
  handle(event) {
5
5
  const {
6
6
  state,
7
- updateState
7
+ updateState,
8
+ dispatch
8
9
  } = event;
9
10
  const {
10
11
  allSelectionUseCase
11
12
  } = this.service;
12
13
  allSelectionUseCase.updateDependencies(state, updateState);
13
- allSelectionUseCase.execute();
14
+ allSelectionUseCase.execute({
15
+ dispatch
16
+ });
14
17
  }
15
18
 
16
19
  }
@@ -0,0 +1,26 @@
1
+ import AbstractController from "./AbstractController";
2
+
3
+ class DeselectController extends AbstractController {
4
+ handle(event) {
5
+ const {
6
+ state,
7
+ action,
8
+ updateState,
9
+ dispatch
10
+ } = event;
11
+ const {
12
+ ids
13
+ } = action.payload;
14
+ const {
15
+ deselectUseCase
16
+ } = this.service;
17
+ deselectUseCase.updateDependencies(state, updateState);
18
+ deselectUseCase.execute({
19
+ ids,
20
+ dispatch
21
+ });
22
+ }
23
+
24
+ }
25
+
26
+ export default DeselectController;
@@ -5,7 +5,8 @@ class RangeSelectionController extends AbstractController {
5
5
  const {
6
6
  state,
7
7
  action,
8
- updateState
8
+ updateState,
9
+ dispatch
9
10
  } = event;
10
11
  const {
11
12
  id
@@ -15,7 +16,8 @@ class RangeSelectionController extends AbstractController {
15
16
  } = this.service;
16
17
  rangeSelectionUseCase.updateDependencies(state, updateState);
17
18
  rangeSelectionUseCase.execute({
18
- id
19
+ id,
20
+ dispatch
19
21
  });
20
22
  }
21
23
 
@@ -0,0 +1,26 @@
1
+ import AbstractController from "./AbstractController";
2
+
3
+ class SelectController extends AbstractController {
4
+ handle(event) {
5
+ const {
6
+ state,
7
+ action,
8
+ updateState,
9
+ dispatch
10
+ } = event;
11
+ const {
12
+ ids
13
+ } = action.payload;
14
+ const {
15
+ selectUseCase
16
+ } = this.service;
17
+ selectUseCase.updateDependencies(state, updateState);
18
+ selectUseCase.execute({
19
+ ids,
20
+ dispatch
21
+ });
22
+ }
23
+
24
+ }
25
+
26
+ export default SelectController;
@@ -5,7 +5,8 @@ class SelectionController extends AbstractController {
5
5
  const {
6
6
  state,
7
7
  action,
8
- updateState
8
+ updateState,
9
+ dispatch
9
10
  } = event;
10
11
  const {
11
12
  selected
@@ -15,7 +16,8 @@ class SelectionController extends AbstractController {
15
16
  } = this.service;
16
17
  selectionUseCase.updateDependencies(state, updateState);
17
18
  selectionUseCase.execute({
18
- selected
19
+ selected,
20
+ dispatch
19
21
  });
20
22
  }
21
23
 
@@ -14,7 +14,8 @@ class Repository {
14
14
  getListItemSelection() {
15
15
  const {
16
16
  behaviours,
17
- properties
17
+ properties,
18
+ data
18
19
  } = this.state;
19
20
  /* eslint-disable-next-line @zohodesk/architecturerules/no-defaultProps-rule */
20
21
 
@@ -24,8 +25,7 @@ class Repository {
24
25
  /* eslint-disable-next-line @zohodesk/architecturerules/no-defaultProps-rule */
25
26
 
26
27
  const {
27
- selectionConfig,
28
- data
28
+ selectionConfig
29
29
  } = properties || {};
30
30
  const itemIds = data === null || data === void 0 ? void 0 : data.rows.map(item => item.id);
31
31
  const maxSelectionCount = selectionConfig === null || selectionConfig === void 0 ? void 0 : selectionConfig.maxSelectionCount;
@@ -5,6 +5,8 @@ import AllItemsSelection from "../../applications/usecases/AllItemSelection";
5
5
  import ItemRangeSelection from "../../applications/usecases/RangeSelection";
6
6
  import ItemsSelection from "../../applications/usecases/ItemsSelection";
7
7
  import Destruct from "../../applications/usecases/Destruct";
8
+ import Select from "../../applications/usecases/Select";
9
+ import Deselect from "../../applications/usecases/Deselect";
8
10
 
9
11
  class Service {
10
12
  constructor(dependencies) {
@@ -18,11 +20,17 @@ class Service {
18
20
 
19
21
  _defineProperty(this, "rangeSelectionUseCase", void 0);
20
22
 
23
+ _defineProperty(this, "selectUseCase", void 0);
24
+
25
+ _defineProperty(this, "deselectUseCase", void 0);
26
+
21
27
  this.initializeUseCase = new Initialize(dependencies);
22
28
  this.destructUseCase = new Destruct(dependencies);
23
29
  this.selectionUseCase = new ItemsSelection(dependencies);
24
30
  this.allSelectionUseCase = new AllItemsSelection(dependencies);
25
31
  this.rangeSelectionUseCase = new ItemRangeSelection(dependencies);
32
+ this.selectUseCase = new Select(dependencies);
33
+ this.deselectUseCase = new Deselect(dependencies);
26
34
  }
27
35
 
28
36
  }
@@ -1,13 +1,17 @@
1
1
  import AbstractUseCase from "./AbstractUseCase";
2
2
 
3
3
  class AllItemsSelection extends AbstractUseCase {
4
- execute() {
4
+ execute(_ref) {
5
+ let {
6
+ dispatch
7
+ } = _ref;
5
8
  const {
6
9
  repository,
7
10
  presenter
8
11
  } = this.dependencies;
9
12
  const listItemSelection = repository.getListItemSelection();
10
13
  listItemSelection.toggleAll();
14
+ listItemSelection.createDispatchProps().map(event => dispatch(event));
11
15
  presenter.updateListItemSelection(listItemSelection.toObject());
12
16
  }
13
17
 
@@ -0,0 +1,21 @@
1
+ import AbstractUseCase from "./AbstractUseCase";
2
+
3
+ class Deselect extends AbstractUseCase {
4
+ execute(inputModel) {
5
+ const {
6
+ repository,
7
+ presenter
8
+ } = this.dependencies;
9
+ const {
10
+ ids,
11
+ dispatch
12
+ } = inputModel;
13
+ const listItemSelection = repository.getListItemSelection();
14
+ listItemSelection.deselectItems(ids);
15
+ listItemSelection.createDispatchProps().map(event => dispatch(event));
16
+ presenter.updateListItemSelection(listItemSelection.toObject());
17
+ }
18
+
19
+ }
20
+
21
+ export default Deselect;
@@ -7,10 +7,12 @@ class ItemsSelection extends AbstractUseCase {
7
7
  presenter
8
8
  } = this.dependencies;
9
9
  const {
10
- selected
10
+ selected,
11
+ dispatch
11
12
  } = inputModel;
12
13
  const listItemSelection = repository.getListItemSelection();
13
14
  listItemSelection.toggleItems(selected);
15
+ listItemSelection.createDispatchProps().map(event => dispatch(event));
14
16
  presenter.updateListItemSelection(listItemSelection.toObject());
15
17
  }
16
18
 
@@ -7,10 +7,12 @@ class ItemRangeSelection extends AbstractUseCase {
7
7
  presenter
8
8
  } = this.dependencies;
9
9
  const {
10
- id
10
+ id,
11
+ dispatch
11
12
  } = inputModel;
12
13
  let listItemSelection = repository.getListItemSelection();
13
14
  listItemSelection.toggleUpto(id);
15
+ listItemSelection.createDispatchProps().map(event => dispatch(event));
14
16
  presenter.updateListItemSelection(listItemSelection.toObject());
15
17
  }
16
18
 
@@ -0,0 +1,21 @@
1
+ import AbstractUseCase from "./AbstractUseCase";
2
+
3
+ class Select extends AbstractUseCase {
4
+ execute(inputModel) {
5
+ const {
6
+ repository,
7
+ presenter
8
+ } = this.dependencies;
9
+ const {
10
+ ids,
11
+ dispatch
12
+ } = inputModel;
13
+ const listItemSelection = repository.getListItemSelection();
14
+ listItemSelection.selectItems(ids);
15
+ listItemSelection.createDispatchProps().map(event => dispatch(event));
16
+ presenter.updateListItemSelection(listItemSelection.toObject());
17
+ }
18
+
19
+ }
20
+
21
+ export default Select;
@@ -1,34 +1,46 @@
1
+ import Event from "../../../../custom-component/domain/entities/Event";
2
+ import { LIST_SELECTION_RECORDS_DESELECTED, LIST_SELECTION_RECORDS_SELECTED, LIST_SELECTION_SELECTION_LIMIT_EXCEEDED } from "../../../../../bc/list-selection/Constants";
3
+
1
4
  class ListItemSelection {
2
5
  constructor(selected, itemIds, maxSelectionCount) {
6
+ let selectionStatus = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'na';
3
7
  this.selected = selected;
4
8
  this.itemIds = itemIds;
5
9
  this.maxSelectionCount = maxSelectionCount;
10
+ this.selectionStatus = selectionStatus;
6
11
  this.selected = this.selected.filter(selectedId => this.itemIds.includes(selectedId)); // NOTE: Remove items that does not exist
7
12
  }
8
13
 
9
- selectItem(id) {
10
- this.selected.push(id);
11
- }
14
+ selectItems(ids) {
15
+ if (!ids) {
16
+ this.selectAllItems();
17
+ return;
18
+ }
12
19
 
13
- deselectItem(id) {
14
- this.selected = this.selected.filter(selectedId => selectedId !== id);
20
+ ids.forEach(id => !this.hasAllSelected() && this.selectItem(id));
15
21
  }
16
22
 
17
- isSelected(id) {
18
- return this.selected.includes(id);
23
+ deselectItems(ids) {
24
+ if (!ids) {
25
+ this.deselectAllItems();
26
+ return;
27
+ }
28
+
29
+ ids.forEach(id => this.deselectItem(id));
19
30
  }
20
31
 
21
- hasAllSelected() {
22
- const hasMaxSelected = this.selected.length >= this.maxSelectionCount;
23
- const allItemsSelected = this.selected.length === this.itemIds.length && this.selected.length > 0;
24
- return hasMaxSelected || allItemsSelected;
32
+ selectAllItems() {
33
+ this.itemIds.forEach(id => !this.hasAllSelected() && this.selectItem(id));
25
34
  }
26
35
 
27
- getStrategy(id) {
28
- return (this.isSelected(id) ? this.deselectItem : this.selectItem).bind(this);
36
+ deselectAllItems() {
37
+ this.selected = [];
38
+ this.selectionStatus = 'na';
29
39
  }
30
40
 
31
41
  toggleItems(ids) {
42
+ // let selectingItems = ids.filter(id => !this.isSelected(id));
43
+ // this.selectItems(selectingItems);
32
44
  for (let id of ids) {
33
45
  if (this.isSelected(id)) {
34
46
  this.deselectItem(id);
@@ -54,8 +66,68 @@ class ListItemSelection {
54
66
  }
55
67
  }
56
68
  } else {
57
- this.selected = [];
69
+ this.deselectAllItems();
70
+ }
71
+ }
72
+
73
+ toggleUpto(id) {
74
+ let lastItem = this.selected.at(-1) || id;
75
+ let startIndex = this.itemIds.indexOf(lastItem);
76
+ let endIndex = this.itemIds.indexOf(id);
77
+ this.toggleRange(startIndex, endIndex);
78
+ }
79
+
80
+ toObject() {
81
+ return {
82
+ selected: this.selected,
83
+ hasAllSelected: this.hasAllSelected()
84
+ };
85
+ }
86
+
87
+ createDispatchProps() {
88
+ const events = [];
89
+
90
+ if (this.selectionStatus === 'selected') {
91
+ events.push(new Event(LIST_SELECTION_RECORDS_SELECTED, {
92
+ recordIds: this.selected
93
+ }));
94
+ }
95
+
96
+ if (this.selectionStatus === 'deselected') {
97
+ events.push(new Event(LIST_SELECTION_RECORDS_DESELECTED, {
98
+ recordIds: this.selected
99
+ }));
100
+ }
101
+
102
+ if (this.selectionStatus === 'na' && this.hasAllSelected()) {
103
+ events.push(new Event(LIST_SELECTION_SELECTION_LIMIT_EXCEEDED));
58
104
  }
105
+
106
+ return events.map(event => event.toObject());
107
+ }
108
+
109
+ selectItem(id) {
110
+ this.selected.push(id);
111
+ this.selectionStatus = 'selected';
112
+ }
113
+
114
+ deselectItem(id) {
115
+ this.selected = this.selected.filter(selectedId => selectedId !== id);
116
+ this.selectionStatus = 'deselected';
117
+ }
118
+
119
+ isSelected(id) {
120
+ return this.selected.includes(id);
121
+ }
122
+
123
+ hasAllSelected() {
124
+ const hasMaxSelected = this.selected.length >= this.maxSelectionCount;
125
+ const allItemsSelected = this.selected.length === this.itemIds.length && this.selected.length > 0;
126
+ return hasMaxSelected || allItemsSelected;
127
+ }
128
+
129
+ getStrategy(id) {
130
+ return (this.isSelected(id) ? this.deselectItem : this.selectItem).bind(this);
59
131
  }
60
132
 
61
133
  toggleRange(startIndex, endIndex) {
@@ -94,20 +166,6 @@ class ListItemSelection {
94
166
  }
95
167
  }
96
168
 
97
- toggleUpto(id) {
98
- let lastItem = this.selected.at(-1) || id;
99
- let startIndex = this.itemIds.indexOf(lastItem);
100
- let endIndex = this.itemIds.indexOf(id);
101
- this.toggleRange(startIndex, endIndex);
102
- }
103
-
104
- toObject() {
105
- return {
106
- selected: this.selected,
107
- hasAllSelected: this.hasAllSelected()
108
- };
109
- }
110
-
111
169
  }
112
170
 
113
171
  export default ListItemSelection;
@@ -1,4 +1,4 @@
1
- import { LIST_SELECTION_TOGGLE_ALL, LIST_SELECTION_TOGGLE_ITEMS, LIST_SELECTION_TOGGLE_ITEMS_IN_RANGE } from "../../../../bc/list-selection/Constants";
1
+ import { LIST_SELECTION_DESELECT_ITEM, LIST_SELECTION_SELECT_ITEM, LIST_SELECTION_TOGGLE_ALL, LIST_SELECTION_TOGGLE_ITEMS, LIST_SELECTION_TOGGLE_ITEMS_IN_RANGE } from "../../../../bc/list-selection/Constants";
2
2
  import InitializeController from "../adapters/controllers/InitializeController";
3
3
  import Repository from "../adapters/gateways/Repository";
4
4
  import Presenter from "../adapters/presenters/Presenter";
@@ -8,6 +8,8 @@ import AllSelectionController from "../adapters/controllers/AllSelectionControll
8
8
  import RangeSelectionController from "../adapters/controllers/RangeSelectionController";
9
9
  import UpdateController from "../adapters/controllers/UpdateController";
10
10
  import DestructController from "../adapters/controllers/DestructController";
11
+ import SelectController from "../adapters/controllers/SelectController";
12
+ import DeselectController from "../adapters/controllers/DeselectController";
11
13
 
12
14
  class ActionHandlerFactory {
13
15
  static create() {
@@ -29,6 +31,8 @@ class ActionHandlerFactory {
29
31
  ['MOUNT']: new InitializeController(service).handle,
30
32
  ['UPDATE_PROPERTIES']: new UpdateController(service).handle,
31
33
  ['UNMOUNT']: new DestructController(service).handle,
34
+ [LIST_SELECTION_SELECT_ITEM]: new SelectController(service).handle,
35
+ [LIST_SELECTION_DESELECT_ITEM]: new DeselectController(service).handle,
32
36
  [LIST_SELECTION_TOGGLE_ITEMS]: new SelectionController(service).handle,
33
37
  [LIST_SELECTION_TOGGLE_ALL]: new AllSelectionController(service).handle,
34
38
  [LIST_SELECTION_TOGGLE_ITEMS_IN_RANGE]: new RangeSelectionController(service).handle
@@ -1,7 +1,9 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
 
3
- class Action {
4
- constructor(type, payload) {
3
+ class Event {
4
+ constructor(type) {
5
+ let payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6
+
5
7
  _defineProperty(this, "type", void 0);
6
8
 
7
9
  _defineProperty(this, "payload", void 0);
@@ -18,6 +20,13 @@ class Action {
18
20
  return this.payload;
19
21
  }
20
22
 
23
+ toObject() {
24
+ return {
25
+ type: this.type,
26
+ payload: this.payload
27
+ };
28
+ }
29
+
21
30
  }
22
31
 
23
- export default Action;
32
+ export default Event;
@@ -4,11 +4,11 @@ class TableTranslator {
4
4
 
5
5
  const {
6
6
  data,
7
- selectionConfig
7
+ selectionConfig,
8
+ selection
8
9
  } = state.properties;
9
10
  const {
10
- sortBy,
11
- selection
11
+ sortBy
12
12
  } = (_state = state) === null || _state === void 0 ? void 0 : _state.behaviours;
13
13
  const headers = TableTranslator.translateHeaders(data.headers, sortBy);
14
14
  const rows = TableTranslator.translateRows(data.rows, selection, selectionConfig);
@@ -42,11 +42,16 @@ class TableTranslator {
42
42
  return { ...row,
43
43
  isSelected: selected.includes(row.id),
44
44
  isSelectable: selected.includes(row.id) || !hasAllSelected,
45
- selectionTooltip: !selected.includes(row.id) && hasAllSelected ? selectionConfig.limitExceedAlertMessage : `Record ${index + 1}`
45
+ selectionTooltip: this.getSelectionTooltip(row.id, index, selected, hasAllSelected, selectionConfig)
46
46
  };
47
47
  });
48
48
  }
49
49
 
50
+ static getSelectionTooltip(id, index, selected, hasAllSelected, selectionConfig) {
51
+ return `Record ${index + 1}`;
52
+ return !selected.includes(id) && hasAllSelected ? selectionConfig.limitExceedAlertMessage : `Record ${index + 1}`;
53
+ }
54
+
50
55
  }
51
56
 
52
57
  export default TableTranslator;
@@ -1,6 +1,5 @@
1
1
  import { TableListProperties } from "../../../../../../cc/table-list";
2
2
  import { createCustomComponent } from "../../../../../custom-component";
3
- import ListItemSelectionBehaviourFactory from "../../../../../behaviours/list-selection/frameworks/ListItemSelectionBehaviourFactory";
4
3
  import TableTranslator from "../../adapters/presenters/TableTranslator";
5
4
  import TableListView from "./TableListView";
6
5
  import EventHandlersFactory from "./EventHandlersFactory";
@@ -12,7 +11,7 @@ const TableList = createCustomComponent({
12
11
  setInitialState: () => ({}),
13
12
  transformState: TableTranslator.translate,
14
13
  eventHandlers: EventHandlersFactory.create(),
15
- behaviours: [ListItemSelectionBehaviourFactory.create(), SortByBehaviourFactory.create(), {
14
+ behaviours: [SortByBehaviourFactory.create(), {
16
15
  name: 'resizerState',
17
16
  properties: {},
18
17
  eventHandlers: {},
@@ -26,11 +26,11 @@ function TableListView(_ref2, _ref) {
26
26
  isFlexibleColumns,
27
27
  rowCursor,
28
28
  rowActionsConfig,
29
+ selection,
29
30
  emptyStateUiType
30
31
  } = state.properties;
31
32
  const {
32
- resizerState,
33
- selection
33
+ resizerState
34
34
  } = state.behaviours;
35
35
  const {
36
36
  headers,
@@ -93,6 +93,7 @@ function renderHeader(_ref3) {
93
93
  } = _ref3;
94
94
  return /*#__PURE__*/React.createElement(Header, {
95
95
  isSelectionEnabled: selectionConfig.isEnabled,
96
+ isSelectAllEnabled: selectionConfig.isSelectAllEnabled,
96
97
  hasAllSelected: selection.hasAllSelected,
97
98
  isResizerEnabled: resizerConfig.isEnabled,
98
99
  currentlyResizingColumn: resizerState.currentlyResizingColumn,
@@ -9,6 +9,7 @@ import ResizerExtraSpace from "./header/ResizerExtraSpace";
9
9
  function Header(_ref) {
10
10
  let {
11
11
  isSelectionEnabled,
12
+ isSelectAllEnabled,
12
13
  hasAllSelected,
13
14
  isResizerEnabled,
14
15
  currentlyResizingColumn,
@@ -28,12 +29,13 @@ function Header(_ref) {
28
29
  return /*#__PURE__*/React.createElement(TableHeader, {
29
30
  $flag_isColumnsFlexible: isFlexibleColumns,
30
31
  $flag_padding: !isSelectionEnabled
31
- }, /*#__PURE__*/React.createElement(TableHeaderRow, null, renderSelectAll(isSelectionEnabled, hasAllSelected, dispatch), renderHeaders(headers, currentlyResizingColumn, isResizerEnabled, isFlexibleColumns, dispatch), renderActionColumn(hasRowActions, rowActionsColumnWidth), renderResizerExtraSpace(isCurrentlyResizing, resizerExtraWidth)));
32
+ }, /*#__PURE__*/React.createElement(TableHeaderRow, null, renderSelectAll(isSelectionEnabled, isSelectAllEnabled, hasAllSelected, dispatch), renderHeaders(headers, currentlyResizingColumn, isResizerEnabled, isFlexibleColumns, dispatch), renderActionColumn(hasRowActions, rowActionsColumnWidth), renderResizerExtraSpace(isCurrentlyResizing, resizerExtraWidth)));
32
33
  }
33
34
 
34
- function renderSelectAll(isSelectionEnabled, hasAllSelected, dispatch) {
35
+ function renderSelectAll(isSelectionEnabled, isSelectAllEnabled, hasAllSelected, dispatch) {
35
36
  return /*#__PURE__*/React.createElement(SelectAll, {
36
37
  isSelectionEnabled: isSelectionEnabled,
38
+ isSelectAllEnabled: isSelectAllEnabled,
37
39
  hasAllSelected: hasAllSelected,
38
40
  dispatch: dispatch
39
41
  });
@@ -6,6 +6,7 @@ import { TableListConstants } from "../../../../../../../../cc/table-list";
6
6
  function SelectAll(_ref) {
7
7
  let {
8
8
  isSelectionEnabled,
9
+ isSelectAllEnabled,
9
10
  hasAllSelected,
10
11
  dispatch
11
12
  } = _ref;
@@ -14,7 +15,7 @@ function SelectAll(_ref) {
14
15
  return null;
15
16
  }
16
17
 
17
- return /*#__PURE__*/React.createElement(TableHeadFirstNode, null, /*#__PURE__*/React.createElement(CheckBox, {
18
+ return /*#__PURE__*/React.createElement(TableHeadFirstNode, null, isSelectAllEnabled && /*#__PURE__*/React.createElement(CheckBox, {
18
19
  checked: hasAllSelected,
19
20
  onChange: () => dispatch({
20
21
  type: TableListConstants.TABLE_LIST_TOGGLE_ALL_SELECTION
@@ -26,8 +26,7 @@ function RowSelection(_ref) {
26
26
  id,
27
27
  event
28
28
  }
29
- }),
30
- $flag_disabled: !selectable
29
+ })
31
30
  });
32
31
  }
33
32
 
@@ -17,14 +17,16 @@ class Repository {
17
17
  departmentId,
18
18
  viewId,
19
19
  moduleName,
20
+ query,
20
21
  context
21
22
  } = this.state.properties;
22
23
  const list = ListFactory.createList({
23
24
  context,
24
- filter: {
25
+ query: {
25
26
  departmentId,
26
27
  viewId,
27
- moduleName
28
+ moduleName,
29
+ ...query
28
30
  },
29
31
  sortBy,
30
32
  limit: 50
@@ -65,6 +65,7 @@ export default class TableTranslator {
65
65
  return {
66
66
  properties,
67
67
  behaviours,
68
+ selection: behaviours === null || behaviours === void 0 ? void 0 : behaviours.selection,
68
69
  rowCursor,
69
70
  rowActionsConfig: {
70
71
  hasActions: Boolean(rowActions === null || rowActions === void 0 ? void 0 : rowActions.length),
@@ -5,10 +5,10 @@ class ListFactory {
5
5
  const {
6
6
  limit,
7
7
  sortBy,
8
- filter,
8
+ query,
9
9
  context
10
10
  } = input;
11
- return new List(limit, sortBy, filter, context);
11
+ return new List(limit, sortBy, query, context);
12
12
  }
13
13
 
14
14
  }
@@ -2,19 +2,19 @@ import { RECORD_EXECUTE, RECORD_FETCH_MORE, RECORD_REFETCH, RecordApiActionName
2
2
  import { FIELD_EXECUTE, FIELD_REFETCH } from "../../../../bc/zfield/Constants";
3
3
  import { ZLIST_RECORD_DELETE_FAILED, ZLIST_RECORD_DELETE_SUCCEEDED, ZLIST_RECORD_UPDATE_FAILED, ZLIST_RECORD_UPDATE_SUCCEEDED } from "../../../../bc/zlist/Constants";
4
4
  import { CLIENTACTION_BEHAVIOUR_EXECUTE } from "../../../client-actions/bc/zclient-actions/Constants";
5
- import { SMART_TABLE_EVENTS } from "../../../../cc/table-connected/Constants";
5
+ import { SmartTableConstants } from "../../../../cc/table-connected";
6
6
 
7
7
  class List {
8
- constructor(limit, sortBy, filter, context) {
8
+ constructor(limit, sortBy, query, context) {
9
9
  this.limit = limit;
10
10
  this.sortBy = sortBy;
11
- this.filter = filter;
11
+ this.query = query;
12
12
  this.context = context;
13
13
  }
14
14
 
15
15
  createApiProps() {
16
16
  const {
17
- filter,
17
+ query,
18
18
  limit,
19
19
  sortBy,
20
20
  context
@@ -22,7 +22,7 @@ class List {
22
22
  return {
23
23
  limit,
24
24
  sortBy,
25
- ...filter,
25
+ ...query,
26
26
  ...context
27
27
  };
28
28
  }
@@ -52,12 +52,14 @@ class List {
52
52
  const {
53
53
  sortBy: prevSortBy,
54
54
  departmentId: preDepartmentId,
55
- viewId: preViewId
55
+ viewId: preViewId,
56
+ query: preQuery
56
57
  } = previousProperties;
57
58
  const {
58
59
  sortBy: sortBy,
59
60
  departmentId: currentDepartmentId,
60
- viewId: currentViewId
61
+ viewId: currentViewId,
62
+ query: curQuery
61
63
  } = currentProperties;
62
64
 
63
65
  if (prevSortBy !== sortBy) {
@@ -70,16 +72,13 @@ class List {
70
72
 
71
73
  if (preViewId !== currentViewId) {
72
74
  return [this.createRecordsRefetchAction(), this.createSelectedFieldsFetchAction()];
73
- } // if (this.shallowDiff(prevFilter, currentFilter)) {
74
- // return [
75
- // this.createRecordsRefetchAction(),
76
- // this.createAvailableFieldsFetchAction(),
77
- // this.createSelectedFieldsFetchAction()
78
- // // TODO: this.createAvailableFieldsRefetchAction(),
79
- // // TODO: this.createSelectedFieldsRefetchAction()
80
- // ];
81
- // }
75
+ }
82
76
 
77
+ if (this.shallowDiff(preQuery, curQuery)) {
78
+ return [this.createRecordsRefetchAction(), this.createAvailableFieldsFetchAction(), this.createSelectedFieldsFetchAction() // TODO: this.createAvailableFieldsRefetchAction(),
79
+ // TODO: this.createSelectedFieldsRefetchAction()
80
+ ];
81
+ }
83
82
 
84
83
  return [];
85
84
  }
@@ -143,14 +142,14 @@ class List {
143
142
 
144
143
  getDeleteSuccessAction(recordIds) {
145
144
  return {
146
- type: SMART_TABLE_EVENTS.DELETE_RECORDS_SUCCESS,
145
+ type: SmartTableConstants.Events.DELETE_RECORDS_SUCCESS,
147
146
  payload: recordIds
148
147
  };
149
148
  }
150
149
 
151
150
  getUpdateSuccessAction(recordId) {
152
151
  return {
153
- type: SMART_TABLE_EVENTS.UPDATE_RECORDS_SUCCESS,
152
+ type: SmartTableConstants.Events.UPDATE_RECORDS_SUCCESS,
154
153
  payload: recordId
155
154
  };
156
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/library-platform",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "",
5
5
  "main": "es/index.js",
6
6
  "files": [
@@ -78,6 +78,6 @@
78
78
  "dependencies": {
79
79
  "ajv": "6.12.6",
80
80
  "object-path-immutable": "4.1.2",
81
- "jsep": "1.4.0"
81
+ "jsep": "0.3.5"
82
82
  }
83
83
  }
@@ -1,4 +0,0 @@
1
- export const SMART_TABLE_EVENTS = {
2
- DELETE_RECORDS_SUCCESS: 'SMART_TABLE#RECORD_DELETED',
3
- UPDATE_RECORDS_SUCCESS: 'SMART_TABLE#RECORD_UPDATED'
4
- };