From 4e2a2c169bde48127975156585c5788f1db6e3ab Mon Sep 17 00:00:00 2001 From: idastambuk Date: Fri, 2 Aug 2024 11:34:38 +0200 Subject: [PATCH] Rename datasource file --- ...rce.test.ts => SitewiseDataSource.test.ts} | 2 +- src/{DataSource.ts => SitewiseDataSource.ts} | 22 +++++++++------- src/components/MetaInspector.tsx | 2 +- src/components/browser/AssetBrowser.tsx | 2 +- src/components/query/QueryEditor.test.tsx | 2 +- src/components/query/QueryEditor.tsx | 2 +- src/components/query/types.ts | 2 +- src/module.ts | 2 +- src/sitewiseCache.ts | 2 +- src/variables.ts | 26 +++++++++---------- 10 files changed, 33 insertions(+), 31 deletions(-) rename src/{DataSource.test.ts => SitewiseDataSource.test.ts} (99%) rename src/{DataSource.ts => SitewiseDataSource.ts} (94%) diff --git a/src/DataSource.test.ts b/src/SitewiseDataSource.test.ts similarity index 99% rename from src/DataSource.test.ts rename to src/SitewiseDataSource.test.ts index a77e69cb..49dc4313 100644 --- a/src/DataSource.test.ts +++ b/src/SitewiseDataSource.test.ts @@ -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'; diff --git a/src/DataSource.ts b/src/SitewiseDataSource.ts similarity index 94% rename from src/DataSource.ts rename to src/SitewiseDataSource.ts index 72e6601c..1cb16860 100644 --- a/src/DataSource.ts +++ b/src/SitewiseDataSource.ts @@ -153,16 +153,18 @@ export class DataSource extends DataSourceWithBackend { - 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); + } + }, + }) + ); } } diff --git a/src/components/MetaInspector.tsx b/src/components/MetaInspector.tsx index 30919139..8d54e881 100644 --- a/src/components/MetaInspector.tsx +++ b/src/components/MetaInspector.tsx @@ -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'; diff --git a/src/components/browser/AssetBrowser.tsx b/src/components/browser/AssetBrowser.tsx index b6b432b6..c45d497c 100644 --- a/src/components/browser/AssetBrowser.tsx +++ b/src/components/browser/AssetBrowser.tsx @@ -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'; diff --git a/src/components/query/QueryEditor.test.tsx b/src/components/query/QueryEditor.test.tsx index cddcab1b..78c48bdf 100644 --- a/src/components/query/QueryEditor.test.tsx +++ b/src/components/query/QueryEditor.test.tsx @@ -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'; diff --git a/src/components/query/QueryEditor.tsx b/src/components/query/QueryEditor.tsx index 1585cdca..5ac82c24 100644 --- a/src/components/query/QueryEditor.tsx +++ b/src/components/query/QueryEditor.tsx @@ -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'; diff --git a/src/components/query/types.ts b/src/components/query/types.ts index ab1b9c98..4e34cdd2 100644 --- a/src/components/query/types.ts +++ b/src/components/query/types.ts @@ -1,4 +1,4 @@ -import { DataSource } from 'DataSource'; +import { DataSource } from 'SitewiseDataSource'; import { SitewiseQuery } from 'types'; export interface SitewiseQueryEditorProps { diff --git a/src/module.ts b/src/module.ts index 70227ef4..4329a1c1 100644 --- a/src/module.ts +++ b/src/module.ts @@ -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'; diff --git a/src/sitewiseCache.ts b/src/sitewiseCache.ts index f4abefc9..916771d1 100644 --- a/src/sitewiseCache.ts +++ b/src/sitewiseCache.ts @@ -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'; diff --git a/src/variables.ts b/src/variables.ts index 8400ad9e..6240f7dc 100644 --- a/src/variables.ts +++ b/src/variables.ts @@ -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'; @@ -25,28 +25,28 @@ export class SitewiseVariableSupport extends CustomVariableSupport ): Observable { + parseOptions(response: Observable): Observable { 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(data)}; + return { data: new DataFrameView(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 }; }) - ) + ); } - }