@tap-payments/auth-jsconnect 2.3.88-test → 2.3.90-test

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.
@@ -31,7 +31,7 @@ import Collapse from '../../../../components/Collapse';
31
31
  import ExpandIcon from '../../../../components/ExpandIcon';
32
32
  import CheckIcon from '@mui/icons-material/Check';
33
33
  import Text from '../../../../components/Text';
34
- import { findCurrencyByIso2, isExist } from '../../../../utils';
34
+ import { findCurrencyByIso2, isExist, groupSectionWithSelectedActivitiesAtBeginning } from '../../../../utils';
35
35
  import { ScreenContainer } from '../../../shared/Containers';
36
36
  import Search from '../../../shared/Search';
37
37
  import Input from '../../../shared/Input';
@@ -105,6 +105,10 @@ var ActivityList = function (_a) {
105
105
  var handleOpenMainMenu = function (event) {
106
106
  if (readOnly)
107
107
  return;
108
+ var list = groupSectionWithSelectedActivitiesAtBeginning(activityList, controlValue);
109
+ if ((list === null || list === void 0 ? void 0 : list.length) > 0) {
110
+ setActivities(list);
111
+ }
108
112
  setAnchorEl(event.currentTarget);
109
113
  onListOpen === null || onListOpen === void 0 ? void 0 : onListOpen();
110
114
  };
@@ -207,6 +211,11 @@ var ActivityList = function (_a) {
207
211
  };
208
212
  var handleSearch = function (value) {
209
213
  if (!value) {
214
+ var list = groupSectionWithSelectedActivitiesAtBeginning(activityList, controlValue);
215
+ if ((list === null || list === void 0 ? void 0 : list.length) > 0) {
216
+ setActivities(list);
217
+ return;
218
+ }
210
219
  setActivities(activityList);
211
220
  return;
212
221
  }
@@ -238,14 +247,14 @@ var ActivityList = function (_a) {
238
247
  var showCheck = section.id === getSelectedActivitySectionFlag(section) && isDivisionNotAvailable;
239
248
  return (_jsxs(ListItemContainer, { children: [_jsxs(ListItem, __assign({ sx: __assign({ bgcolor: 'rgb(196 184 184 / 20%)', borderBottom: '1px solid rgba(227, 232, 238, 1)' }, (isDivisionNotAvailable && { bgcolor: 'inherit', borderBottom: 'none' })) }, { children: [_jsx(NameContainer, __assign({ isAr: isAr, isSelected: section.id === getSelectedActivitySectionFlag(section), sx: __assign({}, (isDivisionNotAvailable && { paddingInlineStart: '5px' })) }, { children: getSelectedActivityName(section) })), showCheck ? _jsx(CheckIconStyled, {}) : !isDivisionNotAvailable && _jsx(ExpandIcon, { anchorEl: subIndex === section.id })] })), _jsx(Collapse, __assign({ in: section.id === subIndex && !isDivisionNotAvailable }, { children: _jsx(DivisionListStyled, { sx: { pt: 0, pb: 0 }, list: (!isDivisionNotAvailable && section.divisions) || [], onSelectItem: function (division, e) {
240
249
  e.stopPropagation();
241
- var isOnlyOneItem = !division.activities || division.activities.length === 1;
250
+ var isOnlyOneItem = !division.activities || division.activities.length <= 1;
242
251
  if (isOnlyOneItem)
243
252
  onSelectItem(division);
244
253
  else
245
254
  handleOpenSubItem(division.id);
246
255
  }, listItemProps: { sx: { padding: 0, '&:last-child': { paddingBottom: 0 } } }, renderItem: function (division, idx) {
247
256
  var _a;
248
- var isOnlyOneItem = !division.activities || ((_a = division.activities) === null || _a === void 0 ? void 0 : _a.length) === 1;
257
+ var isOnlyOneItem = !division.activities || ((_a = division.activities) === null || _a === void 0 ? void 0 : _a.length) <= 1;
249
258
  var showCheck = division.id === getSelectedActivityDivisionFlag(division) && isOnlyOneItem;
250
259
  return (_jsxs(ListItemContainer, { children: [_jsxs(ListItem, __assign({ sx: __assign({ bgcolor: 'rgb(196 184 184 / 6%)', borderBottom: '1px solid rgba(227, 232, 238, 0.6)' }, (isOnlyOneItem && { bgcolor: 'inherit', borderBottom: 'none' })) }, { children: [_jsx(NameContainer, __assign({ isAr: isAr, isSelected: division.id === getSelectedActivityDivisionFlag(division), sx: __assign({}, (isOnlyOneItem && { paddingInlineStart: '5px' })) }, { children: getSelectedActivityName(division) })), showCheck ? _jsx(CheckIconStyled, {}) : !isOnlyOneItem && _jsx(ExpandIcon, { anchorEl: subItemIndex === division.id })] })), _jsx(Collapse, __assign({ in: division.id === subItemIndex && !isOnlyOneItem }, { children: _jsx(ActivityListStyled, { sx: { pt: 0, pb: 0 }, list: (!isOnlyOneItem && division.activities) || [], onSelectItem: function (activity, e) {
251
260
  e.stopPropagation();
@@ -1,4 +1,4 @@
1
- import { Activity, CountryCode, SaleChannel } from '../@types';
1
+ import { ActivitiesIsIc, Activity, CountryCode, SaleChannel } from '../@types';
2
2
  export declare const isArray: (value: any) => value is any[];
3
3
  export declare const joinArray: (items: Array<any>, joiner?: string) => string;
4
4
  export declare const replaceStringArrayItems: (items: Array<string>, include: string, withThis: string) => string[];
@@ -65,3 +65,4 @@ export declare const sortActivitiesByName: (items: Array<Activity>, path: string
65
65
  export declare const getFileDetailsFromDocument: (documents: Array<any>, purpose: string) => any;
66
66
  export declare const getRecentDocumentBasedOnPurpose: (documents: Array<any>, purpose: string) => any;
67
67
  export declare const findInArrayOrSubArray: (items: Array<any>, value: string | number) => null;
68
+ export declare const groupSectionWithSelectedActivitiesAtBeginning: (sections: Array<ActivitiesIsIc>, selectedActivities: Array<Activity>) => ActivitiesIsIc[];
@@ -9,6 +9,15 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
12
21
  import get from 'lodash-es/get';
13
22
  export var isArray = function (value) { return Array.isArray(value); };
14
23
  export var joinArray = function (items, joiner) {
@@ -179,3 +188,66 @@ export var findInArrayOrSubArray = function (items, value) {
179
188
  });
180
189
  return found;
181
190
  };
191
+ export var groupSectionWithSelectedActivitiesAtBeginning = function (sections, selectedActivities) {
192
+ if ((selectedActivities === null || selectedActivities === void 0 ? void 0 : selectedActivities.length) === 0)
193
+ return sections || [];
194
+ if ((sections === null || sections === void 0 ? void 0 : sections.length) === 0)
195
+ return [];
196
+ var filteredSections = sections.filter(function (section) {
197
+ var _a;
198
+ return (selectedActivities.find(function (_a) {
199
+ var id = _a.id;
200
+ return id === section.id;
201
+ }) ||
202
+ ((_a = section.divisions) === null || _a === void 0 ? void 0 : _a.some(function (division) {
203
+ var _a;
204
+ return (selectedActivities.find(function (_a) {
205
+ var id = _a.id;
206
+ return id === division.id;
207
+ }) ||
208
+ ((_a = division === null || division === void 0 ? void 0 : division.activities) === null || _a === void 0 ? void 0 : _a.some(function (activity) {
209
+ return selectedActivities.find(function (_a) {
210
+ var id = _a.id;
211
+ return id === activity.id;
212
+ });
213
+ })));
214
+ })));
215
+ });
216
+ var mapSelectedDivisionBeginning = filteredSections.map(function (section) {
217
+ var _a, _b;
218
+ var selectedDivision = ((_a = section.divisions) === null || _a === void 0 ? void 0 : _a.filter(function (division) {
219
+ var _a;
220
+ return (selectedActivities.find(function (_a) {
221
+ var id = _a.id;
222
+ return id === division.id;
223
+ }) ||
224
+ ((_a = division === null || division === void 0 ? void 0 : division.activities) === null || _a === void 0 ? void 0 : _a.some(function (activity) {
225
+ return selectedActivities.find(function (_a) {
226
+ var id = _a.id;
227
+ return id === activity.id;
228
+ });
229
+ })));
230
+ })) || [];
231
+ var remainingDivision = ((_b = section.divisions) === null || _b === void 0 ? void 0 : _b.filter(function (division) { return !selectedDivision.includes(division); })) || [];
232
+ var divisions = __spreadArray(__spreadArray([], selectedDivision, true), remainingDivision, true);
233
+ return __assign(__assign({}, section), { divisions: divisions });
234
+ });
235
+ var mapSelectedActivitiesBeginning = mapSelectedDivisionBeginning.map(function (section) {
236
+ var _a;
237
+ var divisions = (_a = section.divisions) === null || _a === void 0 ? void 0 : _a.map(function (division) {
238
+ var _a, _b;
239
+ var filterSelectedActivities = ((_a = division === null || division === void 0 ? void 0 : division.activities) === null || _a === void 0 ? void 0 : _a.filter(function (activity) {
240
+ return selectedActivities.find(function (_a) {
241
+ var id = _a.id;
242
+ return id === activity.id;
243
+ });
244
+ })) || [];
245
+ var remainingActivities = ((_b = division.activities) === null || _b === void 0 ? void 0 : _b.filter(function (activity) { return !filterSelectedActivities.includes(activity); })) || [];
246
+ var activities = __spreadArray(__spreadArray([], filterSelectedActivities, true), remainingActivities, true);
247
+ return __assign(__assign({}, division), { activities: activities });
248
+ });
249
+ return __assign(__assign({}, section), { divisions: divisions });
250
+ });
251
+ var remainingSections = sections.filter(function (section) { return !filteredSections.includes(section); });
252
+ return __spreadArray(__spreadArray([], mapSelectedActivitiesBeginning, true), remainingSections, true);
253
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/auth-jsconnect",
3
- "version": "2.3.88-test",
3
+ "version": "2.3.90-test",
4
4
  "description": "connect library, auth",
5
5
  "private": false,
6
6
  "main": "build/index.js",