Skip to content

Commit 486a2c2

Browse files
committed
refactor: streamline render functions in NodeDetails component
1 parent 5f875d8 commit 486a2c2

File tree

1 file changed

+68
-72
lines changed

1 file changed

+68
-72
lines changed

src/components/ClusterNodes/NodeDetails.tsx

Lines changed: 68 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -176,95 +176,91 @@ const NodeDetails = ({ addTab, lowercaseKindToResourceGroupMap, updateTabUrl }:
176176
)
177177
}
178178

179-
const renderYAMLEditor = (): JSX.Element => {
180-
return (
181-
<div className="flex-grow-1 flexbox-col">
182-
<CodeEditor
183-
readOnly={!isEdit}
184-
diffView={isReviewState}
185-
mode={MODES.YAML}
186-
noParsing
187-
theme={AppThemeType.dark}
188-
height="fitToParent"
189-
{...(isReviewState
190-
? {
191-
diffView: true,
192-
originalValue: (nodeDetail?.manifest && YAMLStringify(nodeDetail.manifest)) || '',
193-
modifiedValue: modifiedManifest,
194-
onModifiedValueChange: handleEditorValueChange,
195-
}
196-
: {
197-
diffView: false,
198-
value: modifiedManifest,
199-
onChange: handleEditorValueChange,
200-
})}
201-
>
202-
{isReviewState && isShowWarning && (
203-
<CodeEditor.Warning
204-
className="dc__ellipsis-right"
205-
text="Actual YAML has changed since you made the changes. Please check the diff carefully."
206-
/>
207-
)}
208-
{isReviewState && (
209-
<CodeEditor.Header hideDefaultSplitHeader>
210-
<p className="m-0 fs-12 fw-6 cn-7">Current node YAML</p>
211-
<p className="m-0 fs-12 fw-6 cn-7 pl-16 flex left dc__gap-4">
212-
<Edit className="icon-dim-16" />
213-
<span>YAML (Editing)</span>
214-
</p>
215-
</CodeEditor.Header>
216-
)}
217-
</CodeEditor>
218-
</div>
219-
)
220-
}
179+
const renderYAMLEditor = (): JSX.Element => (
180+
<div className="flex-grow-1 flexbox-col">
181+
<CodeEditor
182+
readOnly={!isEdit}
183+
diffView={isReviewState}
184+
mode={MODES.YAML}
185+
noParsing
186+
theme={AppThemeType.dark}
187+
height="fitToParent"
188+
{...(isReviewState
189+
? {
190+
diffView: true,
191+
originalValue: (nodeDetail?.manifest && YAMLStringify(nodeDetail.manifest)) || '',
192+
modifiedValue: modifiedManifest,
193+
onModifiedValueChange: handleEditorValueChange,
194+
}
195+
: {
196+
diffView: false,
197+
value: modifiedManifest,
198+
onChange: handleEditorValueChange,
199+
})}
200+
>
201+
{isReviewState && isShowWarning && (
202+
<CodeEditor.Warning
203+
className="dc__ellipsis-right"
204+
text="Actual YAML has changed since you made the changes. Please check the diff carefully."
205+
/>
206+
)}
207+
{isReviewState && (
208+
<CodeEditor.Header hideDefaultSplitHeader>
209+
<p className="m-0 fs-12 fw-6 cn-7">Current node YAML</p>
210+
<p className="m-0 fs-12 fw-6 cn-7 pl-16 flex left dc__gap-4">
211+
<Edit className="icon-dim-16" />
212+
<span>YAML (Editing)</span>
213+
</p>
214+
</CodeEditor.Header>
215+
)}
216+
</CodeEditor>
217+
</div>
218+
)
221219

222-
const renderConditions = (): JSX.Element => {
223-
return (
224-
<div className="node-details-container flex-grow-1 flexbox-col dc__overflow-auto">
225-
<div className="ml-20 mr-20 mb-12 mt-12 bg__primary br-8 en-2 bw-1">
226-
<div className="condition-grid cn-7 fw-6 fs-13 dc__border-bottom pt-8 pl-20 pb-8 pr-20">
227-
<div>Type</div>
228-
<div>Status</div>
229-
<div>Message</div>
230-
</div>
231-
{nodeDetail.conditions.map((condition) => (
232-
<div className="condition-grid cn-9 fw-4 fs-13 dc__border-bottom-n1 pt-12 pl-20 pb-12 pr-20">
233-
<div>{condition.type}</div>
234-
<div className="flexbox">
235-
{condition.haveIssue ? (
236-
<Error className="mt-2 mb-2 mr-8 icon-dim-18" />
237-
) : (
238-
<Success className="mt-2 mb-2 mr-8 icon-dim-18" />
239-
)}
240-
{condition.reason}
241-
</div>
242-
<div>{condition.message}</div>
243-
</div>
244-
))}
220+
const renderConditions = (): JSX.Element => (
221+
<div className="node-details-container flex-grow-1 flexbox-col dc__overflow-auto">
222+
<div className="ml-20 mr-20 mb-12 mt-12 bg__primary br-8 en-2 bw-1">
223+
<div className="condition-grid cn-7 fw-6 fs-13 dc__border-bottom pt-8 pl-20 pb-8 pr-20">
224+
<div>Type</div>
225+
<div>Status</div>
226+
<div>Message</div>
245227
</div>
228+
{nodeDetail.conditions.map((condition) => (
229+
<div className="condition-grid cn-9 fw-4 fs-13 dc__border-bottom-n1 pt-12 pl-20 pb-12 pr-20">
230+
<div>{condition.type}</div>
231+
<div className="flexbox">
232+
{condition.haveIssue ? (
233+
<Error className="mt-2 mb-2 mr-8 icon-dim-18" />
234+
) : (
235+
<Success className="mt-2 mb-2 mr-8 icon-dim-18" />
236+
)}
237+
{condition.reason}
238+
</div>
239+
<div>{condition.message}</div>
240+
</div>
241+
))}
246242
</div>
247-
)
248-
}
243+
</div>
244+
)
249245

250246
// id will be populated into url
251247
const NODE_TABS_INFO: NodeDetailTabsInfoType = [
252248
{
253249
id: getSanitizedNodeTabId(NODE_DETAILS_TABS.summary),
254250
label: NODE_DETAILS_TABS.summary,
255-
node: renderSummary,
251+
renderComponent: renderSummary,
256252
},
257253
...(window._env_.FEATURE_REDFISH_NODE_ENABLE ? REDFISH_NODE_UI_TABS : []),
258254
{
259255
id: getSanitizedNodeTabId(NODE_DETAILS_TABS.yaml),
260256
label: NODE_DETAILS_TABS.yaml,
261257
icon: Edit,
262-
node: renderYAMLEditor,
258+
renderComponent: renderYAMLEditor,
263259
},
264260
{
265261
id: getSanitizedNodeTabId(NODE_DETAILS_TABS.nodeConditions),
266262
label: NODE_DETAILS_TABS.nodeConditions,
267-
node: renderConditions,
263+
renderComponent: renderConditions,
268264
},
269265
]
270266

@@ -304,7 +300,7 @@ const NodeDetails = ({ addTab, lowercaseKindToResourceGroupMap, updateTabUrl }:
304300
}
305301

306302
const renderNodeDetailsTabs = (): JSX.Element => {
307-
const tabs: TabProps[] = NODE_TABS_INFO.map(({ node, ...tabDetails }, index) => ({
303+
const tabs: TabProps[] = NODE_TABS_INFO.map(({ renderComponent, ...tabDetails }, index) => ({
308304
...tabDetails,
309305
tabType: 'navLink',
310306
props: {
@@ -994,7 +990,7 @@ const NodeDetails = ({ addTab, lowercaseKindToResourceGroupMap, updateTabUrl }:
994990

995991
const renderTabContent = (): JSX.Element => {
996992
const selectedTab = NODE_TABS_INFO[selectedTabIndex]
997-
const renderNode = selectedTab?.node
993+
const renderNode = selectedTab?.renderComponent
998994

999995
if (renderNode) {
1000996
return renderNode()

0 commit comments

Comments
 (0)