Skip to content

Commit 8cb777d

Browse files
authored
feat: add visualizations (#4754)
1 parent 9ca2b7f commit 8cb777d

File tree

2 files changed

+116
-27
lines changed

2 files changed

+116
-27
lines changed

src/dataExplorer/components/Results.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ $cf-radius-lg: $cf-radius + 4px;
5454
color: $cf-grey-55;
5555
padding: 0 $cf-space-2xs;
5656
}
57+
58+
.de-config-visualization-button {
59+
margin-left: $cf-space-2xs;
60+
}

src/dataExplorer/components/Results.tsx

Lines changed: 112 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import React, {FC, useState, useContext} from 'react'
2-
import {FlexBox, FlexDirection, ComponentStatus} from '@influxdata/clockface'
2+
import {
3+
FlexBox,
4+
FlexDirection,
5+
SelectGroup,
6+
Button,
7+
IconFont,
8+
ComponentStatus,
9+
ComponentColor,
10+
} from '@influxdata/clockface'
311

412
import {RemoteDataState, SimpleTableViewProperties} from 'src/types'
513
import {ResultsContext} from 'src/dataExplorer/components/ResultsContext'
614

715
import SearchWidget from 'src/shared/components/search_widget/SearchWidget'
816
import TimeZoneDropdown from 'src/shared/components/TimeZoneDropdown'
9-
import {View} from 'src/visualization'
17+
import {
18+
View,
19+
ViewTypeDropdown,
20+
SUPPORTED_VISUALIZATIONS,
21+
} from 'src/visualization'
1022

1123
import './Results.scss'
1224

@@ -51,46 +63,119 @@ const EmptyResults: FC = () => {
5163
const Results: FC = () => {
5264
const [search, setSearch] = useState('')
5365
const {result, status} = useContext(ResultsContext)
66+
const [vizState, setVizState] = useState('table')
67+
const [viewProperties, setViewProperties] = useState(
68+
SUPPORTED_VISUALIZATIONS['xy'].initial
69+
)
5470

5571
let resultView
5672

5773
if (status === RemoteDataState.NotStarted) {
5874
resultView = <EmptyResults />
5975
} else {
60-
resultView = (
61-
<View
62-
loading={status}
63-
properties={
64-
{
65-
type: 'simple-table',
66-
showAll: false,
67-
} as SimpleTableViewProperties
68-
}
69-
result={result.parsed}
70-
/>
71-
)
76+
if (vizState === 'table') {
77+
resultView = (
78+
<View
79+
loading={status}
80+
properties={
81+
{
82+
type: 'simple-table',
83+
showAll: false,
84+
} as SimpleTableViewProperties
85+
}
86+
result={result.parsed}
87+
/>
88+
)
89+
} else {
90+
resultView = (
91+
<div style={{height: '100%', width: '100%', padding: 12}}>
92+
<View
93+
loading={status}
94+
properties={viewProperties}
95+
result={result.parsed}
96+
/>
97+
</div>
98+
)
99+
}
100+
}
101+
102+
const dataExists = result.parsed && Object.entries(result.parsed).length
103+
const updateType = viewType => {
104+
setViewProperties(SUPPORTED_VISUALIZATIONS[viewType].initial)
72105
}
106+
const launcher = () => {}
107+
108+
const tableHeader =
109+
vizState === 'table' ? (
110+
<>
111+
<div style={{width: '300px'}}>
112+
<SearchWidget
113+
placeholderText="Search results..."
114+
onSearch={setSearch}
115+
searchTerm={search}
116+
status={
117+
status === RemoteDataState.Done
118+
? ComponentStatus.Default
119+
: ComponentStatus.Disabled
120+
}
121+
/>
122+
</div>
123+
<QueryStat />
124+
</>
125+
) : null
126+
127+
const vizHeader =
128+
vizState === 'graph' ? (
129+
<>
130+
<ViewTypeDropdown
131+
viewType={viewProperties.type}
132+
onUpdateType={updateType}
133+
/>
134+
<Button
135+
text="Customize"
136+
icon={IconFont.CogSolid_New}
137+
onClick={launcher}
138+
status={
139+
dataExists ? ComponentStatus.Default : ComponentStatus.Disabled
140+
}
141+
color={ComponentColor.Default}
142+
titleText={
143+
dataExists ? 'Configure Visualization' : 'No data to visualize yet'
144+
}
145+
className="de-config-visualization-button"
146+
/>
147+
</>
148+
) : null
73149

74150
return (
75151
<div className="data-explorer-results">
76152
<FlexBox direction={FlexDirection.Column} style={{height: '100%'}}>
77153
<div className="data-explorer-results--header">
78154
<FlexBox>
79-
<div style={{width: '300px'}}>
80-
<SearchWidget
81-
placeholderText="Search results..."
82-
onSearch={setSearch}
83-
searchTerm={search}
84-
status={
85-
status === RemoteDataState.Done
86-
? ComponentStatus.Default
87-
: ComponentStatus.Disabled
88-
}
89-
/>
90-
</div>
91-
<QueryStat />
155+
{tableHeader}
156+
{vizHeader}
92157
<div className="data-explorer-results--timezone">
93158
<TimeZoneDropdown />
159+
<SelectGroup style={{marginRight: 12}}>
160+
<SelectGroup.Option
161+
id="table"
162+
name="viz-setting"
163+
value="table"
164+
active={vizState === 'table'}
165+
onClick={setVizState}
166+
>
167+
Table
168+
</SelectGroup.Option>
169+
<SelectGroup.Option
170+
id="graph"
171+
name="viz-setting"
172+
value="graph"
173+
active={vizState === 'graph'}
174+
onClick={setVizState}
175+
>
176+
Graph
177+
</SelectGroup.Option>
178+
</SelectGroup>
94179
</div>
95180
</FlexBox>
96181
</div>

0 commit comments

Comments
 (0)