Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an error message when a js file failed to load #53

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions src/views/tickets/JSViewer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';

import { Dropdown } from 'semantic-ui-react';
import { Dropdown, Message } from 'semantic-ui-react';

import AceEditor from 'react-ace';
import { js as beautify } from 'js-beautify';
Expand All @@ -12,7 +12,7 @@ export default class CodeBlock extends Component {
constructor(props) {
super(props);
this.state = {
ready: false,
filesBeingBlocked: false,
};
}

Expand All @@ -28,8 +28,6 @@ export default class CodeBlock extends Component {
artifact.filename.endsWith('.js')
);

const numberOfFiles = artifacts.count;

for (let i in artifacts) {
const name = artifacts[i].filename;

Expand All @@ -39,7 +37,6 @@ export default class CodeBlock extends Component {
}) === undefined
) {
const fileURL = `http://localhost:8080/api/tickets/${this.props.ticketID}/artifacts/${name}`;

fetch(fileURL, {
method: 'GET',
responseType: 'text',
Expand All @@ -51,10 +48,22 @@ export default class CodeBlock extends Component {
text: <span className="text">{name}</span>,
value: beautify(res),
});

if (this.fileList.count === numberOfFiles) {
this.setState({ ready: true });
}
})
.catch(error => {
this.setState({ filesBeingBlocked: true });
this.fileList.push({
key: name,
text: (
<span className="text">
{name + ' (blocked by the adblocker)'}
</span>
),
value: 'dummy value',
// if we don't put value and this disabled entry is the first one, it will be pre-selected and highlighted
// see https://github.com/Semantic-Org/Semantic-UI-React/issues/3130#issuecomment-530703465
disabled: true,
});
console.log(error);
});
}
}
Expand All @@ -75,6 +84,17 @@ export default class CodeBlock extends Component {
render() {
return (
<>
{this.state.filesBeingBlocked && (
<Message negative style={{ textAlign: 'left' }}>
<Message.Header>
One or more JavaScript files are blocked by your adblocker.
</Message.Header>
<p>
If you want to see all the files, please disable your adblocker
and refresh this page.
</p>
</Message>
)}
<Dropdown
placeholder="Select a File"
fluid
Expand Down