Skip to content

Commit f0b627d

Browse files
committed
Small bug fixes
1 parent a00a621 commit f0b627d

File tree

2 files changed

+99
-52
lines changed

2 files changed

+99
-52
lines changed

frontend/packages/modelServing/src/components/deploy/DeployButton.tsx

Lines changed: 90 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,113 @@
11
import React from 'react';
22
import { Button, Tooltip } from '@patternfly/react-core';
3-
import { ProjectDetailsContext } from '@odh-dashboard/internal/pages/projects/ProjectDetailsContext';
43
import { ServingRuntimePlatform } from '@odh-dashboard/internal/types';
54
import {
65
getSortedTemplates,
76
getTemplateEnabled,
87
getTemplateEnabledForPlatform,
98
} from '@odh-dashboard/internal/pages/modelServing/customServingRuntimes/utils';
10-
import { isProjectNIMSupported } from '@odh-dashboard/internal/pages/modelServing/screens/projects/nimUtils';
119
import ManageServingRuntimeModal from '@odh-dashboard/internal/pages/modelServing/screens/projects/ServingRuntimeModal/ManageServingRuntimeModal';
1210
import ManageKServeModal from '@odh-dashboard/internal/pages/modelServing/screens/projects/kServeModal/ManageKServeModal';
1311
import ManageNIMServingModal from '@odh-dashboard/internal/pages/modelServing/screens/projects/NIMServiceModal/ManageNIMServingModal';
12+
import { byName, ProjectsContext } from '@odh-dashboard/internal/concepts/projects/ProjectsContext';
13+
import { useParams } from 'react-router-dom';
14+
import { POLL_INTERVAL } from '@odh-dashboard/internal/utilities/const';
15+
import useInferenceServices from '@odh-dashboard/internal/pages/modelServing/useInferenceServices';
16+
import useServingRuntimes from '@odh-dashboard/internal/pages/modelServing/useServingRuntimes';
17+
import { useTemplates } from '@odh-dashboard/internal/api/k8s/templates';
18+
import { useDashboardNamespace } from '@odh-dashboard/internal/redux/selectors/index';
19+
import useTemplateOrder from '@odh-dashboard/internal/pages/modelServing/customServingRuntimes/useTemplateOrder';
20+
import useTemplateDisablement from '@odh-dashboard/internal/pages/modelServing/customServingRuntimes/useTemplateDisablement';
21+
import useConnections from '@odh-dashboard/internal/pages/projects/screens/detail/connections/useConnections';
22+
import useServingRuntimeSecrets from '@odh-dashboard/internal/pages/modelServing/screens/projects/useServingRuntimeSecrets';
23+
import { ProjectKind } from '@odh-dashboard/internal/k8sTypes';
24+
import { isProjectNIMSupported } from '@odh-dashboard/internal/pages/modelServing/screens/projects/nimUtils';
25+
import { ModelDeploymentsContext } from '../../concepts/ModelDeploymentsContext';
1426
import {
1527
useProjectServingPlatform,
1628
ModelServingPlatform,
1729
} from '../../concepts/useProjectServingPlatform';
30+
import { useAvailableClusterPlatforms } from '../../concepts/useAvailableClusterPlatforms';
31+
32+
const DeployButtonModal: React.FC<{
33+
platform: ServingRuntimePlatform;
34+
currentProject: ProjectKind;
35+
onClose: (submit: boolean) => void;
36+
}> = ({ platform, currentProject, onClose }) => {
37+
const { namespace } = useParams();
38+
const { dashboardNamespace } = useDashboardNamespace();
39+
const [servingRuntimeTemplates] = useTemplates(dashboardNamespace);
40+
const servingRuntimeTemplateOrder = useTemplateOrder(dashboardNamespace, undefined, {
41+
refreshRate: POLL_INTERVAL,
42+
});
43+
const servingRuntimeTemplateDisablement = useTemplateDisablement(dashboardNamespace, undefined, {
44+
refreshRate: POLL_INTERVAL,
45+
});
46+
const connections = useConnections(namespace);
47+
const templatesSorted = getSortedTemplates(
48+
servingRuntimeTemplates,
49+
servingRuntimeTemplateOrder.data,
50+
);
51+
const templatesEnabled = templatesSorted.filter((template) =>
52+
getTemplateEnabled(template, servingRuntimeTemplateDisablement.data),
53+
);
54+
55+
if (platform === ServingRuntimePlatform.MULTI) {
56+
return (
57+
<ManageServingRuntimeModal
58+
currentProject={currentProject}
59+
servingRuntimeTemplates={templatesEnabled.filter((t) =>
60+
getTemplateEnabledForPlatform(t, ServingRuntimePlatform.MULTI),
61+
)}
62+
onClose={onClose}
63+
/>
64+
);
65+
}
66+
67+
const isNIMSupported = isProjectNIMSupported(currentProject);
68+
if (isNIMSupported) {
69+
return <ManageNIMServingModal projectContext={{ currentProject }} onClose={onClose} />;
70+
}
71+
return (
72+
<ManageKServeModal
73+
projectContext={{ currentProject, connections: connections.data }}
74+
servingRuntimeTemplates={templatesEnabled.filter((t) =>
75+
getTemplateEnabledForPlatform(t, ServingRuntimePlatform.SINGLE),
76+
)}
77+
onClose={onClose}
78+
/>
79+
);
80+
};
1881

1982
export const DeployButton: React.FC<{
2083
platform?: ModelServingPlatform;
2184
variant?: 'primary' | 'secondary';
22-
isDisabled?: boolean;
23-
}> = ({ platform, variant = 'primary', isDisabled }) => {
85+
}> = ({ platform, variant = 'primary' }) => {
2486
const [modalShown, setModalShown] = React.useState<boolean>(false);
2587
const [platformSelected, setPlatformSelected] = React.useState<ServingRuntimePlatform>();
26-
27-
const {
28-
servingRuntimes: { refresh: refreshServingRuntime },
29-
servingRuntimeTemplates: [templates],
30-
servingRuntimeTemplateOrder: { data: templateOrder },
31-
servingRuntimeTemplateDisablement: { data: templateDisablement },
32-
connections: { data: connections },
33-
serverSecrets: { refresh: refreshTokens },
34-
inferenceServices: { refresh: refreshInferenceServices },
35-
currentProject,
36-
} = React.useContext(ProjectDetailsContext);
37-
38-
const { activePlatform, projectPlatform } = useProjectServingPlatform(currentProject);
39-
40-
const templatesSorted = getSortedTemplates(templates, templateOrder);
41-
const templatesEnabled = templatesSorted.filter((template) =>
42-
getTemplateEnabled(template, templateDisablement),
43-
);
44-
45-
const isKServeNIMEnabled = isProjectNIMSupported(currentProject);
88+
const { namespace } = useParams();
89+
const { projects } = React.useContext(ProjectsContext);
90+
const match = namespace ? projects.find(byName(namespace)) ?? null : null;
91+
const { clusterPlatforms } = useAvailableClusterPlatforms();
92+
const { activePlatform, projectPlatform } = useProjectServingPlatform(match, clusterPlatforms);
93+
const inferenceServices = useInferenceServices(namespace, undefined, undefined, undefined, {
94+
refreshRate: POLL_INTERVAL,
95+
});
96+
const inferenceServiceRefresh = inferenceServices.refresh;
97+
const servingRuntimes = useServingRuntimes(namespace, undefined, { refreshRate: POLL_INTERVAL });
98+
const servingRuntimeRefresh = servingRuntimes.refresh;
99+
const serverSecrets = useServingRuntimeSecrets(namespace, { refreshRate: POLL_INTERVAL });
100+
const { projects: modelProjects } = React.useContext(ModelDeploymentsContext);
101+
const { namespace: modelNamespace } = useParams<{ namespace: string }>();
102+
const currentProject = modelProjects?.find(byName(modelNamespace));
46103

47104
const onSubmit = (submit: boolean) => {
48105
setModalShown(false);
49106
setPlatformSelected(undefined);
50107
if (submit) {
51-
refreshServingRuntime();
52-
refreshInferenceServices();
53-
setTimeout(refreshTokens, 500);
108+
servingRuntimeRefresh();
109+
inferenceServiceRefresh();
110+
setTimeout(serverSecrets.refresh, 500);
54111
}
55112
};
56113

@@ -63,7 +120,7 @@ export const DeployButton: React.FC<{
63120
);
64121
} else {
65122
const currentPlatform = activePlatform || projectPlatform;
66-
if (currentPlatform) {
123+
if (currentProject && currentPlatform) {
67124
setPlatformSelected(
68125
currentPlatform.properties.id === 'modelmesh'
69126
? ServingRuntimePlatform.MULTI
@@ -79,39 +136,23 @@ export const DeployButton: React.FC<{
79136
variant={variant}
80137
data-testid="deploy-button"
81138
onClick={handleDeployClick}
82-
isAriaDisabled={isDisabled}
139+
isAriaDisabled={!currentProject}
83140
>
84141
Deploy Model
85142
</Button>
86143
);
87144

88-
const hasPlatform = platform || activePlatform || projectPlatform;
89-
90-
if (!hasPlatform) {
145+
if (!currentProject) {
91146
return <Tooltip content="To deploy a model, select a project.">{deployButton}</Tooltip>;
92147
}
93148

94149
return (
95150
<>
96151
{deployButton}
97-
{modalShown && platformSelected === ServingRuntimePlatform.MULTI ? (
98-
<ManageServingRuntimeModal
152+
{modalShown && platformSelected ? (
153+
<DeployButtonModal
154+
platform={platformSelected}
99155
currentProject={currentProject}
100-
servingRuntimeTemplates={templatesEnabled.filter((template) =>
101-
getTemplateEnabledForPlatform(template, ServingRuntimePlatform.MULTI),
102-
)}
103-
onClose={onSubmit}
104-
/>
105-
) : null}
106-
{modalShown && platformSelected === ServingRuntimePlatform.SINGLE && isKServeNIMEnabled ? (
107-
<ManageNIMServingModal projectContext={{ currentProject }} onClose={onSubmit} />
108-
) : null}
109-
{modalShown && platformSelected === ServingRuntimePlatform.SINGLE && !isKServeNIMEnabled ? (
110-
<ManageKServeModal
111-
projectContext={{ currentProject, connections }}
112-
servingRuntimeTemplates={templatesEnabled.filter((template) =>
113-
getTemplateEnabledForPlatform(template, ServingRuntimePlatform.SINGLE),
114-
)}
115156
onClose={onSubmit}
116157
/>
117158
) : null}

frontend/packages/modelServing/src/concepts/useProjectServingPlatform.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const getMultiProjectServingPlatforms = (
5757
};
5858

5959
export const useProjectServingPlatform = (
60-
project: ProjectKind,
60+
project: ProjectKind | null,
6161
platforms?: ModelServingPlatform[],
6262
): {
6363
activePlatform?: ModelServingPlatform | null; // This includes preselecting a platform if there is only one
@@ -69,14 +69,14 @@ export const useProjectServingPlatform = (
6969
} => {
7070
const [tmpProjectPlatform, setTmpProjectPlatform] = React.useState<
7171
ModelServingPlatform | null | undefined
72-
>(project.metadata.name && platforms ? getProjectServingPlatform(project, platforms) : undefined);
72+
>(project && platforms ? getProjectServingPlatform(project, platforms) : undefined);
7373
const [projectPlatformError, setProjectPlatformError] = React.useState<string | null>(null);
7474
const [newProjectPlatformLoading, setNewProjectPlatformLoading] = React.useState<
7575
ModelServingPlatform | null | undefined
7676
>();
7777

7878
React.useEffect(() => {
79-
if (!project.metadata.name || !platforms) {
79+
if (!project || !platforms) {
8080
return;
8181
}
8282
const p = getProjectServingPlatform(project, platforms);
@@ -88,6 +88,9 @@ export const useProjectServingPlatform = (
8888

8989
const setProjectPlatform = React.useCallback(
9090
(platformToEnable: ModelServingPlatform) => {
91+
if (!project) {
92+
return;
93+
}
9194
setNewProjectPlatformLoading(platformToEnable);
9295
setProjectPlatformError(null);
9396

@@ -103,6 +106,9 @@ export const useProjectServingPlatform = (
103106
);
104107

105108
const resetProjectPlatform = React.useCallback(() => {
109+
if (!project) {
110+
return;
111+
}
106112
setNewProjectPlatformLoading(null);
107113
setProjectPlatformError(null);
108114

0 commit comments

Comments
 (0)