Skip to content

Commit dc692b5

Browse files
Update routing flow for creating accelerator/hardware profile on custom notebook image table (#3688)
* Update routing flow for creating accelerator/hardware profile on custom notebook image table * Update frontend/src/pages/hardwareProfiles/manage/ManageHardwareProfileFooter.tsx * Update frontend/src/pages/acceleratorProfiles/screens/manage/ManageAcceleratorProfileFooter.tsx * Apply suggestions from code review * Update frontend/src/pages/acceleratorProfiles/screens/manage/ManageAcceleratorProfileFooter.tsx --------- Co-authored-by: Gage Krumbach <[email protected]>
1 parent 92dceb0 commit dc692b5

File tree

10 files changed

+92
-18
lines changed

10 files changed

+92
-18
lines changed

frontend/src/app/AppRoutes.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const CustomServingRuntimeRoutes = React.lazy(
5757
);
5858
const GroupSettingsPage = React.lazy(() => import('../pages/groupSettings/GroupSettings'));
5959
const LearningCenterPage = React.lazy(() => import('../pages/learningCenter/LearningCenter'));
60-
const BYONImagesPage = React.lazy(() => import('../pages/BYONImages/BYONImages'));
60+
const BYONImageRoutes = React.lazy(() => import('../pages/BYONImages/BYONImageRoutes'));
6161
const NotFound = React.lazy(() => import('../pages/NotFound'));
6262

6363
const DependencyMissingPage = React.lazy(
@@ -135,7 +135,7 @@ const AppRoutes: React.FC = () => {
135135

136136
{isAdmin && (
137137
<>
138-
<Route path="/notebookImages" element={<BYONImagesPage />} />
138+
<Route path="/notebookImages/*" element={<BYONImageRoutes />} />
139139
<Route path="/clusterSettings" element={<ClusterSettingsPage />} />
140140
<Route path="/acceleratorProfiles/*" element={<AcceleratorProfileRoutes />} />
141141
<Route path="/hardwareProfiles/*" element={<HardwareProfileRoutes />} />

frontend/src/pages/BYONImages/BYONImageAccelerators.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const BYONImageAccelerators: React.FC<BYONImageAcceleratorsProps> = ({
7070
variant="outline"
7171
render={({ className, content }) => (
7272
<Link
73-
to={`/acceleratorProfiles/create?${new URLSearchParams({
73+
to={`/notebookImages/acceleratorProfile/create?${new URLSearchParams({
7474
identifiers: image.recommendedAcceleratorIdentifiers.join(','),
7575
}).toString()}`}
7676
className={className}

frontend/src/pages/BYONImages/BYONImageHardwareProfiles.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const BYONImageHardwareProfiles: React.FC<BYONImageHardwareProfilesProps> = ({
7070
variant="outline"
7171
render={({ className, content }) => (
7272
<Link
73-
to={`/hardwareProfiles/create?${new URLSearchParams({
73+
to={`/notebookImages/hardwareProfile/create?${new URLSearchParams({
7474
identifiers: image.recommendedAcceleratorIdentifiers.join(','),
7575
}).toString()}`}
7676
className={className}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import { Navigate, Route, Routes } from 'react-router-dom';
3+
import ManageAcceleratorProfile from '~/pages/acceleratorProfiles/screens/manage/ManageAcceleratorProfile';
4+
import BYONImages from '~/pages/BYONImages/BYONImages';
5+
import ManageHardwareProfile from '~/pages/hardwareProfiles/manage/ManageHardwareProfile';
6+
7+
const BYONImageRoutes: React.FC = () => (
8+
<Routes>
9+
<Route path="/" element={<BYONImages />} />
10+
<Route
11+
path="/hardwareProfile/create"
12+
element={
13+
<ManageHardwareProfile homepageTitle="Notebook images" contextPath="/notebookImages" />
14+
}
15+
/>
16+
<Route
17+
path="/acceleratorProfile/create"
18+
element={
19+
<ManageAcceleratorProfile homepageTitle="Notebook images" contextPath="/notebookImages" />
20+
}
21+
/>
22+
<Route path="*" element={<Navigate to="." />} />
23+
</Routes>
24+
);
25+
26+
export default BYONImageRoutes;

frontend/src/pages/acceleratorProfiles/screens/manage/ManageAcceleratorProfile.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@ import { ManageAcceleratorProfileDetailsSection } from './ManageAcceleratorProfi
1818

1919
type ManageAcceleratorProfileProps = {
2020
existingAcceleratorProfile?: AcceleratorProfileKind;
21+
contextPath?: string;
22+
homepageTitle?: string;
2123
};
2224

2325
const ManageAcceleratorProfile: React.FC<ManageAcceleratorProfileProps> = ({
2426
existingAcceleratorProfile,
27+
contextPath = '/acceleratorProfiles',
28+
homepageTitle = 'Accelerator profiles',
2529
}) => {
26-
const [state, setState] = useGenericObjectState<AcceleratorProfileKind['spec']>({
30+
const [state, setState] = useGenericObjectState<AcceleratorProfileFormData>({
2731
displayName: '',
2832
identifier: '',
2933
enabled: true,
3034
tolerations: [],
35+
name: '',
3136
});
3237
const { data: profileNameDesc, onDataChange: setProfileNameDesc } =
3338
useK8sNameDescriptionFieldData({
@@ -71,9 +76,7 @@ const ManageAcceleratorProfile: React.FC<ManageAcceleratorProfileProps> = ({
7176
}
7277
breadcrumb={
7378
<Breadcrumb>
74-
<BreadcrumbItem
75-
render={() => <Link to="/acceleratorProfiles">Accelerator profiles</Link>}
76-
/>
79+
<BreadcrumbItem render={() => <Link to={contextPath}>{homepageTitle}</Link>} />
7780
<BreadcrumbItem>
7881
{existingAcceleratorProfile ? 'Edit' : 'Create'} accelerator profile
7982
</BreadcrumbItem>
@@ -118,6 +121,7 @@ const ManageAcceleratorProfile: React.FC<ManageAcceleratorProfileProps> = ({
118121
state={formState}
119122
existingAcceleratorProfile={existingAcceleratorProfile}
120123
validFormData={validFormData}
124+
redirectPath={contextPath}
121125
/>
122126
</PageSection>
123127
</ApplicationsPage>

frontend/src/pages/acceleratorProfiles/screens/manage/ManageAcceleratorProfileDetailsSection.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import React from 'react';
33
import { OutlinedQuestionCircleIcon } from '@patternfly/react-icons';
44
import { useSearchParams } from 'react-router-dom';
55
import { UpdateObjectAtPropAndValue } from '~/pages/projects/types';
6-
import { AcceleratorProfileKind } from '~/k8sTypes';
76
import DashboardPopupIconButton from '~/concepts/dashboard/DashboardPopupIconButton';
87
import { AcceleratorProfileFormData } from './types';
98
import { IdentifierSelectField } from './IdentifierSelectField';
109

1110
type ManageAcceleratorProfileDetailsSectionProps = {
1211
state: AcceleratorProfileFormData;
13-
setState: UpdateObjectAtPropAndValue<AcceleratorProfileKind['spec']>;
12+
setState: UpdateObjectAtPropAndValue<AcceleratorProfileFormData>;
1413
};
1514

1615
export const ManageAcceleratorProfileDetailsSection: React.FC<

frontend/src/pages/acceleratorProfiles/screens/manage/ManageAcceleratorProfileFooter.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,47 @@ import {
1414
updateAcceleratorProfile,
1515
} from '~/services/acceleratorProfileService';
1616
import { AcceleratorProfileFormData } from '~/pages/acceleratorProfiles/screens/manage/types';
17+
import useNotification from '~/utilities/useNotification';
1718

1819
type ManageAcceleratorProfileFooterProps = {
1920
state: AcceleratorProfileFormData;
2021
existingAcceleratorProfile?: AcceleratorProfileKind;
2122
validFormData: boolean;
23+
redirectPath: string;
2224
};
2325

2426
export const ManageAcceleratorProfileFooter: React.FC<ManageAcceleratorProfileFooterProps> = ({
2527
state,
2628
existingAcceleratorProfile,
2729
validFormData,
30+
redirectPath,
2831
}) => {
2932
const [errorMessage, setErrorMessage] = React.useState<string>('');
3033
const [isLoading, setIsLoading] = React.useState<boolean>(false);
3134
const navigate = useNavigate();
35+
const notification = useNotification();
3236

3337
const onCreateAcceleratorProfile = async () => {
3438
setIsLoading(true);
3539
createAcceleratorProfile(state)
3640
.then((res) => {
3741
if (res.success) {
38-
navigate(`/acceleratorProfiles`);
42+
if (redirectPath !== '/acceleratorProfiles') {
43+
notification.success(
44+
'Accelerator profile has been created.',
45+
<Stack hasGutter>
46+
<StackItem>
47+
A new accelerator profile <strong>{state.displayName}</strong> has been created.
48+
</StackItem>
49+
<StackItem>
50+
<Button isInline variant="link" onClick={() => navigate(`/acceleratorProfiles`)}>
51+
View profile details
52+
</Button>
53+
</StackItem>
54+
</Stack>,
55+
);
56+
}
57+
navigate(redirectPath);
3958
} else {
4059
setErrorMessage(res.error || 'Could not create accelerator profile');
4160
}
@@ -54,7 +73,7 @@ export const ManageAcceleratorProfileFooter: React.FC<ManageAcceleratorProfileFo
5473
updateAcceleratorProfile(existingAcceleratorProfile.metadata.name, state)
5574
.then((res) => {
5675
if (res.success) {
57-
navigate(`/acceleratorProfiles`);
76+
navigate(redirectPath);
5877
} else {
5978
setErrorMessage(res.error || 'Could not update accelerator profile');
6079
}
@@ -103,7 +122,7 @@ export const ManageAcceleratorProfileFooter: React.FC<ManageAcceleratorProfileFo
103122
<Button
104123
variant="link"
105124
id="cancel-button"
106-
onClick={() => navigate(`/acceleratorProfiles`)}
125+
onClick={() => navigate(redirectPath)}
107126
isDisabled={isLoading}
108127
>
109128
Cancel

frontend/src/pages/acceleratorProfiles/screens/manage/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export type ManageAcceleratorProfileSectionTitlesType = {
99
[key in ManageAcceleratorProfileSectionID]: string;
1010
};
1111

12-
export type AcceleratorProfileFormData = { name?: string } & AcceleratorProfileKind['spec'];
12+
export type AcceleratorProfileFormData = { name: string } & AcceleratorProfileKind['spec'];

frontend/src/pages/hardwareProfiles/manage/ManageHardwareProfile.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ import { HardwareProfileFormData, ManageHardwareProfileSectionID } from './types
2121
type ManageHardwareProfileProps = {
2222
existingHardwareProfile?: HardwareProfileKind;
2323
duplicatedHardwareProfile?: HardwareProfileKind;
24+
contextPath?: string;
25+
homepageTitle?: string;
2426
};
2527

2628
const ManageHardwareProfile: React.FC<ManageHardwareProfileProps> = ({
2729
existingHardwareProfile,
2830
duplicatedHardwareProfile,
31+
contextPath = '/hardwareProfiles',
32+
homepageTitle = 'Hardware profiles',
2933
}) => {
3034
const [state, setState] = useGenericObjectState<HardwareProfileKind['spec']>(
3135
DEFAULT_HARDWARE_PROFILE_SPEC,
@@ -87,7 +91,7 @@ const ManageHardwareProfile: React.FC<ManageHardwareProfileProps> = ({
8791
}
8892
breadcrumb={
8993
<Breadcrumb>
90-
<BreadcrumbItem render={() => <Link to="/hardwareProfiles">Hardware profiles</Link>} />
94+
<BreadcrumbItem render={() => <Link to={contextPath}>{homepageTitle}</Link>} />
9195
<BreadcrumbItem isActive>
9296
{existingHardwareProfile ? 'Edit' : duplicatedHardwareProfile ? 'Duplicate' : 'Create'}{' '}
9397
hardware profile
@@ -133,6 +137,7 @@ const ManageHardwareProfile: React.FC<ManageHardwareProfileProps> = ({
133137
state={formState}
134138
existingHardwareProfile={existingHardwareProfile}
135139
validFormData={validFormData}
140+
redirectPath={contextPath}
136141
/>
137142
</PageSection>
138143
</ApplicationsPage>

frontend/src/pages/hardwareProfiles/manage/ManageHardwareProfileFooter.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,50 @@ import { HardwareProfileKind } from '~/k8sTypes';
1212
import { HardwareProfileFormData } from '~/pages/hardwareProfiles/manage/types';
1313
import { createHardwareProfile, updateHardwareProfile } from '~/api';
1414
import { useDashboardNamespace } from '~/redux/selectors';
15+
import useNotification from '~/utilities/useNotification';
1516

1617
type ManageHardwareProfileFooterProps = {
1718
state: HardwareProfileFormData;
1819
existingHardwareProfile?: HardwareProfileKind;
1920
validFormData: boolean;
21+
redirectPath: string;
2022
};
2123

2224
const ManageHardwareProfileFooter: React.FC<ManageHardwareProfileFooterProps> = ({
2325
state,
2426
existingHardwareProfile,
2527
validFormData,
28+
redirectPath,
2629
}) => {
2730
const [errorMessage, setErrorMessage] = React.useState<string>('');
2831
const [isLoading, setIsLoading] = React.useState<boolean>(false);
2932
const { dashboardNamespace } = useDashboardNamespace();
3033
const navigate = useNavigate();
34+
const notification = useNotification();
3135

3236
const { name, ...spec } = state;
3337

3438
const onCreateHardwareProfile = async () => {
3539
setIsLoading(true);
3640
createHardwareProfile(name, spec, dashboardNamespace)
37-
.then(() => navigate('/hardwareProfiles'))
41+
.then(() => {
42+
if (redirectPath !== '/hardwareProfiles') {
43+
notification.success(
44+
'Hardware profile has been created.',
45+
<Stack hasGutter>
46+
<StackItem>
47+
A new hardware profile <strong>{state.displayName}</strong> has been created.
48+
</StackItem>
49+
<StackItem>
50+
<Button isInline variant="link" onClick={() => navigate(`/hardwareProfiles`)}>
51+
View profile details
52+
</Button>
53+
</StackItem>
54+
</Stack>,
55+
);
56+
}
57+
navigate(redirectPath);
58+
})
3859
.catch((err) => {
3960
setErrorMessage(err.message);
4061
})
@@ -47,7 +68,7 @@ const ManageHardwareProfileFooter: React.FC<ManageHardwareProfileFooterProps> =
4768
if (existingHardwareProfile) {
4869
setIsLoading(true);
4970
updateHardwareProfile(spec, existingHardwareProfile, dashboardNamespace)
50-
.then(() => navigate(`/hardwareProfiles`))
71+
.then(() => navigate(redirectPath))
5172
.catch((err) => {
5273
setErrorMessage(err.message);
5374
})
@@ -88,7 +109,7 @@ const ManageHardwareProfileFooter: React.FC<ManageHardwareProfileFooterProps> =
88109
<Button
89110
variant="link"
90111
id="cancel-button"
91-
onClick={() => navigate(`/hardwareProfiles`)}
112+
onClick={() => navigate(redirectPath)}
92113
isDisabled={isLoading}
93114
>
94115
Cancel

0 commit comments

Comments
 (0)