Skip to content

Commit

Permalink
Rename datasource file
Browse files Browse the repository at this point in the history
  • Loading branch information
idastambuk committed Aug 2, 2024
1 parent fa74b8d commit 4e2a2c1
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/DataSource.test.ts → src/SitewiseDataSource.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataSource } from './DataSource';
import { DataSource } from './SitewiseDataSource';
import { DataSourceInstanceSettings, PluginMeta, ScopedVar, ScopedVars } from '@grafana/data';
import { QueryType, SitewiseOptions, SitewiseQuery } from './types';

Expand Down
22 changes: 12 additions & 10 deletions src/DataSource.ts → src/SitewiseDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,18 @@ export class DataSource extends DataSourceWithBackend<SitewiseQuery, SitewiseOpt
return super.query(request).toPromise();
},
cachedResponse: cachedInfo?.cachedResponse,
}).toObservable().pipe(
// Cache the last (done) response
tap({
next: (response) => {
if (response.state === LoadingState.Done) {
this.relativeRangeCache.set(request, response);
}
},
},)
);
})
.toObservable()
.pipe(
// Cache the last (done) response
tap({
next: (response) => {
if (response.state === LoadingState.Done) {
this.relativeRangeCache.set(request, response);
}
},
})
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/MetaInspector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { PureComponent } from 'react';
import { MetadataInspectorProps, DataFrame } from '@grafana/data';
import { DataSource } from '../DataSource';
import { DataSource } from '../SitewiseDataSource';
import { SitewiseQuery, SitewiseOptions, SitewiseCustomMeta } from '../types';
import { Tag } from '@grafana/ui';

Expand Down
2 changes: 1 addition & 1 deletion src/components/browser/AssetBrowser.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import { Button, Icon, Modal, Spinner, Tab, TabContent, TabsBar } from '@grafana/ui';
import { AssetInfo } from '../../types';
import { DataSource } from 'DataSource';
import { DataSource } from 'SitewiseDataSource';
import { SitewiseCache } from 'sitewiseCache';
import { BrowseModels } from './BrowseModels';
import { BrowseHierarchy } from './BrowseHierarchy';
Expand Down
2 changes: 1 addition & 1 deletion src/components/query/QueryEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { DataQueryRequest, DataSourceInstanceSettings, QueryEditorProps } from '@grafana/data';
import { DataSource } from 'DataSource';
import { DataSource } from 'SitewiseDataSource';
import { QueryType, SitewiseOptions, SitewiseQuery } from 'types';
import { QueryEditor } from './QueryEditor';
import { of } from 'rxjs';
Expand Down
2 changes: 1 addition & 1 deletion src/components/query/QueryEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import defaults from 'lodash/defaults';
import React from 'react';
import { QueryEditorProps, SelectableValue } from '@grafana/data';
import { DataSource } from 'DataSource';
import { DataSource } from 'SitewiseDataSource';
import { SitewiseQuery, SitewiseOptions, QueryType, ListAssetsQuery } from 'types';
import { Icon, LinkButton, Select } from '@grafana/ui';
import { QueryTypeInfo, siteWiseQueryTypes, changeQueryType } from 'queryInfo';
Expand Down
2 changes: 1 addition & 1 deletion src/components/query/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataSource } from 'DataSource';
import { DataSource } from 'SitewiseDataSource';
import { SitewiseQuery } from 'types';

export interface SitewiseQueryEditorProps<TQuery extends SitewiseQuery = SitewiseQuery> {
Expand Down
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataSourcePlugin } from '@grafana/data';
import { DataSource } from './DataSource';
import { DataSource } from './SitewiseDataSource';
import { SitewiseQuery, SitewiseOptions } from './types';
import { MetaInspector } from 'components/MetaInspector';
import { ConfigEditor } from 'components/ConfigEditor';
Expand Down
2 changes: 1 addition & 1 deletion src/sitewiseCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataFrameView, SelectableValue } from '@grafana/data';
import { DataSource } from 'DataSource';
import { DataSource } from 'SitewiseDataSource';
import { ListAssetsQuery, ListAssociatedAssetsQuery, QueryType } from 'types';
import { AssetModelSummary, AssetSummary, DescribeAssetResult } from './queryResponseTypes';
import { AssetInfo, AssetPropertyInfo } from './types';
Expand Down
26 changes: 13 additions & 13 deletions src/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { assign } from 'lodash';
import { QueryType, SitewiseQuery } from './types';
import { DataSource } from './DataSource';
import { DataSource } from './SitewiseDataSource';
import { DataQueryRequest, DataQueryResponse, CustomVariableSupport, DataFrameView } from '@grafana/data';
import { QueryEditor } from './components/query/QueryEditor';
import { AssetModelSummary } from 'queryResponseTypes';
Expand All @@ -25,28 +25,28 @@ export class SitewiseVariableSupport extends CustomVariableSupport<DataSource, S
case QueryType.ListAssociatedAssets:
return this.parseOptions(response);
default:
return response
return response;
}
}

parseOptions(response: Observable<DataQueryResponse> ): Observable<DataQueryResponse> {
parseOptions(response: Observable<DataQueryResponse>): Observable<DataQueryResponse> {
return response.pipe(
map((res) => {
let data = []
let data = [];
if (res.data.length) {
data = res.data[0]
data = res.data[0];
}
return {data: new DataFrameView<AssetModelSummary>(data)};
return { data: new DataFrameView<AssetModelSummary>(data) };
}),
map((res) => {
const newData = res.data.map((m)=>{
const newData = res.data.map((m) => {
return {
value: m.id,
text: m.name,
}})
return {data:newData}
value: m.id,
text: m.name,
};
});
return { data: newData };
})
)
);
}

}

0 comments on commit 4e2a2c1

Please sign in to comment.