@@ -33,7 +33,6 @@ import {
3333 GenericFilterEmptyState ,
3434 getSelectPickerOptionByValue ,
3535 Icon ,
36- noop ,
3736 numberComparatorBySortOrder ,
3837 OptionType ,
3938 PaginationEnum ,
@@ -55,6 +54,7 @@ import { importComponentFromFELibrary } from '@Components/common'
5554import { URLS } from '@Config/routes'
5655import CreateCluster from '@Pages/GlobalConfigurations/ClustersAndEnvironments/CreateCluster/CreateCluster.component'
5756import { CreateClusterTypeEnum } from '@Pages/GlobalConfigurations/ClustersAndEnvironments/CreateCluster/types'
57+ import { UpgradeToEnterpriseDialog } from '@Pages/Shared/UpgradeToEnterprise'
5858
5959import { getClusterList , getEnvironmentList } from './cluster.service'
6060import {
@@ -84,8 +84,9 @@ const PodSpreadModal = importComponentFromFELibrary('PodSpreadModal', null, 'fun
8484const HibernationRulesModal = importComponentFromFELibrary ( 'HibernationRulesModal' , null , 'function' )
8585
8686const ClusterList = ( ) => {
87- const { isSuperAdmin } = useMainContext ( )
87+ const { isSuperAdmin, licenseData } = useMainContext ( )
8888 const isK8sClient = window . _env_ . K8S_CLIENT
89+ const isFreemium = licenseData ?. isFreemium ?? false
8990
9091 const { push } = useHistory ( )
9192 const { search } = useLocation ( )
@@ -121,6 +122,7 @@ const ClusterList = () => {
121122 )
122123
123124 const [ showUnmappedEnvs , setShowUnmappedEnvs ] = useState ( false )
125+ const [ showUpgradeToEnterprise , setShowUpgradeToEnterprise ] = useState ( false )
124126
125127 const clusterIdVsEnvMap : Record < number , Environment [ ] > = useMemo (
126128 ( ) =>
@@ -244,6 +246,8 @@ const ClusterList = () => {
244246
245247 const isEnvironmentsView = selectedTab === ClusterEnvTabs . ENVIRONMENTS
246248 const isClusterEnvListLoading = clusterListLoading || envListLoading
249+ const isClusterAdditionAllowed =
250+ ! isFreemium || clusterListResult ?. length < licenseData ?. moduleLimits . maxAllowedClusters
247251
248252 // Early return for non super admin users
249253 if ( ! isK8sClient && ! isSuperAdmin ) {
@@ -338,15 +342,76 @@ const ClusterList = () => {
338342 )
339343 }
340344
345+ const handleOpenUpgradeDialog = ( ) => {
346+ setShowUpgradeToEnterprise ( true )
347+ }
348+
349+ const handleCloseUpgradeDialog = ( ) => {
350+ setShowUpgradeToEnterprise ( false )
351+ }
352+
353+ const renderAddEnvButton = ( ) => (
354+ < Button
355+ dataTestId = "add-environment-button"
356+ linkProps = { {
357+ to : {
358+ pathname : `${ URLS . GLOBAL_CONFIG_CLUSTER } ${ URLS . CREATE_ENVIRONMENT } ` ,
359+ search,
360+ } ,
361+ } }
362+ component = { ButtonComponentType . link }
363+ startIcon = { < Icon name = "ic-add" color = { null } /> }
364+ size = { ComponentSizeType . medium }
365+ text = "Add Environment"
366+ />
367+ )
368+
369+ const renderAddClusterButton = ( ) => (
370+ < Button
371+ dataTestId = "add-cluster-button"
372+ component = { ButtonComponentType . link }
373+ startIcon = { < Icon name = "ic-link" color = { null } /> }
374+ size = { ComponentSizeType . medium }
375+ text = "Connect Cluster"
376+ { ...( isClusterAdditionAllowed
377+ ? {
378+ component : ButtonComponentType . link ,
379+ linkProps : {
380+ to : generatePath ( URLS . GLOBAL_CONFIG_CREATE_CLUSTER , {
381+ type : CreateClusterTypeEnum . CONNECT_CLUSTER ,
382+ } ) ,
383+ search,
384+ } ,
385+ }
386+ : {
387+ component : ButtonComponentType . button ,
388+ onClick : handleOpenUpgradeDialog ,
389+ } ) }
390+ />
391+ )
392+
393+ const renderAddClusterRoute = ( ) =>
394+ isClusterAdditionAllowed ? (
395+ < Route path = { URLS . GLOBAL_CONFIG_CREATE_CLUSTER } >
396+ < CreateCluster
397+ handleReloadClusterList = { reloadClusterList }
398+ handleRedirectOnModalClose = { handleRedirectToClusterList }
399+ />
400+ </ Route >
401+ ) : null
402+
341403 if ( clusterListResult && ! clusterListResult . length ) {
342404 return (
343- < GenericEmptyState
344- title = "Manage Clusters and Environments"
345- subTitle = "It looks like you haven't set up any Kubernetes clusters yet. Start by adding your first cluster and environment."
346- isButtonAvailable
347- renderButton = { noop }
348- image = { NoClusterImg }
349- />
405+ < >
406+ < GenericEmptyState
407+ title = "Manage Clusters and Environments"
408+ subTitle = "It looks like you haven't set up any Kubernetes clusters yet. Start by adding your first cluster and environment."
409+ isButtonAvailable
410+ renderButton = { renderAddClusterButton }
411+ image = { NoClusterImg }
412+ />
413+ { renderAddClusterRoute ( ) }
414+ </ >
350415 )
351416 }
352417
@@ -394,23 +459,7 @@ const ClusterList = () => {
394459 keyboardShortcut = "/"
395460 />
396461 { ManageCategoryButton && < ManageCategoryButton search = { search } /> }
397- < Button
398- dataTestId = { isEnvironmentsView ? 'add-environment-button' : 'add-cluster-button' }
399- linkProps = { {
400- to : {
401- pathname : isEnvironmentsView
402- ? `${ URLS . GLOBAL_CONFIG_CLUSTER } ${ URLS . CREATE_ENVIRONMENT } `
403- : generatePath ( URLS . GLOBAL_CONFIG_CREATE_CLUSTER , {
404- type : CreateClusterTypeEnum . CONNECT_CLUSTER ,
405- } ) ,
406- search,
407- } ,
408- } }
409- component = { ButtonComponentType . link }
410- startIcon = { < Icon name = { isEnvironmentsView ? 'ic-add' : 'ic-link' } color = { null } /> }
411- size = { ComponentSizeType . medium }
412- text = { isEnvironmentsView ? 'Add Environment' : 'Connect Cluster' }
413- />
462+ { isEnvironmentsView ? renderAddEnvButton ( ) : renderAddClusterButton ( ) }
414463 { isEnvironmentsView && (
415464 < ActionMenu
416465 id = "additional-options-action-menu"
@@ -451,13 +500,9 @@ const ClusterList = () => {
451500 { /* Body */ }
452501 { renderList ( ) }
453502 { /* Modals and Routes */ }
503+ < UpgradeToEnterpriseDialog open = { showUpgradeToEnterprise } handleClose = { handleCloseUpgradeDialog } />
454504 { ManageCategories && < ManageCategories /> }
455- < Route path = { URLS . GLOBAL_CONFIG_CREATE_CLUSTER } >
456- < CreateCluster
457- handleReloadClusterList = { reloadClusterList }
458- handleRedirectOnModalClose = { handleRedirectToClusterList }
459- />
460- </ Route >
505+ { renderAddClusterRoute ( ) }
461506 < Route path = { COMMON_URLS . GLOBAL_CONFIG_EDIT_CLUSTER } >
462507 < EditCluster
463508 clusterList = { clusterListResult ?? [ ] }
0 commit comments