Skip to content

Commit 55f9ac4

Browse files
committed
Remove charts/<context> request
1 parent 159cfa6 commit 55f9ac4

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

src/QueryEditor.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import { Input, LegacyForms, Select } from '@grafana/ui';
33
import { QueryEditorProps, SelectableValue } from '@grafana/data';
44
import { DataSource } from './datasource';
@@ -11,6 +11,7 @@ import { useFetchNodes } from 'shared/hooks/useFetchNodes';
1111
import { Aggreagations, GroupByList, Methods } from 'shared/constants';
1212
import { useFetchDimensions } from 'shared/hooks/useFetchDimensions';
1313
import { Dropdown } from 'shared/types/dropdown.interface';
14+
import { getDimensions, getFilters, getGroupingByList, defaultFilter } from 'shared/utils/transformations';
1415
import PubSub from 'pubsub-js';
1516

1617
type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>;
@@ -47,7 +48,11 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, range, onChange, onRu
4748
const { rooms, fetchRooms } = useFetchRooms(baseUrl);
4849
const { nodes, fetchNodes } = useFetchNodes(baseUrl);
4950
const { contexts, fetchContexts } = useFetchContexts(baseUrl);
50-
const { allDimensions, groupingByList, filters, units, fetchDimensions } = useFetchDimensions(baseUrl);
51+
//const { fetchDimensions } = useFetchDimensions(baseUrl);
52+
const [allDimensions, setAllDimension] = useState([]);
53+
const [units, setUnits] = useState('');
54+
const [filters, setFilters] = useState<any>(defaultFilter);
55+
const [groupingByList, setGroupingByList] = useState<Dropdown[]>(GroupByList);
5156

5257
const filterList = React.useMemo(() => Object.keys(filters).map((s) => ({ label: s, value: s })), [filters]);
5358
const nodeList = React.useMemo(() => nodes?.map((c: any) => ({ label: c.name, value: c.id })), [nodes]);
@@ -57,7 +62,11 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, range, onChange, onRu
5762
const mySubscriber = (msg: any, data: any) => {
5863
const { summary, view } = data?.data || {};
5964
const { nodes = [], instances = [], labels = [] } = summary || {};
60-
//const { dimensions, units } = view || {};
65+
const { dimensions, units } = view || {};
66+
setFilters(getFilters(labels));
67+
setGroupingByList(getGroupingByList(labels));
68+
setAllDimension(getDimensions(dimensions));
69+
setUnits(units);
6170
setTotalNodes(nodes.length);
6271
setTotalInstances(instances.length);
6372
};
@@ -124,7 +133,7 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, range, onChange, onRu
124133
});
125134
}
126135

127-
fetchDimensions({ spaceId, roomId, contextId, nodeIDs: filteredNodes.map((n: any) => n.value) });
136+
//fetchDimensions({ spaceId, roomId, contextId, nodeIDs: filteredNodes.map((n: any) => n.value) });
128137
}
129138
}, [contextId]); // eslint-disable-line
130139

@@ -196,7 +205,7 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, range, onChange, onRu
196205
setSelectedMethod(Methods[0]);
197206
setSelectedAggregations(Aggreagations[0]);
198207

199-
fetchDimensions({ spaceId, roomId, contextId: v.value, nodeIDs: selectedNodes?.map((n: any) => n.value) || [] });
208+
//fetchDimensions({ spaceId, roomId, contextId: v.value, nodeIDs: selectedNodes?.map((n: any) => n.value) || [] });
200209
onChange({ ...query, contextId: v.value });
201210
onRunQuery();
202211
};
@@ -212,7 +221,7 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, range, onChange, onRu
212221
setSelectedMethod(Methods[0]);
213222
setSelectedAggregations(Aggreagations[0]);
214223

215-
fetchDimensions({ spaceId, roomId, contextId, nodeIDs: data });
224+
//fetchDimensions({ spaceId, roomId, contextId, nodeIDs: data });
216225
setSelectedNodes(data);
217226
onChange({ ...query, spaceId, roomId, contextId, nodes: data } as MyQuery);
218227
onRunQuery();
@@ -239,7 +248,7 @@ const QueryEditor: React.FC<Props> = ({ datasource, query, range, onChange, onRu
239248
onChange({ ...query, filterBy: undefined, filterValue: undefined });
240249
onRunQuery();
241250
} else {
242-
setFilterByValues(filters[v?.value || ''].map((v) => ({ label: v, value: v })));
251+
setFilterByValues(filters[v?.value || ''].map((v: string) => ({ label: v, value: v })));
243252
}
244253
};
245254

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { GroupByList } from 'shared/constants';
2+
3+
export const getDimensions = (dimensions: any) => {
4+
const { ids, names } = dimensions;
5+
if (!ids) return [];
6+
return ids.map((id: string, index: number) => ({ value: id, label: names[index] || id }));
7+
};
8+
9+
export const defaultFilter = { 'No filter': [] };
10+
11+
export const getFilters = (labels: any[]) => {
12+
if (!labels?.length) return defaultFilter;
13+
return {
14+
...defaultFilter,
15+
...labels.reduce((acc: any, label: any) => {
16+
acc[label.id] = (acc.vl || []).map((value: any) => value.id);
17+
return acc;
18+
}, {}),
19+
};
20+
};
21+
22+
export const getGroupingByList = (labels: any) => {
23+
return { ...GroupByList, ...labels.map((label: any) => ({ value: label.id, label: label.id })) };
24+
};

0 commit comments

Comments
 (0)