Skip to content

Commit 97662a7

Browse files
committed
reworking context and usages
1 parent 788f5e7 commit 97662a7

File tree

7 files changed

+65
-29
lines changed

7 files changed

+65
-29
lines changed

frontend/packages/kserve/src/deployments.ts

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

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

frontend/packages/modelServing/extensions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ const extensions: (
5858
title: 'Model deployments',
5959
href: '/modelServing',
6060
section: 'models',
61-
path: '/modelServing/*',
61+
path: '/modelServing/:namespace?/*',
6262
},
6363
},
6464
{
6565
type: 'app.route',
6666
properties: {
67-
path: '/modelServing/*',
67+
path: '/modelServing/:namespace?/*',
6868
component: () => import('./src/GlobalModelsPage'),
6969
},
7070
flags: {
Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
11
import React from 'react';
2+
import { ProjectsContext } from '@odh-dashboard/internal/concepts/projects/ProjectsContext';
3+
import { useParams } from 'react-router-dom';
24
import GlobalDeploymentsView from './components/global/GlobalDeploymentsView';
35
import { ModelDeploymentsProvider } from './concepts/ModelDeploymentsContext';
4-
import { ProjectPlatformContext, ProjectPlatformProvider } from './concepts/ProjectPlatformContext';
6+
import {
7+
ModelServingPlatformContext,
8+
ModelServingPlatformProvider,
9+
} from './concepts/ModelServingPlatformContext';
10+
import ModelServingProjectSelection from './components/global/ModelServingProjectSelection';
511

6-
const WithDeploymentsData: React.FC = () => {
7-
const { availablePlatforms, allProjects } = React.useContext(ProjectPlatformContext);
12+
const GlobalModelsPage: React.FC = () => (
13+
<ModelServingPlatformProvider>
14+
<GlobalModelsPageCoreLoader />
15+
</ModelServingPlatformProvider>
16+
);
817

18+
const GlobalModelsPageCoreLoader: React.FC = () => {
19+
const { availablePlatforms, availablePlatformsLoaded } = React.useContext(
20+
ModelServingPlatformContext,
21+
);
22+
const { namespace } = useParams();
23+
const { projects } = React.useContext(ProjectsContext);
24+
const selectedProject = namespace
25+
? projects.find((project) => project.metadata.name === namespace)
26+
: null;
27+
const projectsToShow = selectedProject ? [selectedProject] : projects;
28+
const selector = (
29+
<ModelServingProjectSelection getRedirectPath={(ns: string) => `/modelServing/${ns}`} />
30+
);
31+
if (!availablePlatformsLoaded) {
32+
return <div>Loading...globalmodelspage</div>;
33+
}
34+
if (projects.length === 0) {
35+
return <div>No projects found</div>;
36+
}
937
return (
10-
<ModelDeploymentsProvider modelServingPlatform={availablePlatforms} projects={allProjects}>
11-
<GlobalDeploymentsView />
38+
<ModelDeploymentsProvider
39+
key={namespace || 'all-projects'}
40+
modelServingPlatform={availablePlatforms}
41+
projects={projectsToShow}
42+
>
43+
<GlobalDeploymentsView headerContent={selector} />
1244
</ModelDeploymentsProvider>
1345
);
1446
};
1547

16-
const GlobalModelsPage: React.FC = () => (
17-
<ProjectPlatformProvider>
18-
<WithDeploymentsData />
19-
</ProjectPlatformProvider>
20-
);
21-
2248
export default GlobalModelsPage;

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ import ApplicationsPage from '@odh-dashboard/internal/pages/ApplicationsPage';
33
import { ProjectObjectType } from '@odh-dashboard/internal/concepts/design/utils';
44
import TitleWithIcon from '@odh-dashboard/internal/concepts/design/TitleWithIcon';
55
import { Bullseye, Spinner } from '@patternfly/react-core';
6-
import ProjectSelectorNavigator from '@odh-dashboard/internal/concepts/projects/ProjectSelectorNavigator';
7-
import { useResolvedExtensions } from '@odh-dashboard/plugin-core';
86
import { ProjectsContext } from '@odh-dashboard/internal/concepts/projects/ProjectsContext';
97
import { GlobalNoModelsView } from './GlobalNoModelsView';
108
import GlobalDeploymentsTable from './GlobalDeploymentsTable';
119
import { ModelDeploymentsContext } from '../../concepts/ModelDeploymentsContext';
12-
import { isModelServingPlatformExtension } from '../../../extension-points';
1310

14-
const GlobalDeploymentsView: React.FC = () => {
11+
const GlobalDeploymentsView: React.FC<{
12+
headerContent: React.ReactNode;
13+
}> = ({ headerContent }) => {
1514
const { deployments, loaded: deploymentsLoaded } = React.useContext(ModelDeploymentsContext);
16-
const [platformsLoaded] = useResolvedExtensions(isModelServingPlatformExtension);
1715
const { preferredProject: currentProject } = React.useContext(ProjectsContext);
1816
const hasDeployments = React.useMemo(() => {
1917
if (!deployments) {
@@ -26,7 +24,7 @@ const GlobalDeploymentsView: React.FC = () => {
2624
(deployment) => deployment.model.metadata.namespace === currentProject.metadata.name,
2725
);
2826
}, [deployments, currentProject]);
29-
const isLoading = !deploymentsLoaded || !platformsLoaded;
27+
const isLoading = !deploymentsLoaded;
3028

3129
return (
3230
<ApplicationsPage
@@ -37,14 +35,7 @@ const GlobalDeploymentsView: React.FC = () => {
3735
title={
3836
<TitleWithIcon title="Model deployments" objectType={ProjectObjectType.deployedModels} />
3937
}
40-
headerContent={
41-
<ProjectSelectorNavigator
42-
invalidDropdownPlaceholder="All projects"
43-
selectAllProjects
44-
showTitle
45-
getRedirectPath={(namespace: string) => `/modelServing/${namespace}`}
46-
/>
47-
}
38+
headerContent={headerContent}
4839
>
4940
{isLoading ? (
5041
<Bullseye>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
import ProjectSelectorNavigator from '@odh-dashboard/internal/concepts/projects/ProjectSelectorNavigator';
3+
4+
type ModelServingProjectSelectionProps = {
5+
getRedirectPath: (namespace: string) => string;
6+
};
7+
8+
const ModelServingProjectSelection: React.FC<ModelServingProjectSelectionProps> = ({
9+
getRedirectPath,
10+
}) => (
11+
<ProjectSelectorNavigator
12+
getRedirectPath={getRedirectPath}
13+
invalidDropdownPlaceholder="All projects"
14+
selectAllProjects
15+
showTitle
16+
/>
17+
);
18+
19+
export default ModelServingProjectSelection;

frontend/packages/modelServing/src/components/projectDetails/ModelsProjectDetailsView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useProjectServingPlatform } from '../../concepts/useProjectServingPlatf
1212
import DeploymentsTable from '../deployments/DeploymentsTable';
1313
import { ModelDeploymentsContext } from '../../concepts/ModelDeploymentsContext';
1414
import { DeployButton } from '../deploy/DeployButton';
15-
import { ModelServingPlatformContext } from '../../concepts/ProjectPlatformContext';
15+
import { ModelServingPlatformContext } from '../../concepts/ModelServingPlatformContext';
1616

1717
const ModelsProjectDetailsView: React.FC<{
1818
project: ProjectKind;

frontend/packages/modelServing/src/concepts/ProjectPlatformContext.tsx renamed to frontend/packages/modelServing/src/concepts/ModelServingPlatformContext.tsx

File renamed without changes.

0 commit comments

Comments
 (0)