@antscorp/antsomi-ui 1.3.5-beta.584 → 1.3.5-beta.586

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.
@@ -12,7 +12,7 @@ export const AccountListing = React.forwardRef((props, ref) => {
12
12
  const { className, apiConfig, showAllAccount = true, currentAccount = '', onChange } = props;
13
13
  // States
14
14
  const [searchValue, setSearchValue] = useState('');
15
- const { accountData, recentData } = useAccountSelection(apiConfig);
15
+ const { accountData, recentData, updateRecentAccount } = useAccountSelection(apiConfig);
16
16
  const isAllAccount = currentAccount === 'all';
17
17
  useImperativeHandle(ref, () => ({
18
18
  getUsers() {
@@ -21,8 +21,17 @@ export const AccountListing = React.forwardRef((props, ref) => {
21
21
  }), [recentData, accountData]);
22
22
  // Handlers
23
23
  const handleSelectAccount = useCallback((userId) => {
24
+ const currentRecent = (recentData === null || recentData === void 0 ? void 0 : recentData.value) || [];
25
+ const body = userId !== currentRecent[0]
26
+ ? [userId, currentRecent[0]]
27
+ : currentRecent[1]
28
+ ? [userId, currentRecent[1]]
29
+ : [userId, currentRecent[0]];
30
+ updateRecentAccount(body.map(id => Number(id)));
24
31
  onChange === null || onChange === void 0 ? void 0 : onChange(userId);
25
- }, [onChange]);
32
+ },
33
+ // eslint-disable-next-line react-hooks/exhaustive-deps
34
+ [onChange, recentData]);
26
35
  return (React.createElement(AccountSelectionStyled, { className: className },
27
36
  React.createElement(Input, { placeholder: "Search", suffix: React.createElement(Icon, { type: "icon-ants-search-2", style: { fontSize: '24px', color: (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.bw8 } }), value: searchValue, onChange: event => setSearchValue(event.target.value) }),
28
37
  React.createElement("div", { className: "account-list" },
@@ -17,5 +17,6 @@ export declare const useAccountSelection: (apiConfig: {
17
17
  }) => {
18
18
  recentData?: AccountRecent;
19
19
  accountData: Array<AccountData>;
20
+ updateRecentAccount: (values: [number, number]) => void;
20
21
  };
21
22
  export {};
@@ -1,7 +1,7 @@
1
1
  // Libraries
2
2
  import { useMemo } from 'react';
3
3
  // Queries
4
- import { useGetAccountList, useGetPermissionAccountList, useGetRecentAccount, } from '@antscorp/antsomi-ui/es/queries';
4
+ import { useGetAccountList, useGetPermissionAccountList, useGetRecentAccount, useUpdateRecentAccount, } from '@antscorp/antsomi-ui/es/queries';
5
5
  // Constant
6
6
  import { APP_CODES } from '@antscorp/antsomi-ui/es/constants';
7
7
  const { APP_ANTALYSER, DATAFLOWS } = APP_CODES;
@@ -41,6 +41,9 @@ export const useAccountSelection = (apiConfig) => {
41
41
  enabled: !isUsePermissionAccount(appCode || ''),
42
42
  },
43
43
  });
44
+ const { mutateAsync: updateRecentAccount } = useUpdateRecentAccount({
45
+ apiConfig,
46
+ });
44
47
  // Memos
45
48
  const accountData = useMemo(() => {
46
49
  if (isUsePermissionAccount(appCode || '')) {
@@ -53,5 +56,5 @@ export const useAccountSelection = (apiConfig) => {
53
56
  }
54
57
  return (data === null || data === void 0 ? void 0 : data.entries) || [];
55
58
  }, [appCode, data === null || data === void 0 ? void 0 : data.entries, permissionAccountList]);
56
- return { recentData, accountData };
59
+ return { recentData, accountData, updateRecentAccount };
57
60
  };
@@ -209,7 +209,11 @@ export const ChildMenu = memo(props => {
209
209
  });
210
210
  };
211
211
  return (React.createElement(MenuWrapper, null,
212
- React.createElement(Menu, { selectedKeys: [currentActiveItem], defaultOpenKeys: [currentActiveItem], openKeys: uniq(openKeys), mode: "inline", items: customMenuItems({ items }), inlineIndent: 12, onOpenChange: openKeys => {
212
+ React.createElement(Menu, { motion: {
213
+ motionAppear: false,
214
+ motionEnter: false,
215
+ motionLeave: false,
216
+ }, selectedKeys: [currentActiveItem], defaultOpenKeys: [currentActiveItem], openKeys: uniq(openKeys), mode: "inline", items: customMenuItems({ items }), inlineIndent: 12, onOpenChange: openKeys => {
213
217
  setOpenKeys(uniq(openKeys));
214
218
  }, expandIcon: ({ isOpen }) => (React.createElement(Icon, { type: "icon-ants-expand-more", style: Object.assign(Object.assign({}, styles.expandIcon), { transform: `rotate(${isOpen ? '180deg' : '0deg'})` }) })), onClick: onClick })));
215
219
  });
@@ -1,5 +1,5 @@
1
- import { UseQueryOptions } from '@tanstack/react-query';
2
- import { TAccountParams } from '../../services/Account';
1
+ import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
2
+ import { TAccountParams, TUpdateRecentAccount } from '../../services/Account';
3
3
  import { AccountListing, AccountRecent, TAccountPermission } from '../../models/AccountListing';
4
4
  type OptionHasDefault = 'queryKey' | 'queryFn';
5
5
  type GetAccountListProps = {
@@ -10,11 +10,20 @@ type GetRecentAccountProps = {
10
10
  apiConfig: TAccountParams;
11
11
  options?: Omit<UseQueryOptions<any, any, AccountRecent, any[]>, OptionHasDefault>;
12
12
  };
13
+ type UpdateRecentAccountProps = {
14
+ apiConfig: TAccountParams;
15
+ options?: UseMutationOptions<{
16
+ status: number;
17
+ }, any, TUpdateRecentAccount['data'], unknown>;
18
+ };
13
19
  type TCheckUserPermissionProps = {
14
20
  apiConfig: TAccountParams;
15
21
  options?: Omit<UseQueryOptions<any, any, TAccountPermission | undefined, any[]>, OptionHasDefault>;
16
22
  };
17
23
  export declare const useGetAccountList: (props: GetAccountListProps) => import("@tanstack/react-query").UseQueryResult<AccountListing, any>;
18
24
  export declare const useGetRecentAccount: (props: GetRecentAccountProps) => import("@tanstack/react-query").UseQueryResult<AccountRecent, any>;
25
+ export declare const useUpdateRecentAccount: (props: UpdateRecentAccountProps) => import("@tanstack/react-query").UseMutationResult<{
26
+ status: number;
27
+ }, any, [number, number], unknown>;
19
28
  export declare const useCheckUserPermission: (props: TCheckUserPermissionProps) => import("@tanstack/react-query").UseQueryResult<TAccountPermission | undefined, any>;
20
29
  export {};
@@ -1,10 +1,10 @@
1
1
  // Libraries
2
- import { useQuery } from '@tanstack/react-query';
2
+ import { useQuery, useMutation, useQueryClient, } from '@tanstack/react-query';
3
3
  // Services
4
4
  import { accountService } from '../../services/Account';
5
5
  // Constants
6
6
  import { QUERY_KEYS } from '../../constants/queries';
7
- const { getList, getRecentAccount, checkPermission } = accountService;
7
+ const { getList, getRecentAccount, updateRecentAccount, checkPermission } = accountService;
8
8
  export const useGetAccountList = (props) => {
9
9
  const { apiConfig, options } = props;
10
10
  return useQuery(Object.assign({ queryKey: [QUERY_KEYS.GET_ACCOUNT_LISTING, apiConfig], queryFn: () => getList(apiConfig) }, options));
@@ -13,6 +13,15 @@ export const useGetRecentAccount = (props) => {
13
13
  const { apiConfig, options } = props;
14
14
  return useQuery(Object.assign({ queryKey: [QUERY_KEYS.GET_RECENT_ACCOUNT], queryFn: () => getRecentAccount(apiConfig) }, options));
15
15
  };
16
+ export const useUpdateRecentAccount = (props) => {
17
+ const { apiConfig, options } = props;
18
+ const queryClient = useQueryClient();
19
+ return useMutation(Object.assign({ mutationFn: variables => updateRecentAccount({ params: apiConfig, data: variables }), onSettled: () => {
20
+ queryClient.invalidateQueries([QUERY_KEYS.GET_RECENT_ACCOUNT], {
21
+ exact: false,
22
+ });
23
+ } }, options));
24
+ };
16
25
  export const useCheckUserPermission = (props) => {
17
26
  const { apiConfig, options } = props;
18
27
  const { languageCode, userId, portalId } = apiConfig;
@@ -7,8 +7,15 @@ export type TAccountParams = {
7
7
  accountId?: number;
8
8
  token?: string;
9
9
  };
10
+ export type TUpdateRecentAccount = {
11
+ params: TAccountParams;
12
+ data: [number, number];
13
+ };
10
14
  export declare const accountService: {
11
15
  getList: (config: TAccountParams) => Promise<AccountListing>;
12
16
  getRecentAccount: (config: TAccountParams) => Promise<AccountRecent | undefined>;
13
17
  checkPermission: (config: TAccountParams) => Promise<TAccountPermission>;
18
+ updateRecentAccount: (args: TUpdateRecentAccount) => Promise<{
19
+ status: number;
20
+ }>;
14
21
  };
@@ -86,4 +86,32 @@ export const accountService = {
86
86
  return Promise.reject(error);
87
87
  }
88
88
  }),
89
+ updateRecentAccount: (args) => __awaiter(void 0, void 0, void 0, function* () {
90
+ const { params, data } = args;
91
+ const { domain, languageCode = 'en', portalId = 33167, userId, token } = params;
92
+ try {
93
+ const response = yield axios({
94
+ method: 'PUT',
95
+ url: `${domain}${API_RECENT}`,
96
+ params: {
97
+ portalId,
98
+ languageCode,
99
+ _user_id: userId,
100
+ },
101
+ headers: {
102
+ Token: token,
103
+ },
104
+ data: {
105
+ value: JSON.stringify(data),
106
+ },
107
+ });
108
+ return {
109
+ status: +get(response, 'data.data.status', ''),
110
+ };
111
+ // return undefined;
112
+ }
113
+ catch (error) {
114
+ return Promise.reject(error);
115
+ }
116
+ }),
89
117
  };
package/es/test.js CHANGED
@@ -20,7 +20,6 @@ import axios from 'axios';
20
20
  import { get } from 'lodash';
21
21
  import { MENU_PERMISSION } from './components/molecules/ShareAccess/constants';
22
22
  import { ConfigProvider } from './providers';
23
- import { DataTableTest } from './tests';
24
23
  const SHARE_ACCESS_DEFAULT_VALUE = {
25
24
  ownerId: 1600085510,
26
25
  isPublic: 1,
@@ -109,7 +108,10 @@ export const App = () => {
109
108
  /* MatchesAnySelect */
110
109
  // return <MatchesAnySelectTest />;
111
110
  /* Data Table */
112
- return React.createElement(DataTableTest, null);
111
+ return (React.createElement("div", null,
112
+ "THIS IS TEST VITE BUILD",
113
+ React.createElement(Button, null, "Click me")));
114
+ // return <DataTableTest />;
113
115
  // --------------------------- Test Layout 2.0 -------------------------------------------
114
116
  return React.createElement(Layout, { leftMenuProps: { objectId: 1, objectType: 'OVERVIEW', isGrouped: true } });
115
117
  // --------------------------- Test SlideBar start -------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.584",
3
+ "version": "1.3.5-beta.586",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",
@@ -36,7 +36,8 @@
36
36
  "test:update-snapshot": "jest -u",
37
37
  "test:changed": "jest --onlyChanged",
38
38
  "test:watch": "jest --watch",
39
- "test:coverage": "yarn test:clean && yarn jest --coverage",
39
+ "test:coverage": "jest --coverage",
40
+ "test:vitest": "vitest",
40
41
  "ts-compile": "tsc -p tsconfig.esm.json",
41
42
  "copy-files": "copyfiles -u 1 src/**/*.json src/**/*.svg src/**/*.scss src/**/*.png es",
42
43
  "icons:add": "tsx scripts/add-icons.ts",
@@ -166,8 +167,8 @@
166
167
  "@storybook/react": "^8.2.4",
167
168
  "@storybook/react-webpack5": "^8.2.4",
168
169
  "@storybook/theming": "^8.2.4",
169
- "@testing-library/jest-dom": "^5.16.5",
170
- "@testing-library/react": "^14.0.0",
170
+ "@testing-library/jest-dom": "^6.4.8",
171
+ "@testing-library/react": "^16.0.0",
171
172
  "@types/jest": "^29.5.0",
172
173
  "@types/node": "^18.15.10",
173
174
  "@types/pako": "2.0.0",
@@ -208,6 +209,7 @@
208
209
  "husky": "^8.0.3",
209
210
  "jest": "^29.5.0",
210
211
  "jest-environment-jsdom": "^29.5.0",
212
+ "jsdom": "^24.1.1",
211
213
  "lint-staged": "^13.2.0",
212
214
  "mini-css-extract-plugin": "^2.7.5",
213
215
  "postcss": "^8.4.21",
@@ -231,8 +233,9 @@
231
233
  "type-fest": "^4.10.2",
232
234
  "tsx": "^4.16.2",
233
235
  "typescript": "^5.4.3",
234
- "vite": "^4.2.1",
235
- "vite-plugin-mkcert": "^1.15.0",
236
+ "vite": "^5.3.4",
237
+ "vite-plugin-mkcert": "^1.17.5",
238
+ "vitest": "^2.0.4",
236
239
  "webpack": "^5.78.0",
237
240
  "webpack-bundle-analyzer": "^4.10.1",
238
241
  "webpack-cli": "^5.0.1"