Skip to content

Commit 0346933

Browse files
authored
fix(CodeEditor): hide button and link when read-only (#9668)
1 parent 8a6d4d4 commit 0346933

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -526,18 +526,20 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
526526
headingLevel="h4"
527527
/>
528528
<EmptyStateBody>{emptyStateBody}</EmptyStateBody>
529-
<EmptyStateFooter>
530-
<EmptyStateActions>
531-
<Button variant="primary" onClick={open}>
532-
{emptyStateButton}
533-
</Button>
534-
</EmptyStateActions>
535-
<EmptyStateActions>
536-
<Button variant="link" onClick={this.toggleEmptyState}>
537-
{emptyStateLink}
538-
</Button>
539-
</EmptyStateActions>
540-
</EmptyStateFooter>
529+
{!isReadOnly && (
530+
<EmptyStateFooter>
531+
<EmptyStateActions>
532+
<Button variant="primary" onClick={open}>
533+
{emptyStateButton}
534+
</Button>
535+
</EmptyStateActions>
536+
<EmptyStateActions>
537+
<Button variant="link" onClick={this.toggleEmptyState}>
538+
{emptyStateLink}
539+
</Button>
540+
</EmptyStateActions>
541+
</EmptyStateFooter>
542+
)}
541543
</EmptyState>
542544
) : (
543545
<EmptyState variant={EmptyStateVariant.sm}>
@@ -546,13 +548,15 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
546548
icon={<EmptyStateIcon icon={CodeIcon} />}
547549
headingLevel="h4"
548550
/>
549-
<EmptyStateFooter>
550-
<EmptyStateActions>
551-
<Button variant="primary" onClick={this.toggleEmptyState}>
552-
{emptyStateLink}
553-
</Button>
554-
</EmptyStateActions>
555-
</EmptyStateFooter>
551+
{!isReadOnly && (
552+
<EmptyStateFooter>
553+
<EmptyStateActions>
554+
<Button variant="primary" onClick={this.toggleEmptyState}>
555+
{emptyStateLink}
556+
</Button>
557+
</EmptyStateActions>
558+
</EmptyStateFooter>
559+
)}
556560
</EmptyState>
557561
));
558562

packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorBasic.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ export const CodeEditorBasic: React.FunctionComponent = () => {
2323
};
2424

2525
const onEditorDidMount = (editor, monaco) => {
26-
// eslint-disable-next-line no-console
27-
console.log(editor.getValue());
2826
editor.layout();
2927
editor.focus();
3028
monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });

packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorShortcutMainHeader.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { Grid, GridItem, Chip } from '@patternfly/react-core';
44

55
export const CodeEditorShortcutMainHeader: React.FunctionComponent = () => {
66
const onEditorDidMount = (editor, monaco) => {
7-
// eslint-disable-next-line no-console
8-
console.log(editor.getValue());
97
editor.layout();
108
editor.focus();
119
monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });

packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorSizeToFit.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { CodeEditor, Language } from '@patternfly/react-code-editor';
33

44
export const CodeEditorSizeToFit: React.FunctionComponent = () => {
55
const onEditorDidMount = (editor, monaco) => {
6-
// eslint-disable-next-line no-console
7-
console.log(editor.getValue());
86
editor.layout();
97
editor.focus();
108
monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });

0 commit comments

Comments
 (0)