@antscorp/antsomi-ui 1.5.2 → 1.5.3
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,8 +65,8 @@ export declare const useTemplateSave: (options: TemplateListingOptions) => {
|
|
|
65
65
|
};
|
|
66
66
|
form: import("antd").FormInstance<FormValue>;
|
|
67
67
|
errors: any[] | undefined;
|
|
68
|
-
refetchCategoryList: <TPageData>(options?: (import("@tanstack/query
|
|
69
|
-
refetchTemplateList: <TPageData_1>(options?: (import("@tanstack/query
|
|
68
|
+
refetchCategoryList: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<TemplateCategory[], any>>;
|
|
69
|
+
refetchTemplateList: <TPageData_1>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData_1>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@tanstack/react-query").InfiniteData<import("@antscorp/antsomi-ui/es/types").ResponseListing<import("@antscorp/antsomi-ui/es/models/ObjectTemplate").ObjectTemplate>>, any>>;
|
|
70
70
|
onLoadMore: () => void;
|
|
71
71
|
onChange: (newValue: Partial<TemplateValueOptions>) => void;
|
|
72
72
|
};
|
|
@@ -9,11 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
// Libraries
|
|
11
11
|
import { useCallback, useMemo, useState } from 'react';
|
|
12
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
12
13
|
import { useGetTemplateCategoryList, useGetObjectTemplateList, useValidateTemplateName, } from '@antscorp/antsomi-ui/es/queries/TemplateListing';
|
|
14
|
+
// Services
|
|
15
|
+
import { templateListingServices } from '@antscorp/antsomi-ui/es/services/TemplateListing';
|
|
13
16
|
// Hooks
|
|
14
|
-
import { useDeepCompareMemo } from '@antscorp/antsomi-ui/es/hooks';
|
|
17
|
+
import { useDeepCompareEffect, useDeepCompareMemo } from '@antscorp/antsomi-ui/es/hooks';
|
|
15
18
|
import { Form } from 'antd';
|
|
16
19
|
import { camelCaseToSnakeCase, snakeCaseToCamelCase } from '@antscorp/antsomi-ui/es/utils';
|
|
20
|
+
import { QUERY_KEYS } from '@antscorp/antsomi-ui/es/constants';
|
|
17
21
|
/**
|
|
18
22
|
* Custom React Hook for managing state and data fetching logic related to a template listing.
|
|
19
23
|
*
|
|
@@ -28,12 +32,15 @@ import { camelCaseToSnakeCase, snakeCaseToCamelCase } from '@antscorp/antsomi-ui
|
|
|
28
32
|
* @property {Function} onLoadMore - A function to load more template data when scrolling in the template listing.
|
|
29
33
|
*/
|
|
30
34
|
export const useTemplateSave = (options) => {
|
|
35
|
+
var _a;
|
|
36
|
+
const queryClient = useQueryClient();
|
|
31
37
|
const { service, config, queriesOptions, defaultValue: valueArg } = options;
|
|
32
38
|
const { objectType, categoryCodes, publicLevel, limitListPerPage = 10, getListType, channel, } = config;
|
|
33
39
|
const { categoryList: categoryListOptions, templateList: templateListOptions } = queriesOptions || {};
|
|
34
40
|
const [searchName, setSearchName] = useState('');
|
|
35
41
|
const [value, setValue] = useState(valueArg || {});
|
|
36
42
|
const [errors, setErrors] = useState();
|
|
43
|
+
const [templateItems, setTemplateItems] = useState([]);
|
|
37
44
|
const handleFormatCategories = (categories) => {
|
|
38
45
|
const snakeCase = camelCaseToSnakeCase(categories || {});
|
|
39
46
|
const camelCase = snakeCaseToCamelCase(categories || {});
|
|
@@ -99,13 +106,34 @@ export const useTemplateSave = (options) => {
|
|
|
99
106
|
});
|
|
100
107
|
return recursiveCategory(categoryList || []);
|
|
101
108
|
}, [categoryList]);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
// Effects
|
|
110
|
+
useDeepCompareEffect(() => {
|
|
111
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
112
|
+
var _a;
|
|
113
|
+
if (infiniteObjectTemplate) {
|
|
114
|
+
const { pages } = infiniteObjectTemplate;
|
|
115
|
+
const selectedTemplateId = +(((_a = value.templateName) === null || _a === void 0 ? void 0 : _a.id) || -1);
|
|
116
|
+
const newTemplateItems = pages.flatMap(({ entities }) => entities.flatMap(entity => (Object.assign(Object.assign({}, entity.toJson()), { label: entity.name, description: entity.description || '' }))));
|
|
117
|
+
if (!newTemplateItems.find(item => +item.id === selectedTemplateId)) {
|
|
118
|
+
const objectTemplate = yield queryClient.fetchQuery({
|
|
119
|
+
queryKey: [QUERY_KEYS.GET_OBJECT_TEMPLATE_DETAIL, selectedTemplateId],
|
|
120
|
+
queryFn: () => templateListingServices.objectTemplate.getDetail({
|
|
121
|
+
auth: service,
|
|
122
|
+
params: {
|
|
123
|
+
object_type: objectType,
|
|
124
|
+
public_level: publicLevel,
|
|
125
|
+
template_id: selectedTemplateId,
|
|
126
|
+
},
|
|
127
|
+
}),
|
|
128
|
+
});
|
|
129
|
+
if (objectTemplate) {
|
|
130
|
+
newTemplateItems.unshift(Object.assign(Object.assign({}, objectTemplate.toJson()), { label: objectTemplate.name, description: objectTemplate.description || '' }));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
setTemplateItems(newTemplateItems);
|
|
134
|
+
}
|
|
135
|
+
}))();
|
|
136
|
+
}, [infiniteObjectTemplate, objectType, publicLevel, (_a = value.templateName) === null || _a === void 0 ? void 0 : _a.id]);
|
|
109
137
|
const onLoadMore = useCallback(() => {
|
|
110
138
|
if (!isFetchingNextPage && hasNextPage) {
|
|
111
139
|
fetchNextPage();
|