@antscorp/antsomi-ui 1.3.5-beta.45 → 1.3.5-beta.46
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 -2
- package/es/components/molecules/TemplateSaveAs/TemplateSaveAs.js +11 -3
- package/es/components/molecules/TemplateSaveAs/hooks/useTemplateSave.d.ts +14 -5
- package/es/components/molecules/TemplateSaveAs/hooks/useTemplateSave.js +36 -9
- package/package.json +1 -1
|
@@ -54,9 +54,8 @@ export interface TemplateSaveAsProps {
|
|
|
54
54
|
templateNamesOptions?: {
|
|
55
55
|
label?: string;
|
|
56
56
|
isLoading?: boolean;
|
|
57
|
-
searchValue?: string;
|
|
58
57
|
defaultNewTemplateName?: string;
|
|
59
|
-
onSearch?:
|
|
58
|
+
onSearch?: (searchValue: string) => void;
|
|
60
59
|
onNamePopupScroll?: SelectProps['onPopupScroll'];
|
|
61
60
|
};
|
|
62
61
|
descriptionOptions?: {
|
|
@@ -10,11 +10,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
// Libraries
|
|
13
|
-
import React, { useState } from 'react';
|
|
13
|
+
import React, { useEffect, useState } from 'react';
|
|
14
14
|
import { Dropdown, Form } from 'antd';
|
|
15
15
|
import dayjs from 'dayjs';
|
|
16
16
|
// Components
|
|
17
17
|
import { Tooltip, Button, Flex, Input, Typography, Select, ShareAccess, RadioGroup, Radio, Space, Spin, } from '@antscorp/antsomi-ui/es/components';
|
|
18
|
+
// Hooks
|
|
19
|
+
import { useDebounce } from '@antscorp/antsomi-ui/es/hooks/useDebounceV2';
|
|
18
20
|
// Styles
|
|
19
21
|
import { TemplateSaveAsStyled } from './styled';
|
|
20
22
|
import { ImageSlider } from './components';
|
|
@@ -25,10 +27,16 @@ export const TemplateSaveAs = props => {
|
|
|
25
27
|
} = props;
|
|
26
28
|
const { show: isShowShareAccess } = shareAccess, shareAccessProps = __rest(shareAccess, ["show"]);
|
|
27
29
|
const { thumbnails, isLoading: isLoadingThumbnail, skeleton, previewNavigation, slidesPerView, hideThumbnailsList, hideDefaultButton, label: imageReviewLabel, } = imageReview;
|
|
28
|
-
const { isLoading,
|
|
30
|
+
const { isLoading, label: templateLabel, defaultNewTemplateName, onSearch, onNamePopupScroll, } = templateNamesOptions || {};
|
|
29
31
|
const { label: descriptionLabel, placeholder: descriptionPlaceholder } = descriptionOptions || {};
|
|
30
32
|
const { saveNewText = 'Save as a new media Template', saveExistText = 'Save as an existing media Template', saveNewValue = 'save-new', saveExistValue = 'save-exist', } = saveOptions || {};
|
|
31
33
|
const { saveOption = saveNewValue, templateName: defaultTemplateName, description: defaultTemplateDesc, defaultThumbnail = 0, categories: categoriesValue = [], accessInfo, } = value || {};
|
|
34
|
+
const [searchValue, setSearchValue] = useState('');
|
|
35
|
+
const searchValueDebounce = useDebounce(searchValue, 1000);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (searchValueDebounce && onSearch)
|
|
38
|
+
onSearch(searchValueDebounce);
|
|
39
|
+
}, [searchValueDebounce, onSearch]);
|
|
32
40
|
const [templateName, setTemplateName] = useState(defaultNewTemplateName || `Untitled Media Template#${dayjs().format('YYYY-MM-DD HH:mm:ss')}`);
|
|
33
41
|
const [templateNameExist, setTemplateNameExist] = useState((defaultTemplateName === null || defaultTemplateName === void 0 ? void 0 : defaultTemplateName.id) ? defaultTemplateName : templateNames === null || templateNames === void 0 ? void 0 : templateNames[0]);
|
|
34
42
|
const handleChangeValue = (newValue) => {
|
|
@@ -96,7 +104,7 @@ export const TemplateSaveAs = props => {
|
|
|
96
104
|
React.createElement(Input, { debounce: 1000, className: "field-input", value: templateName, onAfterChange: value => {
|
|
97
105
|
handleChangeValue({ templateName: { id: undefined, label: value } });
|
|
98
106
|
setTemplateName(value);
|
|
99
|
-
}, required: true }))) : (React.createElement(Select, { className: "field-input", showSearch: true, searchValue: searchValue, onSearch:
|
|
107
|
+
}, required: true }))) : (React.createElement(Select, { className: "field-input", showSearch: true, searchValue: searchValue, onSearch: setSearchValue, onPopupScroll: onNamePopupScroll, filterOption: false, dropdownRender: menu => (React.createElement(React.Fragment, null,
|
|
100
108
|
isLoading && templateNames.length === 0 ? null : menu,
|
|
101
109
|
isLoading ? (React.createElement(Space, { style: {
|
|
102
110
|
padding: '4px 0',
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { PayloadInfo } from '@antscorp/antsomi-ui/es/types';
|
|
2
3
|
import { TCategoryItem } from '../../../template';
|
|
3
4
|
import { TGetTemplateCategoryList, TGetObjectTEmplateList } from '@antscorp/antsomi-ui/es/queries/TemplateListing';
|
|
4
5
|
import { TTemplateListingConfig } from '@antscorp/antsomi-ui/es/types/templateListing';
|
|
5
6
|
import { TemplateCategory } from '@antscorp/antsomi-ui/es/models/TemplateCategory';
|
|
6
|
-
import { TemplateValueOptions } from '../TemplateSaveAs';
|
|
7
|
+
import { TemplateValueOptions, categoriesProps } from '../TemplateSaveAs';
|
|
7
8
|
interface TemplateListingOptions {
|
|
8
9
|
service: PayloadInfo;
|
|
9
|
-
config: TTemplateListingConfig
|
|
10
|
-
filter?: any;
|
|
11
|
-
};
|
|
10
|
+
config: TTemplateListingConfig;
|
|
12
11
|
queriesOptions?: {
|
|
13
12
|
categoryList?: TGetTemplateCategoryList['options'];
|
|
14
13
|
templateList?: TGetObjectTEmplateList['options'];
|
|
15
14
|
};
|
|
16
|
-
defaultValue?: Partial<TemplateValueOptions
|
|
15
|
+
defaultValue?: Partial<TemplateValueOptions> & {
|
|
16
|
+
categoriesWithId?: {
|
|
17
|
+
[key: string]: (number | string)[] | undefined;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
17
20
|
}
|
|
18
21
|
/**
|
|
19
22
|
* Custom React Hook for managing state and data fetching logic related to a template listing.
|
|
@@ -40,8 +43,14 @@ export declare const useTemplateSave: (options: TemplateListingOptions) => {
|
|
|
40
43
|
camelCase: Record<string, any>;
|
|
41
44
|
snakeCase: {};
|
|
42
45
|
};
|
|
46
|
+
handleFormatCategories: (categories: categoriesProps | undefined) => {
|
|
47
|
+
camelCase: Record<string, any>;
|
|
48
|
+
snakeCase: {};
|
|
49
|
+
};
|
|
43
50
|
isLoadingCategoryList: boolean;
|
|
44
51
|
isLoadingTemplateList: boolean;
|
|
52
|
+
searchName: string;
|
|
53
|
+
onSearchName: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
45
54
|
form: import("antd").FormInstance<any>;
|
|
46
55
|
errors: any[] | undefined;
|
|
47
56
|
refetchCategoryList: <TPageData>(options?: (import("@tanstack/query-core").RefetchOptions & import("@tanstack/query-core").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/query-core").QueryObserverResult<TemplateCategory[], any>>;
|
|
@@ -2,9 +2,10 @@
|
|
|
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 { useDeepCompareMemo } from '@antscorp/antsomi-ui/es/hooks';
|
|
5
|
+
import { useDeepCompareEffect, useDeepCompareMemo } from '@antscorp/antsomi-ui/es/hooks';
|
|
6
6
|
import { Form } from 'antd';
|
|
7
7
|
import { snakeCaseToCamelCase } from '@antscorp/antsomi-ui/es/utils';
|
|
8
|
+
import { omit } from 'lodash';
|
|
8
9
|
/**
|
|
9
10
|
* Custom React Hook for managing state and data fetching logic related to a template listing.
|
|
10
11
|
*
|
|
@@ -20,19 +21,20 @@ import { snakeCaseToCamelCase } from '@antscorp/antsomi-ui/es/utils';
|
|
|
20
21
|
*/
|
|
21
22
|
export const useTemplateSave = (options) => {
|
|
22
23
|
const { service, config, queriesOptions, defaultValue: valueArg } = options;
|
|
23
|
-
const { objectType, categoryCodes, publicLevel, limitListPerPage = 10, getListType
|
|
24
|
+
const { objectType, categoryCodes, publicLevel, limitListPerPage = 10, getListType } = config;
|
|
24
25
|
const { categoryList: categoryListOptions, templateList: templateListOptions } = queriesOptions || {};
|
|
25
|
-
const [
|
|
26
|
+
const [searchName, setSearchName] = useState('');
|
|
27
|
+
const [value, setValue] = useState(omit(valueArg, ['categoriesWithId']) || {});
|
|
26
28
|
const [errors, setErrors] = useState();
|
|
27
|
-
const
|
|
28
|
-
var _a;
|
|
29
|
+
const handleFormatCategories = (categories) => {
|
|
29
30
|
const snakeCase = {};
|
|
30
|
-
|
|
31
|
-
snakeCase[category.key] = category.children;
|
|
31
|
+
categories === null || categories === void 0 ? void 0 : categories.forEach(category => {
|
|
32
|
+
snakeCase[category.key] = category.children.map(item => item.key);
|
|
32
33
|
});
|
|
33
34
|
const camelCase = snakeCaseToCamelCase(snakeCase);
|
|
34
35
|
return { camelCase, snakeCase };
|
|
35
|
-
}
|
|
36
|
+
};
|
|
37
|
+
const formattedCategoriesValue = useMemo(() => handleFormatCategories(value.categories), [value]);
|
|
36
38
|
const [form] = Form.useForm();
|
|
37
39
|
const { data: categoryList, isLoading: isLoadingCategoryList, refetch: refetchCategoryList, } = useGetTemplateCategoryList({
|
|
38
40
|
args: {
|
|
@@ -49,7 +51,9 @@ export const useTemplateSave = (options) => {
|
|
|
49
51
|
const { data: infiniteObjectTemplate, isFetchingNextPage, isFetching, hasNextPage, fetchNextPage, refetch: refetchTemplateList, } = useGetObjectTemplateList({
|
|
50
52
|
args: {
|
|
51
53
|
auth: service,
|
|
52
|
-
params: Object.assign({ get_list_type: getListType, object_type: objectType, public_level: publicLevel, limit: limitListPerPage }, (
|
|
54
|
+
params: Object.assign({ get_list_type: getListType, object_type: objectType, public_level: publicLevel, limit: limitListPerPage }, (searchName
|
|
55
|
+
? { filter: JSON.stringify([{ TEMPLATE_NAME: { contain: searchName } }]) }
|
|
56
|
+
: {})),
|
|
53
57
|
},
|
|
54
58
|
options: templateListOptions,
|
|
55
59
|
});
|
|
@@ -64,6 +68,25 @@ export const useTemplateSave = (options) => {
|
|
|
64
68
|
});
|
|
65
69
|
return recursiveCategory(categoryList || []);
|
|
66
70
|
}, [categoryList]);
|
|
71
|
+
useDeepCompareEffect(() => {
|
|
72
|
+
setValue(prev => {
|
|
73
|
+
const result = categoryItems
|
|
74
|
+
.filter(category => Object.keys((valueArg === null || valueArg === void 0 ? void 0 : valueArg.categoriesWithId) || {}).includes(category.key))
|
|
75
|
+
.map(category => {
|
|
76
|
+
var _a;
|
|
77
|
+
return (Object.assign(Object.assign({}, category), { children: (_a = category.children) === null || _a === void 0 ? void 0 : _a.filter(child => {
|
|
78
|
+
var _a;
|
|
79
|
+
return (valueArg === null || valueArg === void 0 ? void 0 : valueArg.categoriesWithId)
|
|
80
|
+
? (_a = valueArg === null || valueArg === void 0 ? void 0 : valueArg.categoriesWithId[category.key]) === null || _a === void 0 ? void 0 : _a.includes(child.key)
|
|
81
|
+
: false;
|
|
82
|
+
}) }));
|
|
83
|
+
});
|
|
84
|
+
return Object.assign(Object.assign({}, prev), { categories: result });
|
|
85
|
+
});
|
|
86
|
+
}, [categoryItems, valueArg === null || valueArg === void 0 ? void 0 : valueArg.categoriesWithId]);
|
|
87
|
+
useDeepCompareEffect(() => {
|
|
88
|
+
setValue(omit(valueArg, ['categoriesWithId']));
|
|
89
|
+
}, [valueArg]);
|
|
67
90
|
const templateItems = useMemo(() => {
|
|
68
91
|
if (infiniteObjectTemplate) {
|
|
69
92
|
const { pages } = infiniteObjectTemplate;
|
|
@@ -92,9 +115,13 @@ export const useTemplateSave = (options) => {
|
|
|
92
115
|
value,
|
|
93
116
|
// formattedValue
|
|
94
117
|
formattedCategoriesValue,
|
|
118
|
+
handleFormatCategories,
|
|
95
119
|
// Values
|
|
96
120
|
isLoadingCategoryList,
|
|
97
121
|
isLoadingTemplateList,
|
|
122
|
+
// Handle Search template name
|
|
123
|
+
searchName,
|
|
124
|
+
onSearchName: setSearchName,
|
|
98
125
|
// Form handler
|
|
99
126
|
form,
|
|
100
127
|
errors,
|