@antscorp/antsomi-ui 1.3.5-beta.277 → 1.3.5-beta.278

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.
@@ -65,6 +65,6 @@ export const AccountListing = props => {
65
65
  recentData.value.map(accountId => accountData === null || accountData === void 0 ? void 0 : accountData.find(account => account.userId === accountId)).filter(Boolean).map(account => (React.createElement(AccountItem, { key: account.userId, userName: account.userName, userId: account.userId, onClick: handleSelectAccount, isSelected: +currentAccount === account.userId }))))), accountData === null || accountData === void 0 ? void 0 :
66
66
  accountData.filter(account => !(recentData === null || recentData === void 0 ? void 0 : recentData.value.includes(account.userId)) &&
67
67
  searchStringQuery(account.userName, searchValue)).map(account => (React.createElement(AccountItem, { key: account.userId, userName: account.userName, userId: account.userId, onClick: handleSelectAccount, isSelected: +currentAccount === account.userId }))))),
68
- showAllAccount ? (React.createElement(Text, { className: `all-account ${isAllAccount ? 'is-selected' : ''}`, onClick: () => handleSelectAccount('') },
68
+ showAllAccount ? (React.createElement(Text, { className: `all-account ${isAllAccount ? 'is-selected' : ''}`, onClick: () => handleSelectAccount('all') },
69
69
  React.createElement("strong", null, "All account"))) : null));
70
70
  };
@@ -32,9 +32,9 @@ export const HeaderV2 = memo(props => {
32
32
  const { env = envContext, language = languageCode, userId = isNaN(Number(auth === null || auth === void 0 ? void 0 : auth.userId)) ? 0 : Number(auth === null || auth === void 0 ? void 0 : auth.userId), portalId = auth === null || auth === void 0 ? void 0 : auth.portalId, token = auth === null || auth === void 0 ? void 0 : auth.token, permissionDomain = PERMISSION_API, iamDomain = IAM_API, appCode = contextAppCode, menuCode = contextMenuCode, } = config || {};
33
33
  const { currentAccount, inputStyle = 'select', onSelectAccount } = accountSelection, accountSelectionProps = __rest(accountSelection, ["currentAccount", "inputStyle", "onSelectAccount"]);
34
34
  const urlParams = useMemo(() => new URLSearchParams(search), [search]);
35
- const oidParam = (_a = urlParams.get('oid')) !== null && _a !== void 0 ? _a : '';
35
+ const oidParam = (_a = urlParams.get('oid')) !== null && _a !== void 0 ? _a : 'all';
36
36
  // States
37
- const [selectedAccount, setSelectedAccount] = useState(`${useURLParam ? oidParam : `${(_b = currentAccount !== null && currentAccount !== void 0 ? currentAccount : userId) !== null && _b !== void 0 ? _b : ''}`}`);
37
+ const [selectedAccount, setSelectedAccount] = useState(`${useURLParam ? oidParam : `${(_b = currentAccount !== null && currentAccount !== void 0 ? currentAccount : userId) !== null && _b !== void 0 ? _b : 'all'}`}`);
38
38
  // Memo
39
39
  const accountSelectionDomain = useMemo(() => {
40
40
  var _a;
@@ -87,7 +87,7 @@ export const HeaderV2 = memo(props => {
87
87
  const handleChangeAccount = (userId) => {
88
88
  setSelectedAccount(userId);
89
89
  if (useURLParam) {
90
- if (userId) {
90
+ if (userId === 'all') {
91
91
  urlParams.set('oid', userId);
92
92
  }
93
93
  else {
@@ -99,7 +99,7 @@ export const HeaderV2 = memo(props => {
99
99
  };
100
100
  return (React.createElement(HeaderV2Styled, { className: className || '', style: style },
101
101
  React.createElement("div", { className: "left-side" },
102
- React.createElement(AccountSelection, Object.assign({}, accountSelectionProps, { currentAccount: selectedAccount || 'all', apiConfig: accountSelectionApiConfig, onChange: handleChangeAccount, inputStyle: inputStyle })),
102
+ React.createElement(AccountSelection, Object.assign({}, accountSelectionProps, { currentAccount: selectedAccount, apiConfig: accountSelectionApiConfig, onChange: handleChangeAccount, inputStyle: inputStyle })),
103
103
  typeof pageTitle === 'string' ? React.createElement("div", { className: "page-title" }, pageTitle) : pageTitle),
104
104
  React.createElement("div", { className: "right-side" },
105
105
  showHelp ? React.createElement(Help, Object.assign({ configs: helpConfigProps }, helpProps)) : null,
@@ -1,28 +1,44 @@
1
1
  // Libraries
2
2
  import { useCallback, useMemo } from 'react';
3
- import { useHistory, useLocation } from 'react-router-dom';
3
+ import { useHistory } from 'react-router-dom';
4
4
  // Constants
5
5
  import { CONFIG_OPTIONS } from './constants';
6
- import { HOME_REPORT_ROUTES } from '../../constants';
6
+ import { HOME_REPORT_ROUTES, HOME_ROUTE } from '../../constants';
7
7
  // Utils
8
8
  import { getGeneratePath, getMenuItem } from '../../utils';
9
9
  // Types
10
10
  import { useLeftMenuStore } from '../../stores';
11
11
  export const useHomeMenu = () => {
12
12
  // Hooks
13
- const { pathname } = useLocation();
13
+ const { pathname, hash, search } = window.location;
14
14
  const history = useHistory();
15
+ // Stores
15
16
  const appMenuChildren = useLeftMenuStore(store => store.state.appMenuChildren);
16
17
  const auth = useLeftMenuStore(store => { var _a; return (_a = store.state.appConfig) === null || _a === void 0 ? void 0 : _a.auth; });
17
18
  // Memos
19
+ const urlParams = useMemo(() => new URLSearchParams(search), [search]);
20
+ // Handlers
21
+ const handleSetSearchParams = useCallback((searchParam) => {
22
+ const url = `${pathname}${hash}`;
23
+ if (url.includes(getGeneratePath(HOME_ROUTE, Object.assign({}, auth)))) {
24
+ urlParams.set('type', searchParam);
25
+ history.replace({ search: urlParams.toString() });
26
+ }
27
+ else {
28
+ history.push(getGeneratePath(HOME_ROUTE, Object.assign({}, auth)));
29
+ urlParams.set('type', searchParam);
30
+ history.replace({ search: urlParams.toString() });
31
+ }
32
+ }, [auth, hash, history, pathname, urlParams]);
33
+ // Memos
18
34
  const onOptionCallback = useCallback((args) => {
19
35
  const { optionKey, menuItemKey } = args;
20
36
  switch (optionKey) {
21
37
  case CONFIG_OPTIONS.CONFIGURE.key: {
22
- const newPathName = getGeneratePath(HOME_REPORT_ROUTES.CONFIGURE, Object.assign(Object.assign({}, auth), { dashboardId: menuItemKey }));
23
- if (newPathName !== pathname) {
24
- history.push(newPathName);
25
- }
38
+ const newPathName = getGeneratePath(HOME_REPORT_ROUTES.DETAIL, Object.assign(Object.assign({}, auth), { dashboardId: menuItemKey }));
39
+ history.push(newPathName);
40
+ urlParams.set('type', HOME_REPORT_ROUTES.CONFIGURE);
41
+ history.replace({ search: urlParams.toString() });
26
42
  break;
27
43
  }
28
44
  case CONFIG_OPTIONS.REMOVE.key:
@@ -30,15 +46,17 @@ export const useHomeMenu = () => {
30
46
  default:
31
47
  break;
32
48
  }
33
- }, [auth, pathname, history]);
49
+ }, [auth, history, urlParams]);
34
50
  const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(appMenuItem => {
35
51
  var _a;
36
52
  return getMenuItem(Object.assign(Object.assign({}, appMenuItem), { children: (_a = appMenuItem === null || appMenuItem === void 0 ? void 0 : appMenuItem.children) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign({}, item), { options: Object.values(CONFIG_OPTIONS), optionCallback: onOptionCallback }))) }));
37
53
  }), [appMenuChildren, onOptionCallback]);
38
54
  // Callbacks
39
55
  const onCreateNewReport = useCallback(() => {
40
- history.push(getGeneratePath(HOME_REPORT_ROUTES.CREATE, auth));
41
- }, [auth, history]);
56
+ history.push(getGeneratePath(HOME_ROUTE, auth));
57
+ urlParams.set('type', HOME_REPORT_ROUTES.CREATE);
58
+ history.replace({ search: urlParams.toString() });
59
+ }, [auth, history, urlParams]);
42
60
  const onMenuClick = useCallback((key, _) => {
43
61
  const newPathName = getGeneratePath(HOME_REPORT_ROUTES.DETAIL, Object.assign(Object.assign({}, auth), { dashboardId: key }));
44
62
  if (newPathName !== pathname) {
@@ -16,6 +16,7 @@ export declare const MENU_ITEM_TYPE: {
16
16
  };
17
17
  export declare const ICON_SIZE = 20;
18
18
  export declare const HOME_MENU_ITEMS: Record<string, TMenuFeatureItem>;
19
+ export declare const HOME_ROUTE = "/gen2/:networkId/dashboard";
19
20
  export declare const HOME_REPORT_ROUTES: {
20
21
  DETAIL: string;
21
22
  CONFIGURE: string;
@@ -32,11 +32,11 @@ export const HOME_MENU_ITEMS = {
32
32
  icon_name: null,
33
33
  },
34
34
  };
35
- const HOME_ROUTE = '/gen2/:networkId/dashboard';
35
+ export const HOME_ROUTE = '/gen2/:networkId/dashboard';
36
36
  export const HOME_REPORT_ROUTES = {
37
37
  DETAIL: `${HOME_ROUTE}/detail/:dashboardId`,
38
- CONFIGURE: `${HOME_ROUTE}/detail/:dashboardId/configure`,
39
- CREATE: `${HOME_ROUTE}/create`,
38
+ CONFIGURE: `configure`,
39
+ CREATE: `create`,
40
40
  };
41
41
  /* MARKETING APP */
42
42
  export const MARKETING_ROUTES = {
@@ -8,6 +8,8 @@ import { findActiveAppCodeByChild, findActiveAppCodeByUrl, findLastMatchedItemBy
8
8
  // Store
9
9
  import { useLeftMenuStore } from '../stores';
10
10
  import { POST_MESSAGE_TYPES } from '@antscorp/antsomi-ui/es/constants/postMessage';
11
+ // Constants
12
+ import { CDP_API, PERMISSION_API, PERMISSION_ENV_API } from '@antscorp/antsomi-ui/es/constants';
11
13
  const initialState = {
12
14
  hoverItem: '',
13
15
  isExpandMenu: true,
@@ -17,21 +19,22 @@ export const useLeftMenu = (props) => {
17
19
  const { objectType = 'OVERVIEW', objectId = 1, isGrouped = true, appConfig, customization, onActiveMenuCodeChange, } = props;
18
20
  const { isExpandable = true, isCustomized = false, items, activeKey } = customization || {};
19
21
  // Hooks
20
- const { pathname, hash } = window.location;
22
+ const { pathname, hash, search } = window.location;
23
+ const urlParams = useMemo(() => new URLSearchParams(search), [search]);
21
24
  // Stores
22
25
  const activeAppCode = useLeftMenuStore(store => store.state.activeAppCode);
23
26
  const customActiveAppKey = useLeftMenuStore(store => store.state.customActiveAppKey);
24
27
  const setLeftMenuState = useLeftMenuStore(store => store.setState);
25
28
  // Destructuring variables
26
- const { auth, languageCode } = appConfig || {};
29
+ const { auth, languageCode, env } = appConfig || {};
27
30
  // State
28
31
  const [state, setState] = useState(initialState);
29
32
  // Queries
30
33
  const { data: menuList } = useGetListMenu({
31
34
  args: {
32
35
  auth: {
33
- token: '5474r2x214r2b4b4v2d4y444u2v5q2p5o4d4c4f424e4' || (auth === null || auth === void 0 ? void 0 : auth.token),
34
- url: 'https://sandbox-permission.ants.vn',
36
+ token: env === 'production' ? auth === null || auth === void 0 ? void 0 : auth.token : '5474r2x214r2b4b4v2d4y444u2v5q2p5o4d4c4f424e4',
37
+ url: env ? PERMISSION_ENV_API[env] : '',
35
38
  portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
36
39
  userId: auth === null || auth === void 0 ? void 0 : auth.userId,
37
40
  accountId: auth === null || auth === void 0 ? void 0 : auth.accountId,
@@ -44,10 +47,10 @@ export const useLeftMenu = (props) => {
44
47
  const { data: menuListPermission } = useGetListMenuPermission({
45
48
  args: {
46
49
  auth: {
47
- token: '5474r2x214z284d4w2b4y454a4p5x2d4j4n4w2q4a4v5' || (auth === null || auth === void 0 ? void 0 : auth.token),
48
- url: 'https://permission.antsomi.com',
49
- userId: '1600083836' || (auth === null || auth === void 0 ? void 0 : auth.userId),
50
- accountId: '1600083836' || (auth === null || auth === void 0 ? void 0 : auth.accountId),
50
+ token: auth === null || auth === void 0 ? void 0 : auth.token,
51
+ url: PERMISSION_API,
52
+ userId: auth === null || auth === void 0 ? void 0 : auth.userId,
53
+ accountId: auth === null || auth === void 0 ? void 0 : auth.accountId,
51
54
  },
52
55
  params: {
53
56
  type: 'list-app',
@@ -61,7 +64,7 @@ export const useLeftMenu = (props) => {
61
64
  args: {
62
65
  auth: {
63
66
  token: auth === null || auth === void 0 ? void 0 : auth.token,
64
- url: 'https://sandbox-app.cdp.asia/hub',
67
+ url: env ? `${CDP_API.production}/hub` : '',
65
68
  portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
66
69
  userId: auth === null || auth === void 0 ? void 0 : auth.userId,
67
70
  },
@@ -76,9 +79,9 @@ export const useLeftMenu = (props) => {
76
79
  const { data: destinationChannel } = useGetDestinationChannel({
77
80
  args: {
78
81
  auth: {
79
- token: '5474r2x214z2a46403e4y4749426s2v544r2i4u2k5t5' || (auth === null || auth === void 0 ? void 0 : auth.token),
80
- url: 'https://sandbox-app.cdp.asia/hub',
81
- userId: '1600085179' || (auth === null || auth === void 0 ? void 0 : auth.userId),
82
+ token: auth === null || auth === void 0 ? void 0 : auth.token,
83
+ url: env ? `${CDP_API[env]}/hub` : '',
84
+ userId: auth === null || auth === void 0 ? void 0 : auth.userId,
82
85
  portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
83
86
  },
84
87
  params: {
@@ -165,35 +168,20 @@ export const useLeftMenu = (props) => {
165
168
  items,
166
169
  customActiveAppKey,
167
170
  ]);
168
- /**
169
- * Active App Item having code matching url
170
- */
171
171
  useEffect(() => {
172
+ var _a;
172
173
  if (!isCustomized) {
173
174
  const url = `${pathname}${hash}`;
175
+ /**
176
+ * Active App Item having code matching url
177
+ */
174
178
  const matchAppCode = findActiveAppCodeByUrl({ url, menuItems: mappingChildrenMenu, auth });
175
179
  if (matchAppCode && matchAppCode !== activeAppCode) {
176
180
  setLeftMenuState({ activeAppCode: matchAppCode });
177
181
  }
178
- }
179
- }, [
180
- isCustomized,
181
- activeAppCode,
182
- appConfig === null || appConfig === void 0 ? void 0 : appConfig.auth,
183
- auth,
184
- hash,
185
- mappingChildrenMenu,
186
- pathname,
187
- permissionMenu,
188
- setLeftMenuState,
189
- ]);
190
- /**
191
- * Callback function when url change
192
- */
193
- useEffect(() => {
194
- var _a;
195
- if (!isCustomized) {
196
- const url = `${pathname}${hash}`;
182
+ /**
183
+ * Callback function when url change
184
+ */
197
185
  const matchedCode = (_a = findLastMatchedItemByUrl({
198
186
  url,
199
187
  menuItems: mappingChildrenMenu,
@@ -209,12 +197,16 @@ export const useLeftMenu = (props) => {
209
197
  }
210
198
  }, [
211
199
  isCustomized,
200
+ activeAppCode,
212
201
  auth,
213
- flattenMenuPermission,
214
202
  hash,
215
203
  mappingChildrenMenu,
216
- onActiveMenuCodeChange,
217
204
  pathname,
205
+ permissionMenu,
206
+ setLeftMenuState,
207
+ onActiveMenuCodeChange,
208
+ flattenMenuPermission,
209
+ urlParams,
218
210
  ]);
219
211
  /* Callbacks */
220
212
  const onToggleChildMenu = useCallback(() => {
@@ -170,7 +170,7 @@ export const FeatureMenuItem = styled.div `
170
170
  .popup-triangle {
171
171
  opacity: 0;
172
172
  visibility: hidden;
173
- right: -4px;
173
+ right: -6px;
174
174
  position: absolute;
175
175
  width: 0;
176
176
  height: 0;
@@ -20,6 +20,11 @@ export declare const APP_PERMISSION_DOMAIN: {
20
20
  production: string;
21
21
  };
22
22
  };
23
+ export declare const PERMISSION_ENV_API: {
24
+ development: string;
25
+ sandbox: string;
26
+ production: string;
27
+ };
23
28
  export declare const APP_IAM_DOMAIN: {
24
29
  [x: string]: {
25
30
  development: string;
@@ -17,18 +17,16 @@ export const PLATFORM_API = 'https://platform.ants.tech';
17
17
  export const PERMISSION_API = 'https://permission.antsomi.com';
18
18
  export const SOCKET_API = 'https://ws.ants.tech';
19
19
  export const IAM_API = 'https://iam.ants.tech';
20
+ const PERMISSION_URLS = {
21
+ [ENV.DEV]: 'https://sandbox-permission.ants.vn',
22
+ [ENV.SANDBOX]: 'https://sandbox-permission.ants.vn',
23
+ [ENV.PROD]: 'https://permission.antsomi.com',
24
+ };
20
25
  export const APP_PERMISSION_DOMAIN = {
21
- [DATAFLOWS]: {
22
- [ENV.DEV]: 'https://sandbox-permission.ants.vn',
23
- [ENV.SANDBOX]: 'https://sandbox-permission.ants.vn',
24
- [ENV.PROD]: 'https://permission.antsomi.com',
25
- },
26
- [APP_ANTALYSER]: {
27
- [ENV.DEV]: 'https://sandbox-permission.ants.vn',
28
- [ENV.SANDBOX]: 'https://sandbox-permission.ants.vn',
29
- [ENV.PROD]: 'https://permission.antsomi.com',
30
- },
26
+ [DATAFLOWS]: PERMISSION_URLS,
27
+ [APP_ANTALYSER]: PERMISSION_URLS,
31
28
  };
29
+ export const PERMISSION_ENV_API = PERMISSION_URLS;
32
30
  export const APP_IAM_DOMAIN = {
33
31
  [DATAFLOWS]: {
34
32
  [ENV.DEV]: 'https://sandbox-aacm.ants.vn',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.277",
3
+ "version": "1.3.5-beta.278",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",