Skip to content

Commit 3f964a9

Browse files
authored
Merge pull request #723 from actiontech/fix/issue-670
[fix](AvailabilityZone): Add support for provision route replacement
2 parents 563d812 + 9054085 commit 3f964a9

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

packages/base/src/page/AvailabilityZone/AvailabilityZoneWrapper/__tests__/index.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,31 @@ describe('base/AvailabilityZone/AvailabilityZoneWrapper', () => {
265265
{ replace: true }
266266
);
267267
});
268+
269+
it('should handle path with provision prefix', async () => {
270+
getRecentlyProjectIdByUserInfoSpy.mockReturnValue('project-123');
271+
272+
(useLocation as jest.Mock).mockImplementation(() => ({
273+
pathname: '/provision/project//dashboard',
274+
search: '?test=true'
275+
}));
276+
277+
superRender(<AvailabilityZoneWrapper />);
278+
279+
const selectElement = screen.getByRole('combobox');
280+
fireEvent.mouseDown(selectElement);
281+
282+
await act(async () => jest.advanceTimersByTime(0));
283+
284+
fireEvent.click(screen.getByText('Test Zone'));
285+
fireEvent.click(screen.getByText('确 认'));
286+
287+
await act(async () => jest.advanceTimersByTime(3000));
288+
289+
expect(navigateSpy).toHaveBeenCalledWith(
290+
'/provision/project/project-123/dashboard?test=true',
291+
{ replace: true }
292+
);
293+
});
268294
});
269295
});

packages/base/src/page/AvailabilityZone/AvailabilityZoneWrapper/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ const AvailabilityZoneWrapper: React.FC = () => {
6969
res.data.data
7070
);
7171

72+
const projectIdReplacementReg =
73+
/^(\/sqle\/|\/provision\/|\/)project\/([^\/]+)\/(.+)$/;
74+
7275
// 当前项目不在用户绑定项目中 并且不存在近期选择项目 则需要去选择项目
7376
if (!!projectID && !isProjectInBindProjects && !memorizedProjectID) {
7477
const newPathname = location.pathname.replace(
75-
/^(\/sqle\/|\/)project\/([^\/]+)\/(.+)$/,
78+
projectIdReplacementReg,
7679
(_, prefix, projectId, target) => {
7780
return `${prefix}project//${target}`;
7881
}
@@ -82,7 +85,7 @@ const AvailabilityZoneWrapper: React.FC = () => {
8285
// 路径中没有默认项目
8386
if (!projectID) {
8487
const newPathname = location.pathname.replace(
85-
/^(\/sqle\/|\/)project\/\/(.+)$/,
88+
/^(\/sqle\/|\/provision\/|\/)project\/\/(.+)$/,
8689
(_, prefix, target) => {
8790
return `${prefix}project/${memorizedProjectID}/${target}`;
8891
}
@@ -94,7 +97,7 @@ const AvailabilityZoneWrapper: React.FC = () => {
9497
// 这是后端的业务逻辑 如果没有给后端传递可用区信息 则默认走当前ip的服务
9598
// 这时项目下的页面路经就会携带项目id,如果选择其他可用区就会报错,因为可能在其他可用区中用户可能不属于该项目
9699
const newPathname = location.pathname.replace(
97-
/^(\/sqle\/|\/)project\/([^\/]+)\/(.+)$/,
100+
projectIdReplacementReg,
98101
(_, prefix, projectId, target) => {
99102
return `${prefix}project/${memorizedProjectID}/${target}`;
100103
}

0 commit comments

Comments
 (0)