Skip to content

Commit 1b1978a

Browse files
authored
Cluster Orch routing updates (#129)
1 parent 931be50 commit 1b1978a

15 files changed

Lines changed: 215 additions & 85 deletions

File tree

apps/cluster-orch/src/components/organism/ClusterNodesTable/ClusterNodesTable.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
TableColumn,
1313
} from "@orch-ui/components";
1414
import {
15+
getInfraPath,
1516
getTrustedComputeCompatibility,
17+
hostDetailsRoute,
1618
hostProviderStatusToString,
1719
nodeStatusToIconStatus,
1820
nodeStatusToText,
@@ -131,11 +133,19 @@ const ClusterNodesTable = ({
131133
Header: "Actions",
132134
textAlign: "center",
133135
padding: "0",
134-
accessor: (node) => (
135-
<Link to={`/infrastructure/host/${node.resourceId}`}>
136-
<Icon icon="clipboard-forward" /> View Host Details
137-
</Link>
138-
),
136+
accessor: (node: ClusterNode) => {
137+
return (
138+
node.resourceId && (
139+
<Link
140+
to={getInfraPath(hostDetailsRoute, {
141+
id: node.resourceId,
142+
})}
143+
>
144+
<Icon icon="clipboard-forward" /> View Host Details
145+
</Link>
146+
)
147+
);
148+
},
139149
},
140150
];
141151

apps/cluster-orch/src/components/organism/ClusterSummary/ClusterSummary.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
import { cm } from "@orch-ui/apis";
77
import { Flex, SquareSpinner, StatusIcon } from "@orch-ui/components";
8-
import { clusterStatusToIconStatus, SharedStorage } from "@orch-ui/utils";
8+
import {
9+
clusterDetailRoute,
10+
clusterStatusToIconStatus,
11+
getInfraPath,
12+
SharedStorage,
13+
} from "@orch-ui/utils";
914
import { Icon, MessageBanner } from "@spark-design/react";
1015
import { MessageBannerAlertState } from "@spark-design/tokens";
1116
import { Link } from "react-router-dom";
@@ -56,9 +61,16 @@ const ClusterSummary = ({ nodeId, site }: ClusterSummaryProps) => {
5661
<div data-cy="site">{site}</div>
5762
<b>Action</b>
5863
<div>
59-
<Link data-cy="link" to={`/infrastructure/cluster/${data.name}`}>
60-
<Icon icon="clipboard-forward" /> View Cluster Details
61-
</Link>
64+
{data.name && (
65+
<Link
66+
data-cy="link"
67+
to={getInfraPath(clusterDetailRoute, {
68+
clusterName: data.name,
69+
})}
70+
>
71+
<Icon icon="clipboard-forward" /> View Cluster Details
72+
</Link>
73+
)}
6274
</div>
6375
</Flex>
6476
</div>

apps/cluster-orch/src/components/organism/DeauthorizeNodeConfirmationDialog/DeauthorizeNodeConfirmationDialog.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55

66
import { cm } from "@orch-ui/apis";
77
import { ConfirmationDialog } from "@orch-ui/components";
8-
import { InternalError, SharedStorage } from "@orch-ui/utils";
8+
import {
9+
hostsRoute,
10+
InternalError,
11+
SharedStorage,
12+
useInfraNavigate,
13+
} from "@orch-ui/utils";
914
import { TextField } from "@spark-design/react";
1015
import { ButtonVariant, InputSize, ModalSize } from "@spark-design/tokens";
1116
import { useState } from "react";
1217
import { Controller, useForm } from "react-hook-form";
13-
import { useNavigate } from "react-router-dom";
1418
import "./DeauthorizeNodeConfirmationDialog.scss";
1519

1620
const dataCy = "deauthorizeNodeConfirmationDialog";
@@ -51,7 +55,7 @@ const DeauthorizeNodeConfirmationDialog = ({
5155
}: DeauthorizeNodeConfirmationDialogProps) => {
5256
const cy = { "data-cy": dataCy };
5357
const projectName = SharedStorage.project?.name ?? "";
54-
const navigate = useNavigate();
58+
const navigate = useInfraNavigate();
5559

5660
const [removeHostNodeFromCluster] =
5761
cm.usePutV2ProjectsByProjectNameClustersAndNameNodesMutation();
@@ -93,7 +97,7 @@ const DeauthorizeNodeConfirmationDialog = ({
9397
})
9498
.then(() => {
9599
setErrorInfo();
96-
navigate("/infrastructure/hosts", { relative: "path" });
100+
navigate(hostsRoute);
97101
});
98102
} catch (e) {
99103
setErrorInfo(e);

apps/cluster-orch/src/components/organism/cluster/ClusterList.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,22 @@ import {
2323
} from "@orch-ui/components";
2424
import {
2525
API_INTERVAL,
26+
clusterCreateRoute,
27+
clusterDetailRoute,
28+
clusterEditRoute,
29+
clusterManagementRoute,
2630
clusterToStatuses,
2731
copyToClipboard,
2832
Direction,
2933
downloadFile,
3034
getFilter,
35+
getInfraPath,
3136
getOrder,
3237
getTrustedComputeCluster,
3338
Operator,
3439
parseError,
3540
SharedStorage,
41+
useInfraNavigate,
3642
} from "@orch-ui/utils";
3743
import { Icon, Toast, ToastProps } from "@spark-design/react";
3844
import {
@@ -43,15 +49,15 @@ import {
4349
ToastVisibility,
4450
} from "@spark-design/tokens";
4551
import { useState } from "react";
46-
import { Link, useNavigate, useSearchParams } from "react-router-dom";
52+
import { Link, useSearchParams } from "react-router-dom";
4753
import "./ClusterList.scss";
4854
import ClusterNodesWrapper from "./ClusterNodesWrapper/ClusterNodesWrapper";
4955

5056
interface ClusterListProps {
5157
hasPermission?: boolean;
5258
}
5359
export default function ClusterList({ hasPermission }: ClusterListProps) {
54-
const navigate = useNavigate();
60+
const navigate = useInfraNavigate();
5561
const [searchParams, setSearchParams] = useSearchParams();
5662
const searchTerm = searchParams.get("searchTerm") ?? undefined;
5763
const [clusterToDelete, setClusterToDelete] = useState<string>();
@@ -150,14 +156,16 @@ export default function ClusterList({ hasPermission }: ClusterListProps) {
150156
{
151157
displayText: "View Details",
152158
onSelect: () => {
153-
navigate(`../cluster/${cluster.name}`);
159+
if (cluster.name)
160+
navigate(clusterDetailRoute, { clusterName: cluster.name });
154161
},
155162
},
156163
{
157164
displayText: "Edit",
158165
disable: !hasPermission,
159166
onSelect: () => {
160-
navigate(`../cluster/${cluster.name}/edit`);
167+
if (cluster.name)
168+
navigate(clusterEditRoute, { clusterName: cluster.name });
161169
},
162170
},
163171
{
@@ -195,7 +203,7 @@ export default function ClusterList({ hasPermission }: ClusterListProps) {
195203
state: ToastState.Success,
196204
visibility: ToastVisibility.Show,
197205
}));
198-
navigate("/infrastructure/clusters");
206+
navigate(clusterManagementRoute);
199207
})
200208
.catch((e) => {
201209
setToast((p) => ({
@@ -214,10 +222,17 @@ export default function ClusterList({ hasPermission }: ClusterListProps) {
214222
accessor: (item) => item.name,
215223
apiName: "name",
216224
Cell: (table: { row: { original: cm.ClusterInfoRead } }) => {
225+
const clusterName = table.row.original.name;
217226
return (
218-
<Link to={`../cluster/${table.row.original.name}`}>
219-
{table.row.original.name}
220-
</Link>
227+
clusterName && (
228+
<Link
229+
to={getInfraPath(clusterDetailRoute, {
230+
clusterName: clusterName,
231+
})}
232+
>
233+
{table.row.original.name}
234+
</Link>
235+
)
221236
);
222237
},
223238
},
@@ -295,7 +310,7 @@ export default function ClusterList({ hasPermission }: ClusterListProps) {
295310
title="Create a cluster using one or more configured hosts."
296311
actions={[
297312
{
298-
action: () => navigate("create"),
313+
action: () => navigate(clusterCreateRoute),
299314
name: "Create Cluster",
300315
disable: !hasPermission,
301316
},
@@ -372,7 +387,7 @@ export default function ClusterList({ hasPermission }: ClusterListProps) {
372387
text="Create Cluster"
373388
disabled={!hasPermission}
374389
onPress={() => {
375-
navigate("/infrastructure/clusters/create");
390+
navigate(clusterCreateRoute);
376391
}}
377392
tooltip={
378393
hasPermission

apps/cluster-orch/src/components/organism/clusterDetail/DeploymentInstancesTable/DeploymentInstancesTable.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import {
2121
admStatusToText,
2222
admStatusToUIStatus,
2323
API_INTERVAL,
24+
deploymentClusterDetailRoute,
2425
Direction,
2526
getOrder,
2627
SharedStorage,
28+
useAppOrchNavigate,
2729
} from "@orch-ui/utils";
2830
import { Hyperlink, Text } from "@spark-design/react";
2931
import {
@@ -32,7 +34,7 @@ import {
3234
TextSize,
3335
} from "@spark-design/tokens";
3436
import { useState } from "react";
35-
import { useNavigate, useSearchParams } from "react-router-dom";
37+
import { useSearchParams } from "react-router-dom";
3638
import "./DeploymentInstancesTable.scss";
3739

3840
const dataCy = "deploymentInstancesTable";
@@ -44,7 +46,7 @@ const DeploymentInstancesTable = ({
4446
clusterId,
4547
}: DeploymentInstancesTableProps) => {
4648
const cy = { "data-cy": dataCy };
47-
const navigate = useNavigate();
49+
const navigate = useAppOrchNavigate();
4850
const [searchParams, setSearchParams] = useSearchParams();
4951
const [showErrorBanner, setShowErrorBanner] = useState<boolean>(false);
5052

@@ -57,13 +59,16 @@ const DeploymentInstancesTable = ({
5759
row: { original: adm.DeploymentInstancesClusterRead };
5860
}) => {
5961
const row = table.row.original;
60-
const route = `/applications/deployment/${row.deploymentUid}/cluster/${clusterId}`;
6162
return (
6263
<Hyperlink
6364
data-cy="link"
6465
variant={HyperlinkVariant.Primary}
6566
onPress={() => {
66-
if (row.deploymentUid) navigate(route);
67+
if (row.deploymentUid && clusterId)
68+
navigate(deploymentClusterDetailRoute, {
69+
deplId: row.deploymentUid,
70+
name: clusterId,
71+
});
6772
else setShowErrorBanner(true);
6873
}}
6974
visualType={HyperlinkType.Quiet}

apps/cluster-orch/src/components/pages/ClusterCreation/ClusterCreation.cy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ describe("<ClusterCreation/>", () => {
188188
.should("contain.text", "Cluster is created");
189189

190190
// check that the redux state has been cleared
191-
pom.getPath().should("eq", "/clusters");
191+
pom.getPath().should("contain", "/clusters");
192192
checkClearState(true);
193193
});
194194
it("should remove disable on button and show error when failed in creating cluster", () => {
@@ -220,7 +220,7 @@ describe("<ClusterCreation/>", () => {
220220

221221
pom.el.nextBtn.should("have.class", "spark-button-disabled");
222222
// run common tests checks
223-
pom.getPath().should("eq", "/clusters"); // should stay in same page
223+
pom.getPath().should("contain", "/clusters"); // should stay in same page
224224
// check that the redux state is unaffected and page is not changed
225225
checkClearState(true);
226226
});

apps/cluster-orch/src/components/pages/ClusterCreation/ClusterCreation.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
import { cm, mbApi } from "@orch-ui/apis";
77
import { Empty, MetadataPair } from "@orch-ui/components";
8-
import { InternalError, SharedStorage } from "@orch-ui/utils";
8+
import {
9+
clusterManagementRoute,
10+
InternalError,
11+
SharedStorage,
12+
useInfraNavigate,
13+
} from "@orch-ui/utils";
914
import {
1015
Button,
1116
ButtonGroup,
@@ -24,7 +29,6 @@ import {
2429
ToastVisibility,
2530
} from "@spark-design/tokens";
2631
import { useEffect, useRef, useState } from "react";
27-
import { useNavigate } from "react-router-dom";
2832
import { useAppDispatch, useAppSelector } from "../../../store/hooks";
2933
import {
3034
clearCluster,
@@ -51,7 +55,7 @@ const ClusterCreation = () => {
5155
const topRef = useRef<HTMLDivElement | null>(null);
5256
const projectName = SharedStorage.project?.name ?? "";
5357

54-
const navigate = useNavigate();
58+
const navigate = useInfraNavigate();
5559
const dispatch = useAppDispatch();
5660

5761
// TODO: reduce below redux states to single redux state
@@ -80,7 +84,7 @@ const ClusterCreation = () => {
8084
const [step, setStep] = useState<number>(0);
8185
useEffect(() => {
8286
if (step === 0 && !window.location.search) {
83-
navigate("?offset=0");
87+
navigate(clusterManagementRoute, undefined, "?offset=0");
8488
}
8589
}, [step]);
8690

@@ -227,7 +231,7 @@ const ClusterCreation = () => {
227231
clearData();
228232
topRef.current?.scrollIntoView({ behavior: "smooth", block: "start" });
229233
const timeoutId = setTimeout(() => {
230-
navigate("../clusters");
234+
navigate(clusterManagementRoute);
231235
clearInterval(timeoutId);
232236
}, 3000);
233237
};
@@ -260,7 +264,7 @@ const ClusterCreation = () => {
260264
clearData();
261265
// If metadata failed then move to cluster page as cluster is created
262266
const timeoutId = setTimeout(() => {
263-
navigate("../clusters");
267+
navigate(clusterManagementRoute);
264268
clearInterval(timeoutId);
265269
}, 3000);
266270
}
@@ -378,7 +382,7 @@ const ClusterCreation = () => {
378382
variant={ButtonVariant.Secondary}
379383
onPress={() => {
380384
clearData();
381-
navigate("../clusters");
385+
navigate(clusterManagementRoute);
382386
}}
383387
>
384388
Cancel

0 commit comments

Comments
 (0)