@antscorp/antsomi-ui 1.3.5-beta.569 → 1.3.5-beta.570

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.
@@ -127,12 +127,12 @@ export const ChildMenu = memo(props => {
127
127
  pathname,
128
128
  activeAppCode,
129
129
  menuItems,
130
- setLeftMenuState,
131
130
  isCustomized,
132
131
  customActiveCurrentKey,
133
132
  customItems,
134
133
  isRecommendation,
135
134
  env,
135
+ setLeftMenuState,
136
136
  ]);
137
137
  const onClick = e => {
138
138
  if (isRecommendation) {
@@ -173,7 +173,7 @@ export const ChildMenu = memo(props => {
173
173
  var _a;
174
174
  return (_a = args === null || args === void 0 ? void 0 : args.items) === null || _a === void 0 ? void 0 : _a.map(item => {
175
175
  const { key, label, children, icon, logo_url, menu_item_path = null, menu_item_domain = null, options, disabled, style, optionCallback, } = item;
176
- const isOwnerDashboardKey = key === HOME_MENU_ITEMS.DASHBOARD.menu_item_code;
176
+ const isOwnerDashboardKey = key === HOME_MENU_ITEMS.DASHBOARD;
177
177
  const renderLabel = () => (React.createElement(LabelWrapper, { gap: 10, align: "center", justify: "space-between", style: style },
178
178
  React.createElement(LabelCustom, { ellipsis: { tooltip: label } }, label),
179
179
  (options === null || options === void 0 ? void 0 : options.length) && !isRecommendation && (React.createElement(OptionDropdownWrapper, { align: "center" },
@@ -1,4 +1,3 @@
1
- import { TMenuFeatureItem } from '../types';
2
1
  export declare const APP_KEYS: {
3
2
  HOME: string;
4
3
  MARKETING: string;
@@ -22,7 +21,10 @@ export declare const HOME_REPORT_ROUTES: {
22
21
  CONFIGURE: string;
23
22
  CREATE: string;
24
23
  };
25
- export declare const HOME_MENU_ITEMS: Record<string, TMenuFeatureItem>;
24
+ export declare const HOME_MENU_ITEMS: {
25
+ RECOMMENDATION: string;
26
+ DASHBOARD: string;
27
+ };
26
28
  export declare const MARKETING_ROUTES: {
27
29
  CHANNEL: string;
28
30
  };
@@ -23,20 +23,8 @@ export const HOME_REPORT_ROUTES = {
23
23
  CREATE: `create`,
24
24
  };
25
25
  export const HOME_MENU_ITEMS = {
26
- RECOMMENDATION: {
27
- menu_item_name: 'Recommendation',
28
- menu_item_code: 'recommendation',
29
- icon_name: 'icon-ants-tips',
30
- menu_item_path: `${HOME_ROUTE}/recommendation`,
31
- page_title: '_recommendation',
32
- },
33
- DASHBOARD: {
34
- menu_item_name: 'Dashboard',
35
- menu_item_code: 'ownedDashboard',
36
- icon_name: 'icon-ants-dashboard',
37
- menu_item_path: HOME_ROUTE,
38
- page_title: '_dashboard',
39
- },
26
+ RECOMMENDATION: 'RECOMMENDATION',
27
+ DASHBOARD: 'DASHBOARD',
40
28
  };
41
29
  /* MARKETING APP */
42
30
  export const MARKETING_ROUTES = {
@@ -1,8 +1,8 @@
1
1
  import { FeatureMenuPermission, TDashboard, TDestinationChannel, TFeatureMenu } from '@antscorp/antsomi-ui/es/models/LeftMenu';
2
2
  import { PayloadInfo } from '@antscorp/antsomi-ui/es/types';
3
3
  import { TMenuFeatureItem, TMenuItem } from '../types';
4
- import { TEnv } from '@antscorp/antsomi-ui/es/types/config';
5
4
  import { TAccountPermission } from '@antscorp/antsomi-ui/es/models/AccountListing';
5
+ import { TEnv } from '@antscorp/antsomi-ui/es/types/config';
6
6
  /**
7
7
  * Converts a feature menu item to a menu item suitable for rendering in the UI.
8
8
  * @param {TMenuFeatureItem} featureMenu - The feature menu item to convert.
@@ -62,6 +62,13 @@ export declare const recursiveGetInitialFeatureMenuItem: (featureMenuItem: Parti
62
62
  children?: TFeatureMenu[] | undefined;
63
63
  dashboardEditable?: boolean | undefined;
64
64
  };
65
+ /**
66
+ * Recursively converts a feature menu item to a menu item, including children,
67
+ * based on permissions.
68
+ *
69
+ * @param {TFeatureMenu} featureMenuItem - The feature menu item to convert.
70
+ * @returns {TMenuItem} - The converted menu item with permissions.
71
+ */
65
72
  export declare const recursiveGetMenuItemByPermission: (featureMenuItem: TFeatureMenu) => TMenuItem;
66
73
  /** Map children to each App Item */
67
74
  export declare const getMappingAppChildren: (args: {
@@ -87,12 +94,30 @@ export declare const findActiveAppCodeByUrl: (args: {
87
94
  auth?: Partial<PayloadInfo>;
88
95
  env?: string;
89
96
  }) => string | undefined;
97
+ /**
98
+ * Finds the last matched menu item based on the provided URL.
99
+ *
100
+ * @param {Object} args - The arguments object.
101
+ * @param {string} args.url - The URL to match against menu items.
102
+ * @param {TFeatureMenu[]} args.menuItems - The array of menu items to search through.
103
+ * @param {Partial<PayloadInfo>} [args.auth] - Optional authorization information for generating paths.
104
+ * @param {TEnv} [args.env='development'] - Optional environment parameter to adjust path comparison.
105
+ * @returns {TFeatureMenu | undefined} - The last matched menu item, or undefined if not found.
106
+ */
90
107
  export declare const findLastMatchedItemByUrl: (args: {
91
108
  url: string;
92
109
  menuItems: TFeatureMenu[];
93
110
  auth?: Partial<PayloadInfo>;
94
111
  env?: TEnv;
95
112
  }) => TFeatureMenu | undefined;
113
+ /**
114
+ * Finds the path of the active menu item in a nested menu structure.
115
+ *
116
+ * @param {Object} args - The arguments object.
117
+ * @param {TFeatureMenu} args.activeMenuItem - The active menu item to find the path for.
118
+ * @param {TFeatureMenu[]} args.menuItems - The array of menu items to search through.
119
+ * @returns {TFeatureMenu[]} - An array representing the path of the active menu item.
120
+ */
96
121
  export declare const findPathOfActiveItem: (args: {
97
122
  activeMenuItem: TFeatureMenu;
98
123
  menuItems: TFeatureMenu[];
@@ -110,6 +135,14 @@ export declare const findActiveAppCodeByChild: (args: {
110
135
  menuItems: TMenuItem[];
111
136
  isRecommendation?: boolean;
112
137
  }) => string | undefined;
138
+ /**
139
+ * Retrieves the custom active application code based on the active key and menu items.
140
+ *
141
+ * @param {Object} args - The arguments object.
142
+ * @param {string} args.activeKey - The active key to search for.
143
+ * @param {TMenuItem[]} args.menuItems - The array of menu items to search through.
144
+ * @returns {string | undefined} - The active application code if found, otherwise undefined.
145
+ */
113
146
  export declare const getCustomActiveAppCode: (args: {
114
147
  activeKey: string;
115
148
  menuItems: TMenuItem[];
@@ -14,9 +14,10 @@ import { cloneDeep, isArray, isEmpty, sortBy } from 'lodash';
14
14
  // Constants
15
15
  import { APP_KEYS, MARKETING_CHANNEL_KEY, HOME_MENU_ITEMS, MARKETING_ROUTES, MENU_ITEM_TYPE, RENDER_OPTION, HOME_REPORT_ROUTES, SETTING_APP, APP_EXCLUDED_KEYS, MAP_MENU_TO_PARENT_APP_CODE, } from '../constants';
16
16
  import { MARKETING_CHANNEL_CODE, KEEP_HASH_PATH_DEV } from '../../../template/Layout/constants';
17
+ import { ENV } from '@antscorp/antsomi-ui/es/config';
17
18
  // Utils
18
19
  import { handleError } from '@antscorp/antsomi-ui/es/utils';
19
- import { ENV } from '@antscorp/antsomi-ui/es/config';
20
+ import { USER_PERMISSIONS } from '@antscorp/antsomi-ui/es/constants';
20
21
  const PATH = 'src/components/organism/LeftMenu/utils/index.ts';
21
22
  /**
22
23
  * Converts a feature menu item to a menu item suitable for rendering in the UI.
@@ -128,6 +129,13 @@ export const getComparePath = (path, env) => {
128
129
  */
129
130
  export const getInitialFeatureMenuItem = (featureMenuItem) => (Object.assign({ menu_item: '', network_id: -1, menu_item_name: '', level_position: 0, icon_name: null, menu_item_path: null, menu_item_code: '', permission_code: null, menu_item_type: 3, menu_item_parent: 0, render_option: null, menu_item_domain: null, total_row: 0, ctime: null, utime: null }, featureMenuItem));
130
131
  export const recursiveGetInitialFeatureMenuItem = (featureMenuItem) => (Object.assign({ menu_item: '', network_id: -1, menu_item_name: '', level_position: 0, icon_name: null, menu_item_path: null, menu_item_code: '', permission_code: null, menu_item_type: 3, menu_item_parent: 0, render_option: null, menu_item_domain: null, total_row: 0, ctime: null, utime: null }, featureMenuItem));
132
+ /**
133
+ * Recursively converts a feature menu item to a menu item, including children,
134
+ * based on permissions.
135
+ *
136
+ * @param {TFeatureMenu} featureMenuItem - The feature menu item to convert.
137
+ * @returns {TMenuItem} - The converted menu item with permissions.
138
+ */
131
139
  export const recursiveGetMenuItemByPermission = (featureMenuItem) => {
132
140
  var _a;
133
141
  return ({
@@ -197,41 +205,32 @@ export const getMappingAppChildren = (args) => {
197
205
  var _a, _b;
198
206
  switch (appItem.menu_item_code) {
199
207
  case APP_KEYS.HOME: {
200
- const dashboardObject = {
201
- sharedDashboard: [],
202
- ownedDashboard: dashboardList,
203
- recentDashboard: [],
204
- };
205
- appItem.children = (_a = Object.values(HOME_MENU_ITEMS)) === null || _a === void 0 ? void 0 : _a.map(childMenuItem => {
208
+ appItem.children = (_a = appItem.children) === null || _a === void 0 ? void 0 : _a.map(childMenuItem => {
206
209
  var _a;
207
- return (Object.assign(Object.assign({}, getInitialFeatureMenuItem({
208
- menu_item_domain: appItem.menu_item_domain,
209
- menu_item: childMenuItem.menu_item_code,
210
- menu_item_code: childMenuItem.menu_item_code,
211
- menu_item_name: childMenuItem.menu_item_name,
212
- menu_item_parent: appItem.menu_item,
213
- menu_item_path: childMenuItem.menu_item_path,
214
- icon_name: childMenuItem.icon_name,
215
- })), { children: (_a = dashboardObject === null || dashboardObject === void 0 ? void 0 : dashboardObject[childMenuItem.menu_item_code]) === null || _a === void 0 ? void 0 : _a.map(item => {
210
+ return (Object.assign(Object.assign({}, childMenuItem), { children: (_a = (childMenuItem.menu_item_code === HOME_MENU_ITEMS.DASHBOARD
211
+ ? dashboardList
212
+ : undefined)) === null || _a === void 0 ? void 0 : _a.map(item => {
216
213
  const { shareAccess } = item || {};
217
214
  const dashboardEditable = (() => {
218
215
  var _a, _b, _c;
219
216
  switch ((_a = userPermission === null || userPermission === void 0 ? void 0 : userPermission.permissions) === null || _a === void 0 ? void 0 : _a.edit) {
220
- case 'EVERYTHING':
217
+ case USER_PERMISSIONS.EVERYTHING:
221
218
  return true;
222
- case 'NONE':
219
+ case USER_PERMISSIONS.NONE:
223
220
  return false;
224
- default:
221
+ default: {
225
222
  if (isEmpty(shareAccess))
226
223
  return true;
227
- return !!((_c = (_b = shareAccess === null || shareAccess === void 0 ? void 0 : shareAccess.list_access) === null || _b === void 0 ? void 0 : _b.find(item => item.user_id === (auth === null || auth === void 0 ? void 0 : auth.userId))) === null || _c === void 0 ? void 0 : _c.allow_edit);
224
+ const allowEdit = ((_c = (_b = shareAccess === null || shareAccess === void 0 ? void 0 : shareAccess.list_access) === null || _b === void 0 ? void 0 : _b.find(item => item.user_id === (auth === null || auth === void 0 ? void 0 : auth.userId))) === null || _c === void 0 ? void 0 : _c.allow_edit) || '0';
225
+ return Boolean(Number(allowEdit));
226
+ }
228
227
  }
229
228
  })();
230
229
  return Object.assign({}, getInitialFeatureMenuItem({
231
230
  menu_item: String(item.dashboardId),
232
231
  menu_item_code: String(item.dashboardId),
233
232
  menu_item_name: item.dashboardName,
234
- menu_item_parent: childMenuItem.menu_item_code,
233
+ menu_item_parent: childMenuItem.menu_item,
235
234
  menu_item_path: getGeneratePath(HOME_REPORT_ROUTES.DETAIL, Object.assign(Object.assign({}, auth), { dashboardId: String(item.dashboardId) })),
236
235
  dashboardEditable,
237
236
  }));
@@ -319,6 +318,16 @@ export const findActiveAppCodeByUrl = (args) => {
319
318
  });
320
319
  }
321
320
  };
321
+ /**
322
+ * Finds the last matched menu item based on the provided URL.
323
+ *
324
+ * @param {Object} args - The arguments object.
325
+ * @param {string} args.url - The URL to match against menu items.
326
+ * @param {TFeatureMenu[]} args.menuItems - The array of menu items to search through.
327
+ * @param {Partial<PayloadInfo>} [args.auth] - Optional authorization information for generating paths.
328
+ * @param {TEnv} [args.env='development'] - Optional environment parameter to adjust path comparison.
329
+ * @returns {TFeatureMenu | undefined} - The last matched menu item, or undefined if not found.
330
+ */
322
331
  export const findLastMatchedItemByUrl = (args) => {
323
332
  try {
324
333
  const { url, menuItems, auth, env = 'development' } = args;
@@ -339,7 +348,7 @@ export const findLastMatchedItemByUrl = (args) => {
339
348
  }
340
349
  };
341
350
  recursiveFindActiveItem(menuItems || []);
342
- const recommendationItem = matchedItems.find(item => item.menu_item_code === HOME_MENU_ITEMS.RECOMMENDATION.menu_item_code);
351
+ const recommendationItem = matchedItems.find(item => item.menu_item_code === HOME_MENU_ITEMS.RECOMMENDATION);
343
352
  if (recommendationItem) {
344
353
  return recommendationItem;
345
354
  }
@@ -353,6 +362,14 @@ export const findLastMatchedItemByUrl = (args) => {
353
362
  });
354
363
  }
355
364
  };
365
+ /**
366
+ * Finds the path of the active menu item in a nested menu structure.
367
+ *
368
+ * @param {Object} args - The arguments object.
369
+ * @param {TFeatureMenu} args.activeMenuItem - The active menu item to find the path for.
370
+ * @param {TFeatureMenu[]} args.menuItems - The array of menu items to search through.
371
+ * @returns {TFeatureMenu[]} - An array representing the path of the active menu item.
372
+ */
356
373
  export const findPathOfActiveItem = (args) => {
357
374
  try {
358
375
  const { activeMenuItem, menuItems } = args;
@@ -441,6 +458,14 @@ export const findActiveAppCodeByChild = (args) => {
441
458
  });
442
459
  }
443
460
  };
461
+ /**
462
+ * Retrieves the custom active application code based on the active key and menu items.
463
+ *
464
+ * @param {Object} args - The arguments object.
465
+ * @param {string} args.activeKey - The active key to search for.
466
+ * @param {TMenuItem[]} args.menuItems - The array of menu items to search through.
467
+ * @returns {string | undefined} - The active application code if found, otherwise undefined.
468
+ */
444
469
  export const getCustomActiveAppCode = (args) => {
445
470
  const { activeKey, menuItems } = args;
446
471
  let activeAppCode;
@@ -187,6 +187,12 @@ export const Layout = memo(props => {
187
187
  replace(`${location.pathname.replace(userIdParam, `${userId}`)}${location.search}`);
188
188
  }
189
189
  }, [params, location, userId, navigate, replace]);
190
+ /** If left menu props has customization then set layout loading to false, because we don't need check permission here */
191
+ useDeepCompareEffect(() => {
192
+ if (mergeLeftMenuProps.customization) {
193
+ setLoadingLayout(false);
194
+ }
195
+ }, [mergeLeftMenuProps.customization]);
190
196
  // Handle access denied
191
197
  const onClickSwitchAccount = useCallback(() => {
192
198
  // Remove cookie when switch account
@@ -275,7 +281,7 @@ export const Layout = memo(props => {
275
281
  showLeftMenu && (React.createElement(LeftMenu, Object.assign({ className: `layout-body__menu ${leftMenuClassName}` }, mergeLeftMenuProps, { customization: Object.assign(Object.assign({}, mergeLeftMenuProps.customization), {
276
282
  // If user has access denied, disable expandable
277
283
  isExpandable: !isAccessDenied && ((_a = mergeLeftMenuProps.customization) === null || _a === void 0 ? void 0 : _a.isExpandable) }), appConfig: leftMenuAppConfig, onActiveMenuCodeChange: onActiveMenuCodeChange }))),
278
- React.createElement(ContentWrapper, Object.assign({ "$noPadding": noPadding, "$noSpaceTopContent": noSpaceTopContent }, mergeContentWrapperProps), (activeMenu === null || activeMenu === void 0 ? void 0 : activeMenu.menu_item_code) === HOME_MENU_ITEMS.RECOMMENDATION.menu_item_code ? (React.createElement("div", { className: "layout-body__content" },
284
+ React.createElement(ContentWrapper, Object.assign({ "$noPadding": noPadding, "$noSpaceTopContent": noSpaceTopContent }, mergeContentWrapperProps), (activeMenu === null || activeMenu === void 0 ? void 0 : activeMenu.menu_item_code) === HOME_MENU_ITEMS.RECOMMENDATION ? (React.createElement("div", { className: "layout-body__content" },
279
285
  React.createElement(RecommendationWorkspace, null))) : (React.createElement("div", Object.assign({ className: `layout-body__content ${(workspaceProps === null || workspaceProps === void 0 ? void 0 : workspaceProps.className) || ''}` }, mergeWorkSpaceProps), isLoadingLayout ? (React.createElement(LayoutLoading, { spinning: true })) : (React.createElement(React.Fragment, null,
280
286
  React.createElement(NotificationWrapper, { className: "process-notification", ref: notificationWrapperRef }, showNotification && (React.createElement(AntsProcessingNotification, Object.assign({}, antsProcessingNotificationConfig, { callback: handleCallbackNotify })))),
281
287
  React.createElement(ChildrenWrapper, Object.assign({}, workspaceContentProps), isAccessDenied ? (React.createElement(AccessDenied, { onClickRequestAccess: onClickRequestAccess, onClickSwitchAccount: onClickSwitchAccount })) : (React.createElement("div", null, children)))))))))));
@@ -11,7 +11,7 @@ export declare const MARKETING_CHANNEL_CODE: {
11
11
  };
12
12
  /**
13
13
  * Check permissions for showing account selection
14
- * Nếu PERMISSION_CODE không được tìm thấy trong api get permissions trong @constant MENU_PERMISSIONS thì sẽ ẩn account selection
14
+ * If PERMISSION_CODE is not found in get permissions api and in @constant MENU_PERMISSIONS then account selection will be hidden
15
15
  */
16
16
  export declare const MENU_PERMISSIONS: {
17
17
  DF_DATA_SOURCE: string;
@@ -19,5 +19,9 @@ export declare const MENU_PERMISSIONS: {
19
19
  REPORT: string;
20
20
  WEB_PERSONALIZE: string;
21
21
  };
22
+ /**
23
+ * In the dev environment, menu items will be removed the hash from menu_item_path,
24
+ * However, menu items with this menu codes will not be removed the hash because they have the same path name.
25
+ */
22
26
  export declare const KEEP_HASH_PATH_DEV: string[];
23
27
  export declare const DUPLICATE_PERMISSION_MENU_CODES: string[];
@@ -11,7 +11,7 @@ export const MARKETING_CHANNEL_CODE = {
11
11
  };
12
12
  /**
13
13
  * Check permissions for showing account selection
14
- * Nếu PERMISSION_CODE không được tìm thấy trong api get permissions trong @constant MENU_PERMISSIONS thì sẽ ẩn account selection
14
+ * If PERMISSION_CODE is not found in get permissions api and in @constant MENU_PERMISSIONS then account selection will be hidden
15
15
  */
16
16
  export const MENU_PERMISSIONS = {
17
17
  DF_DATA_SOURCE: 'DF_DATA_SOURCE',
@@ -19,5 +19,9 @@ export const MENU_PERMISSIONS = {
19
19
  REPORT: 'REPORT',
20
20
  WEB_PERSONALIZE: 'WEB_PERSONALIZE',
21
21
  };
22
+ /**
23
+ * In the dev environment, menu items will be removed the hash from menu_item_path,
24
+ * However, menu items with this menu codes will not be removed the hash because they have the same path name.
25
+ */
22
26
  export const KEEP_HASH_PATH_DEV = ['DF_DATA_SOURCE', 'DATA_SOURCE'];
23
27
  export const DUPLICATE_PERMISSION_MENU_CODES = ['DF_DATA_SOURCE', 'DATA_SOURCE'];
@@ -4,3 +4,9 @@ export declare const FEATURE_PERMISSIONS: {
4
4
  MANAGEMENT_BY_USER: number;
5
5
  EVERYTHING: number;
6
6
  };
7
+ export declare const USER_PERMISSIONS: {
8
+ CREATED_BY_USER: string;
9
+ NONE: string;
10
+ EVERYTHING: string;
11
+ MANAGEMENT_BY_USER: string;
12
+ };
@@ -4,3 +4,9 @@ export const FEATURE_PERMISSIONS = {
4
4
  MANAGEMENT_BY_USER: 3,
5
5
  EVERYTHING: 4,
6
6
  };
7
+ export const USER_PERMISSIONS = {
8
+ CREATED_BY_USER: 'CREATED_BY_USER',
9
+ NONE: 'NONE',
10
+ EVERYTHING: 'EVERYTHING',
11
+ MANAGEMENT_BY_USER: 'MANAGEMENT_BY_USER',
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.569",
3
+ "version": "1.3.5-beta.570",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",