diff --git a/src/RelativeRangeRequestCache/RelativeRangeCache.test.ts b/src/RelativeRangeRequestCache/RelativeRangeCache.test.ts index fc5556da..d83761fd 100644 --- a/src/RelativeRangeRequestCache/RelativeRangeCache.test.ts +++ b/src/RelativeRangeRequestCache/RelativeRangeCache.test.ts @@ -1,7 +1,7 @@ import { FieldType, LoadingState, dateTime } from '@grafana/data'; import { RelativeRangeCache } from 'RelativeRangeRequestCache/RelativeRangeCache'; import { QueryType, SiteWiseTimeOrder } from 'types'; -import { parseSiteWiseRequestCacheId } from './cacheIdUtils'; +import { generateSiteWiseRequestCacheId } from './cacheIdUtils'; describe('RelativeRangeCache', () => { const requestId = 'mock-request-id'; @@ -146,7 +146,7 @@ describe('RelativeRangeCache', () => { ]; const cacheData = { - [parseSiteWiseRequestCacheId(request)]: { + [generateSiteWiseRequestCacheId(request)]: { queries: cachedQueryInfo, range, }, @@ -320,7 +320,7 @@ describe('RelativeRangeCache', () => { ]; const cacheData = { - [parseSiteWiseRequestCacheId(requestDescending)]: { + [generateSiteWiseRequestCacheId(requestDescending)]: { queries: cachedQueryInfoDescending, range, }, @@ -463,7 +463,7 @@ describe('RelativeRangeCache', () => { ]; const cacheData = { - [parseSiteWiseRequestCacheId(request)]: { + [generateSiteWiseRequestCacheId(request)]: { queries: cachedQueryInfo, range, }, diff --git a/src/RelativeRangeRequestCache/RelativeRangeCache.ts b/src/RelativeRangeRequestCache/RelativeRangeCache.ts index 68693431..ed9b00a8 100644 --- a/src/RelativeRangeRequestCache/RelativeRangeCache.ts +++ b/src/RelativeRangeRequestCache/RelativeRangeCache.ts @@ -1,7 +1,7 @@ import { DataFrame, DataQueryRequest, DataQueryResponse, LoadingState, TimeRange } from '@grafana/data'; import { isTimeRangeCoveringStart } from 'timeRangeUtils'; import { SitewiseQuery } from 'types'; -import { RequestCacheId, parseSiteWiseRequestCacheId } from './cacheIdUtils'; +import { RequestCacheId, generateSiteWiseRequestCacheId } from './cacheIdUtils'; import { CachedQueryInfo, TIME_SERIES_QUERY_TYPES } from './types'; import { trimCachedQueryDataFramesAtStart, trimCachedQueryDataFramesEnding } from './dataFrameUtils'; import { getRefreshRequestRange, isCacheableTimeRange } from './timeRangeUtils'; @@ -51,7 +51,7 @@ export class RelativeRangeCache { return; } - const requestCacheId = parseSiteWiseRequestCacheId(request); + const requestCacheId = generateSiteWiseRequestCacheId(request); const queryIdMap = new Map(targets.map(q => [q.refId, q])); @@ -117,7 +117,7 @@ export class RelativeRangeCache { * @returns Cached data info if found, undefined otherwise */ private lookupCachedData(request: DataQueryRequest) { - const requestCacheId = parseSiteWiseRequestCacheId(request); + const requestCacheId = generateSiteWiseRequestCacheId(request); const cachedDataInfo = this.responseDataMap.get(requestCacheId); return cachedDataInfo; diff --git a/src/RelativeRangeRequestCache/cacheIdUtils.test.ts b/src/RelativeRangeRequestCache/cacheIdUtils.test.ts index 7e122f7d..d8a2d33e 100644 --- a/src/RelativeRangeRequestCache/cacheIdUtils.test.ts +++ b/src/RelativeRangeRequestCache/cacheIdUtils.test.ts @@ -1,5 +1,5 @@ import { QueryType, SiteWiseQuality, SiteWiseResolution, SiteWiseResponseFormat, SiteWiseTimeOrder } from 'types'; -import { parseSiteWiseQueriesCacheId, parseSiteWiseRequestCacheId } from './cacheIdUtils'; +import { generateSiteWiseQueriesCacheId, generateSiteWiseRequestCacheId } from './cacheIdUtils'; import { dateTime } from '@grafana/data'; import { SitewiseQueriesUnion } from './types'; @@ -30,9 +30,9 @@ function createSiteWiseQuery(id: number): SitewiseQueriesUnion { }; } -describe('parseSiteWiseQueriesCacheId()', () => { +describe('generateSiteWiseQueriesCacheId()', () => { it('parses SiteWise Queries into cache Id', () => { - const actualId = parseSiteWiseQueriesCacheId([createSiteWiseQuery(1), createSiteWiseQuery(2)]); + const actualId = generateSiteWiseQueriesCacheId([createSiteWiseQuery(1), createSiteWiseQuery(2)]); const expectedId = JSON.stringify([ '["PropertyValueHistory","us-west-2","table","mock-asset-id-1",["mock-asset-id-1"],"mock-property-id-1","mock-property-alias-1","ANY","AUTO",true,true,1000,"grafana-iot-sitewise-datasource","mock-datasource-uid","ASCENDING",true,"mock-hierarchy-1","mock-model-1","ALL"]', '["PropertyValueHistory","us-west-2","table","mock-asset-id-2",["mock-asset-id-2"],"mock-property-id-2","mock-property-alias-2","ANY","AUTO",true,true,1000,"grafana-iot-sitewise-datasource","mock-datasource-uid","ASCENDING",true,"mock-hierarchy-2","mock-model-2","ALL"]' @@ -68,8 +68,8 @@ describe('parseSiteWiseQueriesCacheId()', () => { queryType: QueryType.PropertyValue, }; - const order1 = parseSiteWiseQueriesCacheId([query2, query1]); - const order2 = parseSiteWiseQueriesCacheId([query1, query2]); + const order1 = generateSiteWiseQueriesCacheId([query2, query1]); + const order2 = generateSiteWiseQueriesCacheId([query1, query2]); expect(order1).toEqual(order2); }); @@ -80,7 +80,7 @@ describe('parseSiteWiseQueriesCacheId()', () => { refId: 'A-1', queryType: QueryType.ListAssets, }; - const actualId = parseSiteWiseQueriesCacheId([query]); + const actualId = generateSiteWiseQueriesCacheId([query]); const expectedId = JSON.stringify([ '["ListAssets",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]', ]); @@ -89,7 +89,7 @@ describe('parseSiteWiseQueriesCacheId()', () => { }); }); -describe('parseSiteWiseRequestCacheId()', () => { +describe('generateSiteWiseRequestCacheId()', () => { it('parses SiteWise Queries into cache Id', () => { const request = { requestId: 'mock-request-id', @@ -117,6 +117,6 @@ describe('parseSiteWiseRequestCacheId()', () => { ]) ]); - expect(parseSiteWiseRequestCacheId(request)).toEqual(expectedId); + expect(generateSiteWiseRequestCacheId(request)).toEqual(expectedId); }); }); diff --git a/src/RelativeRangeRequestCache/cacheIdUtils.ts b/src/RelativeRangeRequestCache/cacheIdUtils.ts index 91ca6df3..c54636d0 100644 --- a/src/RelativeRangeRequestCache/cacheIdUtils.ts +++ b/src/RelativeRangeRequestCache/cacheIdUtils.ts @@ -3,16 +3,16 @@ import { SitewiseQueriesUnion } from './types'; export type RequestCacheId = string; -export function parseSiteWiseRequestCacheId(request: DataQueryRequest): RequestCacheId { +export function generateSiteWiseRequestCacheId(request: DataQueryRequest): RequestCacheId { const { targets, range: { raw: { from } } } = request; - return JSON.stringify([from, parseSiteWiseQueriesCacheId(targets)]); + return JSON.stringify([from, generateSiteWiseQueriesCacheId(targets)]); } type QueryCacheId = string; -export function parseSiteWiseQueriesCacheId(queries: SitewiseQueriesUnion[]): QueryCacheId { - const cacheIds = queries.map(parseSiteWiseQueryCacheId).sort(); +export function generateSiteWiseQueriesCacheId(queries: SitewiseQueriesUnion[]): QueryCacheId { + const cacheIds = queries.map(generateSiteWiseQueryCacheId).sort(); return JSON.stringify(cacheIds); } @@ -20,7 +20,7 @@ export function parseSiteWiseQueriesCacheId(queries: SitewiseQueriesUnion[]): Qu /** * Parse query to cache id. */ -function parseSiteWiseQueryCacheId(query: SitewiseQueriesUnion): QueryCacheId { +function generateSiteWiseQueryCacheId(query: SitewiseQueriesUnion): QueryCacheId { const { queryType, region, diff --git a/src/RelativeRangeRequestCache/dataFrameUtils.ts b/src/RelativeRangeRequestCache/dataFrameUtils.ts index 6dce619a..7cbb972e 100644 --- a/src/RelativeRangeRequestCache/dataFrameUtils.ts +++ b/src/RelativeRangeRequestCache/dataFrameUtils.ts @@ -13,10 +13,8 @@ import { trimTimeSeriesDataFrame, trimTimeSeriesDataFrameReversedTime } from 'da * For property value queries, it will return an empty data frame. * For all other queries, it will return the trimmed data frame. * - * @param cachedQueryInfos - Cached query infos - * @param queryType - Query type - * @param cachedQueryInfos - Cached query infos - * @param cacheRange - Cache range + * @param cachedQueryInfos - Cached query infos to trim + * @param cacheRange - Cache range to include * @returns Trimmed data frames */ export function trimCachedQueryDataFramesAtStart(cachedQueryInfos: CachedQueryInfo[], cacheRange: AbsoluteTimeRange): DataFrame[] { @@ -64,10 +62,9 @@ export function trimCachedQueryDataFramesAtStart(cachedQueryInfos: CachedQueryIn * For descending ordered data frames, it will return the trimmed data frame. * For all other queries, it will return an empty data frame. * - * @param cachedQueryInfos - Cached query infos - * @param cachedQueryInfos - * @param cacheRange - * @returns + * @param cachedQueryInfos - Cached query infos to trim + * @param cacheRange - Cache range to include + * @returns Trimmed data frames */ export function trimCachedQueryDataFramesEnding(cachedQueryInfos: CachedQueryInfo[], cacheRange: AbsoluteTimeRange): DataFrame[] { return cachedQueryInfos diff --git a/src/SiteWiseQueryPaginator.ts b/src/SiteWiseQueryPaginator.ts index 179dceed..6bb643bf 100644 --- a/src/SiteWiseQueryPaginator.ts +++ b/src/SiteWiseQueryPaginator.ts @@ -63,7 +63,7 @@ export class SitewiseQueryPaginator { try { let retrievedData = cachedResponse?.start?.data; let nextQueries: SitewiseNextQuery[] | undefined; - let errorEncountered = false; // whether there's a error response + const errorEncountered = false; // whether there's a error response let count = 1; do { diff --git a/src/components/browser/AssetBrowser.tsx b/src/components/browser/AssetBrowser.tsx index bb35d59e..b6b432b6 100644 --- a/src/components/browser/AssetBrowser.tsx +++ b/src/components/browser/AssetBrowser.tsx @@ -40,7 +40,7 @@ export class AssetBrowser extends Component { } async componentDidUpdate(oldProps: Props) { - let update: State = { ...this.state }; + const update: State = { ...this.state }; let shouldUpdate = false; if (this.props.region !== oldProps.region) { diff --git a/src/dataFrameUtils.ts b/src/dataFrameUtils.ts index 1790c479..8af8ce9b 100644 --- a/src/dataFrameUtils.ts +++ b/src/dataFrameUtils.ts @@ -8,10 +8,10 @@ interface TrimParams { /** * Trim the time series data frame to the specified time range. - * @param param0 - The parameters for trimming the data frame. - * @param param0.dataFrame - The data frame to trim. - * @param param0.timeRange - The time range to trim to. - * @param param0.lastObservation - Whether to include the last observation in the range. + * @param trimParams - The parameters for trimming the data frame. + * @param trimParams.dataFrame - The data frame to trim. + * @param trimParams.timeRange - The time range to trim to. + * @param trimParams.lastObservation - Whether to include the last observation in the range. * @returns The trimmed data frame. */ export function trimTimeSeriesDataFrame({ @@ -34,7 +34,7 @@ export function trimTimeSeriesDataFrame({ return dataFrame; } - let timeValues = timeField.values.toArray(); + const timeValues = timeField.values.toArray(); let fromIndex = timeValues.findIndex(time => time > from); // from is exclusive if (fromIndex === -1) { @@ -65,10 +65,10 @@ export function trimTimeSeriesDataFrame({ /** * Trim the time series data frame to the specified time range where the time field is in reversed order. - * @param param0 - The parameters for trimming the data frame. - * @param param0.dataFrame - The data frame to trim. - * @param param0.timeRange - The time range to trim to. - * @param param0.lastObservation - Whether to include the last observation in the range. + * @param trimParams - The parameters for trimming the data frame. + * @param trimParams.dataFrame - The data frame to trim. + * @param trimParams.timeRange - The time range to trim to. + * @param trimParams.lastObservation - Whether to include the last observation in the range. * @returns The trimmed data frame. */ export function trimTimeSeriesDataFrameReversedTime({ @@ -92,7 +92,7 @@ export function trimTimeSeriesDataFrameReversedTime({ } // Copy before reverse in place - let timeValues = [...timeField.values.toArray()].reverse(); + const timeValues = [...timeField.values.toArray()].reverse(); let fromIndex = timeValues.findIndex(time => time > from); // from is exclusive if (fromIndex === -1) { diff --git a/src/sitewiseCache.ts b/src/sitewiseCache.ts index b90fb1de..f4abefc9 100644 --- a/src/sitewiseCache.ts +++ b/src/sitewiseCache.ts @@ -261,7 +261,7 @@ export function frameToAssetInfo(res: DescribeAssetResult): AssetInfo { } export function assetSummaryToAssetInfo(res: DataFrameView): AssetInfo[] { - let results: AssetInfo[] = []; + const results: AssetInfo[] = []; for (const info of res.toArray()) { const hierarchy: AssetPropertyInfo[] = JSON.parse(info.hierarchies); // has Id, Name diff --git a/src/variables.ts b/src/variables.ts index 44afc94d..8400ad9e 100644 --- a/src/variables.ts +++ b/src/variables.ts @@ -18,7 +18,7 @@ export class SitewiseVariableSupport extends CustomVariableSupport): Observable { assign(request.targets, [{ ...request.targets[0], refId: 'A' }]); - let response = this.datasource.query(request); + const response = this.datasource.query(request); switch (request.targets[0].queryType) { case QueryType.ListAssetModels: case QueryType.ListAssets: @@ -39,7 +39,7 @@ export class SitewiseVariableSupport extends CustomVariableSupport(data)}; }), map((res) => { - let newData = res.data.map((m)=>{ + const newData = res.data.map((m)=>{ return { value: m.id, text: m.name,