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

Closes #267. Show error message from queries #272

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
29 changes: 27 additions & 2 deletions src/js/components/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {
filtersToArray,
getDefaultFilters,
getNameByID,
renderError,
validateFilters
} from '../modules/utilities'
import {fetchSearchResults, resetSearchResults} from '../modules/search-results'
import {grey300, white} from 'material-ui/styles/colors'
import {grey300, red500, white} from 'material-ui/styles/colors'
import {header, headerAppName, main, verticalTop} from '../styles/common'
import React, {Component, PropTypes} from 'react'

Expand Down Expand Up @@ -173,11 +174,35 @@ class Search extends Component {
</div>
)
}

if (searchResults.error) {
const {message} = searchResults.error
const spanStyle = {...style.span, color: red500}
let text = {}

try {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we are doing this here and not inside the action?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another point here is why are we interpretting the "data" sent back from the rest side. why doesn't the rest side just figure out what to send and send it back as a string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was so REST could send an error in any format. Sometimes we want the error formatted to display to a user. For example:
You do not have the correct LACs/COIs to view this data:
LACs: 123_456
COIs: ABC_DEF

A string does not allow this.

text = JSON.parse(message)
} catch (err) {
text.label = message
text.data = {}
}

return (
renderError(text, style.wrapper, spanStyle)
)
}

const {data = []} = searchResults

if (data.length === 0) {
return <div />
const message = {
label: 'No data',
data: {}
}

return (
renderError(message, style.wrapper, style.span)
)
}

const visualization = {
Expand Down
74 changes: 53 additions & 21 deletions src/js/components/visualization/Visualization.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {MapComponent} from './MapComponent'
import {SummaryComponent} from './SummaryComponent'
import {TableComponent} from './TableComponent'
import VisualizationToolbar from './VisualizationToolbar'
import {excludeEmptyFilters, filtersToArray, generateMenuItems} from '../../modules/utilities'
import {grey300, white} from 'material-ui/styles/colors'
import {excludeEmptyFilters, filtersToArray, generateMenuItems, renderError} from '../../modules/utilities'
import {grey300, red500, white} from 'material-ui/styles/colors'
import React, {Component, PropTypes} from 'react'

const components = {ChartComponent, MapComponent, SummaryComponent, TableComponent}
Expand All @@ -21,6 +21,16 @@ const style = {
flexDirection: 'column',
height: '100%',
overflow: 'hidden'
},
flex: {
flex: 1,
position: 'relative'
},
span: {
left: '50%',
position: 'absolute',
top: '50%',
transform: 'translate(-50%, -50%)'
}
}
const getTypeGroup = (type) => {
Expand Down Expand Up @@ -93,6 +103,23 @@ class Visualization extends Component {
typeGroup
}
}

renderError (message) {
const {visualization} = this.props
const {name} = visualization
const spanStyle = {...style.span, color: red500}
const error = renderError(message, style.flex, spanStyle)

return (
<div style={style.container}>
<VisualizationToolbar
title={name}
onClose={this.onClose}
/>
{error}
</div>
)
}

renderLoading () {
const {visualization} = this.props
Expand All @@ -103,15 +130,10 @@ class Visualization extends Component {
<VisualizationToolbar
title={name}
/>
<div style={{flex: 1, position: 'relative'}}>
<div style={style.flex}>
<CircularProgress
size={0.5}
spanStyle={{
left: '50%',
position: 'absolute',
top: '50%',
transform: 'translate(-50%, -50%)'
}}
spanStyle={style.span}
style={{
verticalAlign: 'middle'
}}
Expand All @@ -124,27 +146,23 @@ class Visualization extends Component {
renderNoData () {
const {visualization} = this.props
const {name} = visualization

const message = {
label: 'No data',
data: {}
}
const error = renderError(message, style.flex, style.span)

return (
<div style={style.container}>
<VisualizationToolbar
title={name}
onClose={this.onClose}
/>
<div style={{flex: 1, position: 'relative'}}>
<span
style={{
left: '50%',
position: 'absolute',
top: '50%',
transform: 'translate(-50%, -50%)'
}}
>No data</span>
</div>
{error}
</div>
)
}

renderVisualization () {
const {results, visualization} = this.props
const {data = []} = results
Expand Down Expand Up @@ -185,6 +203,20 @@ class Visualization extends Component {
if (results.isFetching) {
return this.renderLoading()
}

if (results.error) {
const {message} = results.error
let text = {}

try {
text = JSON.parse(message)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments as above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sane reason as above

} catch (err) {
text.label = message
text.data = {}
}

return this.renderError(text)
}

if (data.length === 0) {
return this.renderNoData()
Expand Down
26 changes: 26 additions & 0 deletions src/js/modules/utilities.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,30 @@ export const getOptionalFilters = (requiredFilters, dashboardFilters) => {
}

return optional
}

export const renderError = (message, style, spanStyle) => {
const {data, label} = message

return (
<div style={style}>
<span
style={spanStyle}
>
{label}
{
Object.keys(data).map((key) => {
return (
<p key={key}>
<span>
{key}:
{data[key].toString()}
</span>
</p>
)
})
}
</span>
</div>
)
}