Skip to content

Commit 2560c8b

Browse files
committed
cleaning
1 parent 91681c7 commit 2560c8b

File tree

7 files changed

+61
-35
lines changed

7 files changed

+61
-35
lines changed

frontend/src/pages/modelServing/screens/projects/DeployPrefilledModelModal.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { getKServeTemplates } from '#~/pages/modelServing/customServingRuntimes/
2525
import { isRedHatRegistryUri } from '#~/pages/modelRegistry/screens/utils';
2626
import useServingConnections from '#~/pages/projects/screens/detail/connections/useServingConnections';
2727
import { isOciModelUri } from '#~/pages/modelServing/utils';
28-
import { ProjectDetailsContext } from '#~/pages/projects/ProjectDetailsContext';
2928
import { ModelDeployPrefillInfo } from './usePrefillModelDeployModal';
3029

3130
interface DeployPrefilledModelModalProps {
@@ -73,7 +72,6 @@ const DeployPrefilledModelModalContents: React.FC<
7372
loaded: templateDisablementLoaded,
7473
},
7574
} = React.useContext(ModelServingContext);
76-
const { pvcs } = React.useContext(ProjectDetailsContext);
7775
const servingContextLoaded = templatesLoaded && templateOrderLoaded && templateDisablementLoaded;
7876

7977
const servingPlatformStatuses = useServingPlatformStatuses();
@@ -181,7 +179,6 @@ const DeployPrefilledModelModalContents: React.FC<
181179
currentProject: selectedProject,
182180
connections,
183181
}}
184-
pvcs={pvcs.data}
185182
projectSection={projectSection}
186183
existingUriOption={
187184
modelDeployPrefillInfo.modelArtifactUri &&

frontend/src/pages/modelServing/screens/projects/InferenceServiceModal/ConnectionSection.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ export const ConnectionSection: React.FC<Props> = ({
307307
if (!loaded) {
308308
return <Skeleton />;
309309
}
310-
//console.log(platform);
311310
return (
312311
<>
313312
{pvcServingEnabled && platform === ServingRuntimePlatform.SINGLE && (

frontend/src/pages/modelServing/screens/projects/KServeSection/KServeInferenceServiceTable.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const KServeInferenceServiceTable: React.FC = () => {
4242
},
4343
serverSecrets: { refresh: refreshServerSecrets },
4444
filterTokens,
45-
pvcs: { data: pvcs },
4645
} = React.useContext(ProjectDetailsContext);
4746
const columns = getKServeInferenceServiceColumns();
4847

@@ -97,7 +96,6 @@ const KServeInferenceServiceTable: React.FC = () => {
9796
editKserveResources.inferenceService.spec.predictor.model?.runtime,
9897
),
9998
}}
100-
pvcs={pvcs}
10199
onClose={(submit: boolean) => {
102100
setEditKServeResources(undefined);
103101
if (submit) {

frontend/src/pages/modelServing/screens/projects/ModelServingPlatform.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ const ModelServingPlatform: React.FC = () => {
8080
servingRuntimeTemplateOrder: { data: templateOrder },
8181
servingRuntimeTemplateDisablement: { data: templateDisablement },
8282
connections: { data: connections },
83-
pvcs: { data: pvcs },
8483
serverSecrets: { refresh: refreshTokens },
8584
inferenceServices: {
8685
data: { items: inferenceServices },
@@ -211,7 +210,6 @@ const ModelServingPlatform: React.FC = () => {
211210
return (
212211
<ManageKServeModal
213212
projectContext={{ currentProject, connections }}
214-
pvcs={pvcs}
215213
servingRuntimeTemplates={templatesEnabled.filter((template) =>
216214
getTemplateEnabledForPlatform(template, ServingRuntimePlatform.SINGLE),
217215
)}

frontend/src/pages/modelServing/screens/projects/kServeModal/ManageKServeModal.tsx

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
InferenceServiceKind,
2525
AccessReviewResourceAttributes,
2626
SecretKind,
27-
PersistentVolumeClaimKind,
2827
} from '#~/k8sTypes';
2928
import {
3029
getKServeContainerArgs,
@@ -69,9 +68,9 @@ import usePrefillModelDeployModal, {
6968
import { useKServeDeploymentMode } from '#~/pages/modelServing/useKServeDeploymentMode';
7069
import { SERVING_RUNTIME_SCOPE } from '#~/pages/modelServing/screens/const';
7170
import { useModelDeploymentNotification } from '#~/pages/modelServing/screens/projects/useModelDeploymentNotification';
72-
import { getDashboardPvcs } from '#~/api/k8s/pvcs';
7371
import useServingPlatformStatuses from '#~/pages/modelServing/useServingPlatformStatuses';
7472
import { ServingRuntimePlatform } from '#~/types.ts';
73+
import usePvcs from '#~/pages/modelServing/usePvcs';
7574
import KServeAutoscalerReplicaSection from './KServeAutoscalerReplicaSection';
7675
import EnvironmentVariablesSection from './EnvironmentVariablesSection';
7776
import ServingRuntimeArgsSection from './ServingRuntimeArgsSection';
@@ -91,7 +90,6 @@ type ManageKServeModalProps = {
9190
shouldFormHidden?: boolean;
9291
projectSection?: React.ReactNode;
9392
existingUriOption?: string;
94-
pvcs?: PersistentVolumeClaimKind[] | [];
9593
} & EitherOrNone<
9694
{
9795
projectContext?: {
@@ -111,7 +109,6 @@ type ManageKServeModalProps = {
111109
const ManageKServeModal: React.FC<ManageKServeModalProps> = ({
112110
onClose,
113111
servingRuntimeTemplates,
114-
pvcs,
115112
projectContext,
116113
editInfo,
117114
projectSection,
@@ -161,33 +158,15 @@ const ManageKServeModal: React.FC<ManageKServeModalProps> = ({
161158
const isAuthAvailable =
162159
useIsAreaAvailable(SupportedArea.K_SERVE_AUTH).status ||
163160
createDataInferenceService.isKServeRawDeployment;
164-
165161
const currentProjectName = projectContext?.currentProject.metadata.name;
166162
const namespace = currentProjectName || createDataInferenceService.project;
167163
const currentProject = projectContext?.currentProject;
168164
const platformStatuses = useServingPlatformStatuses();
169165
const platform = getPlatform(platformStatuses, currentProject, editInfo);
170166

171-
const projectTemplates = useTemplates(namespace);
172-
const [fallbackPvcs, setFallbackPvcs] = React.useState<PersistentVolumeClaimKind[]>([]);
167+
const utilPvcs = usePvcs(namespace);
173168

174-
React.useEffect(() => {
175-
let isCurrent = true;
176-
getDashboardPvcs(namespace)
177-
.then((data) => {
178-
if (isCurrent) {
179-
setFallbackPvcs(data);
180-
}
181-
})
182-
.catch(() => {
183-
if (isCurrent) {
184-
setFallbackPvcs([]);
185-
}
186-
});
187-
return () => {
188-
isCurrent = false;
189-
};
190-
}, [namespace]);
169+
const projectTemplates = useTemplates(namespace);
191170

192171
const customServingRuntimesEnabled = useCustomServingRuntimesEnabled();
193172
const [allowCreate] = useAccessReview({
@@ -522,7 +501,7 @@ const ManageKServeModal: React.FC<ManageKServeModalProps> = ({
522501
setConnection={setConnection}
523502
setIsConnectionValid={setIsConnectionValid}
524503
connections={connections}
525-
pvcs={pvcs?.length && pvcs.length > 0 ? pvcs : fallbackPvcs}
504+
pvcs={utilPvcs.data}
526505
platform={platform}
527506
/>
528507
</FormSection>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as React from 'react';
2+
import { PersistentVolumeClaimKind } from '#~/k8sTypes';
3+
import { FetchStateObject } from '#~/utilities/useFetch';
4+
import { getDashboardPvcs } from '#~/api/k8s/pvcs';
5+
6+
const DEFAULT_LIST_FETCH_STATE: FetchStateObject<PersistentVolumeClaimKind[]> = {
7+
data: [],
8+
loaded: false,
9+
error: undefined,
10+
refresh: () => Promise.resolve([]),
11+
};
12+
13+
export default function usePvcs(namespace: string): FetchStateObject<PersistentVolumeClaimKind[]> {
14+
const [state, setState] =
15+
React.useState<FetchStateObject<PersistentVolumeClaimKind[]>>(DEFAULT_LIST_FETCH_STATE);
16+
17+
const fetchPvcs = React.useCallback((): Promise<PersistentVolumeClaimKind[]> => {
18+
setState((prev) => ({ ...prev, loaded: false, error: undefined }));
19+
return getDashboardPvcs(namespace)
20+
.then((pvcs) => {
21+
setState({
22+
data: pvcs,
23+
loaded: true,
24+
error: undefined,
25+
refresh: fetchPvcs,
26+
});
27+
return pvcs;
28+
})
29+
.catch((error) => {
30+
setState({
31+
data: [],
32+
loaded: true,
33+
error,
34+
refresh: fetchPvcs,
35+
});
36+
return [];
37+
});
38+
}, [namespace]);
39+
40+
React.useEffect(() => {
41+
if (namespace) {
42+
fetchPvcs();
43+
} else {
44+
setState(DEFAULT_LIST_FETCH_STATE);
45+
}
46+
// Only re-fetch when namespace changes
47+
// eslint-disable-next-line react-hooks/exhaustive-deps
48+
}, [namespace]);
49+
50+
return React.useMemo(
51+
() => ({
52+
...state,
53+
refresh: fetchPvcs,
54+
}),
55+
[state, fetchPvcs],
56+
);
57+
}

frontend/src/pages/projects/screens/detail/overview/serverModels/AddModelFooter.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const AddModelFooter: React.FC<AddModelFooterProps> = ({ selectedPlatform, isNIM
3636
serverSecrets: { refresh: refreshTokens },
3737
inferenceServices: { refresh: refreshInferenceServices },
3838
currentProject,
39-
pvcs,
4039
} = React.useContext(ProjectDetailsContext);
4140

4241
const templatesSorted = getSortedTemplates(templates, templateOrder);
@@ -107,7 +106,6 @@ const AddModelFooter: React.FC<AddModelFooterProps> = ({ selectedPlatform, isNIM
107106
{modalShown && !isProjectModelMesh && !isNIM ? (
108107
<ManageKServeModal
109108
projectContext={{ currentProject, connections }}
110-
pvcs={pvcs.data}
111109
servingRuntimeTemplates={templatesEnabled.filter((template) =>
112110
getTemplateEnabledForPlatform(template, ServingRuntimePlatform.SINGLE),
113111
)}

0 commit comments

Comments
 (0)