Skip to content

Commit 450b52f

Browse files
committed
add: stored stream fields in QueryEditor
1 parent b4e9388 commit 450b52f

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/components/QueryEditor.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props)
1212
const myRef: MutableRefObject<string> = useRef('');
1313
const queryValue: string = myRef.current;
1414

15-
const [streams, setStreams]: any = useState([]);
15+
const [streams, setStreams]: any = useState({});
16+
const [streamOptions, setStreamOptions]: any = useState([]);
1617

1718
useEffect(() => {
1819
getStreams(datasource.url).then((response: any) => {
19-
setStreams([
20+
const streams: { [key: string]: any } = {};
21+
response.list.forEach((stream: any) => {
22+
streams[stream.name] = stream;
23+
});
24+
setStreams({ ...streams });
25+
setStreamOptions([
2026
...response.list.map((stream: any) => ({
2127
label: stream.name,
2228
value: stream.name,
@@ -40,14 +46,12 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props)
4046

4147
const streamUpdated = (stream: { label: string; value: string }) => {
4248
console.log(datasource.instanceSettings);
43-
getStreamSchema({ url: datasource.url, stream: stream.value }).then((response: any) => {
44-
onChange({
45-
...query,
46-
stream: stream.value,
47-
streamFields: response.schema,
48-
});
49-
onRunQuery();
49+
onChange({
50+
...query,
51+
stream: stream.value,
52+
streamFields: streams[stream.value].schema,
5053
});
54+
onRunQuery();
5155
};
5256
return (
5357
<div>
@@ -65,7 +69,7 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props)
6569
width: 200px !important;
6670
margin: 8px 0px;
6771
`}
68-
options={streams}
72+
options={streamOptions}
6973
value={query.stream}
7074
onChange={streamUpdated}
7175
></Select>

src/datasource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
110110
if (expression.length > 0) {
111111
expression += ' and ';
112112
}
113-
expression += `${action.options.key}="${action.options.value}"`;
113+
expression += `${action.options.key}='${action.options.value}'`;
114114
break;
115115
}
116116
case 'ADD_FILTER_OUT': {
117117
if (expression.length > 0) {
118118
expression += ' and ';
119119
}
120-
expression += `${action.options.key}!="${action.options.value}"`;
120+
expression += `${action.options.key}!='${action.options.value}'`;
121121
break;
122122
}
123123
}

0 commit comments

Comments
 (0)