Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 8x 8x 11x 22x 22x 22x 22x 22x 22x 22x 1x 1x 1x 1x 1x 22x 1x 1x 1x 22x 5x 2x 2x 11x 22x 22x 22x 22x 22x 22x 2x 2x 2x 2x 2x 2x 22x 22x 22x 22x 22x 1x 1x 1x 11x | /* * Copyright 2021 Harness Inc. All rights reserved. * Use of this source code is governed by the PolyForm Shield 1.0.0 license * that can be found in the licenses directory at the root of this repository, also available at * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt. */ import React, { useState } from 'react' import ReactTimeago from 'react-timeago' import { set } from 'lodash-es' import { useParams, useHistory } from 'react-router-dom' import { Button, Container, Text, Layout, Popover, Card, useToaster, useConfirmationDialog, Icon } from '@wings-software/uicore' import { Color } from '@harness/design-system' import { Menu, MenuItem, Classes, Position } from '@blueprintjs/core' import { useStrings } from 'framework/strings' import { useDeleteDelegateGroupByIdentifier, DelegateGroupDetails } from 'services/portal' import routes from '@common/RouteDefinitions' import { TagsViewer } from '@common/components/TagsViewer/TagsViewer' import { delegateTypeToIcon } from '@common/utils/delegateUtils' import RbacMenuItem from '@rbac/components/MenuItem/MenuItem' import { PermissionIdentifier } from '@rbac/interfaces/PermissionIdentifier' import { ResourceType } from '@rbac/interfaces/ResourceType' import { usePermission } from '@rbac/hooks/usePermission' import css from './DelegatesPage.module.scss' type delTroubleshoterProps = { delegate: DelegateGroupDetails setOpenTroubleshoter: (prop: { isConnected: boolean | undefined }) => void } const columnWidths = { icon: '80px', name: '25%', tags: '20%', instances: '20%', heartbeat: 'calc(15% - 40px)', status: 'calc(15% - 40px)', actions: '5%' } export const DelegateListingHeader = () => { const { getString } = useStrings() return ( <Layout.Horizontal className={css.delegateListHeader}> <div key="icon" style={{ width: columnWidths.icon }}></div> <div key="del-name" style={{ width: columnWidths.name }}> {getString('delegate.DelegateName')} </div> <div key="tags" style={{ width: columnWidths.tags }}> {getString('tagsLabel')} </div> <div key="instances" style={{ width: columnWidths.instances }}> {getString('instanceFieldOptions.instances')} </div> <div key="heartbeat" style={{ width: columnWidths.heartbeat }}> {getString('delegate.LastHeartBeat')} </div> <div key="status" style={{ width: columnWidths.status }}> {getString('connectivityStatus')} </div> <div key="actions" style={{ width: columnWidths.actions }} /> </Layout.Horizontal> ) } const RenderColumnMenu = ({ delegate, setOpenTroubleshoter }: delTroubleshoterProps) => { const { delegateGroupIdentifier, groupName, activelyConnected } = delegate const { getString } = useStrings() const [menuOpen, setMenuOpen] = useState(false) const { showSuccess, showError } = useToaster() const { accountId, orgIdentifier, projectIdentifier } = useParams<Record<string, string>>() const { mutate: forceDeleteDelegate } = useDeleteDelegateGroupByIdentifier({ queryParams: { accountId: accountId, orgId: orgIdentifier, projectId: projectIdentifier } }) const forceDeleteDialog = useConfirmationDialog({ contentText: `${getString('delegates.questionForceDeleteDelegate')} ${groupName}`, titleText: getString('delegate.deleteDelegate'), confirmButtonText: getString('delete'), cancelButtonText: getString('cancel'), onCloseDialog: async (isConfirmed: boolean) => { Eif (isConfirmed) { try { Eif (delegateGroupIdentifier) { const deleted = await forceDeleteDelegate(delegateGroupIdentifier) Iif (deleted) { showSuccess(getString('delegates.delegateDeleted', { name: groupName })) } } } catch (error) { showError(error.data?.responseMessages?.[0].message || error.message) } } } }) const handleForceDelete = (e: React.MouseEvent<HTMLElement, MouseEvent>): void => { e.stopPropagation() setMenuOpen(false) forceDeleteDialog.openDialog() } return ( <Layout.Horizontal className={css.itemActionContainer}> <Popover isOpen={menuOpen} onInteraction={nextOpenState => { setMenuOpen(nextOpenState) }} className={Classes.DARK} position={Position.RIGHT_TOP} > <Button minimal icon="Options" onClick={e => { e.stopPropagation() setMenuOpen(true) }} /> <Menu style={{ minWidth: 'unset' }}> <RbacMenuItem permission={{ resourceScope: { accountIdentifier: accountId, orgIdentifier, projectIdentifier }, resource: { resourceType: ResourceType.DELEGATE, resourceIdentifier: delegateGroupIdentifier }, permission: PermissionIdentifier.VIEW_DELEGATE }} icon="edit" text={getString('details')} /> <RbacMenuItem permission={{ resourceScope: { accountIdentifier: accountId, orgIdentifier, projectIdentifier }, resource: { resourceType: ResourceType.DELEGATE, resourceIdentifier: delegateGroupIdentifier }, permission: PermissionIdentifier.DELETE_DELEGATE }} icon="trash" text={getString('delete')} onClick={handleForceDelete} /> {delegate.delegateType === 'KUBERNETES' && ( <MenuItem text={getString('delegates.openTroubleshooter')} onClick={(e: React.MouseEvent) => { e.stopPropagation() setOpenTroubleshoter({ isConnected: activelyConnected }) }} icon="book" /> )} </Menu> </Popover> </Layout.Horizontal> ) } export const DelegateListingItem = ({ delegate, setOpenTroubleshoter }: delTroubleshoterProps) => { const { getString } = useStrings() const [isExtended, setIsExtended] = useState(false) const { accountId, orgIdentifier, projectIdentifier, module } = useParams<Record<string, string>>() const history = useHistory() const [canAccessDelegate] = usePermission( { resourceScope: { accountIdentifier: accountId, orgIdentifier, projectIdentifier }, resource: { resourceType: ResourceType.DELEGATE }, permissions: [PermissionIdentifier.VIEW_DELEGATE] }, [] ) const onDelegateClick = (): void => { Eif (canAccessDelegate) { const params = { accountId, delegateIdentifier: delegate.delegateGroupIdentifier as string } Iif (orgIdentifier) { set(params, 'orgIdentifier', orgIdentifier) } Iif (projectIdentifier) { set(params, 'projectIdentifier', projectIdentifier) } Iif (module) { set(params, 'module', module) } history.push(routes.toDelegatesDetails(params)) } } const isConnected = delegate.activelyConnected const text = isConnected ? getString('connected') : getString('delegate.notConnected') const color: Color = isConnected ? Color.GREEN_600 : Color.GREY_400 const allSelectors = Object.keys(delegate.groupImplicitSelectors || {}).concat(delegate.groupCustomSelectors || []) return ( <Card elevation={2} interactive={true} onClick={onDelegateClick} className={css.delegateItemContainer}> <Layout.Horizontal className={css.delegateItemSubcontainer}> <div style={{ width: columnWidths.icon }} className={css.delegateItemIcon}> <Icon name={isExtended ? 'chevron-down' : 'chevron-right'} className={css.expandIcon} size={20} onClick={e => { e.preventDefault() e.stopPropagation() setIsExtended(!isExtended) }} /> <Text icon={delegateTypeToIcon(delegate.delegateType as string)} iconProps={{ size: 24 }} /> </div> <Layout.Horizontal width={columnWidths.name}> <Layout.Vertical> <Layout.Horizontal spacing="small" data-testid={delegate.groupName}> <Text color={Color.BLACK}>{delegate.groupName}</Text> </Layout.Horizontal> </Layout.Vertical> </Layout.Horizontal> <Container className={css.connectivity} width={columnWidths.tags}> {delegate.groupImplicitSelectors && ( <> <TagsViewer key="tags" tags={allSelectors.slice(0, 3)} /> <span key="hidenTags">{allSelectors.length > 3 ? '+' + (allSelectors.length - 3) : ''}</span> </> )} </Container> <Layout.Horizontal width={columnWidths.instances} className={css.instancesColumn}> {delegate.delegateInstanceDetails?.length || 0} </Layout.Horizontal> <Layout.Horizontal width={columnWidths.heartbeat}> {delegate.lastHeartBeat ? <ReactTimeago date={delegate.lastHeartBeat} live /> : getString('na')} </Layout.Horizontal> <Layout.Vertical width={columnWidths.status}> <Text icon="full-circle" iconProps={{ size: 6, color, padding: 'small' }}> {text} </Text> {!isConnected && delegate.delegateType === 'KUBERNETES' && ( <div className={css.troubleshootLink} onClick={e => { e.preventDefault() e.stopPropagation() setOpenTroubleshoter({ isConnected }) }} > {getString('delegates.troubleshootOption')} </div> )} </Layout.Vertical> <Layout.Vertical width={columnWidths.actions}> {RenderColumnMenu({ delegate, setOpenTroubleshoter })} </Layout.Vertical> </Layout.Horizontal> {isExtended && <Layout.Horizontal className={css.podDetailsSeparator}></Layout.Horizontal>} {isExtended && ( <Layout.Vertical className={`${css.instancesContainer} ${css.podDetailsContainer}`}> {!delegate.delegateInstanceDetails?.length && ( <Layout.Horizontal className={css.delegateItemSubcontainer}> <Layout.Horizontal style={{ width: columnWidths.icon }} /> <Layout.Horizontal width={columnWidths.name}> <Text color={Color.BLACK}>{getString('delegates.noInstances')}</Text> </Layout.Horizontal> <Container width={columnWidths.tags} /> <Container width={columnWidths.instances} /> <Layout.Horizontal width={columnWidths.heartbeat} /> <Layout.Vertical width={columnWidths.status} /> <Layout.Vertical width={columnWidths.actions} /> </Layout.Horizontal> )} {delegate.delegateInstanceDetails?.map((instanceDetails, index) => { const podStatusColor = instanceDetails.activelyConnected ? Color.GREEN_600 : Color.GREY_400 const statusText = instanceDetails.activelyConnected ? getString('connected') : getString('delegate.notConnected') return ( <Layout.Horizontal key={instanceDetails.hostName} width="100%" spacing={'small'}> <Layout.Horizontal style={{ width: columnWidths.icon }} /> <Layout.Horizontal width={columnWidths.name}> {index === 0 && <Text color={Color.BLACK}>{getString('instanceFieldOptions.instances')}</Text>} </Layout.Horizontal> <Container className={css.connectivity} width={columnWidths.tags} /> <Container width={columnWidths.instances} className={css.instancesColumn}> {instanceDetails.hostName} </Container> <Layout.Horizontal width={columnWidths.heartbeat}> {instanceDetails.lastHeartbeat ? ( <ReactTimeago date={instanceDetails.lastHeartbeat} live /> ) : ( getString('na') )} </Layout.Horizontal> <Layout.Vertical width={columnWidths.status}> <Text icon="full-circle" iconProps={{ size: 6, color: podStatusColor, padding: 'small' }}> {statusText} </Text> </Layout.Vertical> <Layout.Vertical width={columnWidths.actions} /> </Layout.Horizontal> ) })} </Layout.Vertical> )} </Card> ) } export default DelegateListingItem |