Skip to content

Commit 220e90c

Browse files
committed
feat: extract util for tabs
1 parent d63f2c8 commit 220e90c

File tree

2 files changed

+78
-66
lines changed

2 files changed

+78
-66
lines changed

src/Shared/Components/CICDHistory/TriggerOutput.tsx

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
useInterval,
3232
} from '../../../Common'
3333
import { DEPLOYMENT_STAGE_TO_NODE_MAP, EMPTY_STATE_STATUS } from '../../constants'
34-
import { TabGroup } from '../TabGroup'
34+
import { TabGroup, TabGroupProps } from '../TabGroup'
3535
import Artifacts from './Artifacts'
3636
import DeploymentDetailSteps from './DeploymentDetailSteps'
3737
import { DeploymentHistoryConfigDiff } from './DeploymentHistoryConfigDiff'
@@ -48,6 +48,7 @@ import {
4848
terminalStatus,
4949
TriggerOutputProps,
5050
} from './types'
51+
import { getTriggerOutputTabs } from './utils'
5152

5253
import './cicdHistory.scss'
5354

@@ -317,6 +318,11 @@ const TriggerOutput = ({
317318
(!!triggerDetailsResult?.result?.artifactId || !!triggerDetails?.artifactId),
318319
)
319320

321+
const tabs: TabGroupProps['tabs'] = useMemo(
322+
() => getTriggerOutputTabs(triggerDetails, deploymentAppType),
323+
[triggerDetails, deploymentAppType],
324+
)
325+
320326
useEffect(() => {
321327
if (triggerDetailsLoading) {
322328
return
@@ -411,71 +417,7 @@ const TriggerOutput = ({
411417
namespace={triggerDetails.namespace}
412418
/>
413419
<div className="pl-50 pr-20 pt-8 dc__border-bottom dc__position-sticky dc__top-0 bg__primary dc__zi-3">
414-
<TabGroup
415-
tabs={[
416-
...(triggerDetails.stage === 'DEPLOY' && deploymentAppType !== DeploymentAppTypes.HELM
417-
? [
418-
{
419-
id: 'deployment-history-steps-link',
420-
label: 'Steps',
421-
tabType: 'navLink' as const,
422-
props: {
423-
to: 'deployment-steps',
424-
'data-testid': 'deployment-history-steps-link',
425-
},
426-
},
427-
]
428-
: []),
429-
...(!(triggerDetails.stage === 'DEPLOY' || triggerDetails.IsVirtualEnvironment)
430-
? [
431-
{
432-
id: 'deployment-history-logs-link',
433-
label: 'Logs',
434-
tabType: 'navLink' as const,
435-
props: {
436-
to: 'logs',
437-
'data-testid': 'deployment-history-logs-link',
438-
},
439-
},
440-
]
441-
: []),
442-
{
443-
id: 'deployment-history-source-code-link',
444-
label: 'Source',
445-
tabType: 'navLink',
446-
props: {
447-
to: 'source-code',
448-
'data-testid': 'deployment-history-source-code-link',
449-
},
450-
},
451-
...(triggerDetails.stage === 'DEPLOY'
452-
? [
453-
{
454-
id: 'deployment-history-configuration-link',
455-
label: 'Configuration',
456-
tabType: 'navLink' as const,
457-
props: {
458-
to: 'configuration',
459-
'data-testid': 'deployment-history-configuration-link',
460-
},
461-
},
462-
]
463-
: []),
464-
...(triggerDetails.stage !== 'DEPLOY' || triggerDetails.IsVirtualEnvironment
465-
? [
466-
{
467-
id: 'deployment-history-artifacts-link',
468-
label: 'Artifacts',
469-
tabType: 'navLink' as const,
470-
props: {
471-
to: 'artifacts',
472-
'data-testid': 'deployment-history-artifacts-link',
473-
},
474-
},
475-
]
476-
: []),
477-
]}
478-
/>
420+
<TabGroup tabs={tabs} />
479421
</div>
480422
</>
481423
)}

src/Shared/Components/CICDHistory/utils.tsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ import { ReactComponent as ICInProgress } from '@Icons/ic-in-progress.svg'
2626
import { ReactComponent as TimeOut } from '@Icons/ic-timeout-red.svg'
2727
import { ReactComponent as Timer } from '@Icons/ic-timer.svg'
2828
import { DATE_TIME_FORMATS } from '@Common/Constants'
29+
import { DeploymentAppTypes } from '@Common/Types'
2930
import { ALL_RESOURCE_KIND_FILTER } from '@Shared/constants'
3031
import { isTimeStringAvailable } from '@Shared/Helpers'
3132

3233
import { Node, ResourceKindType, WorkflowStatusEnum } from '../../types'
3334
import { Icon } from '../Icon'
3435
import { AppStatus, DeploymentStatus, StatusType } from '../StatusComponent'
36+
import { TabGroupProps } from '../TabGroup'
3537
import {
3638
DEFAULT_CLUSTER_ID,
3739
DEFAULT_NAMESPACE,
@@ -42,6 +44,7 @@ import {
4244
DeploymentHistory,
4345
DeploymentHistoryResultObject,
4446
ExecutionInfoType,
47+
History,
4548
NodeFilters,
4649
NodeStatus,
4750
PodExecutionStageDTO,
@@ -375,3 +378,70 @@ export const getTriggerStatusIcon = (status: string) => {
375378
return status
376379
}
377380
}
381+
382+
export const getTriggerOutputTabs = (
383+
triggerDetails: History,
384+
deploymentAppType: DeploymentAppTypes,
385+
): TabGroupProps['tabs'] => [
386+
...(triggerDetails.stage === 'DEPLOY' && deploymentAppType !== DeploymentAppTypes.HELM
387+
? [
388+
{
389+
id: 'deployment-history-steps-link',
390+
label: 'Steps',
391+
tabType: 'navLink' as const,
392+
props: {
393+
to: 'deployment-steps',
394+
'data-testid': 'deployment-history-steps-link',
395+
},
396+
},
397+
]
398+
: []),
399+
...(!(triggerDetails.stage === 'DEPLOY' || triggerDetails.IsVirtualEnvironment)
400+
? [
401+
{
402+
id: 'deployment-history-logs-link',
403+
label: 'Logs',
404+
tabType: 'navLink' as const,
405+
props: {
406+
to: 'logs',
407+
'data-testid': 'deployment-history-logs-link',
408+
},
409+
},
410+
]
411+
: []),
412+
{
413+
id: 'deployment-history-source-code-link',
414+
label: 'Source',
415+
tabType: 'navLink',
416+
props: {
417+
to: 'source-code',
418+
'data-testid': 'deployment-history-source-code-link',
419+
},
420+
},
421+
...(triggerDetails.stage === 'DEPLOY'
422+
? [
423+
{
424+
id: 'deployment-history-configuration-link',
425+
label: 'Configuration',
426+
tabType: 'navLink' as const,
427+
props: {
428+
to: 'configuration',
429+
'data-testid': 'deployment-history-configuration-link',
430+
},
431+
},
432+
]
433+
: []),
434+
...(triggerDetails.stage !== 'DEPLOY' || triggerDetails.IsVirtualEnvironment
435+
? [
436+
{
437+
id: 'deployment-history-artifacts-link',
438+
label: 'Artifacts',
439+
tabType: 'navLink' as const,
440+
props: {
441+
to: 'artifacts',
442+
'data-testid': 'deployment-history-artifacts-link',
443+
},
444+
},
445+
]
446+
: []),
447+
]

0 commit comments

Comments
 (0)