-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAppStatusContent.tsx
More file actions
143 lines (122 loc) · 5.81 KB
/
Copy pathAppStatusContent.tsx
File metadata and controls
143 lines (122 loc) · 5.81 KB
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
import { useState } from 'react'
import { SortableTableHeaderCell } from '@Common/SortableTableHeaderCell'
import { Tooltip } from '@Common/Tooltip'
import { ALL_RESOURCE_KIND_FILTER, APP_STATUS_HEADERS, ComponentSizeType } from '@Shared/constants'
import { Node } from '@Shared/types'
import { Button, ButtonStyleType, ButtonVariantType } from '../Button'
import { NodeFilters, StatusFilterButtonComponent } from '../CICDHistory'
import { Icon } from '../Icon'
import { ShowMoreText } from '../ShowMoreText'
import { AppStatusContentProps } from './types'
import { getFlattenedNodesFromAppDetails, getResourceKey } from './utils'
import './AppStatusContent.scss'
const APP_STATUS_ROWS_BASE_CLASS = 'px-16 py-8 dc__grid dc__column-gap-16 app-status-content__row'
const AppStatusContent = ({
appDetails,
handleShowConfigDriftModal,
filterHealthyNodes = false,
isCardLayout = true,
}: AppStatusContentProps) => {
const [currentFilter, setCurrentFilter] = useState<string>(ALL_RESOURCE_KIND_FILTER)
const { appId, environmentId: envId } = appDetails
const flattenedNodes = getFlattenedNodesFromAppDetails({
appDetails,
filterHealthyNodes,
})
const filteredFlattenedNodes = flattenedNodes.filter(
(nodeDetails) =>
currentFilter === ALL_RESOURCE_KIND_FILTER ||
(currentFilter === NodeFilters.drifted && nodeDetails.hasDrift) ||
nodeDetails.health.status?.toLowerCase() === currentFilter,
)
const handleFilterClick = (selectedFilter: string) => {
const lowerCaseSelectedFilter = selectedFilter.toLowerCase()
if (currentFilter !== lowerCaseSelectedFilter) {
setCurrentFilter(lowerCaseSelectedFilter)
}
}
const getNodeMessage = (nodeDetails: Node) => {
const resourceKey = getResourceKey(nodeDetails)
if (
appDetails.resourceTree?.resourcesSyncResult &&
// eslint-disable-next-line no-prototype-builtins
appDetails.resourceTree.resourcesSyncResult.hasOwnProperty(resourceKey)
) {
return appDetails.resourceTree.resourcesSyncResult[resourceKey]
}
return ''
}
const getNodeStatus = (nodeDetails: Node) => (nodeDetails.status ? nodeDetails.status : nodeDetails.health.status)
const renderRows = () => {
if (!flattenedNodes.length) {
return (
<div className="flex column py-16 dc__gap-4 dc__align-center h-100">
<Icon name="ic-info-filled" size={20} color={null} />
<span>Checking resources status</span>
</div>
)
}
return (
<>
{filteredFlattenedNodes.map((nodeDetails) => (
<div
className={`${APP_STATUS_ROWS_BASE_CLASS} cn-9 fs-13 fw-4 lh-20`}
key={getResourceKey(nodeDetails)}
>
<Tooltip content={nodeDetails.kind}>
<span className="dc__word-break">{nodeDetails.kind}</span>
</Tooltip>
<span className="dc__word-break">{nodeDetails.name}</span>
<Tooltip content={getNodeStatus(nodeDetails)}>
<span
className={`app-summary__status-name f-${getNodeStatus(nodeDetails)?.toLowerCase() || ''} dc__first-letter-capitalize--imp fs-13 fw-4 lh-20 dc__ellipsis-right`}
>
{getNodeStatus(nodeDetails)}
</span>
</Tooltip>
<div className="flexbox-col dc__gap-4">
{handleShowConfigDriftModal && nodeDetails.hasDrift && (
<div className="flexbox dc__gap-8 dc__align-items-center">
<span className="fs-13 fw-4 lh-20 cy-7">Config drift detected</span>
{appId && envId && (
<Button
dataTestId="show-config-drift"
text="Compare with desired"
variant={ButtonVariantType.text}
style={ButtonStyleType.default}
onClick={handleShowConfigDriftModal}
size={ComponentSizeType.small}
/>
)}
</div>
)}
<ShowMoreText key={getNodeMessage(nodeDetails)} text={getNodeMessage(nodeDetails)} />
</div>
</div>
))}
</>
)
}
return (
<div className={`flexbox-col app-status-content ${isCardLayout ? 'br-6 border__primary' : ''}`}>
{!!flattenedNodes.length && (
<div className="p-12">
<StatusFilterButtonComponent
nodes={flattenedNodes}
selectedTab={currentFilter}
handleFilterClick={handleFilterClick}
/>
</div>
)}
<div
className={`${APP_STATUS_ROWS_BASE_CLASS} dc__position-sticky dc__top-0 dc__zi-1 cn-7 fs-13 fw-6 lh-20 border__secondary--bottom bg__primary dc__top-radius-6`}
>
{APP_STATUS_HEADERS.map((headerKey) => (
<SortableTableHeaderCell key={`header_${headerKey}`} isSortable={false} title={headerKey} />
))}
</div>
{renderRows()}
</div>
)
}
export default AppStatusContent