@antscorp/antsomi-ui 1.3.5-beta.304 → 1.3.5-beta.306

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-core").RefetchOptions & import("@tanstack/query-core").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/query-core").QueryObserverResult<TemplateCategory[], any>>;
69
- 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("@antscorp/antsomi-ui/es/models/ObjectTemplate").ObjectTemplate>>, any>>;
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
- const templateItems = useMemo(() => {
103
- if (infiniteObjectTemplate) {
104
- const { pages } = infiniteObjectTemplate;
105
- return pages.flatMap(({ entities }) => entities.flatMap(entity => (Object.assign(Object.assign({}, entity.toJson()), { label: entity.name, description: entity.description || '' }))));
106
- }
107
- return [];
108
- }, [infiniteObjectTemplate]);
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();
@@ -2,7 +2,7 @@
2
2
  import React from 'react';
3
3
  import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
4
4
  // Atoms
5
- import { Tag } from '@antscorp/antsomi-ui/es/components/atoms';
5
+ import { StyledTag as Tag } from '@antscorp/antsomi-ui/es/components/molecules/SelectV2/styled';
6
6
  import { StyledSelect } from './styled';
7
7
  // Translations
8
8
  import { translations } from '@antscorp/antsomi-ui/es/locales/translations';
@@ -29,9 +29,10 @@ import get from 'lodash/get';
29
29
  // Icons
30
30
  import Icon from '@antscorp/icons';
31
31
  // Atoms
32
- import { Button, Text, Tag } from '@antscorp/antsomi-ui/es/components/atoms';
32
+ import { Button, Text } from '@antscorp/antsomi-ui/es/components/atoms';
33
33
  // Molecules
34
34
  import { Modal, SelectV2 as Select, RadioGroup, TreeSelect, } from '@antscorp/antsomi-ui/es/components/molecules';
35
+ import { StyledTag as Tag } from '@antscorp/antsomi-ui/es/components/molecules/SelectV2/styled';
35
36
  // Translations
36
37
  import { translations } from '@antscorp/antsomi-ui/es/locales/translations';
37
38
  // Queries
@@ -485,6 +486,10 @@ export const StyledDropdown = styled.div `
485
486
  }
486
487
  `;
487
488
  export const StyledSelect = styled(Select) `
489
+ .antsomi-select-selection-search {
490
+ width: fit-content !important;
491
+ }
492
+
488
493
  .antsomi-select-selection-placeholder {
489
494
  ${props => {
490
495
  var _a;
@@ -28,9 +28,10 @@ import styled from 'styled-components';
28
28
  import { Popover, Input } from 'antd';
29
29
  import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
30
30
  // Atoms
31
- import { Button, Divider, Icon, Text, Tag } from '@antscorp/antsomi-ui/es/components/atoms';
31
+ import { Button, Divider, Icon, Text } from '@antscorp/antsomi-ui/es/components/atoms';
32
32
  // Molecules
33
33
  import { ModalSelect, StyledTreeSelect } from '../InputOrSelect';
34
+ import { StyledTag as Tag } from '@antscorp/antsomi-ui/es/components/molecules/SelectV2/styled';
34
35
  // Components
35
36
  import { TreeContentWrapper } from './Tree';
36
37
  import { ColumnSuggestion } from './ColumnSuggestion';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.304",
3
+ "version": "1.3.5-beta.306",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",