@giteeteam/apps-team-components 1.2.2-alpha.4 → 1.3.0-alpha.1

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.
Files changed (170) hide show
  1. package/README.md +8 -15
  2. package/dist/components/common/expand-component/index.d.ts +23 -0
  3. package/dist/components/common/expand-component/index.js +65 -0
  4. package/dist/components/common/expand-component/style.d.ts +2 -0
  5. package/dist/components/common/expand-component/style.js +8 -0
  6. package/dist/components/common/item-icon/ItemIcon.d.ts +8 -0
  7. package/dist/components/common/item-icon/ItemIcon.js +6 -0
  8. package/dist/components/common/overflow-tooltip/OverflowTooltip.d.ts +19 -0
  9. package/dist/components/common/overflow-tooltip/OverflowTooltip.js +54 -0
  10. package/dist/components/common/style/mixin.d.ts +2 -0
  11. package/dist/components/common/style/mixin.js +17 -0
  12. package/dist/components/common/utils.d.ts +6 -0
  13. package/dist/components/common/utils.js +54 -0
  14. package/dist/components/default-empty-icon/config.d.ts +2 -0
  15. package/dist/components/default-empty-icon/config.js +19 -0
  16. package/dist/components/default-empty-icon/index.d.ts +5 -0
  17. package/dist/components/default-empty-icon/index.js +23 -0
  18. package/dist/components/default-empty-icon/style.d.ts +11 -0
  19. package/dist/components/default-empty-icon/style.js +64 -0
  20. package/dist/components/default-empty-icon/types.d.ts +29 -0
  21. package/dist/components/default-empty-icon/types.js +6 -0
  22. package/dist/components/field-behavior/fields/type.js +1 -1
  23. package/dist/components/fields/base-component/types.d.ts +1 -0
  24. package/dist/components/fields/base-component/utils.d.ts +2 -0
  25. package/dist/components/fields/base-component/utils.js +9 -0
  26. package/dist/components/fields/bind-workspace/hooks.js +3 -3
  27. package/dist/components/fields/dropdown/BaseField.d.ts +24 -2
  28. package/dist/components/fields/dropdown/BaseField.js +562 -1
  29. package/dist/components/fields/dropdown/Cell.d.ts +4 -0
  30. package/dist/components/fields/dropdown/Cell.js +6 -0
  31. package/dist/components/fields/dropdown/ReadView.js +16 -1
  32. package/dist/components/fields/dropdown/data.d.ts +9 -0
  33. package/dist/components/fields/dropdown/data.js +26 -0
  34. package/dist/components/fields/dropdown/hook.d.ts +103 -0
  35. package/dist/components/fields/dropdown/hook.js +152 -0
  36. package/dist/components/fields/dropdown/style.d.ts +16 -0
  37. package/dist/components/fields/dropdown/style.js +90 -0
  38. package/dist/components/fields/hooks/useViewClass.d.ts +11 -0
  39. package/dist/components/fields/hooks/useViewClass.js +18 -0
  40. package/dist/components/fields/item-type/ItemTypeIcon.d.ts +9 -0
  41. package/dist/components/fields/item-type/ItemTypeIcon.js +33 -0
  42. package/dist/components/fields/item-type/style/index.d.ts +1 -0
  43. package/dist/components/fields/item-type/style/index.js +6 -0
  44. package/dist/components/fields/key/ReadView.js +2 -2
  45. package/dist/components/fields/priority/ReadView.js +1 -1
  46. package/dist/components/fields/status/SelectTransition.js +2 -2
  47. package/dist/components/fields/status/TransitionButton.d.ts +0 -3
  48. package/dist/components/fields/status/TransitionButton.js +1 -7
  49. package/dist/components/fields/user-group/ReadView.js +1 -1
  50. package/dist/components/filters/filter-search/utils.d.ts +4 -0
  51. package/dist/components/filters/filter-search/utils.js +28 -0
  52. package/dist/components/table-components/EditTableCell.d.ts +1 -0
  53. package/dist/components/table-components/EditTableCell.js +2 -1
  54. package/dist/components/table-components/index.js +4 -4
  55. package/dist/components/table-components/utils.js +2 -0
  56. package/dist/icons/SyncIconFont.d.ts +6 -0
  57. package/dist/icons/SyncIconFont.js +15 -0
  58. package/dist/icons/createFromIconFontClass.d.ts +4 -0
  59. package/dist/icons/createFromIconFontClass.js +33 -0
  60. package/dist/icons/empty-icon/data-empty.png +0 -0
  61. package/dist/icons/empty-icon/forbidden.png +0 -0
  62. package/dist/icons/empty-icon/index.d.ts +1 -0
  63. package/dist/icons/empty-icon/index.js +8 -0
  64. package/dist/icons/empty-icon/large-item@2x.png +0 -0
  65. package/dist/icons/empty-icon/large-workspace@2x.png +0 -0
  66. package/dist/icons/empty-icon/load-error.png +0 -0
  67. package/dist/icons/empty-icon/not-found.png +0 -0
  68. package/dist/icons/empty-icon/small-default@2x.png +0 -0
  69. package/dist/icons/empty-icon/workspace-empty.svg +127 -0
  70. package/dist/icons/index.d.ts +58 -1
  71. package/dist/icons/index.js +294 -0
  72. package/dist/icons/style/index.d.ts +2 -0
  73. package/dist/icons/style/index.js +23 -0
  74. package/dist/index.d.ts +1 -0
  75. package/dist/index.js +1 -0
  76. package/dist/lib/app/utils.d.ts +3 -0
  77. package/dist/lib/app/utils.js +16 -0
  78. package/dist/lib/config.d.ts +14 -0
  79. package/dist/lib/config.js +45 -0
  80. package/dist/lib/constants/code.d.ts +4 -0
  81. package/dist/lib/constants/code.js +4 -0
  82. package/dist/lib/constants/field.d.ts +1 -0
  83. package/dist/lib/constants/field.js +2 -0
  84. package/dist/lib/contexts/index.js +2 -2
  85. package/dist/lib/contexts/teamConfig.d.ts +3 -0
  86. package/dist/lib/contexts/teamConfig.js +19 -4
  87. package/dist/lib/error/index.d.ts +2 -0
  88. package/dist/lib/error/index.js +2 -0
  89. package/dist/lib/error/log.d.ts +10 -0
  90. package/dist/lib/error/log.js +25 -0
  91. package/dist/lib/error/utils.d.ts +14 -0
  92. package/dist/lib/error/utils.js +50 -0
  93. package/dist/lib/error/withServerError.d.ts +1 -0
  94. package/dist/lib/error/withServerError.js +1 -0
  95. package/dist/lib/fetch.d.ts +45 -0
  96. package/dist/lib/fetch.js +301 -0
  97. package/dist/lib/global.d.ts +18 -0
  98. package/dist/lib/global.js +18 -0
  99. package/dist/lib/i18n.d.ts +1 -0
  100. package/dist/lib/i18n.js +1 -0
  101. package/dist/lib/icons/utils.d.ts +23 -0
  102. package/dist/lib/icons/utils.js +59 -0
  103. package/dist/lib/path.d.ts +5 -0
  104. package/dist/lib/path.js +47 -0
  105. package/dist/lib/router.d.ts +23 -0
  106. package/dist/lib/router.js +20 -0
  107. package/dist/lib/storage.d.ts +10 -0
  108. package/dist/lib/storage.js +62 -0
  109. package/dist/lib/swr/throttleWithCache.d.ts +17 -0
  110. package/dist/lib/swr/throttleWithCache.js +108 -0
  111. package/dist/lib/throttleFetch.d.ts +2 -0
  112. package/dist/lib/throttleFetch.js +66 -0
  113. package/dist/lib/useConfig.d.ts +8 -0
  114. package/dist/lib/useConfig.js +28 -0
  115. package/dist/lib/workflow.js +19 -85
  116. package/dist/locales/index.d.ts +45 -0
  117. package/dist/locales/index.js +45 -0
  118. package/dist/public/icons/BulbIcon.svg +1 -0
  119. package/dist/public/icons/Cloud.svg +1 -0
  120. package/dist/public/icons/ConsultIcon.svg +1 -0
  121. package/dist/public/icons/Demo.svg +1 -0
  122. package/dist/public/icons/ErrorTemplate.svg +1 -0
  123. package/dist/public/icons/Fail.svg +1 -0
  124. package/dist/public/icons/Flag.svg +1 -0
  125. package/dist/public/icons/GiteeIcon.svg +1 -0
  126. package/dist/public/icons/IntelligenceGradient.svg +1 -0
  127. package/dist/public/icons/Issue_Approval.svg +1 -0
  128. package/dist/public/icons/Issue_Bug.svg +1 -0
  129. package/dist/public/icons/Issue_Demand.svg +1 -0
  130. package/dist/public/icons/Issue_Doc.svg +1 -0
  131. package/dist/public/icons/Issue_Idea.svg +1 -0
  132. package/dist/public/icons/Issue_List.svg +1 -0
  133. package/dist/public/icons/Issue_Plan.svg +1 -0
  134. package/dist/public/icons/Issue_Product.svg +1 -0
  135. package/dist/public/icons/Issue_Risk.svg +1 -0
  136. package/dist/public/icons/Issue_Story.svg +1 -0
  137. package/dist/public/icons/Issue_Subtask.svg +1 -0
  138. package/dist/public/icons/Issue_Task.svg +1 -0
  139. package/dist/public/icons/Issue_Test.svg +1 -0
  140. package/dist/public/icons/Issue_TestExcution.svg +1 -0
  141. package/dist/public/icons/Issue_TestPlan.svg +1 -0
  142. package/dist/public/icons/Issue_Time.svg +1 -0
  143. package/dist/public/icons/Issue_develop.svg +1 -0
  144. package/dist/public/icons/KanbanCover.svg +7 -0
  145. package/dist/public/icons/ListCover.svg +118 -0
  146. package/dist/public/icons/ManHour.svg +1 -0
  147. package/dist/public/icons/MobileIcon.svg +1 -0
  148. package/dist/public/icons/NoItemType.svg +10 -0
  149. package/dist/public/icons/ProductIcon.svg +1 -0
  150. package/dist/public/icons/RedFlagIcon.svg +1 -0
  151. package/dist/public/icons/Safe.svg +1 -0
  152. package/dist/public/icons/StarIcon.svg +61 -0
  153. package/dist/public/icons/StructureCover.svg +1 -0
  154. package/dist/public/icons/Success.svg +1 -0
  155. package/dist/public/icons/TeamIcon.svg +1 -0
  156. package/dist/public/icons/WebIcon.svg +1 -0
  157. package/dist/public/icons/iconfont.svg +467 -0
  158. package/dist/public/icons/iconfont.ttf +0 -0
  159. package/dist/public/icons/iconfont.woff +0 -0
  160. package/dist/public/icons/iconfont.woff2 +0 -0
  161. package/dist/public/icons/iconfont_multiple_color.js +1 -0
  162. package/dist/public/icons/iconfont_single_color.css +912 -0
  163. package/dist/public/icons/iconfont_single_color.js +1 -0
  164. package/dist/public/icons/loginBg.svg +1 -0
  165. package/dist/public/mockServiceWorker.js +284 -0
  166. package/dist/style/common.d.ts +1 -0
  167. package/dist/style/common.js +9 -0
  168. package/dist/style/global.d.ts +1 -0
  169. package/dist/style/global.js +8 -0
  170. package/package.json +41 -6
@@ -98,3 +98,21 @@ export const CustomFieldComponentTypes = {
98
98
  Radio: 'Radio',
99
99
  Checkbox: 'Checkbox',
100
100
  };
101
+ export const BASE_FIELD_WIDTH = 104;
102
+ export const CURRENT_WORKSPACE = 'currentWorkspace()';
103
+ export const FIELD_CONTAINERS_PAGE = {
104
+ DETAIL: 'detail',
105
+ MODAL: 'modal',
106
+ DRAWER: 'drawer',
107
+ FILTER: 'filter',
108
+ SCREEN: 'screen',
109
+ AUTOMATION_FIELD: 'automation_field',
110
+ VIEW_MODAL: 'view_modal',
111
+ };
112
+ export const SCREEN_TYPE = {
113
+ View: 'view',
114
+ Create: 'create',
115
+ Edit: 'edit',
116
+ };
117
+ export const CANCEL_FETCH_STRING = 'cancel_fetch_string';
118
+ export const REDIRECT_URL_KEY = 'team_redirect_url';
@@ -3,4 +3,5 @@ export declare const i18n: {
3
3
  t: (key: string, opts?: Record<string, any>) => string;
4
4
  setLocale: (_locale: LocalLng) => void;
5
5
  };
6
+ export declare const nsSeparator = "@";
6
7
  export {};
package/dist/lib/i18n.js CHANGED
@@ -32,3 +32,4 @@ export const i18n = {
32
32
  locale = _locale;
33
33
  },
34
34
  };
35
+ export const nsSeparator = '@';
@@ -0,0 +1,23 @@
1
+ export declare const polyfillItemTypeIconMap: {
2
+ BookMark: string;
3
+ Book: string;
4
+ Flask: string;
5
+ Archive: string;
6
+ EmptyTag: string;
7
+ Branch: string;
8
+ Checked: string;
9
+ Flag: string;
10
+ LightBulb: string;
11
+ List: string;
12
+ Bug: string;
13
+ Task: string;
14
+ Signet: string;
15
+ Risk: string;
16
+ ManHour: string;
17
+ };
18
+ export declare const takeIconFromUrl: (url: string) => string;
19
+ export declare const useIsIconFont: (url: string) => boolean;
20
+ export declare const isServerUrl: (url: string) => boolean;
21
+ export declare const usePolyFillIcon: (url: string, defaultIconFontType?: string) => [boolean, string];
22
+ export declare const joinIconColorSuffix: (icon: string, colored: boolean) => string;
23
+ export declare const isBase64Img: (str: string) => boolean;
@@ -0,0 +1,59 @@
1
+ import { useMemo } from 'react';
2
+ import { useGetBasePath } from 'lib/path';
3
+ export const polyfillItemTypeIconMap = {
4
+ BookMark: 'Issue_Story',
5
+ Book: 'Issue_Demand',
6
+ Flask: 'Issue_Test',
7
+ Archive: 'Issue_Doc',
8
+ EmptyTag: 'Issue_develop',
9
+ Branch: 'Issue_Subtask',
10
+ Checked: 'Issue_Task',
11
+ Flag: 'Issue_Plan',
12
+ LightBulb: 'Issue_Idea',
13
+ List: 'Issue_List',
14
+ Bug: 'Issue_Bug',
15
+ Task: 'Issue_Product',
16
+ Signet: 'Issue_Approval',
17
+ Risk: 'Issue_Risk',
18
+ ManHour: 'Issue_Time',
19
+ };
20
+ export const takeIconFromUrl = (url) => {
21
+ const arr = url.split('/');
22
+ const last = arr[arr.length - 1];
23
+ const [icon] = last.split('.');
24
+ return icon;
25
+ };
26
+ export const useIsIconFont = (url) => {
27
+ const basePath = useGetBasePath();
28
+ return !(url.startsWith('/icons') || url.endsWith('.svg') || url.startsWith(basePath) || url.startsWith('/project'));
29
+ };
30
+ export const isServerUrl = (url) => {
31
+ return url.startsWith('http') || url.startsWith('/parse/files');
32
+ };
33
+ export const usePolyFillIcon = (url, defaultIconFontType) => {
34
+ const isIconFont = useIsIconFont(url);
35
+ const data = useMemo(() => {
36
+ if (!url) {
37
+ return [false, defaultIconFontType];
38
+ }
39
+ if (isServerUrl(url)) {
40
+ return [true, url];
41
+ }
42
+ else {
43
+ if (isIconFont) {
44
+ return [false, url];
45
+ }
46
+ else {
47
+ let icon = takeIconFromUrl(url);
48
+ icon = polyfillItemTypeIconMap[icon] ? polyfillItemTypeIconMap[icon] : icon;
49
+ return [false, icon || defaultIconFontType];
50
+ }
51
+ }
52
+ }, [defaultIconFontType, isIconFont, url]);
53
+ return data;
54
+ };
55
+ const SUFFIX = 'B';
56
+ export const joinIconColorSuffix = (icon, colored) => (colored ? `${icon}${SUFFIX}` : icon);
57
+ export const isBase64Img = (str) => {
58
+ return /^data:image\/(png|jpeg|jpg|gif|svg\+xml);base64,/.test(str);
59
+ };
@@ -0,0 +1,5 @@
1
+ export declare const iconBasePath = "/icons";
2
+ export declare const startsWithIconPath: any;
3
+ export declare const useGetBasePath: () => string;
4
+ export declare const useGetSourcePath: () => (path: string) => string;
5
+ export declare const usePatchIconUrl: () => (path: string) => string;
@@ -0,0 +1,47 @@
1
+ import { useCallback, useContext } from 'react';
2
+ import { startsWith } from 'lodash-es';
3
+ import { TeamConfigContext } from './contexts/teamConfig';
4
+ export const iconBasePath = '/icons';
5
+ export const startsWithIconPath = startsWith(iconBasePath);
6
+ const removeExtraSlash = (paths) => {
7
+ if (!paths)
8
+ return '';
9
+ const isEndsWithSlash = paths.endsWith('/');
10
+ const isStartsWithSlash = paths.startsWith('/');
11
+ const result = paths.split('/').filter(Boolean).join('/');
12
+ return `${isStartsWithSlash ? '/' : ''}${result}${isEndsWithSlash ? '/' : ''}`;
13
+ };
14
+ const mergePath = (path1, path2) => {
15
+ const paths = [path1, path2].filter(Boolean).join('/');
16
+ let result = '';
17
+ try {
18
+ const urlObj = new URL(paths);
19
+ urlObj.pathname = removeExtraSlash(urlObj.pathname);
20
+ result = urlObj.toString();
21
+ }
22
+ catch (error) {
23
+ result = removeExtraSlash(paths);
24
+ }
25
+ return result;
26
+ };
27
+ export const useGetBasePath = () => {
28
+ const { publicRuntimeConfig } = useContext(TeamConfigContext);
29
+ return (publicRuntimeConfig === null || publicRuntimeConfig === void 0 ? void 0 : publicRuntimeConfig.basePath) || '';
30
+ };
31
+ export const useGetSourcePath = () => {
32
+ const basePath = useGetBasePath();
33
+ const getSourcePath = useCallback((path) => {
34
+ return mergePath(basePath, path);
35
+ }, [basePath]);
36
+ return getSourcePath;
37
+ };
38
+ export const usePatchIconUrl = () => {
39
+ const getSourcePath = useGetSourcePath();
40
+ const patchIconUrl = useCallback((iconUrl) => {
41
+ if (startsWithIconPath(iconUrl)) {
42
+ return getSourcePath(iconUrl);
43
+ }
44
+ return iconUrl;
45
+ }, [getSourcePath]);
46
+ return patchIconUrl;
47
+ };
@@ -0,0 +1,23 @@
1
+ import { RouterQuery } from './types/models';
2
+ export type IRouteReplace = (url: string | {
3
+ pathname?: string;
4
+ query: RouterQuery;
5
+ }, state?: any) => void;
6
+ interface IUserRouterRes {
7
+ asPath: string;
8
+ query: {
9
+ [x: string]: string | string[];
10
+ };
11
+ search: {
12
+ [x: string]: string | string[];
13
+ };
14
+ routePath: string;
15
+ push: (url: string | {
16
+ pathname?: string;
17
+ query: RouterQuery;
18
+ }) => void;
19
+ replace: IRouteReplace;
20
+ back: () => void;
21
+ }
22
+ export declare const getCurLocationInfo: () => IUserRouterRes;
23
+ export {};
@@ -0,0 +1,20 @@
1
+ import queryString from 'query-string';
2
+ export const getCurLocationInfo = () => {
3
+ const { pathname, search } = window.location;
4
+ const basePath = window.__PROXIMA_BASE_NAME__ || '';
5
+ const pathWithoutBasePath = basePath !== '/' && pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
6
+ const router = {
7
+ asPath: pathWithoutBasePath + search,
8
+ query: {
9
+ ...queryString.parse(search),
10
+ },
11
+ search: {
12
+ ...queryString.parse(search),
13
+ },
14
+ routePath: '',
15
+ push: history.push,
16
+ replace: history.replace,
17
+ back: history.back,
18
+ };
19
+ return router;
20
+ };
@@ -0,0 +1,10 @@
1
+ export declare const getLocalStorageItem: (key: string, defaults?: any) => any;
2
+ export declare const setLocalStorageItem: (key: string, value: unknown) => boolean;
3
+ export declare const removeParseItems: () => void;
4
+ declare const _default: {
5
+ getItem: (key: string, defaults?: any) => any;
6
+ setItem: (key: string, value: unknown) => boolean;
7
+ removeParseItems: () => void;
8
+ };
9
+ export default _default;
10
+ export declare const getLocalStorageState: (key: string, fn: () => any) => Promise<any>;
@@ -0,0 +1,62 @@
1
+ export const getLocalStorageItem = (key, defaults = '') => {
2
+ let item;
3
+ try {
4
+ item = localStorage.getItem(key);
5
+ return (item && JSON.parse(item)) || defaults;
6
+ }
7
+ catch (e) {
8
+ return item !== null && item !== void 0 ? item : defaults;
9
+ }
10
+ };
11
+ export const setLocalStorageItem = (key, value) => {
12
+ try {
13
+ localStorage.setItem(key, JSON.stringify(value));
14
+ return true;
15
+ }
16
+ catch (e) {
17
+ console.error(e);
18
+ return false;
19
+ }
20
+ };
21
+ const getStorageKeys = () => {
22
+ return Object.keys(localStorage);
23
+ };
24
+ export const removeParseItems = () => {
25
+ try {
26
+ const keys = getStorageKeys();
27
+ const parseKeys = keys.filter(fieldKey => fieldKey.startsWith('Parse/') && fieldKey.endsWith('/currentUser'));
28
+ parseKeys.forEach(paresKey => {
29
+ localStorage.removeItem(paresKey);
30
+ });
31
+ }
32
+ catch (error) {
33
+ console.error('removeParseItems', error);
34
+ }
35
+ };
36
+ export default {
37
+ getItem: getLocalStorageItem,
38
+ setItem: setLocalStorageItem,
39
+ removeParseItems,
40
+ };
41
+ const setLocalStorageState = (key, data) => {
42
+ localStorage.setItem(key, JSON.stringify({ time: new Date().getDate(), data }));
43
+ };
44
+ export const getLocalStorageState = async (key, fn) => {
45
+ try {
46
+ const target = localStorage.getItem(key);
47
+ if (target) {
48
+ const targetFormat = JSON.parse(target);
49
+ if ((targetFormat === null || targetFormat === void 0 ? void 0 : targetFormat.time) === new Date().getDate()) {
50
+ if (typeof targetFormat.data !== 'string') {
51
+ return targetFormat.data;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ catch (e) {
57
+ console.error(e);
58
+ }
59
+ const data = await fn();
60
+ setLocalStorageState(key, data);
61
+ return data;
62
+ };
@@ -0,0 +1,17 @@
1
+ export declare const DISABLE_THROTTLE_API_FETCH = "DISABLE_THROTTLE_API_FETCH";
2
+ declare const throttleWithCache: ({ type, params, fn, method, }: {
3
+ type: THROTTLE_TYPE;
4
+ params: unknown;
5
+ fn: () => Promise<any>;
6
+ method?: string;
7
+ }) => Promise<any>;
8
+ export declare enum THROTTLE_TYPE {
9
+ PLUGIN_RESOURCE_FETCH = "PLUGIN_RESOURCE_FETCH",
10
+ QUERY_FETCH = "QUERY_FETCH",
11
+ CUSTOM_FETCH = "CUSTOM_FETCH"
12
+ }
13
+ export declare const createKeyByParams: ({ type, params }: {
14
+ type: THROTTLE_TYPE;
15
+ params: any;
16
+ }) => string;
17
+ export default throttleWithCache;
@@ -0,0 +1,108 @@
1
+ import debug from 'debug';
2
+ import { getLocalStorageItem } from 'lib/storage';
3
+ export const DISABLE_THROTTLE_API_FETCH = 'DISABLE_THROTTLE_API_FETCH';
4
+ const log = debug('repeat-api');
5
+ const disableThrottle = !!getLocalStorageItem(DISABLE_THROTTLE_API_FETCH) || false;
6
+ let cacheKeys = [];
7
+ let results = [];
8
+ let resolves = [];
9
+ const THROTTLE_TIME = 3000;
10
+ let postPending = false;
11
+ let postPendingTime = 0;
12
+ const refreshCache = () => {
13
+ const dirtyIds = [];
14
+ cacheKeys.forEach(item => {
15
+ if (Date.now() - item.time > THROTTLE_TIME) {
16
+ dirtyIds.push(item.id);
17
+ }
18
+ });
19
+ cacheKeys = cacheKeys.filter(item => !dirtyIds.includes(item.id));
20
+ results = results.filter(item => !dirtyIds.includes(item.id));
21
+ resolves = resolves.filter(item => !dirtyIds.includes(item.id));
22
+ };
23
+ const refreshPostPending = () => {
24
+ if (postPending) {
25
+ const curTime = Date.now();
26
+ if (curTime - postPendingTime > THROTTLE_TIME) {
27
+ postPending = false;
28
+ }
29
+ }
30
+ };
31
+ const throttleWithCache = ({ type, params, fn, method, }) => {
32
+ if (disableThrottle) {
33
+ return fn();
34
+ }
35
+ const key = createKeyByParams({ type, params });
36
+ refreshCache();
37
+ refreshPostPending();
38
+ if (postPending) {
39
+ return fn();
40
+ }
41
+ const _method = String(method).toLowerCase();
42
+ if (_method !== 'get') {
43
+ postPending = true;
44
+ postPendingTime = +new Date();
45
+ return fn();
46
+ }
47
+ return new Promise((resolve, reject) => {
48
+ var _a;
49
+ const findItem = cacheKeys.find(item => item.key === key && +new Date() - item.time < THROTTLE_TIME);
50
+ if (findItem) {
51
+ try {
52
+ const getStackTrace = (limitFrames = 50) => {
53
+ const obj = { stack: '' };
54
+ const stackTraceLimit = Error.stackTraceLimit;
55
+ Error.stackTraceLimit = stackTraceLimit < limitFrames ? limitFrames : stackTraceLimit;
56
+ Error.captureStackTrace(obj, getStackTrace);
57
+ Error.stackTraceLimit = stackTraceLimit;
58
+ return obj.stack.split('\n');
59
+ };
60
+ const stackFrames = getStackTrace();
61
+ log('stackFrame', stackFrames, key);
62
+ }
63
+ catch (e) {
64
+ console.error(e);
65
+ }
66
+ const result = (_a = results.find(item => item.key === findItem.key)) === null || _a === void 0 ? void 0 : _a.data;
67
+ if (result) {
68
+ resolve(result);
69
+ }
70
+ else {
71
+ resolves.push({
72
+ key: findItem.key,
73
+ resolve,
74
+ id: findItem.id,
75
+ });
76
+ }
77
+ }
78
+ else {
79
+ const curTime = +new Date();
80
+ cacheKeys.push({ key, time: curTime, id: `${key}${curTime}` });
81
+ fn()
82
+ .then(res => {
83
+ results.push({ key, data: res, id: `${key}${curTime}` });
84
+ resolve(res);
85
+ resolves.forEach(item => {
86
+ if (item.key === key) {
87
+ item.resolve(res);
88
+ }
89
+ });
90
+ })
91
+ .catch(_error => {
92
+ reject(_error);
93
+ });
94
+ }
95
+ });
96
+ };
97
+ export var THROTTLE_TYPE;
98
+ (function (THROTTLE_TYPE) {
99
+ THROTTLE_TYPE["PLUGIN_RESOURCE_FETCH"] = "PLUGIN_RESOURCE_FETCH";
100
+ THROTTLE_TYPE["QUERY_FETCH"] = "QUERY_FETCH";
101
+ THROTTLE_TYPE["CUSTOM_FETCH"] = "CUSTOM_FETCH";
102
+ })(THROTTLE_TYPE || (THROTTLE_TYPE = {}));
103
+ export const createKeyByParams = ({ type, params }) => {
104
+ if (!params)
105
+ return `${+new Date()}`;
106
+ return `${type}_${JSON.stringify(params)}`;
107
+ };
108
+ export default throttleWithCache;
@@ -0,0 +1,2 @@
1
+ export declare const generateHash: (content: any) => string;
2
+ export declare function throttleFetch<Key = any, Data = any>(key: Key, fetcher: () => Promise<Data>): Promise<Data>;
@@ -0,0 +1,66 @@
1
+ class PubSub {
2
+ constructor() {
3
+ this.events = {};
4
+ }
5
+ subscribe(event, resolve, reject) {
6
+ if (!(event in this.events)) {
7
+ this.events[event] = [];
8
+ }
9
+ this.events[event].push([resolve, reject]);
10
+ }
11
+ publish(event, data, err) {
12
+ if (!(event in this.events)) {
13
+ return;
14
+ }
15
+ while (this.events[event].length) {
16
+ const [resolve, reject] = this.events[event].shift();
17
+ if (err) {
18
+ reject(err);
19
+ }
20
+ else {
21
+ resolve(data);
22
+ }
23
+ }
24
+ delete this.events[event];
25
+ }
26
+ }
27
+ const pubSub = new PubSub();
28
+ export const generateHash = (content) => {
29
+ if (content && typeof content === 'object')
30
+ try {
31
+ content = JSON.stringify(content);
32
+ }
33
+ catch (e) {
34
+ content = content === null || content === void 0 ? void 0 : content.toString();
35
+ console.error('[Error] getStringHash JSON.stringify(content)', e);
36
+ }
37
+ if (!content)
38
+ return;
39
+ let hash = 0;
40
+ let chr;
41
+ if (content.length === 0)
42
+ return '';
43
+ for (let i = 0; i < content.length; i++) {
44
+ chr = content.charCodeAt(i);
45
+ hash = (hash << 5) - hash + chr;
46
+ hash |= 0;
47
+ }
48
+ return btoa('hash-' + hash);
49
+ };
50
+ export async function throttleFetch(key, fetcher) {
51
+ return new Promise((resolve, reject) => {
52
+ const hashKey = generateHash(key);
53
+ const hasEvent = hashKey in pubSub.events;
54
+ pubSub.subscribe(hashKey, resolve, reject);
55
+ if (!hasEvent) {
56
+ pubSub.subscribe(hashKey, resolve, reject);
57
+ fetcher()
58
+ .then(data => {
59
+ pubSub.publish(hashKey, data);
60
+ })
61
+ .catch(err => {
62
+ pubSub.publish(hashKey, undefined, err);
63
+ });
64
+ }
65
+ });
66
+ }
@@ -0,0 +1,8 @@
1
+ export declare const LOCALE_KEY = "lang";
2
+ export declare const PROXIMA_TENANT_KEY = "team_tenant";
3
+ export declare const SESSION_KEY = "sessionToken";
4
+ export declare const useAppProps: () => {
5
+ locale: string;
6
+ sessionToken: string;
7
+ appId: string;
8
+ };
@@ -0,0 +1,28 @@
1
+ import { useContext, useMemo } from 'react';
2
+ import Cookie from 'js-cookie';
3
+ import { TeamConfigContext } from './contexts/teamConfig';
4
+ import { getAcceptLanguageHeader } from './config';
5
+ export const LOCALE_KEY = 'lang';
6
+ export const PROXIMA_TENANT_KEY = 'team_tenant';
7
+ export const SESSION_KEY = 'sessionToken';
8
+ export const useAppProps = () => {
9
+ const { userConfig = {}, publicRuntimeConfig = {} } = useContext(TeamConfigContext);
10
+ const locale = useMemo(() => {
11
+ const userLocale = userConfig.locale;
12
+ const [defaultLang] = navigator.languages;
13
+ const locale = userLocale || Cookie.get(LOCALE_KEY) || defaultLang;
14
+ return getAcceptLanguageHeader(locale);
15
+ }, [userConfig.locale]);
16
+ const { sessionToken, appId } = useMemo(() => {
17
+ const { userTenant, sessionToken } = userConfig;
18
+ return {
19
+ appId: userTenant || Cookie.get(PROXIMA_TENANT_KEY) || publicRuntimeConfig.appId,
20
+ sessionToken: sessionToken || Cookie.get(SESSION_KEY),
21
+ };
22
+ }, [publicRuntimeConfig.appId, userConfig]);
23
+ return {
24
+ locale,
25
+ sessionToken,
26
+ appId,
27
+ };
28
+ };