Skip to content

Commit 90a7fae

Browse files
committed
updated context to work with global
1 parent 8e6deee commit 90a7fae

File tree

5 files changed

+54
-37
lines changed

5 files changed

+54
-37
lines changed

frontend/packages/kserve/src/api.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,42 @@ import {
1515
import { CustomWatchK8sResult } from '@odh-dashboard/internal/types';
1616

1717
export const useWatchInferenceServices = (
18-
project: ProjectKind,
18+
project?: ProjectKind,
1919
opts?: K8sAPIOptions,
2020
): CustomWatchK8sResult<InferenceServiceKind[]> =>
2121
useK8sWatchResourceList<InferenceServiceKind[]>(
2222
{
2323
isList: true,
2424
groupVersionKind: groupVersionKind(InferenceServiceModel),
25-
namespace: project.metadata.name,
25+
namespace: project?.metadata.name,
2626
},
2727
InferenceServiceModel,
2828
opts,
2929
);
3030

3131
export const useWatchServingRuntimes = (
32-
project: ProjectKind,
32+
project?: ProjectKind,
3333
opts?: K8sAPIOptions,
3434
): CustomWatchK8sResult<ServingRuntimeKind[]> =>
3535
useK8sWatchResourceList<ServingRuntimeKind[]>(
3636
{
3737
isList: true,
3838
groupVersionKind: groupVersionKind(ServingRuntimeModel),
39-
namespace: project.metadata.name,
39+
namespace: project?.metadata.name,
4040
},
4141
ServingRuntimeModel,
4242
opts,
4343
);
4444

4545
export const useWatchDeploymentPods = (
46-
project: ProjectKind,
46+
project?: ProjectKind,
4747
opts?: K8sAPIOptions,
4848
): CustomWatchK8sResult<PodKind[]> =>
4949
useK8sWatchResourceList<PodKind[]>(
5050
{
5151
isList: true,
5252
groupVersionKind: groupVersionKind(PodModel),
53-
namespace: project.metadata.name,
53+
namespace: project?.metadata.name,
5454
selector: {
5555
matchExpressions: [
5656
{

frontend/packages/kserve/src/deployments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const isKServeDeployment = (deployment: Deployment): deployment is KServe
1616
deployment.modelServingPlatformId === KSERVE_ID;
1717

1818
export const useWatchDeployments = (
19-
project: ProjectKind,
19+
project?: ProjectKind,
2020
opts?: K8sAPIOptions,
2121
): [KServeDeployment[] | undefined, boolean, Error | undefined] => {
2222
const [inferenceServices, inferenceServiceLoaded, inferenceServiceError] =

frontend/packages/modelServing/extension-points/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type ModelServingPlatformExtension<D extends Deployment = Deployment> = E
4040
deployments: {
4141
watch: CodeRef<
4242
(
43-
project: ProjectKind,
43+
project?: ProjectKind,
4444
opts?: K8sAPIOptions,
4545
) => [D[] | undefined, boolean, Error | undefined]
4646
>;

frontend/packages/modelServing/src/components/global/GlobalDeploymentsView.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import TitleWithIcon from '@odh-dashboard/internal/concepts/design/TitleWithIcon
55
import { Bullseye, Spinner } from '@patternfly/react-core';
66
import ProjectSelectorNavigator from '@odh-dashboard/internal/concepts/projects/ProjectSelectorNavigator';
77
import { useResolvedExtensions } from '@odh-dashboard/plugin-core';
8-
import { useParams } from 'react-router-dom';
9-
import { byName, ProjectsContext } from '@odh-dashboard/internal/concepts/projects/ProjectsContext';
8+
import { ProjectsContext } from '@odh-dashboard/internal/concepts/projects/ProjectsContext';
109
import { GlobalNoModelsView } from './GlobalNoModelsView';
1110
import GlobalDeploymentsTable from './GlobalDeploymentsTable';
1211
import { ModelDeploymentsContext } from '../../concepts/ModelDeploymentsContext';
@@ -15,20 +14,25 @@ import { isModelServingPlatformExtension } from '../../../extension-points';
1514
const GlobalDeploymentsView: React.FC = () => {
1615
const { deployments, loaded: deploymentsLoaded } = React.useContext(ModelDeploymentsContext);
1716
const [platformsLoaded] = useResolvedExtensions(isModelServingPlatformExtension);
18-
const { '*': projectNameFromURL } = useParams();
19-
const { projects } = React.useContext(ProjectsContext);
20-
const currentProject = React.useMemo(
21-
() => (projectNameFromURL ? projects.find(byName(projectNameFromURL)) : undefined),
22-
[projectNameFromURL, projects],
23-
);
24-
const hasDeployments = deployments ? deployments.length > 0 : false;
17+
const { preferredProject: currentProject } = React.useContext(ProjectsContext);
18+
const hasDeployments = React.useMemo(() => {
19+
if (!deployments) {
20+
return false;
21+
}
22+
if (!currentProject) {
23+
return deployments.length > 0;
24+
}
25+
return deployments.some(
26+
(deployment) => deployment.model.metadata.namespace === currentProject.metadata.name,
27+
);
28+
}, [deployments, currentProject]);
2529
const isLoading = !deploymentsLoaded || !platformsLoaded;
2630

2731
return (
2832
<ApplicationsPage
29-
loaded
33+
loaded={!isLoading}
3034
empty={!hasDeployments}
31-
emptyStatePage={<GlobalNoModelsView project={currentProject} />}
35+
emptyStatePage={<GlobalNoModelsView project={currentProject ?? undefined} />}
3236
description="Manage and view the health and performance of your deployed models."
3337
title={
3438
<TitleWithIcon title="Model deployments" objectType={ProjectObjectType.deployedModels} />

frontend/packages/modelServing/src/concepts/ModelDeploymentsContext.tsx

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ type ModelDeploymentsContextType = {
1111

1212
type WatcherProps = {
1313
platform: ModelServingPlatform;
14-
project: ProjectKind;
14+
project?: ProjectKind; // *** CHANGED: optional project (undefined means global) ***
1515
onUpdate: (key: string, result: [Deployment[] | undefined, boolean, Error | undefined]) => void;
1616
};
1717

1818
const DeploymentWatcherComponent: React.FC<WatcherProps> = ({ platform, project, onUpdate }) => {
1919
const watchDeployments = platform.properties.deployments.watch;
20-
const result = watchDeployments(project);
21-
const key = `${platform.properties.id}-${project.metadata.name}`;
20+
// *** CHANGED: pass undefined if project is undefined (global watch) ***
21+
const result = project ? watchDeployments(project) : watchDeployments(undefined);
22+
// call with no args for global watch
23+
24+
// key includes project or "global" for uniqueness
25+
const key = project
26+
? `${platform.properties.id}-${project.metadata.name}`
27+
: `${platform.properties.id}-global`;
2228

2329
React.useEffect(() => {
2430
onUpdate(key, result);
@@ -56,22 +62,26 @@ export const ModelDeploymentsProvider: React.FC<ModelDeploymentsProviderProps> =
5662
[modelServingPlatform],
5763
);
5864

59-
const projectList = React.useMemo(
60-
() => (projects ? (Array.isArray(projects) ? projects : [projects]) : []),
61-
[projects],
62-
);
65+
// *** CHANGED: Determine if we're watching for a single project or global ***
66+
// If multiple projects or undefined, treat as global watch (no project param)
67+
const singleProject = projects && !Array.isArray(projects) ? projects : undefined;
6368

64-
const watchList = React.useMemo(
65-
() =>
66-
platforms.flatMap((platform) =>
67-
projectList.map((project) => ({
68-
key: `${platform.properties.id}-${project.metadata.name}`,
69-
platform,
70-
project,
71-
})),
72-
),
73-
[platforms, projectList],
74-
);
69+
// *** CHANGED: only create watchers for platforms with either one project or global (no multiple watchers) ***
70+
const watchList = React.useMemo(() => {
71+
if (singleProject) {
72+
return platforms.map((platform) => ({
73+
key: `${platform.properties.id}-${singleProject.metadata.name}`,
74+
platform,
75+
project: singleProject,
76+
}));
77+
}
78+
// Global watch, project undefined means watch all deployments globally per platform
79+
return platforms.map((platform) => ({
80+
key: `${platform.properties.id}-global`,
81+
platform,
82+
project: undefined,
83+
}));
84+
}, [platforms, singleProject]);
7585

7686
const [results, setResults] = React.useState<
7787
Record<string, [Deployment[] | undefined, boolean, Error | undefined]>
@@ -92,9 +102,12 @@ export const ModelDeploymentsProvider: React.FC<ModelDeploymentsProviderProps> =
92102

93103
const contextValue = React.useMemo<ModelDeploymentsContextType>(() => {
94104
const allResults = Object.values(results);
105+
// Flatten deployments from all watches
95106
const deployments = allResults.flatMap(([d]) => d || []);
107+
// loaded only if all watchers report loaded
96108
const isLoaded =
97109
watchList.length === Object.keys(results).length && allResults.every(([, l]) => l);
110+
// first error found or undefined
98111
const error = allResults.find(([, , e]) => e)?.[2];
99112
return { deployments, loaded: isLoaded, error };
100113
}, [results, watchList]);

0 commit comments

Comments
 (0)