Skip to content

Commit 63f62ce

Browse files
committed
- Prettify error messages
- Fix info button css - Raise error on compact flag
1 parent 932e604 commit 63f62ce

File tree

3 files changed

+113
-61
lines changed

3 files changed

+113
-61
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import React from 'react'
2+
import { JSONTree } from 'react-json-tree'
3+
import { ResultsParser } from './parser'
4+
import Graph from './Graph'
5+
import { Table } from './Table'
6+
7+
const isDarkTheme = document.body.classList.contains('theme_DARK')
8+
9+
const json_tree_theme = {
10+
scheme: 'solarized',
11+
author: 'ethan schoonover (http://ethanschoonover.com/solarized)',
12+
base00: '#002b36',
13+
base01: '#073642',
14+
base02: '#586e75',
15+
base03: '#657b83',
16+
base04: '#839496',
17+
base05: '#93a1a1',
18+
base06: '#eee8d5',
19+
base07: '#fdf6e3',
20+
base08: '#dc322f',
21+
base09: '#098658',
22+
base0A: '#b58900',
23+
base0B: '#A31515',
24+
base0C: '#2aa198',
25+
base0D: '#0451A5',
26+
base0E: '#6c71c4',
27+
base0F: '#d33682',
28+
}
29+
30+
export function TableApp(props: { command?: string, data: any }) {
31+
32+
const ErrorResponse = HandleError(props)
33+
34+
if (ErrorResponse !== null) return ErrorResponse
35+
36+
const tableData = ResultsParser(props.data[0].response as any)
37+
38+
return (
39+
<div className="table-view">
40+
<Table
41+
data={tableData.results}
42+
columns={tableData.headers.map(h => ({
43+
field: h,
44+
name: h,
45+
render: d => (
46+
<JSONTree
47+
invertTheme={isDarkTheme}
48+
theme={{
49+
extend: json_tree_theme,
50+
tree: ({ style }) => ({
51+
style: { ...style, backgroundColor: undefined }, // removing default background color from styles
52+
}),
53+
}}
54+
labelRenderer={(key) => key ? key : null}
55+
hideRoot
56+
data={d}
57+
/>
58+
)
59+
}))}
60+
/>
61+
</div>
62+
)
63+
}
64+
65+
66+
export function GraphApp(props: { command?: string, data: any }) {
67+
68+
const ErrorResponse = HandleError(props)
69+
70+
if (ErrorResponse !== null) return ErrorResponse
71+
72+
return (
73+
<div style={{ height: "100%" }}>
74+
<Graph graphKey={props.command.split(' ')[1]} data={props.data[0].response} />
75+
</div>
76+
)
77+
}
78+
79+
function HandleError(props: { command?: string, data: any }): JSX.Element {
80+
const { data: [{ response = '', status = '' } = {}] = [] } = props
81+
82+
if (status === 'fail') {
83+
return <div className="responseFail">{JSON.stringify(response)}</div>
84+
}
85+
86+
if (status === 'success' && typeof(response) === 'string') {
87+
return <div className="responseFail">{JSON.stringify(response)}</div>
88+
}
89+
90+
const command = props.command.split(' ')
91+
92+
if (command[command.length - 1] === '--compact') {
93+
return <div className="responseFail">Queries with '--compact' flag is currently not supported.</div>
94+
}
95+
96+
return null
97+
}

redisinsight/ui/src/packages/redisgraph/src/main.tsx

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
/* eslint-disable react/jsx-filename-extension */
22
import React from 'react'
33
import { render } from 'react-dom'
4-
import result from './result'
5-
import { Table } from './Table'
6-
import { ResultsParser } from './parser'
7-
import Graph from './Graph'
8-
import { JSONTree } from 'react-json-tree'
4+
import { GraphApp, TableApp } from './App'
95

106
interface Props {
117
command?: string
128
data?: { response: any, status: string }[]
139
}
1410

15-
const isDarkTheme = document.body.classList.contains('theme_DARK')
16-
1711
import { appendIconComponentCache } from '@elastic/eui/es/components/icon/icon';
1812
import { icon as EuiIconMagnifyWithPlus } from '@elastic/eui/es/components/icon/assets/magnifyWithPlus';
1913
import { icon as EuiIconMagnifyWithMinus } from '@elastic/eui/es/components/icon/assets/magnifyWithMinus';
@@ -39,67 +33,15 @@ appendIconComponentCache({
3933
cross: EuiIconCross,
4034
})
4135

42-
const json_tree_theme = {
43-
scheme: 'solarized',
44-
author: 'ethan schoonover (http://ethanschoonover.com/solarized)',
45-
base00: '#002b36',
46-
base01: '#073642',
47-
base02: '#586e75',
48-
base03: '#657b83',
49-
base04: '#839496',
50-
base05: '#93a1a1',
51-
base06: '#eee8d5',
52-
base07: '#fdf6e3',
53-
base08: '#dc322f',
54-
base09: '#098658',
55-
base0A: '#b58900',
56-
base0B: '#A31515',
57-
base0C: '#2aa198',
58-
base0D: '#0451A5',
59-
base0E: '#6c71c4',
60-
base0F: '#d33682',
61-
}
62-
63-
6436
const renderGraphTable = (props: Props) => {
65-
const tableData = ResultsParser(props.data[0].response as any)
66-
6737
render(
68-
<div className="table-view">
69-
<Table
70-
data={tableData.results}
71-
columns={tableData.headers.map(h => ({
72-
field: h,
73-
name: h,
74-
render: (d: any) => (
75-
<JSONTree
76-
invertTheme={isDarkTheme}
77-
theme={{
78-
extend: json_tree_theme,
79-
tree: ({ style }) => ({
80-
style: { ...style, backgroundColor: undefined }, // removing default background color from styles
81-
}),
82-
}}
83-
labelRenderer={key => key ? key : null}
84-
hideRoot
85-
data={d}
86-
/>
87-
)
88-
}))}
89-
/>
90-
</div>,
38+
<TableApp data={props.data} command={props.command} />,
9139
document.getElementById('app'))
9240
}
9341

94-
if (process.env.NODE_ENV === 'development') {
95-
renderGraphTable({ command: '', data: result || [] })
96-
}
97-
9842
const renderGraph = (props: Props) => {
9943
render(
100-
<div style={{ height: "100%" }}>
101-
<Graph graphKey={props.command.split(' ')[1]} data={props.data[0].response}/>
102-
</div>,
44+
<GraphApp data={props.data} command={props.command} />,
10345
document.getElementById('app'))
10446
}
10547

redisinsight/ui/src/packages/redisgraph/src/styles/styles.less

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@
7575
justify-content: space-between;
7676
padding-top: 12px;
7777
padding-left: 12px;
78+
79+
.euiButtonIcon {
80+
position: relative;
81+
top: 0px !important;
82+
right:6px !important;
83+
}
84+
7885
}
7986

8087
.info-props {
@@ -226,3 +233,9 @@
226233
margin-right: 12px !important;
227234
}
228235

236+
237+
.responseFail {
238+
color: red;
239+
padding: 12px !important;
240+
font-family: monospace !important;
241+
}

0 commit comments

Comments
 (0)