Skip to content

Commit 9b7dda0

Browse files
author
spacedragon
committed
[Code] Change button label based on file type
1 parent 95896c6 commit 9b7dda0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

x-pack/plugins/code/public/components/main/content.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ interface Props extends RouteComponentProps<MainRouteParams> {
8888
repoScope: string[];
8989
fetchMoreCommits(repoUri: string): void;
9090
}
91+
const LANG_MD = 'markdown';
9192

9293
enum ButtonOption {
9394
Code = 'Code',
@@ -96,13 +97,18 @@ enum ButtonOption {
9697
Folder = 'Directory',
9798
}
9899

100+
enum ButtonLabel {
101+
Code = 'Code',
102+
Content = 'Content',
103+
Download = 'Download',
104+
Raw = 'Raw',
105+
}
106+
99107
const Title = styled(EuiTitle)`
100108
margin: ${theme.euiSizeXS} 0 ${theme.euiSize};
101109
`;
102110

103111
class CodeContent extends React.PureComponent<Props> {
104-
public rawButtonOptions = [{ id: 'Raw', label: 'Raw' }];
105-
106112
public findNode = (pathSegments: string[], node: FileTree): FileTree | undefined => {
107113
if (!node) {
108114
return undefined;
@@ -169,12 +175,14 @@ class CodeContent extends React.PureComponent<Props> {
169175
currentTree &&
170176
(currentTree.type === FileTreeItemType.File || currentTree.type === FileTreeItemType.Link)
171177
) {
172-
const { isUnsupported, isOversize, isImage } = this.props.file!;
178+
const { isUnsupported, isOversize, isImage, lang } = this.props.file!;
179+
const isMarkdown = lang === LANG_MD;
180+
const isText = !isUnsupported && !isOversize && !isImage;
173181

174182
const buttonOptions = [
175183
{
176184
id: ButtonOption.Code,
177-
label: ButtonOption.Code,
185+
label: isText && !isMarkdown ? ButtonLabel.Code : ButtonLabel.Content,
178186
},
179187
{
180188
id: ButtonOption.Blame,
@@ -186,6 +194,9 @@ class CodeContent extends React.PureComponent<Props> {
186194
label: ButtonOption.History,
187195
},
188196
];
197+
const rawButtonOptions = [
198+
{ id: 'Raw', label: isText ? ButtonLabel.Raw : ButtonLabel.Download },
199+
];
189200

190201
return (
191202
<ButtonsContainer>
@@ -200,7 +211,7 @@ class CodeContent extends React.PureComponent<Props> {
200211
<EuiButtonGroup
201212
buttonSize="s"
202213
color="primary"
203-
options={this.rawButtonOptions}
214+
options={rawButtonOptions}
204215
type="single"
205216
idSelected={''}
206217
onChange={this.openRawFile}
@@ -338,7 +349,7 @@ class CodeContent extends React.PureComponent<Props> {
338349
/>
339350
);
340351
}
341-
if (fileLanguage === 'markdown') {
352+
if (fileLanguage === LANG_MD) {
342353
return (
343354
<div className="markdown-body code-markdown-container">
344355
<Markdown source={fileContent} escapeHtml={true} skipHtml={true} />

x-pack/plugins/code/public/sagas/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,15 @@ export async function requestFile(
203203
return {
204204
payload,
205205
isImage: true,
206-
content: await response.text(),
206+
content: '',
207207
url,
208208
isUnsupported: false,
209209
};
210210
} else {
211211
return {
212212
payload,
213213
isImage: false,
214-
content: await response.text(),
214+
content: '',
215215
url,
216216
isUnsupported: true,
217217
};

0 commit comments

Comments
 (0)