@antscorp/antsomi-ui 1.3.5-beta.39 → 1.3.5-beta.40
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.
- package/es/components/molecules/TemplateSaveAs/TemplateSaveAs.d.ts +1 -0
- package/es/components/molecules/TemplateSaveAs/TemplateSaveAs.js +4 -1
- package/es/components/molecules/TemplateSaveAs/hooks/useTemplateSave.d.ts +11 -18
- package/es/components/molecules/TemplateSaveAs/hooks/useTemplateSave.js +14 -62
- package/package.json +1 -1
|
@@ -65,5 +65,6 @@ export interface TemplateSaveAsProps {
|
|
|
65
65
|
};
|
|
66
66
|
value?: TemplateValueOptions;
|
|
67
67
|
onChange?: (value: Partial<TemplateValueOptions>) => void;
|
|
68
|
+
onEvent?: (value: Partial<TemplateValueOptions>) => void;
|
|
68
69
|
}
|
|
69
70
|
export declare const TemplateSaveAs: React.FC<TemplateSaveAsProps>;
|
|
@@ -20,7 +20,7 @@ import { TemplateSaveAsStyled } from './styled';
|
|
|
20
20
|
import { ImageSlider } from './components';
|
|
21
21
|
const { Text } = Typography;
|
|
22
22
|
export const TemplateSaveAs = props => {
|
|
23
|
-
const { className, shareAccess, saveOptions, imageReview, categories, omitCategories, templateNames, templateNamesOptions, descriptionOptions, value, onChange,
|
|
23
|
+
const { className, shareAccess, saveOptions, imageReview, categories, omitCategories, templateNames, templateNamesOptions, descriptionOptions, value, onChange, onEvent,
|
|
24
24
|
// onNamePopupScroll,
|
|
25
25
|
} = props;
|
|
26
26
|
const { show: isShowShareAccess } = shareAccess, shareAccessProps = __rest(shareAccess, ["show"]);
|
|
@@ -32,6 +32,9 @@ export const TemplateSaveAs = props => {
|
|
|
32
32
|
const [templateName, setTemplateName] = useState(defaultNewTemplateName || `Untitled Media Template#${dayjs().format('YYYY-MM-DD HH:mm:ss')}`);
|
|
33
33
|
const [templateNameExist, setTemplateNameExist] = useState((defaultTemplateName === null || defaultTemplateName === void 0 ? void 0 : defaultTemplateName.id) ? defaultTemplateName : templateNames === null || templateNames === void 0 ? void 0 : templateNames[0]);
|
|
34
34
|
const handleChangeValue = (newValue) => {
|
|
35
|
+
if (onEvent) {
|
|
36
|
+
onEvent(newValue);
|
|
37
|
+
}
|
|
35
38
|
if (onChange) {
|
|
36
39
|
onChange(Object.assign(Object.assign(Object.assign({}, value), newValue), {
|
|
37
40
|
// TODO: return saveOption and templateName generate default value if not pass as value props
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { PayloadInfo } from '@antscorp/antsomi-ui/es/types';
|
|
2
|
-
import { TCategoryItem
|
|
2
|
+
import { TCategoryItem } from '../../../template';
|
|
3
3
|
import { TGetTemplateCategoryList, TGetObjectTEmplateList } from '@antscorp/antsomi-ui/es/queries/TemplateListing';
|
|
4
4
|
import { TTemplateListingConfig } from '@antscorp/antsomi-ui/es/types/templateListing';
|
|
5
5
|
import { TemplateCategory } from '@antscorp/antsomi-ui/es/models/TemplateCategory';
|
|
6
|
+
import { TemplateValueOptions } from '../TemplateSaveAs';
|
|
6
7
|
interface TemplateListingOptions {
|
|
7
8
|
service: PayloadInfo;
|
|
8
9
|
config: TTemplateListingConfig & {
|
|
9
10
|
filter?: any;
|
|
10
11
|
};
|
|
11
|
-
checkedCategoriesDefault?: TCheckedCategories;
|
|
12
12
|
queriesOptions?: {
|
|
13
13
|
categoryList?: TGetTemplateCategoryList['options'];
|
|
14
14
|
templateList?: TGetObjectTEmplateList['options'];
|
|
15
15
|
};
|
|
16
|
+
value?: Partial<TemplateValueOptions>;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Custom React Hook for managing state and data fetching logic related to a template listing.
|
|
@@ -21,33 +22,25 @@ interface TemplateListingOptions {
|
|
|
21
22
|
* @param {PayloadInfo} options.service - Payload information for making API requests.
|
|
22
23
|
* @param {TTemplateListingConfig} options.config - Configuration options for the template listing.
|
|
23
24
|
*
|
|
24
|
-
* @returns {Object} - An object containing various properties and functions for template listing management.
|
|
25
|
-
*
|
|
26
25
|
* @property {TCategoryItem[]} categoryItems - An array of category items for rendering the template listing's category structure.
|
|
27
|
-
* @property {
|
|
28
|
-
* @property {string[]} openCategoryKeys - An array of keys representing the currently open category items in the template listing.
|
|
29
|
-
* @property {TCheckedCategories} checkedCategories - An object containing information about the checked categories in the template listing.
|
|
26
|
+
* @property {Array<{ id: string | number; label: string; thumbnail?: string }>} templateItems - An array of template items representing the templates available for the specified configuration.
|
|
30
27
|
* @property {boolean} isLoading - A boolean indicating whether data is currently being loaded.
|
|
31
28
|
*
|
|
32
|
-
* @property {Function} onChangeCheckedCategories - A function to update the checked categories in the template listing.
|
|
33
|
-
* @param {TCheckedCategories} checkedCategories - An object containing information about the checked categories.
|
|
34
|
-
*
|
|
35
|
-
* @property {Function} onChangeOpenCategoryKeys - A function to update the open category keys in the template listing.
|
|
36
|
-
* @param {string[]} openKeys - An array of keys representing the currently open category items.
|
|
37
|
-
*
|
|
38
29
|
* @property {Function} onLoadMore - A function to load more template data when scrolling in the template listing.
|
|
39
30
|
*/
|
|
40
31
|
export declare const useTemplateSave: (options: TemplateListingOptions) => {
|
|
41
32
|
categoryItems: TCategoryItem[];
|
|
42
|
-
templateItems:
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
templateItems: {
|
|
34
|
+
id: string | number;
|
|
35
|
+
label: string;
|
|
36
|
+
thumbnail?: string | undefined;
|
|
37
|
+
}[];
|
|
38
|
+
value: Partial<TemplateValueOptions>;
|
|
45
39
|
isLoadingCategoryList: boolean;
|
|
46
40
|
isLoadingTemplateList: boolean;
|
|
47
41
|
refetchCategoryList: <TPageData>(options?: (import("@tanstack/query-core").RefetchOptions & import("@tanstack/query-core").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/query-core").QueryObserverResult<TemplateCategory[], any>>;
|
|
48
42
|
refetchTemplateList: <TPageData_1>(options?: (import("@tanstack/query-core").RefetchOptions & import("@tanstack/query-core").RefetchQueryFilters<TPageData_1>) | undefined) => Promise<import("@tanstack/query-core").QueryObserverResult<import("@tanstack/query-core").InfiniteData<import("@antscorp/antsomi-ui/es/types").ResponseListing<import("../../../../models/ObjectTemplate").ObjectTemplate>>, any>>;
|
|
49
|
-
onChangeCheckedCategories: (checkedCategories: TCheckedCategories) => void;
|
|
50
|
-
onChangeOpenCategoryKeys: (openKeys: string[]) => void;
|
|
51
43
|
onLoadMore: () => void;
|
|
44
|
+
onChange: (newValue: Partial<TemplateValueOptions>) => void;
|
|
52
45
|
};
|
|
53
46
|
export {};
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
import { useCallback, useMemo, useState } from 'react';
|
|
3
3
|
import { useGetTemplateCategoryList, useGetObjectTemplateList, } from '@antscorp/antsomi-ui/es/queries/TemplateListing';
|
|
4
4
|
// Hooks
|
|
5
|
-
import {
|
|
6
|
-
// Constants
|
|
7
|
-
import { CATEGORY_SPLIT_KEY } from '@antscorp/antsomi-ui/es/constants';
|
|
5
|
+
import { useDeepCompareMemo } from '@antscorp/antsomi-ui/es/hooks';
|
|
8
6
|
/**
|
|
9
7
|
* Custom React Hook for managing state and data fetching logic related to a template listing.
|
|
10
8
|
*
|
|
@@ -12,33 +10,17 @@ import { CATEGORY_SPLIT_KEY } from '@antscorp/antsomi-ui/es/constants';
|
|
|
12
10
|
* @param {PayloadInfo} options.service - Payload information for making API requests.
|
|
13
11
|
* @param {TTemplateListingConfig} options.config - Configuration options for the template listing.
|
|
14
12
|
*
|
|
15
|
-
* @returns {Object} - An object containing various properties and functions for template listing management.
|
|
16
|
-
*
|
|
17
13
|
* @property {TCategoryItem[]} categoryItems - An array of category items for rendering the template listing's category structure.
|
|
18
|
-
* @property {
|
|
19
|
-
* @property {string[]} openCategoryKeys - An array of keys representing the currently open category items in the template listing.
|
|
20
|
-
* @property {TCheckedCategories} checkedCategories - An object containing information about the checked categories in the template listing.
|
|
14
|
+
* @property {Array<{ id: string | number; label: string; thumbnail?: string }>} templateItems - An array of template items representing the templates available for the specified configuration.
|
|
21
15
|
* @property {boolean} isLoading - A boolean indicating whether data is currently being loaded.
|
|
22
16
|
*
|
|
23
|
-
* @property {Function} onChangeCheckedCategories - A function to update the checked categories in the template listing.
|
|
24
|
-
* @param {TCheckedCategories} checkedCategories - An object containing information about the checked categories.
|
|
25
|
-
*
|
|
26
|
-
* @property {Function} onChangeOpenCategoryKeys - A function to update the open category keys in the template listing.
|
|
27
|
-
* @param {string[]} openKeys - An array of keys representing the currently open category items.
|
|
28
|
-
*
|
|
29
17
|
* @property {Function} onLoadMore - A function to load more template data when scrolling in the template listing.
|
|
30
18
|
*/
|
|
31
19
|
export const useTemplateSave = (options) => {
|
|
32
|
-
const { service, config, queriesOptions } = options;
|
|
20
|
+
const { service, config, queriesOptions, value: valueArg } = options;
|
|
33
21
|
const { objectType, categoryCodes, publicLevel, limitListPerPage = 10, getListType, filter, } = config;
|
|
34
22
|
const { categoryList: categoryListOptions, templateList: templateListOptions } = queriesOptions || {};
|
|
35
|
-
|
|
36
|
-
// State
|
|
37
|
-
const [state, setState] = useState({
|
|
38
|
-
checkedCategories: {},
|
|
39
|
-
openCategoryKeys: [],
|
|
40
|
-
});
|
|
41
|
-
const { checkedCategories, openCategoryKeys } = state;
|
|
23
|
+
const [value, setValue] = useState(valueArg || {});
|
|
42
24
|
const { data: categoryList, isLoading: isLoadingCategoryList, refetch: refetchCategoryList, } = useGetTemplateCategoryList({
|
|
43
25
|
args: {
|
|
44
26
|
auth: service,
|
|
@@ -62,17 +44,10 @@ export const useTemplateSave = (options) => {
|
|
|
62
44
|
const isLoadingTemplateList = isFetching || isFetchingNextPage;
|
|
63
45
|
// Memo
|
|
64
46
|
const categoryItems = useDeepCompareMemo(() => {
|
|
65
|
-
const recursiveCategory = (categories = []
|
|
66
|
-
const { categoryCode, categoryId, categoryName, children
|
|
67
|
-
const key = Array.isArray(children) && children.length
|
|
68
|
-
|
|
69
|
-
: [parentCategoryCode, categoryId].join(CATEGORY_SPLIT_KEY);
|
|
70
|
-
return {
|
|
71
|
-
key,
|
|
72
|
-
label: categoryName,
|
|
73
|
-
total,
|
|
74
|
-
children: recursiveCategory(children || [], categoryCode),
|
|
75
|
-
};
|
|
47
|
+
const recursiveCategory = (categories = []) => categories.map(category => {
|
|
48
|
+
const { categoryCode, categoryId, categoryName, children } = category;
|
|
49
|
+
const key = Array.isArray(children) && children.length ? categoryCode : categoryId;
|
|
50
|
+
return Object.assign({ key, label: categoryName }, ((children === null || children === void 0 ? void 0 : children.length) > 0 ? { children: recursiveCategory(children) } : {}));
|
|
76
51
|
});
|
|
77
52
|
return recursiveCategory(categoryList || []);
|
|
78
53
|
}, [categoryList]);
|
|
@@ -81,55 +56,32 @@ export const useTemplateSave = (options) => {
|
|
|
81
56
|
const { pages } = infiniteObjectTemplate;
|
|
82
57
|
return pages.flatMap(({ entities }) => entities.flatMap(({ id, name, thumbnail }) => ({
|
|
83
58
|
id,
|
|
84
|
-
name,
|
|
59
|
+
label: name,
|
|
85
60
|
thumbnail,
|
|
86
61
|
})));
|
|
87
62
|
}
|
|
88
63
|
return [];
|
|
89
64
|
}, [infiniteObjectTemplate]);
|
|
90
|
-
// Effects
|
|
91
|
-
useDeepCompareEffect(() => {
|
|
92
|
-
setState(prev => (Object.assign(Object.assign({}, prev), { openCategoryKeys: (categoryList === null || categoryList === void 0 ? void 0 : categoryList.map(({ categoryCode }) => categoryCode)) || [] })));
|
|
93
|
-
}, [categoryList]);
|
|
94
|
-
// useDeepCompareEffect(() => {
|
|
95
|
-
// if (!isEmpty(checkedCategoriesDefault)) {
|
|
96
|
-
// setState(prev => ({
|
|
97
|
-
// ...prev,
|
|
98
|
-
// checkedCategories:
|
|
99
|
-
// Object.entries(checkedCategoriesDefault).reduce((acc, curr) => {
|
|
100
|
-
// const [key, value] = curr;
|
|
101
|
-
// acc[key] = value.map(item => [key, item].join(CATEGORY_SPLIT_KEY));
|
|
102
|
-
// return acc;
|
|
103
|
-
// }, {}) || {},
|
|
104
|
-
// }));
|
|
105
|
-
// }
|
|
106
|
-
// }, [checkedCategoriesDefault]);
|
|
107
|
-
// Handles
|
|
108
|
-
const onChangeCheckedCategories = (checkedCategories) => {
|
|
109
|
-
setState(prev => (Object.assign(Object.assign({}, prev), { checkedCategories })));
|
|
110
|
-
};
|
|
111
|
-
const onChangeOpenCategoryKeys = useCallback((openKeys) => {
|
|
112
|
-
setState(prev => (Object.assign(Object.assign({}, prev), { openCategoryKeys: openKeys })));
|
|
113
|
-
}, []);
|
|
114
65
|
const onLoadMore = useCallback(() => {
|
|
115
66
|
if (!isFetchingNextPage && hasNextPage) {
|
|
116
67
|
fetchNextPage();
|
|
117
68
|
}
|
|
118
69
|
}, [fetchNextPage, hasNextPage, isFetchingNextPage]);
|
|
70
|
+
const onChange = (newValue) => {
|
|
71
|
+
setValue(newValue);
|
|
72
|
+
};
|
|
119
73
|
return {
|
|
120
74
|
// MapKeys
|
|
121
75
|
categoryItems,
|
|
122
76
|
templateItems,
|
|
123
|
-
|
|
77
|
+
value,
|
|
124
78
|
// Values
|
|
125
|
-
checkedCategories,
|
|
126
79
|
isLoadingCategoryList,
|
|
127
80
|
isLoadingTemplateList,
|
|
128
81
|
// Functions
|
|
129
82
|
refetchCategoryList,
|
|
130
83
|
refetchTemplateList,
|
|
131
|
-
onChangeCheckedCategories,
|
|
132
|
-
onChangeOpenCategoryKeys,
|
|
133
84
|
onLoadMore,
|
|
85
|
+
onChange,
|
|
134
86
|
};
|
|
135
87
|
};
|