|
| 1 | +import { Link } from 'react-router-dom' |
| 2 | + |
| 3 | +import { |
| 4 | + ALL_NAMESPACE_OPTION, |
| 5 | + BulkSelectionIdentifiersType, |
| 6 | + Button, |
| 7 | + ButtonComponentType, |
| 8 | + ButtonStyleType, |
| 9 | + ButtonVariantType, |
| 10 | + ClusterDetail, |
| 11 | + ClusterStatusType, |
| 12 | + ComponentSizeType, |
| 13 | + Icon, |
| 14 | + Tooltip, |
| 15 | + URLS, |
| 16 | + useBulkSelection, |
| 17 | +} from '@devtron-labs/devtron-fe-common-lib' |
| 18 | + |
| 19 | +import { ReactComponent as Error } from '@Icons/ic-error-exclamation.svg' |
| 20 | +import { importComponentFromFELibrary } from '@Components/common' |
| 21 | +import { K8S_EMPTY_GROUP, SIDEBAR_KEYS } from '@Components/ResourceBrowser/Constants' |
| 22 | +import { AppDetailsTabs } from '@Components/v2/appDetails/appDetails.store' |
| 23 | + |
| 24 | +import { ClusterMapInitialStatus } from '../ClusterMapInitialStatus' |
| 25 | +import { CLUSTER_PROD_TYPE } from '../constants' |
| 26 | +import { ClusterListRowTypes } from './types' |
| 27 | + |
| 28 | +const CompareClusterButton = importComponentFromFELibrary('CompareClusterButton', null, 'function') |
| 29 | +const ClusterStatusCell = importComponentFromFELibrary('ClusterStatus', null, 'function') |
| 30 | +const KubeConfigButton = importComponentFromFELibrary('KubeConfigButton', null, 'function') |
| 31 | +const KubeConfigRowCheckbox = importComponentFromFELibrary('KubeConfigRowCheckbox', null, 'function') |
| 32 | + |
| 33 | +const ClusterListRow = ({ |
| 34 | + clusterData, |
| 35 | + clusterListLoader, |
| 36 | + onChangeShowKubeConfigModal, |
| 37 | + setSelectedClusterName, |
| 38 | +}: ClusterListRowTypes) => { |
| 39 | + const { selectedIdentifiers: bulkSelectionState, getSelectedIdentifiersCount } = |
| 40 | + useBulkSelection<BulkSelectionIdentifiersType<ClusterDetail>>() |
| 41 | + const errorCount = clusterData.nodeErrors ? Object.keys(clusterData.nodeErrors).length : 0 |
| 42 | + const identifierCount = getSelectedIdentifiersCount() |
| 43 | + |
| 44 | + const hideDataOnLoad = (value) => { |
| 45 | + if (clusterListLoader) { |
| 46 | + return null |
| 47 | + } |
| 48 | + return value |
| 49 | + } |
| 50 | + |
| 51 | + const renderClusterStatus = ({ errorInNodeListing, status }: ClusterDetail) => { |
| 52 | + if (ClusterStatusCell && status) { |
| 53 | + return <ClusterStatusCell status={status} errorInNodeListing={errorInNodeListing} /> |
| 54 | + } |
| 55 | + |
| 56 | + return <ClusterMapInitialStatus errorInNodeListing={errorInNodeListing} /> |
| 57 | + } |
| 58 | + const isIdentifierSelected = !!bulkSelectionState[clusterData.name] |
| 59 | + |
| 60 | + // TODO: @Elessar1802 will be replacing all terminal url with new utils |
| 61 | + |
| 62 | + return ( |
| 63 | + <div |
| 64 | + key={`cluster-${clusterData.id}`} |
| 65 | + className={`cluster-list-row fw-4 cn-9 fs-13 dc__border-bottom-n1 py-12 px-20 hover-class dc__visible-hover dc__visible-hover--parent |
| 66 | + ${clusterListLoader ? 'show-shimmer-loading dc__align-items-center' : ''}`} |
| 67 | + > |
| 68 | + {KubeConfigRowCheckbox && <KubeConfigRowCheckbox clusterData={clusterData} />} |
| 69 | + {!isIdentifierSelected && identifierCount === 0 && ( |
| 70 | + <div className="dc__visible-hover--hide-child flex left"> |
| 71 | + <Icon name="ic-bg-cluster" color={null} size={24} /> |
| 72 | + </div> |
| 73 | + )} |
| 74 | + <div data-testid={`cluster-row-${clusterData.name}`} className="flex left dc__overflow-hidden"> |
| 75 | + <Link |
| 76 | + className="dc__ellipsis-right dc__no-decor lh-24" |
| 77 | + to={`${URLS.RESOURCE_BROWSER}/${clusterData.id}/${ALL_NAMESPACE_OPTION.value}/${SIDEBAR_KEYS.nodeGVK.Kind.toLowerCase()}/${K8S_EMPTY_GROUP}`} |
| 78 | + > |
| 79 | + {clusterData.name} |
| 80 | + </Link> |
| 81 | + {/* NOTE: visible-hover plays with display prop; therefore need to set display: flex on a new div */} |
| 82 | + <div className="cursor dc__visible-hover--child ml-8"> |
| 83 | + <div className="flexbox dc__align-items-center dc__gap-4"> |
| 84 | + {!!clusterData.nodeCount && !clusterListLoader && ( |
| 85 | + <Button |
| 86 | + icon={<Icon name="ic-terminal-fill" color={null} size={16} />} |
| 87 | + ariaLabel="View terminal" |
| 88 | + size={ComponentSizeType.xs} |
| 89 | + dataTestId={`cluster-terminal-${clusterData.name}`} |
| 90 | + style={ButtonStyleType.neutral} |
| 91 | + variant={ButtonVariantType.borderLess} |
| 92 | + component={ButtonComponentType.link} |
| 93 | + linkProps={{ |
| 94 | + to: `${URLS.RESOURCE_BROWSER}/${clusterData.id}/${ALL_NAMESPACE_OPTION.value}/${AppDetailsTabs.terminal}/${K8S_EMPTY_GROUP}`, |
| 95 | + }} |
| 96 | + /> |
| 97 | + )} |
| 98 | + {CompareClusterButton && clusterData.status !== ClusterStatusType.CONNECTION_FAILED && ( |
| 99 | + <CompareClusterButton sourceClusterId={clusterData.id} isIconButton /> |
| 100 | + )} |
| 101 | + {KubeConfigButton && ( |
| 102 | + <KubeConfigButton |
| 103 | + onChangeShowKubeConfigModal={onChangeShowKubeConfigModal} |
| 104 | + clusterName={clusterData.name} |
| 105 | + setSelectedClusterName={setSelectedClusterName} |
| 106 | + /> |
| 107 | + )} |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + {renderClusterStatus(clusterData)} |
| 112 | + <div className="child-shimmer-loading"> |
| 113 | + {hideDataOnLoad(clusterData.isProd ? CLUSTER_PROD_TYPE.PRODUCTION : CLUSTER_PROD_TYPE.NON_PRODUCTION)} |
| 114 | + </div> |
| 115 | + <div className="child-shimmer-loading">{hideDataOnLoad(clusterData.nodeCount)}</div> |
| 116 | + <div className="child-shimmer-loading"> |
| 117 | + {errorCount > 0 && |
| 118 | + hideDataOnLoad( |
| 119 | + <> |
| 120 | + <Error className="mr-3 icon-dim-16 dc__position-rel top-3" /> |
| 121 | + <span className="cr-5">{errorCount}</span> |
| 122 | + </>, |
| 123 | + )} |
| 124 | + </div> |
| 125 | + <div className="flexbox child-shimmer-loading"> |
| 126 | + {hideDataOnLoad( |
| 127 | + <Tooltip content={clusterData.serverVersion}> |
| 128 | + <span className="dc__truncate">{clusterData.serverVersion}</span> |
| 129 | + </Tooltip>, |
| 130 | + )} |
| 131 | + </div> |
| 132 | + <div className="child-shimmer-loading">{hideDataOnLoad(clusterData.cpu?.capacity)}</div> |
| 133 | + <div className="child-shimmer-loading">{hideDataOnLoad(clusterData.memory?.capacity)}</div> |
| 134 | + </div> |
| 135 | + ) |
| 136 | +} |
| 137 | + |
| 138 | +export default ClusterListRow |
0 commit comments