@instructure/quiz-core 22.10.1 → 22.11.0

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/banks/api/banks.js +18 -97
  2. package/es/banks/components/SharingModal/index.js +6 -3
  3. package/es/banks/components/SharingModal/presenter.js +207 -131
  4. package/es/building/api/items.js +120 -24
  5. package/es/building/api/quizEntries.js +78 -15
  6. package/es/building/components/resources/quizEntry/QuizEntryShow/presenter.js +11 -2
  7. package/es/common/actions/sharedBanks.js +13 -1
  8. package/es/common/actions/sharingModal.js +7 -0
  9. package/es/common/components/resources/quiz/AddContent/Body/index.js +1 -1
  10. package/es/common/components/resources/quiz/AddContent/Body/presenter.js +129 -141
  11. package/es/common/components/resources/quiz/AddContent/Popover/presenter.js +126 -119
  12. package/es/common/components/shared/InteractionTypes/index.js +1 -4
  13. package/es/common/components/shared/InteractionTypes/presenter.js +1 -3
  14. package/es/common/middleware/sharedBanksMiddleware.js +243 -0
  15. package/es/common/records/Item.js +2 -1
  16. package/es/common/records/QuizEntry.js +7 -0
  17. package/es/common/reducers/sharingModal.js +17 -0
  18. package/es/common/util/useRemoteComponent.js +127 -0
  19. package/es/configureStore.js +4 -1
  20. package/es/index.js +3 -2
  21. package/lib/banks/api/banks.js +17 -96
  22. package/lib/banks/components/SharingModal/index.js +5 -2
  23. package/lib/banks/components/SharingModal/presenter.js +205 -129
  24. package/lib/building/api/items.js +120 -23
  25. package/lib/building/api/quizEntries.js +78 -14
  26. package/lib/building/components/resources/quizEntry/QuizEntryShow/presenter.js +10 -1
  27. package/lib/common/actions/sharedBanks.js +13 -1
  28. package/lib/common/actions/sharingModal.js +13 -0
  29. package/lib/common/components/resources/quiz/AddContent/Body/index.js +1 -1
  30. package/lib/common/components/resources/quiz/AddContent/Body/presenter.js +132 -141
  31. package/lib/common/components/resources/quiz/AddContent/Popover/presenter.js +127 -119
  32. package/lib/common/components/shared/InteractionTypes/index.js +1 -4
  33. package/lib/common/components/shared/InteractionTypes/presenter.js +1 -3
  34. package/lib/common/middleware/sharedBanksMiddleware.js +250 -0
  35. package/lib/common/records/Item.js +2 -1
  36. package/lib/common/records/QuizEntry.js +7 -0
  37. package/lib/common/reducers/sharingModal.js +23 -0
  38. package/lib/common/util/useRemoteComponent.js +134 -0
  39. package/lib/configureStore.js +4 -1
  40. package/lib/index.js +22 -0
  41. package/package.json +8 -8
@@ -8,12 +8,13 @@ import ExhaustivePaginatedFetcher from '../../common/util/ExhaustivePaginatedFet
8
8
  import { handleBanksResponse, handleBankResponse, handleShareBankResponse, handleShareBanksResponse } from '../../common/api/callHandlers';
9
9
  import { archiveBankEntry } from '../../common/actions/bankEntries';
10
10
  import { archiveBank } from '../../common/actions/banks';
11
- import { removeSharedBank, updateSharedBankPermission as updateSharedBankPermissionAction } from '../../common/actions/sharedBanks';
11
+ import { removeSharedBank, updateSharedBankPermission as updateSharedBankPermissionAction, getSharedBanksAction } from '../../common/actions/sharedBanks';
12
+ import { sharedBankLoadingAction } from '../../common/actions/sharingModal';
12
13
  import { clear, newActiveBankEntry, newActiveBank } from '../../common/actions/ui';
13
14
  import t from '@instructure/quiz-i18n/es/format-message';
14
15
  import { handleError } from '../../common/api/helpers';
15
16
  import { removeFromPolling } from './copyingBanksPoller';
16
- import { BANKS_BANK_PAGINATION, BANKS_BANK_ENTRY_PAGINATION, DELETE_BANK_CALL, UPDATE_BANK_CALL, CAN_EDIT, READ_ONLY, REMOVED_ACCESS, SHARED_WITH_USER, SHARED_WITH_COURSE, SHARED_WITH_ACCOUNT } from '@instructure/quiz-common';
17
+ import { BANKS_BANK_PAGINATION, BANKS_BANK_ENTRY_PAGINATION, DELETE_BANK_CALL, UPDATE_BANK_CALL, READ_ONLY, REMOVED_ACCESS, SHARED_WITH_USER, SHARED_WITH_COURSE } from '@instructure/quiz-common';
17
18
  import { noop } from 'lodash';
18
19
  import { NIL } from 'uuid';
19
20
  var banksApiEndpoint = '/api/banks';
@@ -268,102 +269,22 @@ export var getSharedBank = function getSharedBank(bankId, entityType, entityId)
268
269
  };
269
270
  };
270
271
  export var getSharedBanks = function getSharedBanks(bank, getUserInfo, getCourseInfo, getAccountInfo) {
271
- var url = "".concat(banksApiEndpoint, "/").concat(bank.id, "/shared_banks");
272
272
  return function (dispatch, getState) {
273
- var fetcher = new Fetcher({
274
- onError: handleError(dispatch, t('Failed to fetch shared banks.'))
275
- });
276
- return fetcher.get(url).then(function (sharedBanksInfo) {
277
- // if the API returns no data, we manually add the bank's creator to the response
278
- if (sharedBanksInfo.length === 0) {
279
- sharedBanksInfo.push({
280
- id: '-1',
281
- entity_type: SHARED_WITH_USER,
282
- entity_id: bank.creator,
283
- permission: CAN_EDIT,
284
- bank_id: bank.id
285
- });
286
- }
287
-
288
- // USERS
289
- var userSharedBanks = [];
290
- var userUuids = sharedBanksInfo.filter(function (sb) {
291
- return sb.entity_type === SHARED_WITH_USER;
292
- }).map(function (sb) {
293
- return sb.entity_id;
294
- });
295
- getUserInfo(userUuids).then(function (usersInfo) {
296
- usersInfo.forEach(function (userInfo) {
297
- var sharedBankInfo = sharedBanksInfo.find(function (sb) {
298
- return sb.entity_type === SHARED_WITH_USER && sb.entity_id === userInfo.uuid;
299
- });
300
- if (sharedBankInfo) {
301
- userSharedBanks.push({
302
- id: sharedBankInfo.id,
303
- entityType: sharedBankInfo.entity_type,
304
- entityId: sharedBankInfo.entity_id,
305
- title: userInfo.fullName,
306
- avatar: userInfo.avatar,
307
- permission: sharedBankInfo.permission,
308
- bankId: sharedBankInfo.bank_id
309
- });
310
- }
311
- });
312
- dispatch(handleShareBanksResponse(userSharedBanks));
313
- });
314
-
315
- // COURSES
316
- var courseSharedBanks = [];
317
- var courseUuids = sharedBanksInfo.filter(function (sb) {
318
- return sb.entity_type === SHARED_WITH_COURSE;
319
- }).map(function (sb) {
320
- return sb.entity_id;
321
- });
322
- getCourseInfo(courseUuids).then(function (coursesInfo) {
323
- coursesInfo.forEach(function (courseInfo) {
324
- var sharedBankInfo = sharedBanksInfo.find(function (sb) {
325
- return sb.entity_type === SHARED_WITH_COURSE && sb.entity_id === courseInfo.uuid;
326
- });
327
- if (sharedBankInfo) {
328
- courseSharedBanks.push({
329
- id: sharedBankInfo.id,
330
- entityType: sharedBankInfo.entity_type,
331
- entityId: sharedBankInfo.entity_id,
332
- title: courseInfo.title,
333
- permission: sharedBankInfo.permission,
334
- bankId: sharedBankInfo.bank_id
335
- });
336
- }
337
- });
338
- dispatch(handleShareBanksResponse(courseSharedBanks));
339
- });
340
-
341
- // ACCOUNTS
342
- var accountSharedBanks = [];
343
- var accountUuids = sharedBanksInfo.filter(function (sb) {
344
- return sb.entity_type === SHARED_WITH_ACCOUNT;
345
- }).map(function (sb) {
346
- return sb.entity_id;
347
- });
348
- getAccountInfo(accountUuids).then(function (accountsInfo) {
349
- accountsInfo.forEach(function (accountInfo) {
350
- var sharedBankInfo = sharedBanksInfo.find(function (sb) {
351
- return sb.entity_type === SHARED_WITH_ACCOUNT && sb.entity_id === accountInfo.uuid;
352
- });
353
- if (sharedBankInfo) {
354
- accountSharedBanks.push({
355
- id: sharedBankInfo.id,
356
- entityType: sharedBankInfo.entity_type,
357
- entityId: sharedBankInfo.entity_id,
358
- title: accountInfo.name,
359
- permission: sharedBankInfo.permission,
360
- bankId: sharedBankInfo.bank_id
361
- });
362
- }
363
- });
364
- dispatch(handleShareBanksResponse(accountSharedBanks));
365
- });
366
- });
273
+ var payload = {
274
+ bank: bank,
275
+ getUserInfo: getUserInfo,
276
+ getCourseInfo: getCourseInfo,
277
+ getAccountInfo: getAccountInfo
278
+ };
279
+ dispatch(getSharedBanksAction(payload));
280
+ };
281
+ };
282
+ export var changeSharedBankLoading = function changeSharedBankLoading(isLoading) {
283
+ return function (dispatch, getState) {
284
+ var payload = {
285
+ loading: isLoading
286
+ };
287
+ dispatch(sharedBankLoadingAction(payload));
367
288
  };
368
289
  };
369
290
  export var updateSharedBankPermission = function updateSharedBankPermission(bankId, sharedBankId, permission) {
@@ -1,7 +1,7 @@
1
1
  import { compose } from 'redux';
2
2
  import { Map } from 'immutable';
3
3
  import { connect } from '../../../common/react-redux';
4
- import { shareBank, getSharedBanks, updateSharedBankPermission, getBank, updateBank } from '../../api/banks';
4
+ import { shareBank, getSharedBanks, updateSharedBankPermission, getBank, updateBank, changeSharedBankLoading } from '../../api/banks';
5
5
  import { removeSharedBank } from '../../../common/actions/sharedBanks';
6
6
  import { withConfirm } from '../../../common/actions/modal';
7
7
  import SharingModal from './presenter';
@@ -9,8 +9,10 @@ function mapStateToProps(state, ownProps) {
9
9
  var sharedBanks = state.get('sharedBanks', Map()).filter(function (sharedBank) {
10
10
  return sharedBank.get('bankId') === ownProps.bank.id;
11
11
  }).toList();
12
+ var loading = state.getIn(['sharingModal', 'loading']);
12
13
  return {
13
- sharedBanks: sharedBanks
14
+ sharedBanks: sharedBanks,
15
+ loading: loading
14
16
  };
15
17
  }
16
18
  var mapDispatchToProps = {
@@ -20,6 +22,7 @@ var mapDispatchToProps = {
20
22
  getBank: getBank,
21
23
  removeSharedBank: removeSharedBank,
22
24
  updateBank: updateBank,
23
- withConfirm: withConfirm
25
+ withConfirm: withConfirm,
26
+ changeSharedBankLoading: changeSharedBankLoading
24
27
  };
25
28
  export default compose(connect(mapStateToProps, mapDispatchToProps))(SharingModal);
@@ -1,5 +1,4 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
3
  import _createClass from "@babel/runtime/helpers/esm/createClass";
5
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
@@ -8,8 +7,6 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
8
7
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
8
  var _dec, _class, _SharingModalPresenter;
10
9
  import _regeneratorRuntime from "@babel/runtime/regenerator";
11
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
12
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
13
10
  function _callSuper(_this, derived, args) {
14
11
  function isNativeReflectConstruct() {
15
12
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
@@ -30,9 +27,10 @@ import PropTypes from 'prop-types';
30
27
  import { List, Map } from 'immutable';
31
28
  import ImmutablePropTypes from 'react-immutable-proptypes';
32
29
  import partial from 'lodash/partial';
33
- import { Modal, ModalHeader, ModalBody, ModalFooter, CAN_EDIT, READ_ONLY, REMOVED_ACCESS, SHARED_WITH_USER, SHARED_WITH_COURSE, SHARED_WITH_ACCOUNT, SimpleSelect, withStyleOverrides } from '@instructure/quiz-common';
30
+ import debounce from 'lodash/debounce';
31
+ import { Modal, ModalHeader, ModalBody, ModalFooter, CAN_EDIT, READ_ONLY, REMOVED_ACCESS, SHARED_WITH_USER, SHARED_WITH_COURSE, SHARED_WITH_ACCOUNT, SimpleSelect, withStyleOverrides, TextInput } from '@instructure/quiz-common';
34
32
  import { Heading } from '@instructure/ui-heading';
35
- import { Button, CloseButton } from '@instructure/ui-buttons';
33
+ import { Button, CloseButton, CondensedButton, IconButton } from '@instructure/ui-buttons';
36
34
  import { View } from '@instructure/ui-view';
37
35
  import { Grid } from '@instructure/ui-grid';
38
36
  import { Tabs } from '@instructure/ui-tabs';
@@ -46,29 +44,32 @@ import Spinner from '../../../common/components/shared/spinner/Spinner';
46
44
  import generateStyle from './styles';
47
45
  import generateComponentTheme from './theme';
48
46
  import t from '@instructure/quiz-i18n/es/format-message';
47
+ import { IconSearchLine, IconTroubleLine } from '@instructure/ui-icons';
49
48
  var noop = function noop() {};
50
49
  export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, generateComponentTheme), _dec(_class = (_SharingModalPresenter = /*#__PURE__*/function (_Component) {
51
- function SharingModalPresenter() {
50
+ // =============
51
+ // LIFECYCLE
52
+ // =============
53
+
54
+ function SharingModalPresenter(props) {
52
55
  var _this2;
53
56
  _classCallCheck(this, SharingModalPresenter);
54
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
55
- args[_key] = arguments[_key];
56
- }
57
- _this2 = _callSuper(this, SharingModalPresenter, [].concat(args));
57
+ _this2 = _callSuper(this, SharingModalPresenter, [props]);
58
58
  _defineProperty(_this2, "state", {
59
59
  accountPermission: null,
60
60
  shares: List(),
61
61
  newEntities: List(),
62
62
  searchSelection: [],
63
63
  searchPermission: READ_ONLY,
64
- entitiesWithChangedPermission: {},
65
- selectedTabIndex: 0
64
+ selectedTabIndex: 0,
65
+ value: '',
66
+ startingPoint: 0,
67
+ numOfResults: 0,
68
+ searchValue: '',
69
+ displayEntities: []
66
70
  });
67
71
  _defineProperty(_this2, "shareListRef", null);
68
72
  _defineProperty(_this2, "shareButtonRef", null);
69
- // =============
70
- // LIFECYCLE
71
- // =============
72
73
  _defineProperty(_this2, "checkForSharedBanks", function () {
73
74
  var size = _this2.props.sharedBanks.size;
74
75
  if (size >= 0 && size !== _this2.props.bank.sharedCount || size === 0) {
@@ -79,13 +80,70 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
79
80
  });
80
81
  }
81
82
  });
83
+ _defineProperty(_this2, "normalizeText", function (text) {
84
+ return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase();
85
+ });
82
86
  // =============
83
87
  // HELPERS
84
88
  // =============
89
+ _defineProperty(_this2, "createFilteredList", function () {
90
+ var entities = _this2.state.shares;
91
+ var users = entities.filter(function (s) {
92
+ return s.get('entityType') === SHARED_WITH_USER;
93
+ });
94
+ var courses = entities.filter(function (s) {
95
+ return s.get('entityType') === SHARED_WITH_COURSE;
96
+ });
97
+ var accounts = entities.filter(function (s) {
98
+ return s.get('entityType') === SHARED_WITH_ACCOUNT;
99
+ });
100
+ switch (_this2.state.selectedTabIndex) {
101
+ case 0:
102
+ {
103
+ var displayedUsers = users.filter(function (item) {
104
+ return _this2.normalizeText(item.get('title')).includes(_this2.normalizeText(_this2.state.searchValue));
105
+ });
106
+ _this2.setState({
107
+ numOfResults: displayedUsers.size,
108
+ displayEntities: displayedUsers.slice(0, _this2.state.startingPoint + _this2.props.limit)
109
+ });
110
+ _this2.debouncedStopLoading();
111
+ break;
112
+ }
113
+ case 1:
114
+ {
115
+ var displayedCourses = courses.filter(function (item) {
116
+ return _this2.normalizeText(item.get('title')).includes(_this2.normalizeText(_this2.state.searchValue));
117
+ });
118
+ _this2.setState({
119
+ numOfResults: displayedCourses.size,
120
+ displayEntities: displayedCourses.slice(0, _this2.state.startingPoint + _this2.props.limit)
121
+ });
122
+ _this2.debouncedStopLoading();
123
+ break;
124
+ }
125
+ case 2:
126
+ {
127
+ var displayedAccounts = accounts.filter(function (item) {
128
+ return _this2.normalizeText(item.get('title')).includes(_this2.normalizeText(_this2.state.searchValue));
129
+ });
130
+ _this2.setState({
131
+ numOfResults: displayedAccounts.size,
132
+ displayEntities: displayedAccounts.slice(0, _this2.state.startingPoint + _this2.props.limit)
133
+ });
134
+ _this2.debouncedStopLoading();
135
+ break;
136
+ }
137
+ }
138
+ });
85
139
  _defineProperty(_this2, "handleTabChange", function (event, _ref) {
86
140
  var index = _ref.index;
87
141
  _this2.setState({
88
- selectedTabIndex: index
142
+ selectedTabIndex: index,
143
+ startingPoint: 0,
144
+ value: ''
145
+ }, function () {
146
+ _this2.checkForSharedBanks();
89
147
  });
90
148
  });
91
149
  _defineProperty(_this2, "modalDismissCleanup", function () {
@@ -99,30 +157,6 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
99
157
  // removes the creator's temporary sharedBank record
100
158
  _this2.props.removeSharedBank('-1');
101
159
  });
102
- _defineProperty(_this2, "numEntitiesToRemove", function () {
103
- var permissions = Object.values(_this2.state.entitiesWithChangedPermission);
104
- return permissions.reduce(function (count, val) {
105
- return val === REMOVED_ACCESS ? count + 1 : count;
106
- }, 0);
107
- });
108
- _defineProperty(_this2, "newEntitiesToSubmit", function () {
109
- var newEntities = _this2.state.newEntities.filter(function (entity) {
110
- return _this2.state.entitiesWithChangedPermission[entity.get('id')] !== REMOVED_ACCESS;
111
- });
112
-
113
- // special case if the creator tries to change their own permissions before
114
- // first share, since they don't have a SharedBank record to update
115
- var newCreatorPerm = _this2.state.entitiesWithChangedPermission['-1'];
116
- if (newCreatorPerm && newCreatorPerm !== CAN_EDIT) {
117
- var creatorSharedBank = _this2.props.sharedBanks.find(function (sharedBank) {
118
- return sharedBank.get('id') == '-1';
119
- });
120
- newEntities = newEntities.push(Map(_objectSpread(_objectSpread({}, creatorSharedBank.toJS()), {}, {
121
- permission: newCreatorPerm
122
- })));
123
- }
124
- return newEntities;
125
- });
126
160
  _defineProperty(_this2, "isSharedWithAccount", function () {
127
161
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this2.state;
128
162
  return [READ_ONLY, CAN_EDIT].includes(state.accountPermission);
@@ -134,50 +168,11 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
134
168
  _this2.props.updateSharedCount(null);
135
169
  _this2.modalDismissCleanup();
136
170
  });
137
- _defineProperty(_this2, "handleSubmit", function () {
138
- // calls the sharedBank api with the new entities you shared the current bank with
139
- var promises = [];
140
- if (_this2.state.accountPermission !== _this2.props.bank.accountPermission) {
141
- var updatedBank = _this2.props.bank.set('accountPermission', _this2.state.accountPermission);
142
- promises.push(_this2.props.updateBank(updatedBank));
143
- }
144
- _this2.newEntitiesToSubmit().forEach(function (entity) {
145
- _this2.props.onShare(entity.toJS());
146
- promises.push(_this2.props.shareBank(_this2.sharedBankForEntity(entity), _this2.props.getUserInfo));
147
- });
148
-
149
- // call the update api if any shared bank permission was updated
150
- Object.entries(_this2.state.entitiesWithChangedPermission).forEach(function (_ref2) {
151
- var _ref3 = _slicedToArray(_ref2, 2),
152
- sharedBankId = _ref3[0],
153
- permission = _ref3[1];
154
- var sharedBank = _this2.props.sharedBanks.find(function (sharedBank) {
155
- return sharedBank.get('id') === sharedBankId;
156
- });
157
- if (sharedBank && sharedBank.get('permission') !== permission && sharedBankId != '-1') {
158
- promises.push(_this2.props.updateSharedBankPermission(_this2.props.bank.id, sharedBankId, permission));
159
- }
160
- });
161
-
162
- // waits till all the calls to the shareBank and updateSharedBank apis have completed
163
- Promise.all(promises).then(function (values) {
164
- // calls getBank for the current bank to update the sharedCount
165
- _this2.props.getBank(_this2.props.bank.id);
166
- });
167
- _this2.setState({
168
- newEntities: List()
169
- });
170
- _this2.modalDismissCleanup(!!_this2.numEntitiesToRemove());
171
- });
172
171
  _defineProperty(_this2, "handleSearchSelectionChange", function (searchSelection) {
173
172
  _this2.setState({
174
173
  searchSelection: searchSelection
175
174
  });
176
175
  });
177
- _defineProperty(_this2, "updateEntitiesCount", function () {
178
- // state.shares is a list containing everyone in the list,
179
- _this2.props.updateSharedCount(_this2.state.shares.size - _this2.numEntitiesToRemove());
180
- });
181
176
  _defineProperty(_this2, "originalPermissionForEntity", function (entity) {
182
177
  var originalEntity = _this2.props.sharedBanks.find(function (sb) {
183
178
  return sb.get('id') == entity.get('id');
@@ -187,15 +182,15 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
187
182
  _defineProperty(_this2, "handleEntityRemove", function (entity, undoRemove) {
188
183
  _this2.confirmPermissionChange(entity, REMOVED_ACCESS);
189
184
  });
190
- _defineProperty(_this2, "handleSearchPermissionChange", function (e, _ref4) {
191
- var value = _ref4.value;
185
+ _defineProperty(_this2, "handleSearchPermissionChange", function (e, _ref2) {
186
+ var value = _ref2.value;
192
187
  _this2.setState({
193
188
  searchPermission: value
194
189
  });
195
190
  });
196
191
  _defineProperty(_this2, "handleSearchFilter", function (searchResults) {
197
192
  return searchResults.filter(function (result) {
198
- return !_this2.state.shares.some(function (entity) {
193
+ return !_this2.props.sharedBanks.some(function (entity) {
199
194
  return entity.get('entityId') === result.uuid;
200
195
  }) && (result.uuid !== _this2.props.bank.creator || _this2.props.bank.sharedCount > 0);
201
196
  });
@@ -221,7 +216,7 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
221
216
  });
222
217
  });
223
218
  _defineProperty(_this2, "updatePermission", /*#__PURE__*/function () {
224
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(entity, permission) {
219
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(entity, permission) {
225
220
  var _this2$props, updateSharedBankPermission, getBank, bank;
226
221
  return _regeneratorRuntime.wrap(function _callee$(_context) {
227
222
  while (1) switch (_context.prev = _context.next) {
@@ -238,7 +233,7 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
238
233
  }, _callee);
239
234
  }));
240
235
  return function (_x, _x2) {
241
- return _ref5.apply(this, arguments);
236
+ return _ref3.apply(this, arguments);
242
237
  };
243
238
  }());
244
239
  _defineProperty(_this2, "translatedPermissionLevel", function (permission) {
@@ -269,18 +264,24 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
269
264
  };
270
265
  });
271
266
  });
272
- _defineProperty(_this2, "handleAccountPermissionChange", function (e, _ref6) {
273
- var value = _ref6.value;
267
+ _defineProperty(_this2, "handleAccountPermissionChange", function (e, _ref4) {
268
+ var value = _ref4.value;
274
269
  return _this2.setState({
275
270
  accountPermission: value
276
271
  });
277
272
  });
278
- _defineProperty(_this2, "handleShareListRef", function (node) {
279
- _this2.shareListRef = node;
280
- });
281
273
  _defineProperty(_this2, "handleShareButtonRef", function (node) {
282
274
  _this2.shareButtonRef = node;
283
275
  });
276
+ _defineProperty(_this2, "handleChange", function (e, value) {
277
+ _this2.setState({
278
+ value: value
279
+ });
280
+ });
281
+ _defineProperty(_this2, "handleClear", function (e) {
282
+ e.stopPropagation();
283
+ _this2.handleChange(e, '');
284
+ });
284
285
  _defineProperty(_this2, "renderSearchSection", function (searchType) {
285
286
  if (_this2.props.bank.canEdit()) {
286
287
  return jsx(React.Fragment, null, jsx(Grid, {
@@ -319,15 +320,105 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
319
320
  }));
320
321
  }
321
322
  });
322
- _defineProperty(_this2, "renderShareList", function (entities) {
323
- return jsx(ShareList, {
324
- canEdit: _this2.props.bank.canEdit(),
325
- entities: entities,
326
- onPermissionChange: _this2.handleEntityPermissionChange,
327
- onEntityRemove: _this2.handleEntityRemove,
328
- sharedBanks: _this2.props.sharedBanks
323
+ _defineProperty(_this2, "renderShareList", function () {
324
+ if (_this2.props.loading) {
325
+ return jsx(View, {
326
+ height: "12em",
327
+ as: "div"
328
+ }, jsx(View, {
329
+ position: "absolute",
330
+ as: "div",
331
+ insetBlockEnd: "0"
332
+ }, jsx(Spinner, {
333
+ renderTitle: "Loading...",
334
+ size: "small",
335
+ fontSize: "medium"
336
+ })));
337
+ }
338
+ if (_this2.state.displayEntities.size > 0) {
339
+ return jsx(View, {
340
+ height: "12em",
341
+ overflowY: "auto",
342
+ overflowX: "hidden",
343
+ as: "div",
344
+ padding: "xx-small xx-small none"
345
+ }, jsx(ShareList, {
346
+ canEdit: _this2.props.bank.canEdit(),
347
+ entities: _this2.state.displayEntities,
348
+ onPermissionChange: _this2.handleEntityPermissionChange,
349
+ onEntityRemove: _this2.handleEntityRemove,
350
+ sharedBanks: _this2.props.sharedBanks
351
+ }), jsx("div", null, _this2.renderShowMoreButton()));
352
+ }
353
+ return jsx(View, {
354
+ height: "12em",
355
+ as: "div"
356
+ }, t('No results found'));
357
+ });
358
+ _defineProperty(_this2, "showMoreResult", function () {
359
+ _this2.setState({
360
+ startingPoint: _this2.state.startingPoint + _this2.props.limit
329
361
  });
330
362
  });
363
+ _defineProperty(_this2, "renderShowMoreButton", function () {
364
+ var shouldShowButton = _this2.state.startingPoint + _this2.props.limit < _this2.state.numOfResults;
365
+ if (!shouldShowButton) {
366
+ return null;
367
+ }
368
+ return jsx(View, {
369
+ css: {
370
+ display: shouldShowButton
371
+ },
372
+ background: "primary",
373
+ padding: "small none",
374
+ as: "div"
375
+ }, jsx(CondensedButton, {
376
+ onClick: function onClick(e) {
377
+ e.preventDefault();
378
+ e.stopPropagation();
379
+ _this2.showMoreResult();
380
+ }
381
+ }, t('Show more')));
382
+ });
383
+ _defineProperty(_this2, "renderClearButton", function () {
384
+ if (!_this2.state.value.length || _this2.state.readOnly || _this2.state.disabled) return null;
385
+ return jsx(IconButton, {
386
+ type: "button",
387
+ size: "small",
388
+ withBackground: false,
389
+ withBorder: false,
390
+ screenReaderLabel: "Clear search",
391
+ disabled: _this2.state.disabled || _this2.state.readOnly,
392
+ onClick: _this2.handleClear
393
+ }, jsx(IconTroubleLine, null));
394
+ });
395
+ _defineProperty(_this2, "renderSharedSearch", function () {
396
+ return jsx(View, {
397
+ margin: "none large none medium"
398
+ }, jsx(TextInput, {
399
+ size: 'medium',
400
+ placeholder: t('Search...'),
401
+ value: _this2.state.value,
402
+ onChange: _this2.handleChange,
403
+ interaction: 'enabled',
404
+ inputRef: function inputRef(el) {
405
+ return _this2.inputRef = el;
406
+ },
407
+ renderBeforeInput: jsx(IconSearchLine, {
408
+ inline: false
409
+ }),
410
+ renderAfterInput: _this2.renderClearButton(),
411
+ shouldNotWrap: true
412
+ }));
413
+ });
414
+ _this2.debouncedSearch = debounce(function () {
415
+ _this2.setState({
416
+ searchValue: _this2.state.value
417
+ });
418
+ }, 300);
419
+ _this2.debouncedStopLoading = debounce(function () {
420
+ if (_this2.props.loading != false) _this2.props.changeSharedBankLoading(false);
421
+ }, 300);
331
422
  return _this2;
332
423
  }
333
424
  _inherits(SharingModalPresenter, _Component);
@@ -354,6 +445,16 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
354
445
  var updatedBank = this.props.bank.set('accountPermission', this.state.accountPermission);
355
446
  this.props.updateBank(updatedBank, false);
356
447
  }
448
+ if (prevState.value !== this.state.value) {
449
+ if (this.props.loading == false) this.props.changeSharedBankLoading(true);
450
+ this.setState({
451
+ startingPoint: 0
452
+ });
453
+ this.debouncedSearch();
454
+ }
455
+ if (prevState.searchValue !== this.state.searchValue || prevState.startingPoint !== this.state.startingPoint || prevState.selectedTabIndex !== this.state.selectedTabIndex || prevState.shares.size !== this.state.shares.size) {
456
+ this.createFilteredList();
457
+ }
357
458
  }
358
459
  }, {
359
460
  key: "sharedBankForEntity",
@@ -401,7 +502,7 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
401
502
  as: "div",
402
503
  weight: "bold",
403
504
  lineHeight: "double"
404
- }, t('Currently shared with')), this.renderShareList(existingPeople)), jsx(Tabs.Panel, {
505
+ }, t('Currently shared with')), this.renderSharedSearch(), this.renderShareList()), jsx(Tabs.Panel, {
405
506
  renderTitle: t('Courses ({ coursesCount })', {
406
507
  coursesCount: existingCourses.size
407
508
  }),
@@ -411,7 +512,7 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
411
512
  as: "div",
412
513
  weight: "bold",
413
514
  lineHeight: "double"
414
- }, t('Currently shared with')), this.renderShareList(existingCourses)), ((currentUser === null || currentUser === void 0 ? void 0 : currentUser.bank_admin) || (currentUser === null || currentUser === void 0 ? void 0 : currentUser.can_share_banks_with_subaccounts)) && jsx(Tabs.Panel, {
515
+ }, t('Currently shared with')), this.renderSharedSearch(), this.renderShareList()), ((currentUser === null || currentUser === void 0 ? void 0 : currentUser.bank_admin) || (currentUser === null || currentUser === void 0 ? void 0 : currentUser.can_share_banks_with_subaccounts)) && jsx(Tabs.Panel, {
415
516
  renderTitle: t('Accounts ({ accountsCount })', {
416
517
  accountsCount: existingAccounts.size
417
518
  }),
@@ -421,37 +522,7 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
421
522
  as: "div",
422
523
  weight: "bold",
423
524
  lineHeight: "double"
424
- }, t('Currently shared with')), this.renderShareList(existingAccounts))));
425
- }
426
- }, {
427
- key: "renderOriginalDesignEntities",
428
- value: function renderOriginalDesignEntities(existingPeople, existingCourses) {
429
- return jsx("div", {
430
- className: "fs-mask"
431
- }, jsx(Text, {
432
- as: "div",
433
- weight: "bold"
434
- }, t('Currently shared with')), jsx(View, {
435
- as: "div",
436
- "data-automation": "sdk-shared-bank-user-list"
437
- }, !this.state.newEntities.isEmpty() && jsx(View, {
438
- as: "div",
439
- margin: "0 0 medium 0"
440
- }, this.renderShareList(this.state.newEntities)), jsx(Tabs, {
441
- onRequestTabChange: this.handleTabChange
442
- }, jsx(Tabs.Panel, {
443
- renderTitle: t('People ({ peopleCount })', {
444
- peopleCount: existingPeople.size
445
- }),
446
- isSelected: this.state.selectedTabIndex === 0,
447
- padding: "large small small small"
448
- }, this.renderShareList(existingPeople)), !existingCourses.isEmpty() && jsx(Tabs.Panel, {
449
- renderTitle: t('Courses ({ coursesCount })', {
450
- coursesCount: existingCourses.size
451
- }),
452
- isSelected: this.state.selectedTabIndex === 1,
453
- padding: "large small small small"
454
- }, this.renderShareList(existingCourses)))));
525
+ }, t('Currently shared with')), this.renderSharedSearch(), this.renderShareList())));
455
526
  }
456
527
  }, {
457
528
  key: "renderEntitiesSection",
@@ -534,7 +605,10 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
534
605
  updateSharedBankPermission: PropTypes.func.isRequired,
535
606
  updateSharedCount: PropTypes.func,
536
607
  withConfirm: PropTypes.func.isRequired,
537
- styles: PropTypes.object
608
+ styles: PropTypes.object,
609
+ limit: PropTypes.number,
610
+ loading: PropTypes.bool,
611
+ changeSharedBankLoading: PropTypes.func.isRequired
538
612
  }), _defineProperty(_SharingModalPresenter, "defaultProps", {
539
613
  bank: null,
540
614
  currentUser: null,
@@ -544,6 +618,8 @@ export var SharingModalPresenter = (_dec = withStyleOverrides(generateStyle, gen
544
618
  onDismiss: noop,
545
619
  onShare: function onShare() {},
546
620
  sharedBanks: List(),
547
- updateSharedCount: Function.prototype
621
+ updateSharedCount: Function.prototype,
622
+ limit: 10,
623
+ loading: false
548
624
  }), _SharingModalPresenter)) || _class);
549
625
  export default SharingModalPresenter;