11import React from 'react' ;
22import { Button , Tooltip } from '@patternfly/react-core' ;
3- import { ProjectDetailsContext } from '@odh-dashboard/internal/pages/projects/ProjectDetailsContext' ;
43import { ServingRuntimePlatform } from '@odh-dashboard/internal/types' ;
54import {
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' ;
119import ManageServingRuntimeModal from '@odh-dashboard/internal/pages/modelServing/screens/projects/ServingRuntimeModal/ManageServingRuntimeModal' ;
1210import ManageKServeModal from '@odh-dashboard/internal/pages/modelServing/screens/projects/kServeModal/ManageKServeModal' ;
1311import 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' ;
1426import {
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
1982export 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 }
0 commit comments