14
14
* limitations under the License.
15
15
*/
16
16
17
- import React , { useState , useEffect , useRef , useMemo } from 'react'
17
+ import React , { useState , useEffect , useRef , useMemo , ReactNode } from 'react'
18
18
import {
19
19
showError ,
20
20
Progressing ,
@@ -37,6 +37,7 @@ import {
37
37
noop ,
38
38
AppThemeType ,
39
39
Icon ,
40
+ NodeDetailTabsInfoType ,
40
41
} from '@devtron-labs/devtron-fe-common-lib'
41
42
import { useParams , useLocation , useHistory } from 'react-router-dom'
42
43
import YAML from 'yaml'
@@ -157,20 +158,117 @@ const NodeDetails = ({ addTab, lowercaseKindToResourceGroupMap, updateTabUrl }:
157
158
158
159
const getSanitizedNodeTabId = ( id : string ) => id . toLowerCase ( ) . replace ( ' ' , '-' )
159
160
161
+ const renderSummary = ( ) : JSX . Element | null => {
162
+ if ( ! nodeDetail ) {
163
+ return null
164
+ }
165
+
166
+ return (
167
+ < div className = "node-details-container node-data-wrapper dc__overflow-hidden flexbox-col flex-grow-1" >
168
+ < div className = "mt-12 node-details-grid dc__overflow-hidden" >
169
+ < div className = "pl-20 fw-6 fs-16 cn-9 dc__overflow-auto" >
170
+ { renderErrorOverviewCard ( ) }
171
+ { renderProbableIssuesOverviewCard ( ) }
172
+ { renderNodeOverviewCard ( ) }
173
+ </ div >
174
+ < div className = "dc__overflow-auto pr-20" >
175
+ { renderResourceList ( ) }
176
+ { renderLabelAnnotationTaint ( ) }
177
+ { renderPodList ( ) }
178
+ </ div >
179
+ </ div >
180
+ </ div >
181
+ )
182
+ }
183
+
184
+ const renderYAMLEditor = ( ) : JSX . Element => {
185
+ return (
186
+ < div className = "flex-grow-1 flexbox-col" >
187
+ < CodeEditor
188
+ readOnly = { ! isEdit }
189
+ diffView = { isReviewState }
190
+ mode = { MODES . YAML }
191
+ noParsing
192
+ theme = { AppThemeType . dark }
193
+ height = "fitToParent"
194
+ { ...( isReviewState
195
+ ? {
196
+ diffView : true ,
197
+ originalValue : ( nodeDetail ?. manifest && YAMLStringify ( nodeDetail . manifest ) ) || '' ,
198
+ modifiedValue : modifiedManifest ,
199
+ onModifiedValueChange : handleEditorValueChange ,
200
+ }
201
+ : {
202
+ diffView : false ,
203
+ value : modifiedManifest ,
204
+ onChange : handleEditorValueChange ,
205
+ } ) }
206
+ >
207
+ { isReviewState && isShowWarning && (
208
+ < CodeEditor . Warning
209
+ className = "dc__ellipsis-right"
210
+ text = "Actual YAML has changed since you made the changes. Please check the diff carefully."
211
+ />
212
+ ) }
213
+ { isReviewState && (
214
+ < CodeEditor . Header hideDefaultSplitHeader >
215
+ < p className = "m-0 fs-12 fw-6 cn-7" > Current node YAML</ p >
216
+ < p className = "m-0 fs-12 fw-6 cn-7 pl-16 flex left dc__gap-4" >
217
+ < Edit className = "icon-dim-16" />
218
+ < span > YAML (Editing)</ span >
219
+ </ p >
220
+ </ CodeEditor . Header >
221
+ ) }
222
+ </ CodeEditor >
223
+ </ div >
224
+ )
225
+ }
226
+
227
+ const renderConditions = ( ) : JSX . Element => {
228
+ return (
229
+ < div className = "node-details-container flex-grow-1 flexbox-col dc__overflow-auto" >
230
+ < div className = "ml-20 mr-20 mb-12 mt-16 bg__primary br-8 en-2 bw-1" >
231
+ < div className = "condition-grid cn-7 fw-6 fs-13 dc__border-bottom pt-8 pl-20 pb-8 pr-20" >
232
+ < div > Type</ div >
233
+ < div > Status</ div >
234
+ < div > Message</ div >
235
+ </ div >
236
+ { nodeDetail . conditions . map ( ( condition ) => (
237
+ < div className = "condition-grid cn-9 fw-4 fs-13 dc__border-bottom-n1 pt-12 pl-20 pb-12 pr-20" >
238
+ < div > { condition . type } </ div >
239
+ < div className = "flexbox" >
240
+ { condition . haveIssue ? (
241
+ < Error className = "mt-2 mb-2 mr-8 icon-dim-18" />
242
+ ) : (
243
+ < Success className = "mt-2 mb-2 mr-8 icon-dim-18" />
244
+ ) }
245
+ { condition . reason }
246
+ </ div >
247
+ < div > { condition . message } </ div >
248
+ </ div >
249
+ ) ) }
250
+ </ div >
251
+ </ div >
252
+ )
253
+ }
254
+
160
255
// id will be populated into url
161
- const NODE_TABS_INFO : ( Pick < TabProps , 'label' | 'icon' > & { id : string } ) [ ] = [
256
+ const NODE_TABS_INFO : NodeDetailTabsInfoType = [
162
257
{
163
258
id : getSanitizedNodeTabId ( NODE_DETAILS_TABS . summary ) ,
164
259
label : NODE_DETAILS_TABS . summary ,
260
+ node : renderSummary ,
165
261
} ,
166
262
{
167
263
id : getSanitizedNodeTabId ( NODE_DETAILS_TABS . yaml ) ,
168
264
label : NODE_DETAILS_TABS . yaml ,
169
265
icon : Edit ,
266
+ node : renderYAMLEditor ,
170
267
} ,
171
268
{
172
269
id : getSanitizedNodeTabId ( NODE_DETAILS_TABS . nodeConditions ) ,
173
270
label : NODE_DETAILS_TABS . nodeConditions ,
271
+ node : renderConditions ,
174
272
} ,
175
273
...REDFISH_NODE_UI_TABS ,
176
274
]
@@ -211,7 +309,7 @@ const NodeDetails = ({ addTab, lowercaseKindToResourceGroupMap, updateTabUrl }:
211
309
}
212
310
213
311
const renderNodeDetailsTabs = ( ) : JSX . Element => {
214
- const tabs : TabProps [ ] = NODE_TABS_INFO . map ( ( tabDetails , index ) => ( {
312
+ const tabs : TabProps [ ] = NODE_TABS_INFO . map ( ( { node , ... tabDetails } , index ) => ( {
215
313
...tabDetails ,
216
314
tabType : 'navLink' ,
217
315
props : {
@@ -803,29 +901,6 @@ const NodeDetails = ({ addTab, lowercaseKindToResourceGroupMap, updateTabUrl }:
803
901
</ div >
804
902
)
805
903
806
- const renderSummary = ( ) : JSX . Element | null => {
807
- if ( ! nodeDetail ) {
808
- return null
809
- }
810
-
811
- return (
812
- < div className = "node-details-container node-data-wrapper dc__overflow-hidden flexbox-col flex-grow-1" >
813
- < div className = "mt-12 node-details-grid dc__overflow-hidden" >
814
- < div className = "pl-20 fw-6 fs-16 cn-9 dc__overflow-auto" >
815
- { renderErrorOverviewCard ( ) }
816
- { renderProbableIssuesOverviewCard ( ) }
817
- { renderNodeOverviewCard ( ) }
818
- </ div >
819
- < div className = "dc__overflow-auto pr-20" >
820
- { renderResourceList ( ) }
821
- { renderLabelAnnotationTaint ( ) }
822
- { renderPodList ( ) }
823
- </ div >
824
- </ div >
825
- </ div >
826
- )
827
- }
828
-
829
904
const cancelYAMLEdit = ( ) : void => {
830
905
setIsReviewStates ( false )
831
906
setIsEdit ( false )
@@ -900,85 +975,15 @@ const NodeDetails = ({ addTab, lowercaseKindToResourceGroupMap, updateTabUrl }:
900
975
}
901
976
}
902
977
903
- const renderYAMLEditor = ( ) : JSX . Element => {
904
- return (
905
- < div className = "flex-grow-1 flexbox-col" >
906
- < CodeEditor
907
- readOnly = { ! isEdit }
908
- diffView = { isReviewState }
909
- mode = { MODES . YAML }
910
- noParsing
911
- theme = { AppThemeType . dark }
912
- height = "fitToParent"
913
- { ...( isReviewState
914
- ? {
915
- diffView : true ,
916
- originalValue : ( nodeDetail ?. manifest && YAMLStringify ( nodeDetail . manifest ) ) || '' ,
917
- modifiedValue : modifiedManifest ,
918
- onModifiedValueChange : handleEditorValueChange ,
919
- }
920
- : {
921
- diffView : false ,
922
- value : modifiedManifest ,
923
- onChange : handleEditorValueChange ,
924
- } ) }
925
- >
926
- { isReviewState && isShowWarning && (
927
- < CodeEditor . Warning
928
- className = "dc__ellipsis-right"
929
- text = "Actual YAML has changed since you made the changes. Please check the diff carefully."
930
- />
931
- ) }
932
- { isReviewState && (
933
- < CodeEditor . Header hideDefaultSplitHeader >
934
- < p className = "m-0 fs-12 fw-6 cn-7" > Current node YAML</ p >
935
- < p className = "m-0 fs-12 fw-6 cn-7 pl-16 flex left dc__gap-4" >
936
- < Edit className = "icon-dim-16" />
937
- < span > YAML (Editing)</ span >
938
- </ p >
939
- </ CodeEditor . Header >
940
- ) }
941
- </ CodeEditor >
942
- </ div >
943
- )
944
- }
945
-
946
- const renderConditions = ( ) : JSX . Element => {
947
- return (
948
- < div className = "node-details-container flex-grow-1 flexbox-col dc__overflow-auto" >
949
- < div className = "ml-20 mr-20 mb-12 mt-16 bg__primary br-8 en-2 bw-1" >
950
- < div className = "condition-grid cn-7 fw-6 fs-13 dc__border-bottom pt-8 pl-20 pb-8 pr-20" >
951
- < div > Type</ div >
952
- < div > Status</ div >
953
- < div > Message</ div >
954
- </ div >
955
- { nodeDetail . conditions . map ( ( condition ) => (
956
- < div className = "condition-grid cn-9 fw-4 fs-13 dc__border-bottom-n1 pt-12 pl-20 pb-12 pr-20" >
957
- < div > { condition . type } </ div >
958
- < div className = "flexbox" >
959
- { condition . haveIssue ? (
960
- < Error className = "mt-2 mb-2 mr-8 icon-dim-18" />
961
- ) : (
962
- < Success className = "mt-2 mb-2 mr-8 icon-dim-18" />
963
- ) }
964
- { condition . reason }
965
- </ div >
966
- < div > { condition . message } </ div >
967
- </ div >
968
- ) ) }
969
- </ div >
970
- </ div >
971
- )
972
- }
973
-
974
978
const renderTabs = ( ) : JSX . Element => {
975
- if ( selectedTabIndex === 1 ) {
976
- return renderYAMLEditor ( )
977
- }
978
- if ( selectedTabIndex === 2 ) {
979
- return renderConditions ( )
979
+ const selectedTab = NODE_TABS_INFO [ selectedTabIndex ]
980
+ const renderNode = selectedTab ?. node
981
+
982
+ if ( renderNode ) {
983
+ return renderNode ( )
980
984
}
981
- return renderSummary ( )
985
+
986
+ return null
982
987
}
983
988
984
989
const showCordonNodeModal = ( ) : void => {
0 commit comments