Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
revert to old query and state names
Browse files Browse the repository at this point in the history
  • Loading branch information
Biglr committed Jul 23, 2021
1 parent c9d9f2e commit 5c2de61
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class DataSource extends DataSourceApi<AkenzaQuery, AkenzaDataSourceConfi
const to: DateTime = options.range.to;
const panelData: MutableDataFrame[] = [];
for (let target of options.targets) {
if (target.deviceId && target.topic && target.dataKey && !target.hide) {
if (target.assetId && target.topic && target.dataKey && !target.hide) {
const timeSeriesData = await this.getTimeSeriesData(target, from.toISOString(), to.toISOString());
const data: number[] = [];
const time: number[] = [];
Expand All @@ -62,7 +62,7 @@ export class DataSource extends DataSourceApi<AkenzaQuery, AkenzaDataSourceConfi
fields: [
{ name: 'Time', values: time, type: FieldType.time },
{
name: target.device?.name + ' - ' + target.dataKey,
name: target.asset?.name + ' - ' + target.dataKey,
values: data,
type: FieldType.number,
},
Expand All @@ -85,7 +85,7 @@ export class DataSource extends DataSourceApi<AkenzaQuery, AkenzaDataSourceConfi
},
};

return this.doRequest('/v2/assets/' + query.deviceId + '/query/time-series', 'POST', null, body).then(
return this.doRequest('/v2/assets/' + query.assetId + '/query/time-series', 'POST', null, body).then(
(timeSeriesData: HttpPromise<TimeSeriesData>) => {
return timeSeriesData.data;
},
Expand Down
50 changes: 25 additions & 25 deletions src/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export class QueryEditor extends PureComponent<Props, QueryEditorState> {
super(props);
const query = this.props.query;
// initialize the select values and their options if the panel has been saved before, will initialize empty otherwise
const deviceSelectValue = {
label: query.device?.name || undefined,
value: query.deviceId || null,
device: query.device,
const assetSelectValue = {
label: query.asset?.name || undefined,
value: query.assetId || null,
device: query.asset,
};
const topicSelectValue = {
label: query.topic,
Expand All @@ -37,8 +37,8 @@ export class QueryEditor extends PureComponent<Props, QueryEditorState> {
};
// initialize the state
this.state = {
deviceValue: deviceSelectValue,
deviceOptions: [deviceSelectValue],
assetValue: assetSelectValue,
assetOptions: [assetSelectValue],
topicValue: topicSelectValue,
topicOptions: [topicSelectValue],
dataKeyValue: dataKeySelectValue,
Expand Down Expand Up @@ -73,10 +73,10 @@ export class QueryEditor extends PureComponent<Props, QueryEditorState> {
}
// load the device list
this.queryDevicesAndAssembleSelectionOptions(undefined, false, () => {
if (query.deviceId && query.topic) {
if (query.assetId && query.topic) {
// query contains values if the panel was saved at some point, meaning the topic and data key selection should be loaded as well
this.loadTopicsAndAssembleSelectionOptions(query.deviceId!, () => {
this.loadDataKeysAndAssembleSelectionOptions(query.deviceId!, query.topic!, () => {
this.loadTopicsAndAssembleSelectionOptions(query.assetId!, () => {
this.loadDataKeysAndAssembleSelectionOptions(query.assetId!, query.topic!, () => {
// set the initial loading state once everything has been loaded
this.initialLoadingComplete = true;
});
Expand Down Expand Up @@ -107,7 +107,7 @@ export class QueryEditor extends PureComponent<Props, QueryEditorState> {
// modify the state
this.setState((prevState) => ({
...prevState,
deviceOptions: deviceSelectOptions,
assetOptions: deviceSelectOptions,
}));
// execute the callback if set
if (callback) {
Expand Down Expand Up @@ -179,8 +179,8 @@ export class QueryEditor extends PureComponent<Props, QueryEditorState> {
loadingDevices,
loadingTopics,
loadingDataKeys,
deviceOptions,
deviceValue,
assetOptions,
assetValue,
dataKeyOptions,
dataKeyValue,
topicOptions,
Expand All @@ -198,8 +198,8 @@ export class QueryEditor extends PureComponent<Props, QueryEditorState> {
isLoading={loadingDevices}
placeholder={'Select a device'}
noOptionsMessage={'No devices available'}
options={deviceOptions}
value={deviceValue}
options={assetOptions}
value={assetValue}
onChange={this.onDeviceSelectionChange}
width={48}
onInputChange={this.onDeviceInputChange}
Expand All @@ -209,7 +209,7 @@ export class QueryEditor extends PureComponent<Props, QueryEditorState> {
<div className="gf-form-label">Topic:</div>
<Select
menuPlacement={'bottom'}
disabled={!query.deviceId}
disabled={!query.assetId}
isLoading={loadingTopics}
placeholder={'Select a topic'}
noOptionsMessage={'No topics available'}
Expand Down Expand Up @@ -252,17 +252,17 @@ export class QueryEditor extends PureComponent<Props, QueryEditorState> {
onDeviceSelectionChange = (deviceSelection: SelectableValue<string>): void => {
const { onChange, query, onRunQuery } = this.props;
// check if the same value was selected again (no need to re-trigger any updates in this case)
if (deviceSelection?.value !== query.deviceId) {
if (deviceSelection?.value !== query.assetId) {
// modify the query
onChange({
...query,
deviceId: deviceSelection?.value,
device: deviceSelection?.device,
assetId: deviceSelection?.value,
asset: deviceSelection?.device,
});
// modify the state
this.setState((prevState) => ({
...prevState,
deviceValue: deviceSelection,
assetValue: deviceSelection,
}));
// load the topics if the event contains a device id
if (deviceSelection?.value) {
Expand All @@ -288,8 +288,8 @@ export class QueryEditor extends PureComponent<Props, QueryEditorState> {
topicValue: topicSelection,
}));
// load data keys if the topic and the deviceId are present
if (topicSelection.value && query.deviceId) {
this.loadDataKeysAndAssembleSelectionOptions(query.deviceId, topicSelection.value);
if (topicSelection.value && query.assetId) {
this.loadDataKeysAndAssembleSelectionOptions(query.assetId, topicSelection.value);
}
// execute the query
onRunQuery();
Expand Down Expand Up @@ -320,15 +320,15 @@ export class QueryEditor extends PureComponent<Props, QueryEditorState> {
// modify the query
onChange({
...query,
deviceId: '',
device: undefined,
assetId: '',
asset: undefined,
topic: '',
dataKey: '',
});
// reset the state
this.setState({
deviceValue: {},
deviceOptions: [],
assetValue: {},
assetOptions: [],
topicValue: {},
topicOptions: [],
dataKeyValue: {},
Expand Down
4 changes: 2 additions & 2 deletions src/types/PluginTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { DataQuery, DataSourceJsonData } from '@grafana/data';
import { Device } from './AkenzaTypes';

export interface AkenzaQuery extends DataQuery {
deviceId?: string;
device?: Device;
assetId?: string;
asset?: Device;
topic?: string;
dataKey?: string;
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export interface AkenzaErrorMessage {
}

export interface QueryEditorState {
deviceValue: SelectableValue;
deviceOptions: SelectableValue[];
assetValue: SelectableValue;
assetOptions: SelectableValue[];
topicValue?: SelectableValue;
topicOptions: SelectableValue[];
dataKeyValue?: SelectableValue;
Expand Down

0 comments on commit 5c2de61

Please sign in to comment.