@antscorp/antsomi-ui 1.3.5-beta.376 → 1.3.5-beta.377

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,8 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { TServiceAuth } from '@antscorp/antsomi-ui/es/types';
2
+ import { ResponseListing, TServiceAuth } from '@antscorp/antsomi-ui/es/types';
3
3
  import { TCategoryItem, TCheckedCategories, TSelectTemplateAction, TTemplateItem } from '../types';
4
4
  import { TTemplateListingConfig } from '@antscorp/antsomi-ui/es/types/templateListing';
5
5
  import { TThumbnailCardId } from '../../../molecules/ThumbnailCard';
6
+ import { InfiniteData } from '@tanstack/react-query';
7
+ import { ObjectTemplate } from '@antscorp/antsomi-ui/es/models/ObjectTemplate';
6
8
  import { TemplateCategory } from '@antscorp/antsomi-ui/es/models/TemplateCategory';
7
9
  interface TemplateListingOptions {
8
10
  serviceAuth: TServiceAuth;
@@ -60,7 +62,7 @@ export declare const useTemplateListing: <T = undefined>(options: TemplateListin
60
62
  templateItems: (TTemplateItem | undefined)[];
61
63
  openCategoryKeys: string[];
62
64
  similarTemplates: (TTemplateItem | undefined)[];
63
- templateDetail: import("@antscorp/antsomi-ui/es/models/ObjectTemplate").ObjectTemplate | undefined;
65
+ templateDetail: ObjectTemplate | undefined;
64
66
  checkedCategories: TCheckedCategories;
65
67
  selectTemplateAction: string | T | undefined;
66
68
  previewTemplateCategories: TCategoryItem[];
@@ -68,8 +70,8 @@ export declare const useTemplateListing: <T = undefined>(options: TemplateListin
68
70
  isLoadingCategoryList: boolean;
69
71
  isLoadingTemplateList: boolean;
70
72
  isLoadingTemplateDetail: boolean;
71
- refetchCategoryList: <TPageData>(options?: (import("@tanstack/query-core").RefetchOptions & import("@tanstack/query-core").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/query-core").QueryObserverResult<TemplateCategory[], any>>;
72
- 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>>;
73
+ refetchCategoryList: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<TemplateCategory[], any>>;
74
+ refetchTemplateList: <TPageData_1>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData_1>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<ResponseListing<ObjectTemplate>>, any>>;
73
75
  onChangeCheckedCategories: (checkedCategories: TCheckedCategories) => void;
74
76
  onChangeOpenCategoryKeys: (openKeys: string[]) => void;
75
77
  onRemoveObjectTemplate: (id: TThumbnailCardId) => void;
@@ -3,12 +3,14 @@ import { useCallback, useMemo, useState } from 'react';
3
3
  import { App } from 'antd';
4
4
  import { isEmpty } from 'lodash';
5
5
  import { useGetTemplateCategoryList, useGetObjectTemplateList, useBulkUpdateTemplate, } from '@antscorp/antsomi-ui/es/queries/TemplateListing';
6
+ import { useQueryClient } from '@tanstack/react-query';
7
+ import { removeObjectTemplate } from '../utils';
6
8
  // Locales
7
9
  import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
8
10
  // Hooks
9
11
  import { useDeepCompareEffect, useDeepCompareMemo } from '@antscorp/antsomi-ui/es/hooks';
10
12
  // Constants
11
- import { CATEGORY_SPLIT_KEY, TEMPLATE_STATUS } from '@antscorp/antsomi-ui/es/constants';
13
+ import { CATEGORY_SPLIT_KEY, QUERY_KEYS, TEMPLATE_STATUS } from '@antscorp/antsomi-ui/es/constants';
12
14
  import { translations } from '@antscorp/antsomi-ui/es/locales/translations';
13
15
  import { getShuffleArray, random } from '@antscorp/antsomi-ui/es/utils';
14
16
  /**
@@ -96,10 +98,22 @@ export const useTemplateListing = (options) => {
96
98
  auth: serviceAuth,
97
99
  params: getTemplateListParams,
98
100
  },
101
+ // options: {
102
+ // enabled: false,
103
+ // },
99
104
  });
105
+ // useDeepCompareEffect(() => {
106
+ // refetchTemplateList();
107
+ // }, [getTemplateListParams]);
108
+ const queryClient = useQueryClient();
100
109
  const { mutateAsync: bulkUpdateTemplate } = useBulkUpdateTemplate({
101
110
  options: {
102
- onSuccess: () => {
111
+ onSuccess: (data, variables) => {
112
+ const currentTemplateListCache = queryClient.getQueryData([QUERY_KEYS.GET_OBJECT_TEMPLATE_LIST, getTemplateListParams]);
113
+ if (currentTemplateListCache) {
114
+ const newTemplateList = removeObjectTemplate(currentTemplateListCache, variables.params.template_ids);
115
+ queryClient.setQueryData([QUERY_KEYS.GET_OBJECT_TEMPLATE_LIST, getTemplateListParams], newTemplateList);
116
+ }
103
117
  message.success(t(translations.templateListing.removeSuccess));
104
118
  },
105
119
  onError: () => {
@@ -0,0 +1,11 @@
1
+ import { ObjectTemplate } from '@antscorp/antsomi-ui/es/models/ObjectTemplate';
2
+ import { ResponseListing } from '@antscorp/antsomi-ui/es/types';
3
+ import { InfiniteData } from '@tanstack/react-query';
4
+ /**
5
+ * Removes template from the provided template list based on a list of IDs and updates the itemsPerPage meta value.
6
+ *
7
+ * @param {InfiniteData<ResponseListing<ObjectTemplate>>} templateList - The original template list containing pages of template.
8
+ * @param {number[]} templateIds - The list of entity IDs to be removed.
9
+ * @returns {InfiniteData<ResponseListing<ObjectTemplate>>} - The new template list with specified templates removed and meta.itemsPerPage updated.
10
+ */
11
+ export declare const removeObjectTemplate: (templateList: InfiniteData<ResponseListing<ObjectTemplate>>, templateIds: number[]) => InfiniteData<ResponseListing<ObjectTemplate>>;
@@ -0,0 +1,18 @@
1
+ import { cloneDeep } from 'lodash';
2
+ /**
3
+ * Removes template from the provided template list based on a list of IDs and updates the itemsPerPage meta value.
4
+ *
5
+ * @param {InfiniteData<ResponseListing<ObjectTemplate>>} templateList - The original template list containing pages of template.
6
+ * @param {number[]} templateIds - The list of entity IDs to be removed.
7
+ * @returns {InfiniteData<ResponseListing<ObjectTemplate>>} - The new template list with specified templates removed and meta.itemsPerPage updated.
8
+ */
9
+ export const removeObjectTemplate = (templateList, templateIds) => {
10
+ const newObject = cloneDeep(templateList);
11
+ newObject.pages = newObject.pages.map((page) => {
12
+ page.entities = page.entities.filter((entity) => !templateIds.includes(entity.id));
13
+ const finalCount = page.entities.length;
14
+ page.meta.itemsPerPage = finalCount;
15
+ return page;
16
+ });
17
+ return newObject;
18
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.376",
3
+ "version": "1.3.5-beta.377",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",