@giteeteam/apps-team-components 1.2.2 → 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.
- package/README.md +21 -28
- package/dist/components/common/PriceTag.js +18 -18
- package/dist/components/common/expand-component/index.d.ts +23 -0
- package/dist/components/common/expand-component/index.js +65 -0
- package/dist/components/common/expand-component/style.d.ts +2 -0
- package/dist/components/common/expand-component/style.js +8 -0
- package/dist/components/common/item-icon/ItemIcon.d.ts +8 -0
- package/dist/components/common/item-icon/ItemIcon.js +6 -0
- package/dist/components/common/overflow-tooltip/OverflowTooltip.d.ts +19 -0
- package/dist/components/common/overflow-tooltip/OverflowTooltip.js +54 -0
- package/dist/components/common/overflow-tooltip/style/index.js +13 -13
- package/dist/components/common/style/global.js +2 -2
- package/dist/components/common/style/mixin.d.ts +2 -0
- package/dist/components/common/style/mixin.js +17 -0
- package/dist/components/common/user-field/style/index.js +21 -21
- package/dist/components/common/utils.d.ts +6 -0
- package/dist/components/common/utils.js +54 -0
- package/dist/components/default-empty-icon/config.d.ts +2 -0
- package/dist/components/default-empty-icon/config.js +19 -0
- package/dist/components/default-empty-icon/index.d.ts +5 -0
- package/dist/components/default-empty-icon/index.js +23 -0
- package/dist/components/default-empty-icon/style.d.ts +11 -0
- package/dist/components/default-empty-icon/style.js +64 -0
- package/dist/components/default-empty-icon/types.d.ts +29 -0
- package/dist/components/default-empty-icon/types.js +6 -0
- package/dist/components/field-behavior/fields/type.js +1 -1
- package/dist/components/fields/base-component/types.d.ts +1 -0
- package/dist/components/fields/base-component/utils.d.ts +2 -0
- package/dist/components/fields/base-component/utils.js +9 -0
- package/dist/components/fields/bind-workspace/hooks.js +3 -3
- package/dist/components/fields/bind-workspace/style/index.js +3 -3
- package/dist/components/fields/dropdown/BaseField.d.ts +24 -2
- package/dist/components/fields/dropdown/BaseField.js +562 -1
- package/dist/components/fields/dropdown/Cell.d.ts +4 -0
- package/dist/components/fields/dropdown/Cell.js +6 -0
- package/dist/components/fields/dropdown/ReadView.js +1 -1
- package/dist/components/fields/dropdown/data.d.ts +9 -0
- package/dist/components/fields/dropdown/data.js +26 -0
- package/dist/components/fields/dropdown/hook.d.ts +103 -0
- package/dist/components/fields/dropdown/hook.js +152 -0
- package/dist/components/fields/dropdown/style.d.ts +16 -0
- package/dist/components/fields/dropdown/style.js +90 -0
- package/dist/components/fields/hooks/useViewClass.d.ts +11 -0
- package/dist/components/fields/hooks/useViewClass.js +18 -0
- package/dist/components/fields/hyper-link/style/index.js +14 -14
- package/dist/components/fields/item-type/ItemTypeIcon.d.ts +9 -0
- package/dist/components/fields/item-type/ItemTypeIcon.js +33 -0
- package/dist/components/fields/item-type/style/index.d.ts +1 -0
- package/dist/components/fields/item-type/style/index.js +6 -0
- package/dist/components/fields/key/ReadView.js +2 -2
- package/dist/components/fields/long-text/style/index.js +5 -5
- package/dist/components/fields/priority/ReadView.js +1 -1
- package/dist/components/fields/priority/style/index.js +50 -50
- package/dist/components/fields/status/style/index.js +323 -323
- package/dist/components/fields/tag/style/index.js +5 -5
- package/dist/components/fields/team/style/index.js +2 -2
- package/dist/components/fields/user/style/index.js +8 -8
- package/dist/components/fields/user-group/ReadView.js +1 -1
- package/dist/components/filters/filter-search/utils.d.ts +4 -0
- package/dist/components/filters/filter-search/utils.js +28 -0
- package/dist/components/table-components/EditTableCell.d.ts +1 -0
- package/dist/components/table-components/EditTableCell.js +2 -1
- package/dist/components/table-components/index.js +4 -4
- package/dist/components/table-components/style/index.js +5 -5
- package/dist/components/table-components/utils.js +2 -0
- package/dist/icons/SyncIconFont.d.ts +6 -0
- package/dist/icons/SyncIconFont.js +15 -0
- package/dist/icons/createFromIconFontClass.d.ts +4 -0
- package/dist/icons/createFromIconFontClass.js +33 -0
- package/dist/icons/empty-icon/data-empty.png +0 -0
- package/dist/icons/empty-icon/forbidden.png +0 -0
- package/dist/icons/empty-icon/index.d.ts +1 -0
- package/dist/icons/empty-icon/index.js +8 -0
- package/dist/icons/empty-icon/large-item@2x.png +0 -0
- package/dist/icons/empty-icon/large-workspace@2x.png +0 -0
- package/dist/icons/empty-icon/load-error.png +0 -0
- package/dist/icons/empty-icon/not-found.png +0 -0
- package/dist/icons/empty-icon/small-default@2x.png +0 -0
- package/dist/icons/empty-icon/workspace-empty.svg +127 -0
- package/dist/icons/index.d.ts +58 -1
- package/dist/icons/index.js +294 -0
- package/dist/icons/style/index.d.ts +2 -0
- package/dist/icons/style/index.js +23 -0
- package/dist/icons/svg/DottedCircle.svg +7 -7
- package/dist/icons/svg/HollowCircle.svg +6 -6
- package/dist/icons/svg/Workflow.svg +12 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/app/utils.d.ts +3 -0
- package/dist/lib/app/utils.js +16 -0
- package/dist/lib/config.d.ts +14 -0
- package/dist/lib/config.js +45 -0
- package/dist/lib/constants/code.d.ts +4 -0
- package/dist/lib/constants/code.js +4 -0
- package/dist/lib/constants/field.d.ts +1 -0
- package/dist/lib/constants/field.js +2 -0
- package/dist/lib/contexts/index.js +2 -2
- package/dist/lib/contexts/teamConfig.d.ts +3 -0
- package/dist/lib/contexts/teamConfig.js +19 -4
- package/dist/lib/error/index.d.ts +2 -0
- package/dist/lib/error/index.js +2 -0
- package/dist/lib/error/log.d.ts +10 -0
- package/dist/lib/error/log.js +25 -0
- package/dist/lib/error/utils.d.ts +14 -0
- package/dist/lib/error/utils.js +50 -0
- package/dist/lib/error/withServerError.d.ts +1 -0
- package/dist/lib/error/withServerError.js +1 -0
- package/dist/lib/fetch.d.ts +45 -0
- package/dist/lib/fetch.js +301 -0
- package/dist/lib/global.d.ts +18 -0
- package/dist/lib/global.js +18 -0
- package/dist/lib/i18n.d.ts +1 -0
- package/dist/lib/i18n.js +1 -0
- package/dist/lib/icons/utils.d.ts +23 -0
- package/dist/lib/icons/utils.js +59 -0
- package/dist/lib/path.d.ts +5 -0
- package/dist/lib/path.js +47 -0
- package/dist/lib/router.d.ts +23 -0
- package/dist/lib/router.js +20 -0
- package/dist/lib/storage.d.ts +10 -0
- package/dist/lib/storage.js +62 -0
- package/dist/lib/swr/throttleWithCache.d.ts +17 -0
- package/dist/lib/swr/throttleWithCache.js +108 -0
- package/dist/lib/throttleFetch.d.ts +2 -0
- package/dist/lib/throttleFetch.js +66 -0
- package/dist/lib/useConfig.d.ts +8 -0
- package/dist/lib/useConfig.js +28 -0
- package/dist/locales/index.d.ts +45 -0
- package/dist/locales/index.js +45 -0
- package/dist/public/icons/BulbIcon.svg +1 -0
- package/dist/public/icons/Cloud.svg +1 -0
- package/dist/public/icons/ConsultIcon.svg +1 -0
- package/dist/public/icons/Demo.svg +1 -0
- package/dist/public/icons/ErrorTemplate.svg +1 -0
- package/dist/public/icons/Fail.svg +1 -0
- package/dist/public/icons/Flag.svg +1 -0
- package/dist/public/icons/GiteeIcon.svg +1 -0
- package/dist/public/icons/IntelligenceGradient.svg +1 -0
- package/dist/public/icons/Issue_Approval.svg +1 -0
- package/dist/public/icons/Issue_Bug.svg +1 -0
- package/dist/public/icons/Issue_Demand.svg +1 -0
- package/dist/public/icons/Issue_Doc.svg +1 -0
- package/dist/public/icons/Issue_Idea.svg +1 -0
- package/dist/public/icons/Issue_List.svg +1 -0
- package/dist/public/icons/Issue_Plan.svg +1 -0
- package/dist/public/icons/Issue_Product.svg +1 -0
- package/dist/public/icons/Issue_Risk.svg +1 -0
- package/dist/public/icons/Issue_Story.svg +1 -0
- package/dist/public/icons/Issue_Subtask.svg +1 -0
- package/dist/public/icons/Issue_Task.svg +1 -0
- package/dist/public/icons/Issue_Test.svg +1 -0
- package/dist/public/icons/Issue_TestExcution.svg +1 -0
- package/dist/public/icons/Issue_TestPlan.svg +1 -0
- package/dist/public/icons/Issue_Time.svg +1 -0
- package/dist/public/icons/Issue_develop.svg +1 -0
- package/dist/public/icons/KanbanCover.svg +7 -0
- package/dist/public/icons/ListCover.svg +118 -0
- package/dist/public/icons/ManHour.svg +1 -0
- package/dist/public/icons/MobileIcon.svg +1 -0
- package/dist/public/icons/NoItemType.svg +10 -0
- package/dist/public/icons/ProductIcon.svg +1 -0
- package/dist/public/icons/RedFlagIcon.svg +1 -0
- package/dist/public/icons/Safe.svg +1 -0
- package/dist/public/icons/StarIcon.svg +61 -0
- package/dist/public/icons/StructureCover.svg +1 -0
- package/dist/public/icons/Success.svg +1 -0
- package/dist/public/icons/TeamIcon.svg +1 -0
- package/dist/public/icons/WebIcon.svg +1 -0
- package/dist/public/icons/iconfont.svg +467 -0
- package/dist/public/icons/iconfont.ttf +0 -0
- package/dist/public/icons/iconfont.woff +0 -0
- package/dist/public/icons/iconfont.woff2 +0 -0
- package/dist/public/icons/iconfont_multiple_color.js +1 -0
- package/dist/public/icons/iconfont_single_color.css +912 -0
- package/dist/public/icons/iconfont_single_color.js +1 -0
- package/dist/public/icons/loginBg.svg +1 -0
- package/dist/public/mockServiceWorker.js +284 -0
- package/dist/style/common.d.ts +1 -0
- package/dist/style/common.js +9 -0
- package/dist/style/global.d.ts +1 -0
- package/dist/style/global.js +8 -0
- package/package.json +105 -69
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isEmpty } from 'lodash-es';
|
|
2
|
+
export const LOGIN_PAGE_URL = '/login';
|
|
3
|
+
export const REDIRECT_API = '/frame';
|
|
4
|
+
export const getRedirectURI = (errorPageURL, baseAPI = LOGIN_PAGE_URL) => {
|
|
5
|
+
const redirectApi = new URL(baseAPI, errorPageURL);
|
|
6
|
+
redirectApi.searchParams.append('redirect_uri', errorPageURL);
|
|
7
|
+
return encodeURIComponent(redirectApi.toString());
|
|
8
|
+
};
|
|
9
|
+
export const getRedirectURL = (redirectConfig, errorPageURL) => {
|
|
10
|
+
if (isEmpty(redirectConfig))
|
|
11
|
+
return LOGIN_PAGE_URL;
|
|
12
|
+
if ((redirectConfig === null || redirectConfig === void 0 ? void 0 : redirectConfig.enabled) !== 'true')
|
|
13
|
+
return LOGIN_PAGE_URL;
|
|
14
|
+
const redirectUri = getRedirectURI(errorPageURL);
|
|
15
|
+
return redirectUri;
|
|
16
|
+
};
|
|
17
|
+
export const getKeycloakErrorMsg = errorData => {
|
|
18
|
+
if (!(errorData === null || errorData === void 0 ? void 0 : errorData.error_description) || !(errorData === null || errorData === void 0 ? void 0 : errorData.error))
|
|
19
|
+
return null;
|
|
20
|
+
return `${errorData.error}: ${errorData.error_description}`;
|
|
21
|
+
};
|
|
22
|
+
export const getParseErrorMsg = errorData => {
|
|
23
|
+
if (!(errorData === null || errorData === void 0 ? void 0 : errorData.code) || !(errorData === null || errorData === void 0 ? void 0 : errorData.error))
|
|
24
|
+
return null;
|
|
25
|
+
if ('string' === typeof errorData.error) {
|
|
26
|
+
return errorData.error;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
let msg;
|
|
30
|
+
try {
|
|
31
|
+
msg = JSON.stringify(errorData.error, null, 2);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.warn('parse error fail, source error', errorData);
|
|
35
|
+
}
|
|
36
|
+
if (msg)
|
|
37
|
+
return msg;
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export const getNormalErrorMsg = errorData => 'string' === typeof errorData ? errorData : null;
|
|
42
|
+
export const getErrorMessage = (errorData, defaultMsg = '请求失败.') => {
|
|
43
|
+
const errorMessage = getNormalErrorMsg(errorData) ||
|
|
44
|
+
(errorData === null || errorData === void 0 ? void 0 : errorData.message) ||
|
|
45
|
+
(errorData === null || errorData === void 0 ? void 0 : errorData.error) ||
|
|
46
|
+
getKeycloakErrorMsg(errorData) ||
|
|
47
|
+
getParseErrorMsg(errorData) ||
|
|
48
|
+
defaultMsg;
|
|
49
|
+
return errorMessage;
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const IGNORE_URL: string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const IGNORE_URL = ['/', '/login', '/register', '/resetPassword', '/configuration-guide', '/reset-config'];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
export type WrapperAxiosRequestConfig<T = any> = AxiosRequestConfig<T> & {
|
|
3
|
+
useJson?: boolean;
|
|
4
|
+
useCompress?: boolean;
|
|
5
|
+
useJsonDecompress?: boolean;
|
|
6
|
+
hiddenErrorModal?: boolean;
|
|
7
|
+
ignoreParseHeaders?: boolean;
|
|
8
|
+
hiddenTimeout?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export interface IFetchInstance extends AxiosInstance {
|
|
11
|
+
$get<T = any, P = any>(url: string, config?: {
|
|
12
|
+
params?: P;
|
|
13
|
+
} & Omit<WrapperAxiosRequestConfig, 'params'>): Promise<T>;
|
|
14
|
+
$delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
15
|
+
$head<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
16
|
+
$options<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
17
|
+
$post<T = any>(url: string, data?: any, config?: WrapperAxiosRequestConfig): Promise<T>;
|
|
18
|
+
$put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
19
|
+
$patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
export declare const useGetConfigTimeout: () => number;
|
|
22
|
+
export declare const baseApi = "/parse/api";
|
|
23
|
+
export declare const useGetLoginBasePath: () => string;
|
|
24
|
+
export declare const useGetServerGateway: () => string;
|
|
25
|
+
export declare const useGetGateway: (extraPath?: string) => string;
|
|
26
|
+
interface GetConfigParams {
|
|
27
|
+
sessionToken: string;
|
|
28
|
+
tenant: string;
|
|
29
|
+
Cookie: string;
|
|
30
|
+
}
|
|
31
|
+
interface ConfigType {
|
|
32
|
+
baseURL: string;
|
|
33
|
+
headers: {
|
|
34
|
+
'X-Parse-Session-Token': string;
|
|
35
|
+
'X-Parse-Application-Id': string;
|
|
36
|
+
Cookie: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export declare function useGetRequestConfig({ sessionToken, tenant, Cookie }: GetConfigParams): ConfigType;
|
|
40
|
+
export declare const useAxiosConfig: () => AxiosRequestConfig;
|
|
41
|
+
export declare const LOCALE_KEY = "lang";
|
|
42
|
+
export declare const useGetHeaderLang: () => string;
|
|
43
|
+
export declare const getGlobalEnv: () => Record<string, any>;
|
|
44
|
+
declare const useFetch: () => IFetchInstance;
|
|
45
|
+
export default useFetch;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { useCallback, useContext, useEffect, useMemo } from 'react';
|
|
2
|
+
import axios, { HttpStatusCode } from 'axios';
|
|
3
|
+
import cjson from 'compressed-json';
|
|
4
|
+
import debug from 'debug';
|
|
5
|
+
import { toNumber } from 'lodash-es';
|
|
6
|
+
import { CANCEL_FETCH_STRING, REDIRECT_URL_KEY } from 'lib/global';
|
|
7
|
+
import throttleWithCache, { THROTTLE_TYPE } from 'lib/swr/throttleWithCache';
|
|
8
|
+
import { ParseErrorCode } from './constants/code';
|
|
9
|
+
import { TeamConfigContext } from './contexts/teamConfig';
|
|
10
|
+
import { IGNORE_URL } from './error/withServerError';
|
|
11
|
+
import { getErrorMessage, log as ErrorLog } from './error';
|
|
12
|
+
import { i18n } from './i18n';
|
|
13
|
+
import isInOne from './isInOne';
|
|
14
|
+
import { useGetSourcePath } from './path';
|
|
15
|
+
import { getCurLocationInfo } from './router';
|
|
16
|
+
import { removeParseItems } from './storage';
|
|
17
|
+
import { useAppProps } from './useConfig';
|
|
18
|
+
const Blob = window.Blob;
|
|
19
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
20
|
+
const DEFAULT_TIMEOUT = 15 * 1000;
|
|
21
|
+
export const useGetConfigTimeout = () => {
|
|
22
|
+
const { publicRuntimeConfig = {} } = useContext(TeamConfigContext);
|
|
23
|
+
const { globalFetchTimeout } = publicRuntimeConfig;
|
|
24
|
+
return toNumber(globalFetchTimeout) || DEFAULT_TIMEOUT;
|
|
25
|
+
};
|
|
26
|
+
export const baseApi = '/parse/api';
|
|
27
|
+
export const useGetLoginBasePath = () => {
|
|
28
|
+
const { publicRuntimeConfig = {} } = useContext(TeamConfigContext);
|
|
29
|
+
const basePath = useMemo(() => {
|
|
30
|
+
const { basePath = '' } = publicRuntimeConfig;
|
|
31
|
+
if (isDev)
|
|
32
|
+
return basePath;
|
|
33
|
+
return '';
|
|
34
|
+
}, [publicRuntimeConfig]);
|
|
35
|
+
return basePath;
|
|
36
|
+
};
|
|
37
|
+
export const useGetServerGateway = () => {
|
|
38
|
+
const { publicRuntimeConfig } = useContext(TeamConfigContext);
|
|
39
|
+
return (publicRuntimeConfig === null || publicRuntimeConfig === void 0 ? void 0 : publicRuntimeConfig.gateway) || '';
|
|
40
|
+
};
|
|
41
|
+
export const useGetGateway = (extraPath = '') => {
|
|
42
|
+
const gateway = useGetServerGateway();
|
|
43
|
+
const result = useMemo(() => {
|
|
44
|
+
const inOne = isInOne(gateway);
|
|
45
|
+
if (!gateway)
|
|
46
|
+
return inOne ? '' : extraPath;
|
|
47
|
+
if (inOne)
|
|
48
|
+
return gateway;
|
|
49
|
+
return extraPath;
|
|
50
|
+
}, [extraPath, gateway]);
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
export function useGetRequestConfig({ sessionToken, tenant, Cookie }) {
|
|
54
|
+
const gateway = useGetServerGateway();
|
|
55
|
+
const baseURL = useMemo(() => {
|
|
56
|
+
return `${gateway}${baseApi}`;
|
|
57
|
+
}, [gateway]);
|
|
58
|
+
return {
|
|
59
|
+
baseURL,
|
|
60
|
+
headers: {
|
|
61
|
+
'X-Parse-Session-Token': sessionToken,
|
|
62
|
+
'X-Parse-Application-Id': tenant,
|
|
63
|
+
...(Cookie && {
|
|
64
|
+
Cookie,
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export const useAxiosConfig = () => {
|
|
70
|
+
const gateway = useGetGateway();
|
|
71
|
+
const baseURL = useMemo(() => {
|
|
72
|
+
return `${gateway}${baseApi}`;
|
|
73
|
+
}, [gateway]);
|
|
74
|
+
const defaultTimeout = useGetConfigTimeout();
|
|
75
|
+
return {
|
|
76
|
+
baseURL,
|
|
77
|
+
timeout: defaultTimeout,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const errorLog = msg => {
|
|
81
|
+
return ErrorLog.show(msg);
|
|
82
|
+
};
|
|
83
|
+
export const LOCALE_KEY = 'lang';
|
|
84
|
+
export const useGetHeaderLang = () => {
|
|
85
|
+
const { locale } = useAppProps();
|
|
86
|
+
return locale;
|
|
87
|
+
};
|
|
88
|
+
export const getGlobalEnv = () => {
|
|
89
|
+
return window.env || {};
|
|
90
|
+
};
|
|
91
|
+
const checkLog = debug('lib:fetch:checkSessionToken');
|
|
92
|
+
const NO_SESSION_KEY = 'sessionToken is required';
|
|
93
|
+
const CHECK_WHITE_LIST = [
|
|
94
|
+
'/api/auth/demo/login',
|
|
95
|
+
'/api/auth/login',
|
|
96
|
+
'/api/auth/logout',
|
|
97
|
+
'/api/auth/code',
|
|
98
|
+
'/api/license/serviceId',
|
|
99
|
+
'/api/license/register',
|
|
100
|
+
'/api/license/status',
|
|
101
|
+
'/api/auth/install/addAdminUser',
|
|
102
|
+
'/submit/',
|
|
103
|
+
'/api/license/licenseInfo',
|
|
104
|
+
];
|
|
105
|
+
function checkSessionToken(config) {
|
|
106
|
+
checkLog('......checkSessionToken', config.headers['X-Parse-Session-Token'], !!config.headers['X-Parse-Session-Token'], config.url, config.baseURL);
|
|
107
|
+
if (!config.baseURL) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (config.baseURL.endsWith('apps/api'))
|
|
111
|
+
return;
|
|
112
|
+
if (CHECK_WHITE_LIST.includes(config.url))
|
|
113
|
+
return;
|
|
114
|
+
const hasToken = config.headers['X-Parse-Session-Token'] != null;
|
|
115
|
+
if (!hasToken) {
|
|
116
|
+
throw new Error(NO_SESSION_KEY, { cause: config.url });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const useRedirectToLogin = () => {
|
|
120
|
+
const { publicRuntimeConfig = {} } = useContext(TeamConfigContext);
|
|
121
|
+
const router = getCurLocationInfo();
|
|
122
|
+
const getSourcePath = useGetSourcePath();
|
|
123
|
+
const redirectToLogin = useCallback((_error, _form) => {
|
|
124
|
+
checkLog('......redirectToLogin', _error, _form);
|
|
125
|
+
if (publicRuntimeConfig.disableRedirect) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (!IGNORE_URL.includes(router.asPath)) {
|
|
129
|
+
const redirectURL = getSourcePath(router.asPath);
|
|
130
|
+
const loginURL = getSourcePath('/login');
|
|
131
|
+
console.info('..........currentPath', redirectURL, loginURL);
|
|
132
|
+
removeParseItems();
|
|
133
|
+
localStorage.setItem(REDIRECT_URL_KEY, redirectURL);
|
|
134
|
+
window.location.href = loginURL;
|
|
135
|
+
}
|
|
136
|
+
}, [getSourcePath, publicRuntimeConfig.disableRedirect, router.asPath]);
|
|
137
|
+
return redirectToLogin;
|
|
138
|
+
};
|
|
139
|
+
const useRequestInterceptors = () => {
|
|
140
|
+
const { sessionToken, locale, appId } = useAppProps();
|
|
141
|
+
const requestInterceptors = useCallback(config => {
|
|
142
|
+
if (!config.ignoreParseHeaders) {
|
|
143
|
+
if (!config.headers)
|
|
144
|
+
config.headers = {};
|
|
145
|
+
if (!config.headers['X-Parse-Application-Id']) {
|
|
146
|
+
config.headers['X-Parse-Application-Id'] = appId;
|
|
147
|
+
}
|
|
148
|
+
if (config.headers['X-Parse-Session-Token'] == null && sessionToken) {
|
|
149
|
+
config.headers['X-Parse-Session-Token'] = sessionToken;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (Object.hasOwnProperty.call(config.headers, 'Cookie') && !config.headers.Cookie) {
|
|
153
|
+
delete config.headers.Cookie;
|
|
154
|
+
}
|
|
155
|
+
if (Object.hasOwnProperty.call(config.headers, 'cookie') && !config.headers.cookie) {
|
|
156
|
+
delete config.headers.cookie;
|
|
157
|
+
}
|
|
158
|
+
const parseHeaderLang = locale;
|
|
159
|
+
if (parseHeaderLang && !config.headers['Accept-Language']) {
|
|
160
|
+
config.headers['Accept-Language'] = parseHeaderLang;
|
|
161
|
+
}
|
|
162
|
+
if (config.useCompress) {
|
|
163
|
+
config.headers['x-has-compression'] = 'true';
|
|
164
|
+
}
|
|
165
|
+
if (config.useJsonDecompress) {
|
|
166
|
+
config.headers['x-has-json-compression'] = 'true';
|
|
167
|
+
}
|
|
168
|
+
checkSessionToken(config);
|
|
169
|
+
return config;
|
|
170
|
+
}, [appId, locale, sessionToken]);
|
|
171
|
+
return requestInterceptors;
|
|
172
|
+
};
|
|
173
|
+
const useAddResponseInterceptors = (fetch) => {
|
|
174
|
+
const { publicRuntimeConfig } = useContext(TeamConfigContext);
|
|
175
|
+
const redirectToLogin = useRedirectToLogin();
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
fetch.interceptors.response.use((response) => {
|
|
178
|
+
if (response.status >= 200 && response.status <= 300) {
|
|
179
|
+
return Promise.resolve(response);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
return Promise.reject(response);
|
|
183
|
+
}
|
|
184
|
+
}, async (error) => {
|
|
185
|
+
var _a;
|
|
186
|
+
console.error('[$fetch] response ERROR', error);
|
|
187
|
+
const { showTimeoutMessage: showTimeout } = publicRuntimeConfig;
|
|
188
|
+
const { hiddenErrorModal, hiddenTimeout } = error.config || {};
|
|
189
|
+
const inOne = isInOne();
|
|
190
|
+
if (error.code === 'ECONNREFUSED') {
|
|
191
|
+
errorLog(i18n.t('apis.error.refused'));
|
|
192
|
+
}
|
|
193
|
+
else if (error.code === 'ECONNABORTED') {
|
|
194
|
+
!hiddenTimeout && showTimeout && errorLog(i18n.t('apis.error.timeout'));
|
|
195
|
+
return Promise.reject('timeout');
|
|
196
|
+
}
|
|
197
|
+
else if (error.code === 'ERR_CANCELED') {
|
|
198
|
+
console.info('request canceled', error.message);
|
|
199
|
+
return Promise.reject('canceled');
|
|
200
|
+
}
|
|
201
|
+
else if (error.code === 'ERR_BAD_REQUEST' && HttpStatusCode.PayloadTooLarge === ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
|
|
202
|
+
errorLog(i18n.t('apis.error.payloadTooLarge'));
|
|
203
|
+
return Promise.reject(error.response.statusText);
|
|
204
|
+
}
|
|
205
|
+
else if (error.response) {
|
|
206
|
+
if (error.response.status) {
|
|
207
|
+
let errorData = error.response.data;
|
|
208
|
+
if (error.response.data instanceof Blob) {
|
|
209
|
+
errorData = await new Response(error.response.data).json();
|
|
210
|
+
}
|
|
211
|
+
if (typeof errorData === 'object') {
|
|
212
|
+
if (!inOne && errorData.code === ParseErrorCode.INVALID_SESSION_TOKEN) {
|
|
213
|
+
redirectToLogin(error, errorData.message);
|
|
214
|
+
return Promise.reject(error.response);
|
|
215
|
+
}
|
|
216
|
+
const errorMessage = getErrorMessage(errorData, i18n.t('apis.error.responseError', { dot: '.' }));
|
|
217
|
+
!hiddenErrorModal && errorLog(errorMessage);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
!hiddenErrorModal && errorLog(errorData || i18n.t('apis.error.responseError', { dot: '' }));
|
|
221
|
+
}
|
|
222
|
+
return Promise.reject(error.response);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
if (!inOne && (error === null || error === void 0 ? void 0 : error.message) === NO_SESSION_KEY) {
|
|
227
|
+
redirectToLogin(error, NO_SESSION_KEY);
|
|
228
|
+
}
|
|
229
|
+
else if ((error === null || error === void 0 ? void 0 : error.message) !== CANCEL_FETCH_STRING) {
|
|
230
|
+
errorLog(error.message);
|
|
231
|
+
}
|
|
232
|
+
else if (axios.isCancel(error)) {
|
|
233
|
+
console.info('.........is cancel', error);
|
|
234
|
+
}
|
|
235
|
+
return Promise.reject(error);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}, [fetch.interceptors.response, publicRuntimeConfig, redirectToLogin]);
|
|
239
|
+
};
|
|
240
|
+
const $fetch = async (method, url, ...args) => {
|
|
241
|
+
if (!url) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const toSuccessData = response => {
|
|
245
|
+
var _a, _b;
|
|
246
|
+
const requestConfig = (args[0] || {});
|
|
247
|
+
const { useJson, useJsonDecompress } = requestConfig;
|
|
248
|
+
if (useJson) {
|
|
249
|
+
if (response.data.code !== 0) {
|
|
250
|
+
return Promise.reject(response.data);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
if (useJsonDecompress) {
|
|
254
|
+
return cjson.decompress((_a = response.data) === null || _a === void 0 ? void 0 : _a.payload);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
return (_b = response.data) === null || _b === void 0 ? void 0 : _b.payload;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return response.data;
|
|
262
|
+
};
|
|
263
|
+
const response = await throttleWithCache({
|
|
264
|
+
type: THROTTLE_TYPE.CUSTOM_FETCH,
|
|
265
|
+
params: {
|
|
266
|
+
url,
|
|
267
|
+
args,
|
|
268
|
+
},
|
|
269
|
+
fn: () => {
|
|
270
|
+
return fetch[method](url, ...args);
|
|
271
|
+
},
|
|
272
|
+
method,
|
|
273
|
+
});
|
|
274
|
+
return toSuccessData(response);
|
|
275
|
+
};
|
|
276
|
+
const setFetchInstance = (config) => {
|
|
277
|
+
const fetch = axios.create(config);
|
|
278
|
+
fetch.$get = async (...args) => $fetch('get', ...args);
|
|
279
|
+
fetch.$post = async (...args) => $fetch('post', ...args);
|
|
280
|
+
fetch.$delete = async (...args) => $fetch('delete', ...args);
|
|
281
|
+
fetch.$put = async (...args) => $fetch('put', ...args);
|
|
282
|
+
fetch.$patch = async (...args) => $fetch('patch', ...args);
|
|
283
|
+
fetch.$head = async (...args) => $fetch('head', ...args);
|
|
284
|
+
fetch.$options = async (...args) => $fetch('options', ...args);
|
|
285
|
+
return fetch;
|
|
286
|
+
};
|
|
287
|
+
const useFetch = () => {
|
|
288
|
+
const config = useAxiosConfig();
|
|
289
|
+
const requestInterceptors = useRequestInterceptors();
|
|
290
|
+
const fetch = useMemo(() => {
|
|
291
|
+
const fetch = setFetchInstance(config);
|
|
292
|
+
fetch.interceptors.request.use(requestInterceptors, error => {
|
|
293
|
+
console.error('[$fetch] request ERROR', error);
|
|
294
|
+
return Promise.reject(error);
|
|
295
|
+
});
|
|
296
|
+
return fetch;
|
|
297
|
+
}, [config, requestInterceptors]);
|
|
298
|
+
useAddResponseInterceptors(fetch);
|
|
299
|
+
return fetch;
|
|
300
|
+
};
|
|
301
|
+
export default useFetch;
|
package/dist/lib/global.d.ts
CHANGED
|
@@ -101,3 +101,21 @@ export declare const CustomFieldComponentTypes: {
|
|
|
101
101
|
Radio: string;
|
|
102
102
|
Checkbox: string;
|
|
103
103
|
};
|
|
104
|
+
export declare const BASE_FIELD_WIDTH = 104;
|
|
105
|
+
export declare const CURRENT_WORKSPACE = "currentWorkspace()";
|
|
106
|
+
export declare const FIELD_CONTAINERS_PAGE: {
|
|
107
|
+
readonly DETAIL: "detail";
|
|
108
|
+
readonly MODAL: "modal";
|
|
109
|
+
readonly DRAWER: "drawer";
|
|
110
|
+
readonly FILTER: "filter";
|
|
111
|
+
readonly SCREEN: "screen";
|
|
112
|
+
readonly AUTOMATION_FIELD: "automation_field";
|
|
113
|
+
readonly VIEW_MODAL: "view_modal";
|
|
114
|
+
};
|
|
115
|
+
export declare const SCREEN_TYPE: {
|
|
116
|
+
readonly View: "view";
|
|
117
|
+
readonly Create: "create";
|
|
118
|
+
readonly Edit: "edit";
|
|
119
|
+
};
|
|
120
|
+
export declare const CANCEL_FETCH_STRING = "cancel_fetch_string";
|
|
121
|
+
export declare const REDIRECT_URL_KEY = "team_redirect_url";
|
package/dist/lib/global.js
CHANGED
|
@@ -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';
|
package/dist/lib/i18n.d.ts
CHANGED
package/dist/lib/i18n.js
CHANGED
|
@@ -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;
|
package/dist/lib/path.js
ADDED
|
@@ -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>;
|