@@ -33,7 +33,6 @@ import {
33
33
GenericFilterEmptyState ,
34
34
getSelectPickerOptionByValue ,
35
35
Icon ,
36
- noop ,
37
36
numberComparatorBySortOrder ,
38
37
OptionType ,
39
38
PaginationEnum ,
@@ -55,6 +54,7 @@ import { importComponentFromFELibrary } from '@Components/common'
55
54
import { URLS } from '@Config/routes'
56
55
import CreateCluster from '@Pages/GlobalConfigurations/ClustersAndEnvironments/CreateCluster/CreateCluster.component'
57
56
import { CreateClusterTypeEnum } from '@Pages/GlobalConfigurations/ClustersAndEnvironments/CreateCluster/types'
57
+ import { UpgradeToEnterpriseDialog } from '@Pages/Shared/UpgradeToEnterprise'
58
58
59
59
import { getClusterList , getEnvironmentList } from './cluster.service'
60
60
import {
@@ -84,8 +84,9 @@ const PodSpreadModal = importComponentFromFELibrary('PodSpreadModal', null, 'fun
84
84
const HibernationRulesModal = importComponentFromFELibrary ( 'HibernationRulesModal' , null , 'function' )
85
85
86
86
const ClusterList = ( ) => {
87
- const { isSuperAdmin } = useMainContext ( )
87
+ const { isSuperAdmin, licenseData } = useMainContext ( )
88
88
const isK8sClient = window . _env_ . K8S_CLIENT
89
+ const isFreemium = licenseData ?. isFreemium ?? false
89
90
90
91
const { push } = useHistory ( )
91
92
const { search } = useLocation ( )
@@ -121,6 +122,7 @@ const ClusterList = () => {
121
122
)
122
123
123
124
const [ showUnmappedEnvs , setShowUnmappedEnvs ] = useState ( false )
125
+ const [ showUpgradeToEnterprise , setShowUpgradeToEnterprise ] = useState ( false )
124
126
125
127
const clusterIdVsEnvMap : Record < number , Environment [ ] > = useMemo (
126
128
( ) =>
@@ -244,6 +246,8 @@ const ClusterList = () => {
244
246
245
247
const isEnvironmentsView = selectedTab === ClusterEnvTabs . ENVIRONMENTS
246
248
const isClusterEnvListLoading = clusterListLoading || envListLoading
249
+ const isClusterAdditionAllowed =
250
+ ! isFreemium || clusterListResult ?. length < licenseData ?. moduleLimits . maxAllowedClusters
247
251
248
252
// Early return for non super admin users
249
253
if ( ! isK8sClient && ! isSuperAdmin ) {
@@ -338,15 +342,76 @@ const ClusterList = () => {
338
342
)
339
343
}
340
344
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
+
341
403
if ( clusterListResult && ! clusterListResult . length ) {
342
404
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
+ </ >
350
415
)
351
416
}
352
417
@@ -394,23 +459,7 @@ const ClusterList = () => {
394
459
keyboardShortcut = "/"
395
460
/>
396
461
{ 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 ( ) }
414
463
{ isEnvironmentsView && (
415
464
< ActionMenu
416
465
id = "additional-options-action-menu"
@@ -451,13 +500,9 @@ const ClusterList = () => {
451
500
{ /* Body */ }
452
501
{ renderList ( ) }
453
502
{ /* Modals and Routes */ }
503
+ < UpgradeToEnterpriseDialog open = { showUpgradeToEnterprise } handleClose = { handleCloseUpgradeDialog } />
454
504
{ ManageCategories && < ManageCategories /> }
455
- < Route path = { URLS . GLOBAL_CONFIG_CREATE_CLUSTER } >
456
- < CreateCluster
457
- handleReloadClusterList = { reloadClusterList }
458
- handleRedirectOnModalClose = { handleRedirectToClusterList }
459
- />
460
- </ Route >
505
+ { renderAddClusterRoute ( ) }
461
506
< Route path = { COMMON_URLS . GLOBAL_CONFIG_EDIT_CLUSTER } >
462
507
< EditCluster
463
508
clusterList = { clusterListResult ?? [ ] }
0 commit comments