|
| 1 | +import { ZERO_TIME_STRING } from '@Common/Constants' |
| 2 | +import { getTimeDifference } from '@Shared/Helpers' |
| 3 | +import { LogStageAccordionProps } from './types' |
| 4 | +import { getStageStatusIcon } from './utils' |
| 5 | +import { ReactComponent as ICCaretDown } from '../../../Assets/Icon/ic-caret-down.svg' |
| 6 | + |
| 7 | +const LogStageAccordion = ({ |
| 8 | + stage, |
| 9 | + isOpen, |
| 10 | + logs, |
| 11 | + endTime, |
| 12 | + startTime, |
| 13 | + status, |
| 14 | + handleStageClose, |
| 15 | + handleStageOpen, |
| 16 | + accordionIndex, |
| 17 | +}: LogStageAccordionProps) => { |
| 18 | + const handleAccordionToggle = () => { |
| 19 | + if (isOpen) { |
| 20 | + handleStageClose(accordionIndex) |
| 21 | + } else { |
| 22 | + handleStageOpen(accordionIndex) |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + return ( |
| 27 | + <div className="flexbox-col dc__gap-8"> |
| 28 | + <button |
| 29 | + className="flexbox dc__transparent dc__content-space py-6 px-8 br-4 dc__align-items-center dc__select-text logs-renderer__stage-accordion-hover" |
| 30 | + style={{ |
| 31 | + backgroundColor: isOpen ? '#2C3354' : '#0C1021', |
| 32 | + }} |
| 33 | + type="button" |
| 34 | + role="tab" |
| 35 | + onClick={handleAccordionToggle} |
| 36 | + > |
| 37 | + <div className="flexbox dc__gap-8 dc__transparent dc__align-items-center"> |
| 38 | + <ICCaretDown |
| 39 | + className={`icon-dim-16 dc__no-shrink dc__transition--transform ${!isOpen ? 'dc__flip-n90 dc__opacity-0_5' : ''}`} |
| 40 | + /> |
| 41 | + |
| 42 | + <div className="flexbox dc__gap-12 dc__align-items-center"> |
| 43 | + {getStageStatusIcon(status)} |
| 44 | + |
| 45 | + <h3 className="m-0 cn-0 fs-13 fw-6 lh-20 dc__word-break">{stage}</h3> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + |
| 49 | + {endTime !== ZERO_TIME_STRING && ( |
| 50 | + <span className="cn-0 fs-13 fw-4 lh-20">{getTimeDifference(startTime, endTime)}</span> |
| 51 | + )} |
| 52 | + </button> |
| 53 | + |
| 54 | + {isOpen && |
| 55 | + logs.map((log: string, logsIndex: number) => ( |
| 56 | + <div |
| 57 | + className="flex top left pl-24 dc__gap-10 lh-24 pb-10" |
| 58 | + // eslint-disable-next-line react/no-array-index-key |
| 59 | + key={`logs-${stage}-${startTime}-${logsIndex}`} |
| 60 | + > |
| 61 | + <span className="cn-4 col-2">{logsIndex + 1}</span> |
| 62 | + <p |
| 63 | + className="mono fs-14 mb-0-imp cn-0 dc__word-break" |
| 64 | + // eslint-disable-next-line react/no-danger |
| 65 | + dangerouslySetInnerHTML={{ |
| 66 | + __html: log, |
| 67 | + }} |
| 68 | + /> |
| 69 | + </div> |
| 70 | + ))} |
| 71 | + </div> |
| 72 | + ) |
| 73 | +} |
| 74 | + |
| 75 | +export default LogStageAccordion |
0 commit comments