|
| 1 | +/* |
| 2 | + * Copyright (c) 2024. Devtron Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import ICCaretDown from '@Icons/ic-caret-down.svg?react' |
| 18 | +import ICStack from '@Icons/ic-stack.svg?react' |
| 19 | +import { getTimeDifference } from '@Shared/Helpers' |
| 20 | + |
| 21 | +import { TargetPlatformListTooltip } from '../TargetPlatforms' |
| 22 | +import { LogStageHeaderProps } from './types' |
| 23 | +import { getStageStatusIcon } from './utils' |
| 24 | + |
| 25 | +const LogStageHeader = ({ |
| 26 | + stage, |
| 27 | + isOpen, |
| 28 | + status, |
| 29 | + startTime, |
| 30 | + endTime, |
| 31 | + targetPlatforms, |
| 32 | + stageIndex, |
| 33 | + fullScreenView, |
| 34 | + handleStageClose, |
| 35 | + handleStageOpen, |
| 36 | + logsRendererRef, |
| 37 | + applySticky = true, |
| 38 | +}: LogStageHeaderProps) => { |
| 39 | + const handleAccordionToggle = () => { |
| 40 | + if (isOpen) { |
| 41 | + handleStageClose(stageIndex) |
| 42 | + } else { |
| 43 | + handleStageOpen(stageIndex) |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + const getFormattedTimeDifference = (): string => { |
| 48 | + const timeDifference = getTimeDifference({ startTime, endTime }) |
| 49 | + if (timeDifference === '0s') { |
| 50 | + return '< 1s' |
| 51 | + } |
| 52 | + return timeDifference |
| 53 | + } |
| 54 | + |
| 55 | + const getLogsRendererReference = () => logsRendererRef.current |
| 56 | + |
| 57 | + return ( |
| 58 | + <button |
| 59 | + className={`flexbox dc__transparent dc__content-space py-6 px-8 br-4 dc__align-items-center dc__select-text logs-renderer__stage-accordion w-100 ${ |
| 60 | + isOpen ? 'logs-renderer__stage-accordion--open-stage' : '' |
| 61 | + } ${applySticky ? `dc__position-sticky dc__zi-1 ${fullScreenView ? 'dc__top-44' : 'dc__top-80'}` : ''}`} |
| 62 | + type="button" |
| 63 | + role="tab" |
| 64 | + onClick={handleAccordionToggle} |
| 65 | + > |
| 66 | + <div className="flexbox dc__gap-8 dc__transparent dc__align-items-center"> |
| 67 | + <ICCaretDown |
| 68 | + className={`icon-dim-16 dc__no-shrink dc__transition--transform icon-stroke__white ${!isOpen ? 'dc__flip-n90 dc__opacity-0_5' : ''}`} |
| 69 | + /> |
| 70 | + |
| 71 | + <div className="flexbox dc__gap-12 dc__align-items-center"> |
| 72 | + {getStageStatusIcon(status)} |
| 73 | + |
| 74 | + <h3 className="m-0 text__white fs-13 fw-4 lh-20 dc__word-break">{stage}</h3> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + |
| 78 | + <div className="flexbox dc__gap-8 dc__align-items-center"> |
| 79 | + {!!targetPlatforms?.length && ( |
| 80 | + <> |
| 81 | + <TargetPlatformListTooltip |
| 82 | + targetPlatforms={targetPlatforms} |
| 83 | + appendTo={getLogsRendererReference} |
| 84 | + > |
| 85 | + <div className="flexbox dc__gap-4 dc__align-items-center"> |
| 86 | + <ICStack className="dc__no-shrink icon-stroke__white icon-dim-12" /> |
| 87 | + <span className="text__white fs-13 fw-4 lh-20"> |
| 88 | + {targetPlatforms.length} target platform |
| 89 | + {targetPlatforms.length > 1 ? 's' : ''} |
| 90 | + </span> |
| 91 | + </div> |
| 92 | + </TargetPlatformListTooltip> |
| 93 | + |
| 94 | + {!!endTime && <div className="dc__bullet--white dc__bullet" />} |
| 95 | + </> |
| 96 | + )} |
| 97 | + |
| 98 | + {!!endTime && <span className="text__white fs-13 fw-4 lh-20">{getFormattedTimeDifference()}</span>} |
| 99 | + </div> |
| 100 | + </button> |
| 101 | + ) |
| 102 | +} |
| 103 | + |
| 104 | +export default LogStageHeader |
0 commit comments