@antscorp/antsomi-ui 1.3.5-beta.265 → 1.3.5-beta.266

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.
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  // Libraries
2
11
  import React, { memo, useEffect, useLayoutEffect, useState } from 'react';
3
12
  import { get, isArray, isEmpty, set } from 'lodash';
@@ -16,12 +25,13 @@ import { FILTERS_DEFAULT, ITEM_TYPE_NAME, PRODUCT_ITEM_TYPE_ID, PRODUCT_RANKING_
16
25
  // Queries
17
26
  import { useGetListBO } from '@antscorp/antsomi-ui/es/queries/BusinessObject';
18
27
  import { useGetListFallbackBO } from '@antscorp/antsomi-ui/es/queries/ThirdParty';
28
+ import { getDataTableBOQuery } from '@antscorp/antsomi-ui/es/queries/BusinessObject/useGetDataTableBO';
19
29
  // Hooks
20
30
  import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
21
31
  import { useDebounce } from '@antscorp/antsomi-ui/es/hooks/useDebounceV2';
22
32
  // Provider
23
- import { useContentSourceDispatch, useSelectContentSources, useSelectModeView } from './provider';
24
- import { deleteContentSourceGroup, setContentSourceGroup, updateContentSourceSettings, updateModeView, } from './reducer';
33
+ import { useContentSourceDispatch, useSelectBoIdByGroupFromCS, useSelectContentSources, useSelectModeView, } from './provider';
34
+ import { deleteContentSourceGroup, setContentSourceGroup, setContentSourceGroupBOData, updateContentSourceSettings, updateModeView, } from './reducer';
25
35
  // Utils
26
36
  import { handleError } from '@antscorp/antsomi-ui/es/utils';
27
37
  const PATH = 'src/components/organism/ContentSources/Settings.tsx';
@@ -29,11 +39,13 @@ const Settings = (props) => {
29
39
  const { serviceAuth, mode, isShowErrorAlert, initValue, journeySettings, onChange } = props;
30
40
  const { url = '', userId, token, accountId } = serviceAuth;
31
41
  const { t } = i18nInstance;
42
+ const boIdByGroupCS = useSelectBoIdByGroupFromCS();
32
43
  const contentSources = useSelectContentSources();
33
44
  const { groups, expanded } = contentSources;
34
45
  const modeView = useSelectModeView();
35
46
  const isCDP = modeView === 'CDP';
36
47
  const [isInitDataCDPDone, setIsInitDataCDPDone] = useState(false);
48
+ const [isLoadingDataTableBO, setIsLoadingDataTableBO] = useState(false);
37
49
  const contentSourcesDebounce = useDebounce(contentSources, 400);
38
50
  const { data: listBO, isLoading: isLoadingListBO, refetch: refetchListBO, } = useGetListBO({
39
51
  url,
@@ -232,6 +244,35 @@ const Settings = (props) => {
232
244
  }
233
245
  }
234
246
  }, [initValue, contentSourceDispatch, isCDP]);
247
+ useDeepCompareEffect(() => {
248
+ let ignore = false;
249
+ if (!isEmpty(boIdByGroupCS) && !isEmpty(serviceAuth)) {
250
+ const groupKeyList = Object.keys(boIdByGroupCS);
251
+ const fetchListCSDataTableBO = () => __awaiter(void 0, void 0, void 0, function* () {
252
+ const listPromises = [];
253
+ groupKeyList.forEach(groupId => {
254
+ const itemTypeId = boIdByGroupCS[groupId];
255
+ const promise = getDataTableBOQuery(serviceAuth, itemTypeId, { groupId });
256
+ listPromises.push(promise);
257
+ });
258
+ setIsLoadingDataTableBO(true);
259
+ const listBOResponses = yield Promise.all(listPromises);
260
+ const boDataByGroupId = {};
261
+ listBOResponses.forEach(item => {
262
+ const { data, params } = item;
263
+ boDataByGroupId[params.groupId] = data.data;
264
+ });
265
+ if (!ignore) {
266
+ contentSourceDispatch(setContentSourceGroupBOData(boDataByGroupId));
267
+ }
268
+ setIsLoadingDataTableBO(false);
269
+ });
270
+ fetchListCSDataTableBO();
271
+ }
272
+ return () => {
273
+ ignore = true;
274
+ };
275
+ }, [boIdByGroupCS, serviceAuth, contentSourceDispatch]);
235
276
  // callback data out
236
277
  useDeepCompareEffect(() => {
237
278
  if (typeof onChange === 'function') {
@@ -239,7 +280,7 @@ const Settings = (props) => {
239
280
  }
240
281
  }, [contentSourcesDebounce]);
241
282
  return (React.createElement(ContentContainer, { className: "contentsource-container" },
242
- React.createElement(Content, { isLoadingListBO: isLoadingListBO, listBO: listBO, groups: groups, expanded: expanded, onChangeExpand: expanded => {
283
+ React.createElement(Content, { isLoadingListBO: isLoadingListBO || isLoadingDataTableBO, listBO: listBO, groups: groups, expanded: expanded, onChangeExpand: expanded => {
243
284
  contentSourceDispatch({
244
285
  type: 'EXPANDED',
245
286
  payload: {
@@ -11,4 +11,7 @@ export declare const useContentSourceState: () => ContentSourceState;
11
11
  export declare const useContentSourceDispatch: () => React.Dispatch<UpdateGroupAction>;
12
12
  export declare const useSelectServiceAuth: () => import("@antscorp/antsomi-ui/es/types").PayloadInfo;
13
13
  export declare const useSelectContentSources: () => import("./types").TContentSourceSettings;
14
+ export declare const useSelectCSGroups: () => import("./types").TContentSourceGroup[];
14
15
  export declare const useSelectModeView: () => import("./types").ContentSourceModeView;
16
+ export declare const useSelectBoIdByGroupFromCS: () => Record<string, number>;
17
+ export declare const useSelectDataTableBOByGroupId: (groupId: string) => Record<string, any>[];
@@ -1,5 +1,6 @@
1
1
  // Libraries
2
2
  import React, { createContext, useContext, useMemo, useReducer } from 'react';
3
+ import _ from 'lodash';
3
4
  // Reducer
4
5
  import { contentSourceReducer, initialContentSourceState } from './reducer';
5
6
  export const ContentSourceContext = createContext(initialContentSourceState);
@@ -21,7 +22,35 @@ export const useSelectContentSources = () => {
21
22
  const { contentSources } = useContentSourceState();
22
23
  return useMemo(() => contentSources, [contentSources]);
23
24
  };
25
+ export const useSelectCSGroups = () => {
26
+ const { contentSources } = useContentSourceState();
27
+ return useMemo(() => contentSources.groups || [], [contentSources]);
28
+ };
24
29
  export const useSelectModeView = () => {
25
30
  const { mode } = useContentSourceState();
26
31
  return useMemo(() => mode, [mode]);
27
32
  };
33
+ export const useSelectBoIdByGroupFromCS = () => {
34
+ const csGroups = useSelectCSGroups();
35
+ const result = useMemo(() => {
36
+ const collectItemTypeId = {};
37
+ csGroups.forEach(group => {
38
+ if (group.itemTypeId !== null) {
39
+ collectItemTypeId[group.groupId] = group.itemTypeId;
40
+ }
41
+ });
42
+ return collectItemTypeId;
43
+ }, [csGroups]);
44
+ return result;
45
+ };
46
+ export const useSelectDataTableBOByGroupId = (groupId) => {
47
+ const csGroups = useSelectCSGroups();
48
+ const result = useMemo(() => {
49
+ const group = csGroups.find(group => group.groupId === groupId);
50
+ if (group) {
51
+ return _.get(group, 'data', []) || [];
52
+ }
53
+ return [];
54
+ }, [csGroups, groupId]);
55
+ return result;
56
+ };
@@ -1,5 +1,5 @@
1
1
  import { TServiceAuth } from '@antscorp/antsomi-ui/es/types';
2
- import { UpdateGroupAction, TContentSourceSettings, TContentSourceGroup, ActionSetContentSourceGroup, ActionDeleteContentSourceGroup, ContentSourceModeView, ActionUpdateModeView, ActionUpdateContentSourceSettings } from './types';
2
+ import { UpdateGroupAction, TContentSourceSettings, TContentSourceGroup, ActionSetContentSourceGroup, ActionDeleteContentSourceGroup, ContentSourceModeView, ActionUpdateModeView, ActionUpdateContentSourceSettings, ActionSetContentSourceGroupBOData } from './types';
3
3
  export interface ContentSourceState {
4
4
  serviceAuth: TServiceAuth;
5
5
  mode: ContentSourceModeView;
@@ -15,3 +15,4 @@ export declare const setContentSourceGroup: (payload: {
15
15
  export declare const deleteContentSourceGroup: (groupId: string) => ActionDeleteContentSourceGroup;
16
16
  export declare const updateModeView: (mode: ContentSourceModeView) => ActionUpdateModeView;
17
17
  export declare const updateContentSourceSettings: (contentSources: TContentSourceSettings) => ActionUpdateContentSourceSettings;
18
+ export declare const setContentSourceGroupBOData: (boDataByGroupId: Record<string, any[]>) => ActionSetContentSourceGroupBOData;
@@ -1,5 +1,6 @@
1
1
  // Libraries
2
2
  import produce from 'immer';
3
+ import { has } from 'lodash';
3
4
  // Utils
4
5
  import { initGroup as initContentSourceGroup } from './utils';
5
6
  // Constants
@@ -61,6 +62,16 @@ export const contentSourceReducer = (state, action) => produce(state, draft => {
61
62
  }
62
63
  break;
63
64
  }
65
+ case 'SET_CONTENT_SOURCE_GROUP_BODATA': {
66
+ const { boDataByGroupId } = action.payload;
67
+ draft.contentSources.groups.map(g => {
68
+ if (has(boDataByGroupId, g.groupId)) {
69
+ g.data = boDataByGroupId[g.groupId];
70
+ }
71
+ return g;
72
+ });
73
+ break;
74
+ }
64
75
  default: {
65
76
  return state;
66
77
  }
@@ -85,3 +96,9 @@ export const updateContentSourceSettings = (contentSources) => ({
85
96
  contentSources,
86
97
  },
87
98
  });
99
+ export const setContentSourceGroupBOData = (boDataByGroupId) => ({
100
+ type: 'SET_CONTENT_SOURCE_GROUP_BODATA',
101
+ payload: {
102
+ boDataByGroupId,
103
+ },
104
+ });
@@ -130,5 +130,11 @@ export interface ActionUpdateContentSourceSettings extends Action {
130
130
  contentSources: TContentSourceSettings;
131
131
  };
132
132
  }
133
- export type UpdateGroupAction = ActionUpdateContentSourceSettings | ActionServiceAuth | ActionAddContentSource | ActionUpdateModeView | ActionDeleteContentSourceGroup | ActionSetContentSourceGroup | ActionUpdateSource | ActionUpdateFilter | ActionUpdateFallback | ActionUpdateName | ActionUpdateAlgorithms | ActionUpdateExpanded | ActionUpdateLevel;
133
+ export interface ActionSetContentSourceGroupBOData extends Action {
134
+ type: 'SET_CONTENT_SOURCE_GROUP_BODATA';
135
+ payload: {
136
+ boDataByGroupId: Record<string, any[]>;
137
+ };
138
+ }
139
+ export type UpdateGroupAction = ActionUpdateContentSourceSettings | ActionSetContentSourceGroupBOData | ActionServiceAuth | ActionAddContentSource | ActionUpdateModeView | ActionDeleteContentSourceGroup | ActionSetContentSourceGroup | ActionUpdateSource | ActionUpdateFilter | ActionUpdateFallback | ActionUpdateName | ActionUpdateAlgorithms | ActionUpdateExpanded | ActionUpdateLevel;
134
140
  export {};
@@ -7,3 +7,4 @@ export { Table, ExplorePivotTable, EXPLORE_PIVOT_TABLE_TEST_DATA } from './Table
7
7
  export { GenerativeInsights } from './GenerativeInsights';
8
8
  export { default as ContentSources } from './ContentSources';
9
9
  export { LeftMenu, type LeftMenuProps } from './LeftMenu';
10
+ export * from './ContentSources/provider';
@@ -7,3 +7,4 @@ export { Table, ExplorePivotTable, EXPLORE_PIVOT_TABLE_TEST_DATA } from './Table
7
7
  export { GenerativeInsights } from './GenerativeInsights';
8
8
  export { default as ContentSources } from './ContentSources';
9
9
  export { LeftMenu } from './LeftMenu';
10
+ export * from './ContentSources/provider';
@@ -6,6 +6,7 @@ export declare const QUERY_KEYS: {
6
6
  GET_LIST_BO: string;
7
7
  GET_EVENT_ATTRIBUTE_BO: string;
8
8
  GET_BO_DETAIL: string;
9
+ GET_DATA_TABLE_BO: string;
9
10
  GET_LIST_PROMOTION_CODE_ATTR: string;
10
11
  GET_EVENT_TRACKING_ATTRIBUTES: string;
11
12
  GET_LIST_DYNAMIC_CONTENT_ATTR: string;
@@ -8,6 +8,7 @@ export const QUERY_KEYS = {
8
8
  GET_LIST_BO: 'GET_LIST_BO',
9
9
  GET_EVENT_ATTRIBUTE_BO: 'GET_EVENT_ATTRIBUTE_BO',
10
10
  GET_BO_DETAIL: 'GET_BO_DETAIL',
11
+ GET_DATA_TABLE_BO: 'GET_DATA_TABLE_BO',
11
12
  // Promotion Code Attr
12
13
  GET_LIST_PROMOTION_CODE_ATTR: 'GET_LIST_PROMOTION_CODE_ATTR',
13
14
  // Event tracking attributes
@@ -0,0 +1,6 @@
1
+ import type { TServiceAuth } from '../../types';
2
+ export declare const getDataTableBOQuery: (serviceAuth: TServiceAuth, itemTypeId: number | string, params?: Record<string, any>) => Promise<{
3
+ data: import("../../services/ThirParty/TableBO").TDataTableBO;
4
+ boId: string | number;
5
+ params: Record<string, any> | undefined;
6
+ }>;
@@ -0,0 +1,26 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ // Constants
11
+ import { QUERY_KEYS } from '../../constants/queries';
12
+ // Services
13
+ import { getDataTableBO } from '../../services/ThirParty/TableBO';
14
+ // QueryClients
15
+ import { queryClientAntsomiUI } from '../configs';
16
+ export const getDataTableBOQuery = (serviceAuth, itemTypeId, params) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const data = yield queryClientAntsomiUI.fetchQuery({
18
+ queryKey: [QUERY_KEYS.GET_DATA_TABLE_BO, itemTypeId],
19
+ queryFn: () => getDataTableBO(serviceAuth, itemTypeId),
20
+ });
21
+ return {
22
+ data: data !== null && data !== void 0 ? data : [],
23
+ boId: itemTypeId,
24
+ params,
25
+ };
26
+ });
@@ -0,0 +1,6 @@
1
+ import type { TServiceAuth } from '@antscorp/antsomi-ui/es/types';
2
+ export interface TDataTableBO {
3
+ header: any[];
4
+ data: any[];
5
+ }
6
+ export declare const getDataTableBO: (serviceAuth: TServiceAuth, id: string | number) => Promise<TDataTableBO>;
@@ -0,0 +1,28 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ // Libraries
11
+ import get from 'lodash/get';
12
+ import omit from 'lodash/omit';
13
+ // Services
14
+ import { services } from '@antscorp/antsomi-ui/es/services';
15
+ export const getDataTableBO = (serviceAuth, id) => __awaiter(void 0, void 0, void 0, function* () {
16
+ try {
17
+ const response = yield services.mediaTemplateDesign.get({
18
+ API_HOST: `${serviceAuth.url}/third-party/data-table-bo`,
19
+ id,
20
+ }, omit(serviceAuth, 'url'));
21
+ return get(response, 'data.data', null);
22
+ }
23
+ catch (error) {
24
+ return new Promise((_, reject) => {
25
+ reject(error);
26
+ });
27
+ }
28
+ });
@@ -9,6 +9,7 @@ type UpdateParams = {
9
9
  };
10
10
  export declare const services: {
11
11
  mediaTemplateDesign: {
12
+ get: (params: any, payloadInfo: PayloadInfo) => false | Promise<AxiosResponse<any, any>>;
12
13
  getList: (params: any, infos: PayloadInfo) => any;
13
14
  create: (params: any, infos: PayloadInfo) => Promise<AxiosResponse<any, any> | any>;
14
15
  update: (params: UpdateParams, infos: PayloadInfo) => Promise<AxiosResponse<any, any> | any>;
@@ -23,6 +23,29 @@ const { CancelToken } = axios;
23
23
  const isDebugApi = searchParamsToObject((((_a = window.location) === null || _a === void 0 ? void 0 : _a.href) || '').split('?')[1])['debug-api'] != null;
24
24
  export const services = {
25
25
  mediaTemplateDesign: {
26
+ get: function get(params, payloadInfo) {
27
+ if (typeof params.API_HOST !== 'undefined' && typeof params.id !== 'undefined') {
28
+ const { API_HOST } = params;
29
+ const { userId, accountId, token } = payloadInfo;
30
+ const cancelToken = params.cancelToken ? params.cancelToken : new CancelToken(() => { });
31
+ const { signal } = params;
32
+ delete params.API_HOST;
33
+ delete params.cancelToken;
34
+ delete params.signal;
35
+ if (has(params, 'url')) {
36
+ delete params.url;
37
+ }
38
+ const snapParams = Object.assign(Object.assign({}, params), { _token: token, _user_id: userId, _account_id: accountId });
39
+ return instance.get(API_HOST + '/' + params.id, {
40
+ params: snapParams,
41
+ cancelToken: cancelToken,
42
+ signal,
43
+ });
44
+ }
45
+ else {
46
+ return false;
47
+ }
48
+ },
26
49
  getList: function getList(params, infos) {
27
50
  if (typeof params.API_HOST !== 'undefined') {
28
51
  const { API_HOST } = params;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.265",
3
+ "version": "1.3.5-beta.266",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",