Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 278b28f

Browse files
committed
fix(plugins/plugin-client-common): Improve rendering of Source Reference UI
This PR addresses both issues described in the associated issue. Fixes #6582
1 parent e539a53 commit 278b28f

File tree

5 files changed

+46
-26
lines changed

5 files changed

+46
-26
lines changed

plugins/plugin-client-common/src/components/Views/Terminal/Block/Input.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,17 @@ export abstract class InputProvider<S extends State = State> extends React.PureC
252252

253253
/** render sourceRef content. Currently only use SimpleEditor. */
254254
protected sourceRefContent(content: string, contentType: string) {
255-
return (
256-
<SimpleEditor
257-
tabUUID={getPrimaryTabId(this.props.tab)}
258-
content={content.replace(/\n$/, '')} /* monaco's renderFinalNewline option doesn't seem to do what we need */
259-
contentType={contentType}
260-
className="kui--source-ref-editor kui--inverted-color-context"
261-
fontSize={12}
262-
simple
263-
/>
255+
return () => (
256+
<React.Suspense fallback={<div />}>
257+
<SimpleEditor
258+
tabUUID={getPrimaryTabId(this.props.tab)}
259+
content={content.replace(/\n$/, '')} /* monaco's renderFinalNewline option doesn't seem to do what we need */
260+
contentType={contentType}
261+
className="kui--source-ref-editor kui--inverted-color-context"
262+
fontSize={12}
263+
simple
264+
/>
265+
</React.Suspense>
264266
)
265267
}
266268

plugins/plugin-client-common/src/components/spi/Accordion/impl/Carbon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class CarbonAccordion extends React.PureComponent<Props, State> {
5151
eventBus.emitTabLayoutChange(getPrimaryTabId(this.props.tab))
5252
}}
5353
>
54-
{this.props.content[idx]}
54+
{this.props.content[idx]()}
5555
</AccordionItem>
5656
))}
5757
</Accordion>

plugins/plugin-client-common/src/components/spi/Accordion/impl/PatternFly.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,34 @@ export default class PatternFlyAccordion extends React.PureComponent<Props, Stat
3838
}
3939
}
4040

41+
private content(idx: number) {
42+
const isHidden = this.state.expandedIdx !== idx
43+
return <AccordionContent isHidden={isHidden}>{!isHidden && this.props.content[idx]()}</AccordionContent>
44+
}
45+
4146
public render() {
4247
return (
4348
<Accordion
4449
asDefinitionList={false}
4550
className={`kui--accordion ${this.props.isWidthConstrained ? 'flex-fill' : ''}`}
4651
>
4752
{this.props.names.map((name, idx) => (
48-
<AccordionItem key={idx}>
49-
<AccordionToggle
50-
id={idx.toString()}
51-
onClick={() => {
52-
this.setState(curState => ({ expandedIdx: curState.expandedIdx !== idx ? idx : -1 }))
53-
eventBus.emitTabLayoutChange(getPrimaryTabId(this.props.tab))
54-
}}
55-
isExpanded={this.state.expandedIdx === idx}
56-
>
57-
{this.state.expandedIdx !== idx ? strings('Show X', name) : strings('Hide X', name)}
58-
</AccordionToggle>
59-
<AccordionContent isHidden={this.state.expandedIdx !== idx}>{this.props.content[idx]}</AccordionContent>
60-
</AccordionItem>
53+
<div key={idx} className="kui--accordion-item">
54+
{/* ^^^^^^^^^ AccordionItem does not accept className */}
55+
<AccordionItem>
56+
<AccordionToggle
57+
id={idx.toString()}
58+
onClick={() => {
59+
this.setState(curState => ({ expandedIdx: curState.expandedIdx !== idx ? idx : -1 }))
60+
eventBus.emitTabLayoutChange(getPrimaryTabId(this.props.tab))
61+
}}
62+
isExpanded={this.state.expandedIdx === idx}
63+
>
64+
{this.state.expandedIdx !== idx ? strings('Show X', name) : strings('Hide X', name)}
65+
</AccordionToggle>
66+
{this.content(idx)}
67+
</AccordionItem>
68+
</div>
6169
))}
6270
</Accordion>
6371
)

plugins/plugin-client-common/src/components/spi/Accordion/model.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,19 @@ import { Tab } from '@kui-shell/core'
1818

1919
interface Props {
2020
className?: string
21-
names: string[]
22-
content: React.ReactNode[]
2321
isWidthConstrained?: boolean
2422
tab: Tab
23+
24+
/** The titles of the accordion entries */
25+
names: string[]
26+
27+
/**
28+
* The content for the accordion entries. These are intentionally
29+
* delayed via the `() => ...`, to avoid rendering the content for
30+
* all accordion elements up front. See https://github.com/IBM/kui/issues/6582
31+
*
32+
*/
33+
content: (() => React.ReactNode)[]
2534
}
2635

2736
export default Props

plugins/plugin-client-common/web/scss/components/Accordion/PatternFly.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
@import '_mixins';
17+
@import 'mixins';
1818

1919
@include Accordion {
2020
margin: 0.5rem 0 0;
@@ -37,6 +37,7 @@
3737
}
3838

3939
@include AccordionContentBody {
40+
padding: 0;
4041
&:before {
4142
display: none;
4243
}

0 commit comments

Comments
 (0)