|
1 | 1 | 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' |
3 | 11 |
|
4 | 12 | import {RemoteDataState, SimpleTableViewProperties} from 'src/types' |
5 | 13 | import {ResultsContext} from 'src/dataExplorer/components/ResultsContext' |
6 | 14 |
|
7 | 15 | import SearchWidget from 'src/shared/components/search_widget/SearchWidget' |
8 | 16 | 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' |
10 | 22 |
|
11 | 23 | import './Results.scss' |
12 | 24 |
|
@@ -51,46 +63,119 @@ const EmptyResults: FC = () => { |
51 | 63 | const Results: FC = () => { |
52 | 64 | const [search, setSearch] = useState('') |
53 | 65 | const {result, status} = useContext(ResultsContext) |
| 66 | + const [vizState, setVizState] = useState('table') |
| 67 | + const [viewProperties, setViewProperties] = useState( |
| 68 | + SUPPORTED_VISUALIZATIONS['xy'].initial |
| 69 | + ) |
54 | 70 |
|
55 | 71 | let resultView |
56 | 72 |
|
57 | 73 | if (status === RemoteDataState.NotStarted) { |
58 | 74 | resultView = <EmptyResults /> |
59 | 75 | } 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) |
72 | 105 | } |
| 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 |
73 | 149 |
|
74 | 150 | return ( |
75 | 151 | <div className="data-explorer-results"> |
76 | 152 | <FlexBox direction={FlexDirection.Column} style={{height: '100%'}}> |
77 | 153 | <div className="data-explorer-results--header"> |
78 | 154 | <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} |
92 | 157 | <div className="data-explorer-results--timezone"> |
93 | 158 | <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> |
94 | 179 | </div> |
95 | 180 | </FlexBox> |
96 | 181 | </div> |
|
0 commit comments