Skip to content

Commit

Permalink
Merge pull request #197 from smacker/fix_error_handling
Browse files Browse the repository at this point in the history
Small face-lifting before solving the issue with blank screen
  • Loading branch information
smacker authored Mar 5, 2019
2 parents 23b1a24 + 28225d2 commit c26b450
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 38 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"redux-devtools-extension": "^2.13.2",
"redux-thunk": "^2.2.0",
"styled-components": "^3.3.3",
"uast-viewer": "^0.2.0"
"uast-viewer": "^0.3.0"
},
"devDependencies": {
"enzyme": "^3.3.0",
Expand All @@ -42,6 +42,7 @@
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"lint": "eslint 'src/**/*.js' && prettier -l 'src/**/*.js'",
"fix-lint-errors": "eslint --fix 'src/**/*.js'; prettier --write 'src/**/*.js'"
"fix-lint-errors":
"eslint --fix 'src/**/*.js'; prettier --write 'src/**/*.js'"
}
}
42 changes: 21 additions & 21 deletions server/asset/asset.go

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/components/UASTViewer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import Viewer from 'uast-viewer';
import FlatUASTViewer from 'uast-viewer';
import styled from 'styled-components';

const ROOT_ID = 1;
Expand Down Expand Up @@ -30,21 +30,21 @@ const NotFound = styled.div`
class UASTViewer extends Component {
render() {
const { uastViewerProps, showLocations } = this.props;
const { uast } = uastViewerProps;
const { flatUast } = uastViewerProps;

if (!uast) {
if (!flatUast) {
return null;
}

const searchResults = getSearchResults(uast);
const searchResults = getSearchResults(flatUast);
let rootIds = searchResults || [ROOT_ID];

if (searchResults && !searchResults.length) {
return <NotFound>Nothing found</NotFound>;
}

return (
<Viewer
<FlatUASTViewer
{...uastViewerProps}
rootIds={rootIds}
showLocations={showLocations}
Expand Down
10 changes: 5 additions & 5 deletions src/components/UASTViewer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const shouldMatchSnapshot = comp => {
};

it('empty render', () => {
shouldMatchSnapshot(<UASTViewer uastViewerProps={{ uast: {} }} />);
shouldMatchSnapshot(<UASTViewer uastViewerProps={{ flatUast: {} }} />);
});

const posValue = {
Expand All @@ -28,7 +28,7 @@ const posValue = {

it('tree render', () => {
const uastViewerProps = {
uast: {
flatUast: {
1: { id: 1, expanded: true, n: { '@pos': posValue } },
},
};
Expand All @@ -40,7 +40,7 @@ it('tree render', () => {

it('tree render with locations', () => {
const uastViewerProps = {
uast: {
flatUast: {
1: { id: 1, expanded: true, n: { '@pos': posValue } },
},
};
Expand All @@ -53,7 +53,7 @@ it('tree render with locations', () => {
describe('search results', () => {
it('render', () => {
const uastViewerProps = {
uast: {
flatUast: {
1: { id: 1, n: [{ id: 2 }] },
2: { id: 2, n: { '@type': 'TestType' } },
},
Expand All @@ -64,7 +64,7 @@ describe('search results', () => {

it('empty', () => {
const uastViewerProps = {
uast: {
flatUast: {
1: { id: 1, n: [] },
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/examples/javascript.js.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const javascript_example_1 = ` // Set variables
export const javascript_example_1 = `// Set variables
var user = { firstname: "Homer", surname: "Rubble", email: "[email protected]" };
var output = "";
Expand Down
13 changes: 13 additions & 0 deletions src/state/__snapshots__/errors.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ Array [
]
`;

exports[`errors/reducer ADD single error 1`] = `
Array [
"error1",
]
`;

exports[`errors/reducer ADD single error 2`] = `
Array [
"error1",
"error2",
]
`;

exports[`errors/reducer CLEAR 1`] = `Array []`;

exports[`errors/reducer REMOVE 1`] = `
Expand Down
4 changes: 4 additions & 0 deletions src/state/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function error(obj, type) {
}

function convertErrors(errors, type) {
// it's hard to make sure that errors is an array on higher level
if (!Array.isArray(errors)) {
errors = [errors];
}
return errors.filter(e => !!e).map(e => error(e, type));
}

Expand Down
12 changes: 12 additions & 0 deletions src/state/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ describe('errors/reducer', () => {
).toMatchSnapshot();
});

it('ADD single error', () => {
expect(
reducer(initialState, { type: ADD, errors: 'error1' })
).toMatchSnapshot();
expect(
reducer(initialState.concat(['error1']), {
type: ADD,
errors: ['error2'],
})
).toMatchSnapshot();
});

it('SET', () => {
expect(
reducer(initialState.concat(['error1']), {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8454,10 +8454,10 @@ ua-parser-js@^0.7.18:
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.18.tgz#a7bfd92f56edfb117083b69e31d2aa8882d4b1ed"
integrity sha512-LtzwHlVHwFGTptfNSgezHp7WUlwiqb0gA9AALRbKaERfxwJoiX0A73QbTToxteIAuIaFshhgIZfqK8s7clqgnA==

uast-viewer@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/uast-viewer/-/uast-viewer-0.2.0.tgz#081cc7f2f67bf5db03dc53cd8a451f491c49e699"
integrity sha512-BTYLYY6xSu0ITjC4lO2Kb14Nw4oYKh7i3mChf4HygNJRTJ93FHaYTmyqS38cA3+1FsGnEyKSz+BwATGONLJPDQ==
uast-viewer@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/uast-viewer/-/uast-viewer-0.3.0.tgz#ea5857521e573418cd71c050027f40a413bd8a7c"
integrity sha512-uSYBdRX5GRsrYHqBo6m07YcM7nkoP6RnbUkH0x7+eRUlxpwaNthYjsjv0rgt2yGMfn5NEjdBULBCG9ob4TZs0Q==

[email protected], uglify-js@^3.0.13, uglify-js@^3.1.4:
version "3.4.9"
Expand Down

0 comments on commit c26b450

Please sign in to comment.