Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 5f02ee6

Browse files
committed
chore
1 parent 7188f7e commit 5f02ee6

File tree

5 files changed

+54
-7
lines changed

5 files changed

+54
-7
lines changed

packages/console-utils/xconsole-context/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alicloud/xconsole-context",
3-
"version": "2.5.4",
3+
"version": "2.6.0-alpha.0",
44
"main": "lib/index.js",
55
"module": "es/index.js",
66
"types": "lib/index.d.ts",

packages/console-utils/xconsole-context/src/console/ConsoleConfig.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ class ConsoleConfig {
150150
}
151151
return undefined;
152152
};
153+
154+
/**
155+
* 获取应用版本灰度信息
156+
* @returns
157+
*/
158+
getVersionGrayConfig = () => {
159+
return this.consoleConfig.VERSION_GRAY_CONFIG || {};
160+
};
153161
}
154162

155163
export default ConsoleConfig;

packages/console-utils/xconsole-context/src/rc/Gray.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ interface IProps {
99
export const useGray = (grayId: string) => {
1010
if (typeof grayId === 'undefined') {
1111
throw new Error(
12-
'[Gray] grayId is required'
13-
)
12+
'[Gray] grayId is required',
13+
);
1414
}
1515
const { consoleConfig } = useContext(ConsoleContext);
1616
return consoleConfig.getGrayStatus(grayId);
17-
}
17+
};
1818

1919
const Gray: React.FunctionComponent<IProps> = (props: IProps) => {
2020
const { grayId, children } = props;
2121
const grayStatus = useGray(grayId);
2222
if (grayStatus === false) return null;
2323
return children;
24-
}
24+
};
2525

2626

27-
export default Gray;
27+
export default Gray;

packages/console-utils/xconsole-context/src/region/useRegion.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { reroute } from './reroute';
77
import { determineRegionId } from './determineRegionId';
88
import { RegionContext } from '../context/RegionContext';
99
import { getActiveId } from './cookies';
10+
import consoleConfig from '../console';
1011
import type { IConsoleContextRegionProp } from '../types/index';
1112

1213
export type TConsoleRegion = typeof ConsoleRegion;
@@ -15,6 +16,23 @@ export interface Region extends TConsoleRegion {
1516
loading?: boolean;
1617
}
1718

19+
/**
20+
* 如果要切换的地域是灰度地域,则重新加载页面
21+
*/
22+
export function shouldReload(currentRegionId, targetRegionId) {
23+
const { enabled, type, grayRegions } = consoleConfig.getVersionGrayConfig();
24+
25+
// 如果未开启灰度逻辑不刷新
26+
if (!enabled || type !== 'region') return false;
27+
28+
if (currentRegionId === targetRegionId) return false;
29+
30+
// 如果当前 region 和跳转 region 都在灰度范围内不刷新
31+
if (grayRegions.indexOf(currentRegionId) > -1 && grayRegions.indexOf(targetRegionId) > -1) return false;
32+
33+
return true;
34+
}
35+
1836
/**
1937
* regionBar 相关的交互
2038
* - 发送 regionId 和 regionList 给 regionBar
@@ -39,7 +57,9 @@ export default (props: IConsoleContextRegionProp<{regionId?: string}>): Region =
3957
);
4058
const regionContext = useContext(RegionContext);
4159
const consoleBase = useMemo(() => passInConsoleBase || ConsoleBaseFallback, [passInConsoleBase]);
60+
// react-router match
4261
const matchRef = useRef(match);
62+
// react-router location
4363
const locationRef = useRef(location);
4464

4565
matchRef.current = match;
@@ -65,14 +85,19 @@ export default (props: IConsoleContextRegionProp<{regionId?: string}>): Region =
6585
]);
6686

6787
/**
68-
* 如果是 region 路由,且 regionId 变化时重定向
88+
* 如果路由参数里有 regionId,替换 regionId 值并重定向路由
6989
*/
7090
const rerouteIfNeed = useCallback((regionId: string) => {
7191
reroute({
7292
history,
7393
match: matchRef.current,
7494
location: locationRef.current,
7595
}, regionId, historyAction);
96+
97+
// @ts-ignore
98+
if (shouldReload(window.__XCONSOLE_CURRENT_REGION_ID__, regionId)) {
99+
window.location.reload();
100+
}
76101
}, [
77102
history,
78103
historyAction,

packages/console-utils/xconsole-context/src/types/AliyunConsoleConfig.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,18 @@ export interface IAliyunConsoleConfig {
216216
* portal 类型
217217
*/
218218
portalType?: string;
219+
220+
/**
221+
* region 灰度配置
222+
*/
223+
VERSION_GRAY_CONFIG: {
224+
grayRegions?: string[];
225+
regionId?: string;
226+
grayVersion?: string;
227+
grayId?: string;
228+
type?: string;
229+
version?: string;
230+
enabled?: boolean;
231+
onlineVersion?: string;
232+
};
219233
}

0 commit comments

Comments
 (0)